69 lines
2.2 KiB
Lua
69 lines
2.2 KiB
Lua
local impact = require "lib.utils.impact"
|
||
|
||
--- @alias Class "dev_warrior"|"dev_mage"
|
||
--- @alias Chars "strength"|"intelligence"|"agility"|"stamina"|"lunacy"
|
||
|
||
--- @class StatsBehavior : Behavior
|
||
--- @field hp integer
|
||
--- @field mana integer
|
||
--- @field initiative integer
|
||
--- @field chars table<Chars, integer>
|
||
--- @field class Class
|
||
--- @field isInTurnOrder boolean
|
||
--- @field amIAlive boolean
|
||
local behavior = {}
|
||
behavior.__index = behavior
|
||
behavior.id = "stats"
|
||
|
||
--- план прост, если что-то не так, то мы просто убиваем бехавиор (по крайней мере так должно было быть, но пиаш мне запретил :sob:)
|
||
function behavior:checkStats()
|
||
-- if self.hp <= 0 then behavior:die() end
|
||
if self.hp <= 0 then
|
||
self.amIAlive = false
|
||
end
|
||
end
|
||
|
||
function behavior:maxHealth()
|
||
return self.chars["stamina"] * 2
|
||
end
|
||
|
||
--- @param damage integer
|
||
--- @param impactType ImpactType
|
||
function behavior:dealDamage(damage, impactType)
|
||
local damageImpact = impact(damage, impactType)
|
||
local effects = self.owner:has(Tree.behaviors.effects)
|
||
if effects then damageImpact = effects:beforeDamage(damageImpact) end
|
||
self.hp = self.hp - damageImpact.intensity
|
||
self:checkStats()
|
||
end
|
||
|
||
--- @param class? Class
|
||
--- @param chars? table<Chars, integer>
|
||
--- @param isInTurnOrder? boolean
|
||
function behavior.new(class, chars, isInTurnOrder)
|
||
--- @type Chars
|
||
local _chars = {}
|
||
if not chars then
|
||
_chars = { 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,
|
||
}
|
||
end
|
||
return setmetatable({
|
||
hp = _chars["stamina"] * 2,
|
||
mana = 10, -- я полагаю, у всех будет одинаковое кол-во маны (оно же кол-во действий)
|
||
initiative = _chars.agility,
|
||
chars = _chars,
|
||
class = class or "dev_warrior",
|
||
isInTurnOrder = isInTurnOrder or true,
|
||
amIAlive = true
|
||
}, behavior)
|
||
end
|
||
|
||
return behavior
|