add healHealth 🤪 🍪 & add before/afterRegeneration
This commit is contained in:
parent
5112a42672
commit
3a566f447f
@ -190,4 +190,31 @@ function behavior:afterDamage()
|
||||
end
|
||||
end
|
||||
|
||||
--- должен вызываться перед регенерацией
|
||||
---
|
||||
--- возвращает кол-во здоровья
|
||||
--- @return Impact
|
||||
function behavior:beforeRegeneration(amount)
|
||||
local totalAmount = amount
|
||||
for i, ef in ipairs(self.effectsPriority) do
|
||||
local task1
|
||||
task1, totalAmount = book[ef]:beforeRegeneration(self.owner, self.effectsProperties[ef].intensity,
|
||||
totalAmount or amount)
|
||||
if task1 then
|
||||
task1(function() end)
|
||||
end
|
||||
end
|
||||
return totalAmount or amount
|
||||
end
|
||||
|
||||
--- должен вызываться после регенерации
|
||||
function behavior:afterRegeneration()
|
||||
for i, ef in ipairs(self.effectsPriority) do
|
||||
local task1 = book[ef]:afterRegeneration(self.owner, self.effectsProperties[ef].intensity)
|
||||
if task1 then
|
||||
task1(function() end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return behavior
|
||||
|
||||
@ -34,9 +34,20 @@ function behavior:dealDamage(damage, impactType)
|
||||
local effects = self.owner:has(Tree.behaviors.effects)
|
||||
if effects then damageImpact = effects:beforeDamage(damageImpact) end
|
||||
self.hp = self.hp - damageImpact.intensity
|
||||
if effects then effects:afterDamage() end
|
||||
self:checkStats()
|
||||
end
|
||||
|
||||
--- @param amount integer
|
||||
--- @param impactType ImpactType
|
||||
function behavior:healHealth(amount, impactType)
|
||||
local healthImpact = impact(amount, impactType)
|
||||
local effects = self.owner:has(Tree.behaviors.effects)
|
||||
if effects then healthImpact = effects:beforeRegeneration(healthImpact) end
|
||||
self.hp = self.hp + healthImpact.intensity
|
||||
if effects then effects:afterRegeneration() end
|
||||
end
|
||||
|
||||
--- позволяет изменять значение характеристики персонажа
|
||||
---
|
||||
--- менять характеристики мы должны с помощью функции, которая возвращает значение на сколько мы должны изменить характеристику
|
||||
@ -52,9 +63,9 @@ 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])
|
||||
--- @param fn fun(charAmount: integer): integer charAmount здесь это сырое значение характеристики
|
||||
function behavior:changeChar(char, fn)
|
||||
self.chars.final[char] = fn(self.chars.raw[char])
|
||||
end
|
||||
|
||||
--- @param class? Class
|
||||
|
||||
@ -48,6 +48,7 @@ local regenerateMana = spell.new {
|
||||
onCast = function(caster, target)
|
||||
caster:try(Tree.behaviors.stats, function(stats)
|
||||
stats.mana = 10
|
||||
stats:healHealth(10, "magic")
|
||||
end)
|
||||
|
||||
local sprite = caster:has(Tree.behaviors.sprite)
|
||||
@ -84,7 +85,7 @@ local attack = spell.new {
|
||||
local targetCharacterId = Tree.level.characterGrid:get(target)
|
||||
local targetCharacter = Tree.level.characters[targetCharacterId]
|
||||
targetCharacter:try(Tree.behaviors.stats, function(stats)
|
||||
stats.hp = stats.hp - 4
|
||||
stats:dealDamage(4, "physic")
|
||||
end)
|
||||
|
||||
local targetEffects = targetCharacter:has(Tree.behaviors.effects)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user