fix manapool and refactor stats
This commit is contained in:
parent
d2caa40a0a
commit
4b3df0ae24
17
lib/character/behaviors/stats.lua
Normal file
17
lib/character/behaviors/stats.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
--- @class StatsBehavior : Behavior
|
||||||
|
--- @field hp integer
|
||||||
|
--- @field mana integer
|
||||||
|
local behavior = {}
|
||||||
|
behavior.__index = behavior
|
||||||
|
behavior.id = "stats"
|
||||||
|
|
||||||
|
--- @param hp? integer
|
||||||
|
--- @param mana? integer
|
||||||
|
function behavior.new(hp, mana)
|
||||||
|
return setmetatable({
|
||||||
|
hp = hp or 20,
|
||||||
|
mana = mana or 10
|
||||||
|
}, behavior)
|
||||||
|
end
|
||||||
|
|
||||||
|
return behavior
|
||||||
@ -6,7 +6,6 @@ local characterId = 1
|
|||||||
|
|
||||||
--- @class Character
|
--- @class Character
|
||||||
--- @field id Id
|
--- @field id Id
|
||||||
--- @field stats Stats
|
|
||||||
--- @field behaviors Behavior[]
|
--- @field behaviors Behavior[]
|
||||||
--- @field _behaviorsIdx {string: integer}
|
--- @field _behaviorsIdx {string: integer}
|
||||||
local character = {}
|
local character = {}
|
||||||
@ -25,11 +24,11 @@ local function spawn(name, template, spriteDir, position, size, level)
|
|||||||
char = setmetatable(char, character)
|
char = setmetatable(char, character)
|
||||||
char.id = characterId
|
char.id = characterId
|
||||||
characterId = characterId + 1
|
characterId = characterId + 1
|
||||||
char.stats = require('lib.character.stats').new()
|
|
||||||
char.behaviors = {}
|
char.behaviors = {}
|
||||||
char._behaviorsIdx = {}
|
char._behaviorsIdx = {}
|
||||||
|
|
||||||
char:addBehavior {
|
char:addBehavior {
|
||||||
|
Tree.behaviors.stats.new(),
|
||||||
Tree.behaviors.map.new(position, size),
|
Tree.behaviors.map.new(position, size),
|
||||||
Tree.behaviors.sprite.new(spriteDir),
|
Tree.behaviors.sprite.new(spriteDir),
|
||||||
Tree.behaviors.spellcaster.new()
|
Tree.behaviors.spellcaster.new()
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
--- @alias ClassTemplate "warrior"|"mage"|"archer"
|
|
||||||
|
|
||||||
--- @class Class
|
|
||||||
--- @field skills table
|
|
||||||
--- @field stats Stats
|
|
||||||
local class = {}
|
|
||||||
|
|
||||||
--- @param template ClassTemplate
|
|
||||||
--- @param level? integer
|
|
||||||
local function new(template, level)
|
|
||||||
return setmetatable({
|
|
||||||
stats = (require "lib/character/stats").fromTemplate(template),
|
|
||||||
skills = {}
|
|
||||||
}, class)
|
|
||||||
end
|
|
||||||
|
|
||||||
return { new = new }
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
--- @class Info
|
|
||||||
--- @field name string
|
|
||||||
--- @field class Class
|
|
||||||
local info = {}
|
|
||||||
|
|
||||||
--- @param name string
|
|
||||||
--- @param classTemplate ClassTemplate
|
|
||||||
--- @param level? integer
|
|
||||||
local function new(name, classTemplate, level)
|
|
||||||
return setmetatable({
|
|
||||||
name = name,
|
|
||||||
class = (require 'lib/character/class').new(classTemplate, level)
|
|
||||||
}, info)
|
|
||||||
end
|
|
||||||
|
|
||||||
return { new = new }
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
--- @class Stats
|
|
||||||
--- @field hp integer
|
|
||||||
--- @field mana integer
|
|
||||||
local stats = {}
|
|
||||||
stats.__index = stats
|
|
||||||
|
|
||||||
--- @param level? integer
|
|
||||||
local function new(level)
|
|
||||||
return {
|
|
||||||
hp = 20,
|
|
||||||
mana = 10
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
--- creates stats from character template (like warrior etc etc)
|
|
||||||
---
|
|
||||||
--- TODO: написать скалирование по уровню
|
|
||||||
--- @param template ClassTemplate
|
|
||||||
--- @param level? integer
|
|
||||||
local function fromTemplate(template, level)
|
|
||||||
local tempStats = {}
|
|
||||||
if template == "warrior" then
|
|
||||||
tempStats = {
|
|
||||||
hp = 30,
|
|
||||||
initiative = 10,
|
|
||||||
damage = 5,
|
|
||||||
defence = 10,
|
|
||||||
}
|
|
||||||
elseif template == "mage" then
|
|
||||||
tempStats = {
|
|
||||||
hp = 15,
|
|
||||||
initiative = 8,
|
|
||||||
damage = 8,
|
|
||||||
defence = 0,
|
|
||||||
}
|
|
||||||
elseif template == "archer" then
|
|
||||||
tempStats = {
|
|
||||||
hp = 20,
|
|
||||||
initiative = 12,
|
|
||||||
damage = 5,
|
|
||||||
defence = 5,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return { new = new, fromTemplate = fromTemplate }
|
|
||||||
@ -26,11 +26,10 @@ local walk = setmetatable({
|
|||||||
}, spell)
|
}, spell)
|
||||||
|
|
||||||
function walk:cast(caster, target)
|
function walk:cast(caster, target)
|
||||||
if caster.stats.mana < 2 then
|
if not caster:try(Tree.behaviors.stats, function (stats)
|
||||||
print("not enough mana!")
|
return stats.mana >= 2
|
||||||
return false
|
end) then return false end
|
||||||
end
|
|
||||||
|
|
||||||
local path = self.path
|
local path = self.path
|
||||||
if path:is_empty() then return false end
|
if path:is_empty() then return false end
|
||||||
path:pop_front()
|
path:pop_front()
|
||||||
@ -40,8 +39,10 @@ function walk:cast(caster, target)
|
|||||||
end)
|
end)
|
||||||
-- TODO: списать деньги за каст (антиутопия какая-то)
|
-- TODO: списать деньги за каст (антиутопия какая-то)
|
||||||
-- TODO: привязка тинькоффа
|
-- TODO: привязка тинькоффа
|
||||||
caster.stats.mana = caster.stats.mana - 2
|
caster:try(Tree.behaviors.stats, function (stats)
|
||||||
print(caster.stats.mana)
|
stats.mana = stats.mana - 2
|
||||||
|
print(stats.mana)
|
||||||
|
end)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,7 +66,9 @@ end
|
|||||||
local regenerateMana = setmetatable({}, spell)
|
local regenerateMana = setmetatable({}, spell)
|
||||||
|
|
||||||
function regenerateMana:cast(caster, target)
|
function regenerateMana:cast(caster, target)
|
||||||
caster.stats.mana = 10
|
caster:try(Tree.behaviors.stats, function (stats)
|
||||||
|
stats.mana = 10
|
||||||
|
end)
|
||||||
print(caster.id, "has regenerated mana")
|
print(caster.id, "has regenerated mana")
|
||||||
caster:try(Tree.behaviors.sprite, function (sprite) -- бойлерплейт (временный)
|
caster:try(Tree.behaviors.sprite, function (sprite) -- бойлерплейт (временный)
|
||||||
-- В данный момент заклинание не позволяет отслеживать состояние последствий своего применения, так что надо повесить хоть какую-то анимашку просто для того, чтобы отложить завершение каста куда-то в будущее
|
-- В данный момент заклинание не позволяет отслеживать состояние последствий своего применения, так что надо повесить хоть какую-то анимашку просто для того, чтобы отложить завершение каста куда-то в будущее
|
||||||
|
|||||||
@ -14,3 +14,4 @@ Tree.behaviors = {}
|
|||||||
Tree.behaviors.map = require "lib.character.behaviors.map"
|
Tree.behaviors.map = require "lib.character.behaviors.map"
|
||||||
Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
|
Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
|
||||||
Tree.behaviors.sprite = require "lib.character.behaviors.sprite"
|
Tree.behaviors.sprite = require "lib.character.behaviors.sprite"
|
||||||
|
Tree.behaviors.stats = require "lib.character.behaviors.stats"
|
||||||
Loading…
x
Reference in New Issue
Block a user