some character refactor
This commit is contained in:
parent
d07d26680c
commit
1a2a7ab60f
@ -9,13 +9,10 @@ local characterId = 1
|
|||||||
--- @todo Композиция лучше наследования, но не до такой же степени! Надо отрефакторить и избавиться от сотни полей в таблице
|
--- @todo Композиция лучше наследования, но не до такой же степени! Надо отрефакторить и избавиться от сотни полей в таблице
|
||||||
--- @class Character
|
--- @class Character
|
||||||
--- @field id integer
|
--- @field id integer
|
||||||
--- @field name string
|
|
||||||
--- @field animationTable table<string, table>
|
--- @field animationTable table<string, table>
|
||||||
--- @field state "idle"|"run"|"attack"|"hurt"
|
--- @field state "idle"|"run"|"attack"|"hurt"
|
||||||
--- @field stats table<string, integer>
|
--- @field info Info
|
||||||
--- @field player table
|
--- @field player table
|
||||||
--- @field skills table
|
|
||||||
--- @field class "warrior"|"mage"
|
|
||||||
--- @field position Vec3
|
--- @field position Vec3
|
||||||
--- @field latestPosition Vec3 позиция, где character был один тик назад
|
--- @field latestPosition Vec3 позиция, где character был один тик назад
|
||||||
--- @field runTarget Vec3 точка, в которую в данный момент бежит персонаж
|
--- @field runTarget Vec3 точка, в которую в данный момент бежит персонаж
|
||||||
@ -25,9 +22,10 @@ character.__index = character
|
|||||||
|
|
||||||
--- Создаёт персонажа, которым будет управлять или игрок или компьютер
|
--- Создаёт персонажа, которым будет управлять или игрок или компьютер
|
||||||
--- @param name string
|
--- @param name string
|
||||||
|
--- @param template ClassTemplate
|
||||||
--- @param spriteDir table
|
--- @param spriteDir table
|
||||||
--- @param level? integer
|
--- @param level? integer
|
||||||
local function spawn(name, spriteDir, level)
|
local function spawn(name, template, spriteDir, level)
|
||||||
local animationGrid = {}
|
local animationGrid = {}
|
||||||
-- n: name; i: image
|
-- n: name; i: image
|
||||||
for n, i in pairs(spriteDir) do
|
for n, i in pairs(spriteDir) do
|
||||||
@ -37,7 +35,6 @@ local function spawn(name, spriteDir, level)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local char = {
|
local char = {
|
||||||
name = name,
|
|
||||||
animationTable = {}
|
animationTable = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,14 +55,7 @@ local function spawn(name, spriteDir, level)
|
|||||||
char.state = "idle"
|
char.state = "idle"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
char.stats = {}
|
char.info = (require "lib/character/info").new(name, template)
|
||||||
--- @todo придумать формулу расчёта статов относительно уровня
|
|
||||||
char.stats.level = 1
|
|
||||||
|
|
||||||
char.stats.initiative = 10
|
|
||||||
char.stats.damage = 5
|
|
||||||
char.stats.defence = 0
|
|
||||||
char.stats.hp = 30
|
|
||||||
|
|
||||||
char = setmetatable(char, character)
|
char = setmetatable(char, character)
|
||||||
Tree.level.characters[char.id] = char
|
Tree.level.characters[char.id] = char
|
||||||
17
lib/character/class.lua
Normal file
17
lib/character/class.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
--- @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 }
|
||||||
16
lib/character/info.lua
Normal file
16
lib/character/info.lua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
--- @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 }
|
||||||
45
lib/character/stats.lua
Normal file
45
lib/character/stats.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
--- @class Stats
|
||||||
|
--- @field level integer
|
||||||
|
--- @field initiative integer
|
||||||
|
--- @field hp integer
|
||||||
|
--- @field damage integer
|
||||||
|
--- @field defence integer
|
||||||
|
local stats = {}
|
||||||
|
|
||||||
|
--- @param level? integer
|
||||||
|
local function new(level)
|
||||||
|
|
||||||
|
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 }
|
||||||
4
main.lua
4
main.lua
@ -1,6 +1,6 @@
|
|||||||
-- CameraLoader = require 'lib/camera'
|
-- CameraLoader = require 'lib/camera'
|
||||||
|
|
||||||
local character = require "lib/character"
|
local character = require "lib/character/character"
|
||||||
require "lib/tree"
|
require "lib/tree"
|
||||||
|
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
@ -8,7 +8,7 @@ function love.conf(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
local char = character.spawn("Hero", Tree.assets.files.sprites.character)
|
local char = character.spawn("Hero", "warrior", Tree.assets.files.sprites.character)
|
||||||
char:runTo(Vec3 { 5, 5 })
|
char:runTo(Vec3 { 5, 5 })
|
||||||
|
|
||||||
-- PlayerFaction.characters = { Hero1, Hero2 }
|
-- PlayerFaction.characters = { Hero1, Hero2 }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user