2026-04-24 11:13:47 +03:00

96 lines
3.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local task = require "lib.utils.task"
--- ===========ЛОГИКА ЭФФЕКТОВ И ЧТО С ЭТИМ ЕДЯТ===========
--- читать здесь: https://docs.google.com/document/d/1Hxa5dOLaeRpLQOs5H-oIDDuLLhKbDw40lR9d62Zb4Tg/edit?usp=sharing
--- behavior thats holds all effects that we applied
--- @class EffectsBehavior : Behavior
--- @field effectsPriority Effect[] хранит эффекты в порядке их применения
--- @field effectsProperties table<Effect, { stacks: integer, intensity: integer }> хранит характеристики эффектов
--- @field effectbook Effect[] все возможные эффекты (хз надо ли так вообще)
local behavior = {}
behavior.__index = behavior
behavior.id = "effects"
--- @return EffectsBehavior
function behavior.new()
local efb = require "lib.effectbook"
return setmetatable({
effectbook = efb.of { efb.bleeding },
effectsPriority = {},
effectsProperties = {},
}, behavior)
end
--- проверяет, можно ли наложить эффект и при наложении его применяет
--- @param effect Effect
--- @param stacks integer
function behavior:addEffect(effect, stacks, intensity)
-- if not effect:beforeBirth() then return end
-- проверяем эффект на возможности суммирования (aka противоречия)
for i, ef in ipairs(self.effectsPriority) do
if ef == effect then
self.effectsProperties[ef] = { stacks = stacks, intensity = intensity }
local task1 = effect:afterBirth(self.owner, intensity)
if task1 then
task1(function() end)
end
return
end
local effectSum = effect:sum(ef)
if effectSum then
-- применяем результат суммы и удаляем эффект
return
end
end
self.effectsPriority[#self.effectsPriority + 1] = effect
self.effectsProperties[effect] = { stacks = stacks, intensity = intensity }
print("[Effects]: мы применили эффект!!")
local task1 = effect:afterBirth(self.owner, intensity)
if task1 then
task1(function() end)
end
end
--- должен вызываться в начале хода
function behavior:beforeTurn()
for i, ef in ipairs(self.effectsPriority) do
local task1 = ef:beforeTurn(self.owner, self.effectsProperties[ef].intensity)
if task1 then
task1(function() end)
end
end
end
--- О ДААА ЭТА ФУНКЦИЯ МЕНЯЕТ СОСТОЯНИЕ О ДАААААА О ДАААААААААА
--- @param effect Effect
--- @param amount integer
function behavior:deleteStacks(effect, amount)
print("[Effects]: удаляем стаки!!")
self.effectsProperties[effect].stacks = self.effectsProperties[effect].stacks -
amount -- !!!!!!!!!!!!!!!! <<<<< 21+ only
if self.effectsProperties[effect].stacks <= 0 then
print("[Effects]:", effect.tag, "ДОЛЖЕН БЫТЬ СТЁРТ")
self.effectsProperties[effect] = nil
for i, ef in ipairs(self.effectsPriority) do
if ef == effect then
table.remove(self.effectsPriority, i)
print("[Effects]:", effect.tag, "СТЁРТ")
end
end
end
end
--- должен вызываться в конце хода
function behavior:afterTurn()
for i, ef in pairs(self.effectsPriority) do
local task1 = ef:afterTurn(self.owner, self.effectsProperties[ef].intensity)
if task1 then
task1(function() end)
end
end
end
return behavior