add final and raw chars 🤪 🍪
& new effect rule before/afterDelete 🤪 🍪 & intensity replaced by chars.agility 🤪 🍪 & rewrite some regenerateMana spell logic for development purposes 🤪 🍪
This commit is contained in:
parent
138502ce3f
commit
5112a42672
@ -59,6 +59,10 @@ end
|
||||
--- Удаляет один эффект по порядку
|
||||
--- @param effect EffectTag
|
||||
function behavior:deleteEffect(effect)
|
||||
if not self.effectsProperties[effect] then return end
|
||||
local task1, deleteStatement = book[effect]:beforeDelete(self.owner, self.effectsProperties[effect].intensity)
|
||||
task1(function() end)
|
||||
if not deleteStatement then return end
|
||||
self.effectsProperties[effect] = nil
|
||||
for i, ef in ipairs(self.effectsPriority) do
|
||||
if ef == effect then
|
||||
@ -66,19 +70,21 @@ function behavior:deleteEffect(effect)
|
||||
return
|
||||
end
|
||||
end
|
||||
local task2 = book[effect]:afterDelete(self.owner, self.effectsProperties[effect].intensity)
|
||||
task2(function() end)
|
||||
end
|
||||
|
||||
--- О ДААА ЭТА ФУНКЦИЯ МЕНЯЕТ СОСТОЯНИЕ О ДАААААА О ДАААААААААА
|
||||
--- @param effect EffectTag
|
||||
--- @param amount integer
|
||||
function behavior:deleteStacks(effect, amount)
|
||||
print("[Effects]: удаляем стаки!!")
|
||||
-- print("[Effects]: удаляем стаки!!")
|
||||
self.effectsProperties[effect].stacks = self.effectsProperties[effect].stacks -
|
||||
amount -- !!!!!!!!!!!!!!!! <<<<< 21+ only
|
||||
if self.effectsProperties[effect].stacks <= 0 then
|
||||
print("[Effects]:", effect, "ДОЛЖЕН БЫТЬ СТЁРТ")
|
||||
-- print("[Effects]:", effect, "ДОЛЖЕН БЫТЬ СТЁРТ")
|
||||
self:deleteEffect(effect)
|
||||
print("[Effects]:", effect, "СТЁРТ")
|
||||
-- print("[Effects]:", effect, "СТЁРТ")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,12 +2,12 @@ local impact = require "lib.utils.impact"
|
||||
|
||||
--- @alias Class "dev_warrior"|"dev_mage"
|
||||
--- @alias Chars "strength"|"intelligence"|"agility"|"stamina"|"lunacy"
|
||||
--- @alias CharsTable table<Chars, integer>
|
||||
|
||||
--- @class StatsBehavior : Behavior
|
||||
--- @field hp integer
|
||||
--- @field mana integer
|
||||
--- @field initiative integer
|
||||
--- @field chars table<Chars, integer>
|
||||
--- @field chars { raw: CharsTable, final: CharsTable } по хорошему, мы не должны менять эту таблицу руками, а делать это только через метод `changeChar`
|
||||
--- @field class Class
|
||||
--- @field isInTurnOrder boolean
|
||||
--- @field amIAlive boolean
|
||||
@ -24,7 +24,7 @@ function behavior:checkStats()
|
||||
end
|
||||
|
||||
function behavior:maxHealth()
|
||||
return self.chars["stamina"] * 2
|
||||
return self.chars.final["stamina"] * 2
|
||||
end
|
||||
|
||||
--- @param damage integer
|
||||
@ -37,28 +37,59 @@ function behavior:dealDamage(damage, impactType)
|
||||
self:checkStats()
|
||||
end
|
||||
|
||||
--- позволяет изменять значение характеристики персонажа
|
||||
---
|
||||
--- менять характеристики мы должны с помощью функции, которая возвращает значение на сколько мы должны изменить характеристику
|
||||
--- относительно сырой характеристики, и это значение мы прибавляем к финальным характеристикам
|
||||
---
|
||||
--- такой системой (вроде как) мы гарантируем, что все операции над статами будут обратимыми
|
||||
---
|
||||
--- @TODO: возможно в будущем при появлении эвентов в игре, мы должны регать эвент изменения стата
|
||||
---
|
||||
--- пара примеров:
|
||||
---
|
||||
--- прибавляем 1 к стату: `behavior:changeChar("strength", function (charAmount) return 1 end)`
|
||||
---
|
||||
--- отнимаем от стата 50%: `behavior:changeChar("strength", function (charAmount) return -charAmount / 2 end)`
|
||||
--- @param char Chars
|
||||
--- @param func fun(charAmount: integer): integer charAmount здесь это сырое значение характеристики
|
||||
function behavior:changeChar(char, func)
|
||||
self.chars.final[char] = func(self.chars.raw[char])
|
||||
end
|
||||
|
||||
--- @param class? Class
|
||||
--- @param chars? table<Chars, integer>
|
||||
--- @param rawChars? table<Chars, integer>
|
||||
--- @param isInTurnOrder? boolean
|
||||
function behavior.new(class, chars, isInTurnOrder)
|
||||
function behavior.new(class, rawChars, isInTurnOrder)
|
||||
--- @type Chars
|
||||
local _chars = {}
|
||||
if not chars then
|
||||
_chars = { strength = 10, stamina = 10, intelligence = 10, agility = 10, lunacy = 0 }
|
||||
local chars = { raw = {}, final = {} }
|
||||
if not rawChars then
|
||||
chars = {
|
||||
raw = { strength = 10, stamina = 10, intelligence = 10, agility = 10, lunacy = 0 },
|
||||
final = { strength = 10, stamina = 10, intelligence = 10, agility = 10, lunacy = 0 }
|
||||
}
|
||||
else
|
||||
_chars = {
|
||||
strength = chars.strength or 10,
|
||||
stamina = chars.stamina or 10,
|
||||
intelligence = chars.intelligence or 10,
|
||||
agility = chars.agility or 10,
|
||||
lunacy = chars.lunacy or 0,
|
||||
chars = {
|
||||
raw = {
|
||||
strength = rawChars.strength or 10,
|
||||
stamina = rawChars.stamina or 10,
|
||||
intelligence = rawChars.intelligence or 10,
|
||||
agility = rawChars.agility or 10,
|
||||
lunacy = rawChars.lunacy or 0,
|
||||
},
|
||||
final = {
|
||||
strength = rawChars.strength or 10,
|
||||
stamina = rawChars.stamina or 10,
|
||||
intelligence = rawChars.intelligence or 10,
|
||||
agility = rawChars.agility or 10,
|
||||
lunacy = rawChars.lunacy or 0,
|
||||
},
|
||||
}
|
||||
end
|
||||
return setmetatable({
|
||||
hp = _chars["stamina"] * 2,
|
||||
hp = chars.final["stamina"] * 2,
|
||||
mana = 10, -- я полагаю, у всех будет одинаковое кол-во маны (оно же кол-во действий)
|
||||
initiative = _chars.agility,
|
||||
chars = _chars,
|
||||
chars = chars,
|
||||
class = class or "dev_warrior",
|
||||
isInTurnOrder = isInTurnOrder or true,
|
||||
amIAlive = true
|
||||
|
||||
@ -63,6 +63,15 @@ local aversionToDeath = effect.new {
|
||||
tag = "aversionToDeath"
|
||||
}
|
||||
|
||||
function aversionToDeath:afterCast(owner, intensity)
|
||||
local stats = owner:has(Tree.behaviors.stats)
|
||||
if not stats then return task.fromValue() end
|
||||
stats:changeChar("agility", function(charAmount)
|
||||
return 10
|
||||
end)
|
||||
return task.fromValue()
|
||||
end
|
||||
|
||||
function aversionToDeath:beforeDamage(owner, intensity, damage)
|
||||
local stats = owner:has(Tree.behaviors.stats)
|
||||
local effects = owner:has(Tree.behaviors.effects)
|
||||
@ -85,6 +94,15 @@ function aversionToDeath:beforeTurn(owner, intensity)
|
||||
}, false
|
||||
end
|
||||
|
||||
function aversionToDeath:afterDelete(owner, intensity)
|
||||
local stats = owner:has(Tree.behaviors.stats)
|
||||
if not stats then return task.fromValue() end
|
||||
stats:changeChar("agility", function(charAmount)
|
||||
return -10
|
||||
end)
|
||||
return task.fromValue()
|
||||
end
|
||||
|
||||
----------------- Effectbook & Sum -----------------
|
||||
|
||||
--- @alias EffectSumFunc fun(owner: Character, effect1: EffectTag, effect2: EffectTag): boolean
|
||||
|
||||
@ -4,7 +4,7 @@ local easing = require "lib.utils.easing"
|
||||
local initiativeComparator = function(id_a, id_b)
|
||||
local res = Tree.level.characters[id_a]:try(Tree.behaviors.stats, function(astats)
|
||||
local res = Tree.level.characters[id_b]:try(Tree.behaviors.stats, function(bstats)
|
||||
return astats.initiative > bstats.initiative
|
||||
return astats.chars.final["agility"] > bstats.chars.final["agility"]
|
||||
end)
|
||||
return res
|
||||
end)
|
||||
|
||||
@ -29,6 +29,16 @@ function effect:beforeBirth(owner, intensity) return taskUtils.fromValue(), true
|
||||
--- @type EffectFunc
|
||||
function effect:afterBirth(owner, intensity) return taskUtils.fromValue() end
|
||||
|
||||
--- Срабатывает перед удалением эффекта
|
||||
---
|
||||
--- Возвращает, а можно ли удалить эффект?
|
||||
--- @type EffectStatementFunc
|
||||
function effect:beforeDelete(owner, intensity) return taskUtils.fromValue(), true end
|
||||
|
||||
--- Срабатывает после удаления эффекта
|
||||
--- @type EffectFunc
|
||||
function effect:afterDelete(owner, intensity) return taskUtils.fromValue() end
|
||||
|
||||
--- Срабатывает перед смертью владельца эффекта
|
||||
---
|
||||
--- Возвращает, умирает ли персонаж?
|
||||
|
||||
@ -48,7 +48,6 @@ local regenerateMana = spell.new {
|
||||
onCast = function(caster, target)
|
||||
caster:try(Tree.behaviors.stats, function(stats)
|
||||
stats.mana = 10
|
||||
stats.initiative = stats.initiative + 10
|
||||
end)
|
||||
|
||||
local sprite = caster:has(Tree.behaviors.sprite)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user