diff --git a/lib/character/behaviors/effects.lua b/lib/character/behaviors/effects.lua index 75add33..6d4c5f1 100644 --- a/lib/character/behaviors/effects.lua +++ b/lib/character/behaviors/effects.lua @@ -1,4 +1,5 @@ local task = require "lib.utils.task" +local efb = require "lib.effectbook" --- ===========ЛОГИКА ЭФФЕКТОВ И ЧТО С ЭТИМ ЕДЯТ=========== --- читать здесь: https://docs.google.com/document/d/1Hxa5dOLaeRpLQOs5H-oIDDuLLhKbDw40lR9d62Zb4Tg/edit?usp=sharing @@ -15,7 +16,6 @@ behavior.id = "effects" --- @return EffectsBehavior function behavior.new() - local efb = require "lib.effectbook" return setmetatable({ effectbook = efb.of { efb.bleeding, efb.aversionToDeath }, effectsPriority = {}, @@ -45,10 +45,12 @@ function behavior:addEffect(effect, stacks, intensity) end return end - local effectSum = effect:sum(ef) - if effectSum then - -- применяем результат суммы и удаляем эффект - return + + if effect.tag == ef.tag then break end + for k, v in pairs(efb.sums) do + if k[effect.tag] and k[ef.tag] then + if not v(self.owner, effect, ef) then return end + end end end diff --git a/lib/effectbook.lua b/lib/effectbook.lua index 259df83..a860b5e 100644 --- a/lib/effectbook.lua +++ b/lib/effectbook.lua @@ -33,7 +33,7 @@ end function bleeding:afterTurn(owner, intensity) local behavior = owner:has(Tree.behaviors.effects) if not behavior then - print('[Effect]: yo man what the hell wheres your behavior how thats possible please stop thats not normal') + print('[EffectBook]: yo man what the hell wheres your behavior how thats possible please stop thats not normal') else behavior:deleteStacks(self, 1) end @@ -80,7 +80,26 @@ function aversionToDeath:beforeTurn(owner, intensity) }, false end +--- Принимает таблицу, в ключах которых тэги эффектов, которые мы хотим просуммировать, и в значениях которых функция, +--- возвращающая применять ли эффект после суммирования. +--- +--- В функции порядок эффектов, что передали в качестве аргумента, не определён. +--- @type table, fun(owner: Character, effect1: Effect, effect2: Effect): boolean> +local sums = {} +sums[{ [bleeding.tag] = true, [aversionToDeath.tag] = true }] = function(owner, effect1, effect2) + print("[EffectBook]: применяем сумму, удаляем оба эффекта") + local behaviorEffect = owner:has(Tree.behaviors.effects) + if not behaviorEffect then + print("[EffectBook]: yo man what the hell wheres your behavior how thats possible please stop thats not normal") + return true + end + behaviorEffect:deleteEffect(effect1) + behaviorEffect:deleteEffect(effect2) + return false +end + local effectbook = { + sums = sums, bleeding = bleeding, aversionToDeath = aversionToDeath } diff --git a/lib/spell/effect.lua b/lib/spell/effect.lua index 4aa9568..24fbf70 100644 --- a/lib/spell/effect.lua +++ b/lib/spell/effect.lua @@ -114,9 +114,9 @@ function effect:beforeRegeneration(owner, intensity, amountHp) return taskUtils. --- @return Task function effect:afterRegeneration(owner, intensity) return taskUtils.wait {} end ---- @param other Effect ---- @return Effect|nil -function effect:sum(other) end +-- --- @param other Effect +-- --- @return function +-- function effect:sum(other) return function() end end function effect:update(dt) end