1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/scripts/lib/erm/TM_T.lua
AlexVinS ecaa9f5d0b Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2021-02-14 19:05:43 +03:00

52 lines
1.1 KiB
Lua

local TriggerBase = require("core:erm.TriggerBase")
local PlayerGotTurn = require("events.PlayerGotTurn")
local bit = bit
local band, bor = bit.band, bit.bor
local lshift, rshift = bit.lshift, bit.rshift
local TM_T = TriggerBase:new()
function TM_T:new(o)
o = TriggerBase.new(self, o)
o.sub = PlayerGotTurn.subscribeAfter(EVENT_BUS, function(event)
o:update(event)
end)
o.timerId = tostring(o.id[1])
return o
end
function TM_T:update(event)
local timerData = DATA.ERM.timers[self.timerId]
if not timerData then
error("Timer" ..self.timerId .." is not set")
end
local today = self.ERM.Q.c -- this assumes that ERM updates before this
local activePlayer = event:getPlayer()
assert(type(activePlayer) == "number")
--TODO: special player constants
if activePlayer < 0 or activePlayer > 8 then
return
end
if band(timerData.players, lshift(1, activePlayer)) == 0 then
return
end
if (today < timerData.dayFirst) or ((today > timerData.dayLast) and (timerData.dayLast ~= 0)) then
return
end
--
local d = today - timerData.dayFirst
--
if d % timerData.interval == 0 then
self:call(event)
end
end
return TM_T