TM_T.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local TriggerBase = require("core:erm.TriggerBase")
  2. local PlayerGotTurn = require("events.PlayerGotTurn")
  3. local bit = bit
  4. local band, bor = bit.band, bit.bor
  5. local lshift, rshift = bit.lshift, bit.rshift
  6. local TM_T = TriggerBase:new()
  7. function TM_T:new(o)
  8. o = TriggerBase.new(self, o)
  9. o.sub = PlayerGotTurn.subscribeAfter(EVENT_BUS, function(event)
  10. o:update(event)
  11. end)
  12. o.timerId = tostring(o.id[1])
  13. return o
  14. end
  15. function TM_T:update(event)
  16. local timerData = DATA.ERM.timers[self.timerId]
  17. if not timerData then
  18. error("Timer" ..self.timerId .." is not set")
  19. end
  20. local today = self.ERM.Q.c -- this assumes that ERM updates before this
  21. local activePlayer = event:getPlayer()
  22. assert(type(activePlayer) == "number")
  23. --TODO: special player constants
  24. if activePlayer < 0 or activePlayer > 8 then
  25. return
  26. end
  27. if band(timerData.players, lshift(1, activePlayer)) == 0 then
  28. return
  29. end
  30. if (today < timerData.dayFirst) or ((today > timerData.dayLast) and (timerData.dayLast ~= 0)) then
  31. return
  32. end
  33. --
  34. local d = today - timerData.dayFirst
  35. --
  36. if d % timerData.interval == 0 then
  37. self:call(event)
  38. end
  39. end
  40. return TM_T