feature/stats #39
@ -1,9 +1,13 @@
|
||||
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
|
||||
@ -19,24 +23,42 @@ function behavior:checkStats()
|
||||
end
|
||||
end
|
||||
|
||||
--- @param damage Impact
|
||||
function behavior:dealDamage(damage)
|
||||
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 damage = effects:beforeDamage(damage) end
|
||||
self.hp = self.hp - damage.intensity
|
||||
if effects then damageImpact = effects:beforeDamage(damageImpact) end
|
||||
self.hp = self.hp - damageImpact.intensity
|
||||
self:checkStats()
|
||||
end
|
||||
|
||||
--- @param hp? integer
|
||||
--- @param mana? integer
|
||||
--- @param initiative? integer
|
||||
--- @param class? Class
|
||||
--- @param chars? table<Chars, integer>
|
||||
--- @param isInTurnOrder? boolean
|
||||
function behavior.new(hp, mana, initiative, class, isInTurnOrder)
|
||||
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 = hp or 20,
|
||||
mana = mana or 10,
|
||||
initiative = initiative or 10,
|
||||
hp = _chars["stamina"] * 2,
|
||||
mana = 10, -- я полагаю, у всех будет одинаковое кол-во маны (оно же кол-во действий)
|
||||
initiative = _chars.agility,
|
||||
chars = _chars,
|
||||
class = class or "dev_warrior",
|
||||
isInTurnOrder = isInTurnOrder or true,
|
||||
amIAlive = true
|
||||
|
||||
@ -31,7 +31,7 @@ function bleeding:beforeTurn(owner, intensity)
|
||||
local stats = owner:has(Tree.behaviors.stats)
|
||||
local sprite = owner:has(Tree.behaviors.sprite)
|
||||
if not stats or not sprite then return task.fromValue(), true end
|
||||
stats:dealDamage(impact(intensity, "physic"))
|
||||
stats:dealDamage(intensity, "physic")
|
||||
return task.wait({ sprite:animate("hurt") }), true
|
||||
end
|
||||
|
||||
@ -42,18 +42,18 @@ function bleeding:afterTurn(owner, intensity)
|
||||
else
|
||||
behavior:deleteStacks("bleeding", 1)
|
||||
end
|
||||
return task.wait {}
|
||||
return task.fromValue()
|
||||
end
|
||||
|
||||
--- meow
|
||||
function bleeding:afterCast(owner, intensity)
|
||||
Tree.audio:play(Tree.assets.files.audio.sounds.meow)
|
||||
return task.wait {}
|
||||
return task.fromValue()
|
||||
end
|
||||
|
||||
function bleeding:beforeCast(owner, intensity)
|
||||
Tree.audio:play(Tree.assets.files.audio.sounds.meow)
|
||||
return task.wait {}, true
|
||||
return task.fromValue(), true
|
||||
end
|
||||
|
||||
--- Отвращение к смерти.
|
||||
@ -70,15 +70,15 @@ function aversionToDeath:beforeDamage(owner, intensity, damage)
|
||||
if stats.hp <= damage.intensity then
|
||||
effects:deleteStacks("aversionToDeath", 1)
|
||||
-- тут должен быть какой-нибудь классный спецэффект, но я не умею в шейдеры
|
||||
return task.wait({}), impact(stats.hp - 1, "magic")
|
||||
return task.fromValue(), impact(stats.hp - 1, "magic")
|
||||
end
|
||||
return task.wait {}, damage
|
||||
return task.fromValue(), damage
|
||||
end
|
||||
|
||||
function aversionToDeath:beforeTurn(owner, intensity)
|
||||
local sprite = owner:has(Tree.behaviors.sprite)
|
||||
if not sprite then
|
||||
return task.wait {}, false
|
||||
return task.fromValue(), false
|
||||
end
|
||||
return task.wait {
|
||||
sprite:animate("hurt")
|
||||
|
||||
@ -10,20 +10,22 @@ impact.__index = impact
|
||||
|
||||
--- @param other Impact
|
||||
function impact:__add(other)
|
||||
self.intensity = self.intensity + other.intensity
|
||||
return self
|
||||
assert(self.impactType == other.impactType, "Impact types not equals each other!")
|
||||
local newImpact = Impact(self.intensity + other.intensity, self.impactType)
|
||||
return newImpact
|
||||
end
|
||||
|
||||
--- @param other Impact
|
||||
function impact:__sub(other)
|
||||
self.intensity = self.intensity - other.intensity
|
||||
return self
|
||||
assert(self.impactType == other.impactType, "Impact types not equals each other!")
|
||||
local newImpact = Impact(self.intensity - other.intensity, self.impactType)
|
||||
return newImpact
|
||||
end
|
||||
|
||||
--- @param intensity integer
|
||||
--- @param impactType ImpactType
|
||||
local function new(intensity, impactType)
|
||||
function Impact(intensity, impactType)
|
||||
return setmetatable({ intensity = intensity, impactType = impactType }, impact)
|
||||
end
|
||||
|
||||
return new
|
||||
return Impact
|
||||
|
||||
4
main.lua
4
main.lua
@ -29,7 +29,7 @@ function love.load()
|
||||
character.spawn("Foodor")
|
||||
:addBehavior {
|
||||
Tree.behaviors.residentsleeper.new(),
|
||||
Tree.behaviors.stats.new(nil, nil, 1),
|
||||
Tree.behaviors.stats.new(nil, { agility = 1 }),
|
||||
Tree.behaviors.positioned.new(Vec3 { 3, 1 }),
|
||||
Tree.behaviors.tiled.new(),
|
||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||
@ -40,7 +40,7 @@ function love.load()
|
||||
character.spawn("Foodor")
|
||||
:addBehavior {
|
||||
Tree.behaviors.residentsleeper.new(),
|
||||
Tree.behaviors.stats.new(nil, nil, 3),
|
||||
Tree.behaviors.stats.new(nil, { agility = 3 }),
|
||||
Tree.behaviors.positioned.new(Vec3 { 7, 2 }),
|
||||
Tree.behaviors.tiled.new(),
|
||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user