added effect sum functional (its tough (in bad way))

This commit is contained in:
neckrat 2026-04-28 21:32:33 +03:00
parent d8a89ec24b
commit 53c83bf1a1
3 changed files with 30 additions and 9 deletions

View File

@ -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

View File

@ -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<table<string, boolean>, 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
}

View File

@ -114,9 +114,9 @@ function effect:beforeRegeneration(owner, intensity, amountHp) return taskUtils.
--- @return Task<nil>
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