1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/scripts/lib/erm/TM.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

58 lines
1.1 KiB
Lua

local ReceiverBase = require("core:erm.ReceiverBase")
local TM = ReceiverBase:new()
local bit = bit
local band, bor, bxor = bit.band, bit.bor, bit.bxor
local ALL_PLAYERS = 0xFF
local DATA = DATA
DATA.ERM.timers = DATA.ERM.timers or {}
local timers = DATA.ERM.timers
local function newTimer(timerId)
return
{
id = timerId,
dayFirst = 1,
dayLast = 1,
interval = 0,
players = 0
}
end
local function getTimer(timerId)
timerId = tostring(timerId)
timers[timerId] = timers[timerId] or newTimer(timerId)
return timers[timerId]
end
function TM:new(ERM, timerId)
assert(timerId ~= nil, "!!TM requires timer identifier")
return ReceiverBase.new(self,
{
timerId = timerId,
timer = getTimer(timerId),
ERM = ERM
})
end
function TM:D(x, playerMask)
--disable by mask
self.timer.players = band(self.timer.players, bnot(playerMask), ALL_PLAYERS)
end
function TM:E(x, playerMask)
--enable by mask
self.timer.players = bor(self.timer.players, playerMask)
end
function TM:S(x, dayFirst, dayLast, interval, playerMask)
local t = self.timer
t.dayFirst = dayFirst
t.dayLast = dayLast
t.interval = interval
t.players = playerMask
end
return TM