some silly additions to silly functions
This commit is contained in:
parent
9b10557435
commit
f3d74440ce
@ -15,10 +15,10 @@ end
|
|||||||
|
|
||||||
--- проверяет, можно ли наложить эффект и при наложении его применяет
|
--- проверяет, можно ли наложить эффект и при наложении его применяет
|
||||||
--- @param effect Effect
|
--- @param effect Effect
|
||||||
--- @param cooldown integer
|
--- @param stacks integer
|
||||||
function behavior:addEffect(effect, cooldown)
|
function behavior:addEffect(effect, stacks)
|
||||||
-- проверяем эффект на возможности суммирования (aka противоречия)
|
-- проверяем эффект на возможности суммирования (aka противоречия)
|
||||||
for ef, t in pairs(self.effects) do
|
for ef, st in pairs(self.effects) do
|
||||||
local effectSum = effect:sum(ef)
|
local effectSum = effect:sum(ef)
|
||||||
if effectSum then
|
if effectSum then
|
||||||
-- применяем результат суммы и удаляем эффект
|
-- применяем результат суммы и удаляем эффект
|
||||||
@ -26,25 +26,23 @@ function behavior:addEffect(effect, cooldown)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.effects[effect] = cooldown
|
self.effects[effect] = stacks
|
||||||
effect:onBirth()
|
effect:onBirth(self.owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- должен вызываться в начале хода
|
--- должен вызываться в начале хода
|
||||||
|
---
|
||||||
|
--- @todo надо написать применение всех эффектов так, чтобы они применялись одновременно
|
||||||
function behavior:onStartTurn()
|
function behavior:onStartTurn()
|
||||||
for ef, t in pairs(self.effects) do
|
for ef, st in pairs(self.effects) do
|
||||||
if t == 0 then
|
ef:onStartTurn(self.owner)
|
||||||
ef:onDeath()
|
|
||||||
self.effects[ef] = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- должен вызываться в конце хода
|
--- должен вызываться в конце хода
|
||||||
function behavior:onEndTurn()
|
function behavior:onEndTurn()
|
||||||
for ef, t in pairs(self.effects) do
|
for ef, st in pairs(self.effects) do
|
||||||
self.effects[ef] = t - 1
|
ef:onEndTurn(self.owner)
|
||||||
ef:onEndTurn()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
23
lib/effectbook.lua
Normal file
23
lib/effectbook.lua
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
local effect = require "lib.spell.effect"
|
||||||
|
|
||||||
|
local bleeding = effect.new({
|
||||||
|
tag = "bleeding",
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
local effectbook = {
|
||||||
|
bleeding = bleeding
|
||||||
|
}
|
||||||
|
|
||||||
|
--- не уверен зачем нам это, но вай нот ай саппоуз
|
||||||
|
--- @param list Effect[]
|
||||||
|
function effectbook.of(list)
|
||||||
|
local efb = {}
|
||||||
|
for i, ef in ipairs(list) do
|
||||||
|
print(i)
|
||||||
|
efb[i] = setmetatable({}, { __index = ef })
|
||||||
|
end
|
||||||
|
return efb
|
||||||
|
end
|
||||||
|
|
||||||
|
return effectbook
|
||||||
@ -1,40 +1,40 @@
|
|||||||
--- @class Effect
|
--- @class Effect
|
||||||
|
--- @field tag string
|
||||||
local effect = {}
|
local effect = {}
|
||||||
effect.__index = effect
|
effect.__index = effect
|
||||||
|
|
||||||
function effect:onBirth()
|
--- @param owner Character
|
||||||
|
function effect:onBirth(owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
function effect:onDeath()
|
--- @param owner Character
|
||||||
|
function effect:onDeath(owner) end
|
||||||
|
|
||||||
end
|
--- @param owner Character
|
||||||
|
function effect:onStartTurn(owner) end
|
||||||
|
|
||||||
function effect:onStartTurn()
|
--- @param owner Character
|
||||||
|
function effect:onEndTurn(owner) end
|
||||||
end
|
|
||||||
|
|
||||||
function effect:onEndTurn()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param other Effect
|
--- @param other Effect
|
||||||
--- @return Effect|nil
|
--- @return Effect|nil
|
||||||
function effect:sum(other)
|
function effect:sum(other) end
|
||||||
|
|
||||||
end
|
function effect:update(dt) end
|
||||||
|
|
||||||
function effect:update(dt)
|
function effect:draw() end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function effect:draw()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
--- @param data {tag: string, onBirth: fun(owner: Character)?, onDeath: fun(owner: Character)?, onStartTurn: fun(owner: Character)?, onEndTurn: fun(owner: Character)?, sum: fun(owner: Character)?}
|
||||||
--- @return Effect
|
--- @return Effect
|
||||||
local function new()
|
local function new(data)
|
||||||
return setmetatable({}, effect)
|
return setmetatable({
|
||||||
|
tag = data.tag,
|
||||||
|
onBirth = data.onBirth,
|
||||||
|
onDeath = data.onDeath,
|
||||||
|
onStartTurn = data.onStartTurn,
|
||||||
|
onEndTurn = data.onEndTurn,
|
||||||
|
sum = data.sum
|
||||||
|
}, effect)
|
||||||
end
|
end
|
||||||
|
|
||||||
return { new = new }
|
return { new = new }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user