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