2023-04-09 05:35:35 +00:00
|
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-04-12 05:28:01 +00:00
|
|
|
|
--- General用来描述一个武将。
|
|
|
|
|
---
|
|
|
|
|
--- 所谓武将,就是所属包、武将基础信息的集合。
|
|
|
|
|
---
|
|
|
|
|
--- 也许···类似于身份证?
|
|
|
|
|
---
|
2022-03-31 05:29:23 +00:00
|
|
|
|
---@class General : Object
|
2023-04-12 05:28:01 +00:00
|
|
|
|
---@field public package Package @ 武将所属包
|
|
|
|
|
---@field public name string @ 武将名字
|
|
|
|
|
---@field public trueName string @ 武将真名,也许可以分辨标界?
|
|
|
|
|
---@field public kingdom string @ 武将所属势力
|
2023-04-30 10:55:59 +00:00
|
|
|
|
---@field public subkingdom string @ 武将副势力
|
2023-04-12 05:28:01 +00:00
|
|
|
|
---@field public hp integer @ 武将初始体力
|
|
|
|
|
---@field public maxHp integer @ 武将初始最大体力
|
2023-08-24 13:37:06 +00:00
|
|
|
|
---@field public mainMaxHpAdjustedValue integer @ 主将体力上限调整
|
|
|
|
|
---@field public deputyMaxHpAdjustedValue integer @ 副将体力上限调整
|
2023-04-13 12:17:39 +00:00
|
|
|
|
---@field public shield integer @ 初始护甲
|
2023-04-12 05:28:01 +00:00
|
|
|
|
---@field public gender Gender @ 武将性别
|
|
|
|
|
---@field public skills Skill[] @ 武将技能
|
|
|
|
|
---@field public other_skills string[] @ 武将身上属于其他武将的技能,通过字符串调用
|
2023-04-13 14:01:25 +00:00
|
|
|
|
---@field public related_skills Skill[] @ 武将相关的不属于其他武将的技能,例如邓艾的急袭
|
|
|
|
|
---@field public related_other_skills string [] @ 武将相关的属于其他武将的技能,例如孙策的英姿
|
2023-08-24 13:37:06 +00:00
|
|
|
|
---@field public companions string [] @ 有珠联璧合关系的武将
|
|
|
|
|
---@field public hidden boolean @ 不在选将框里出现,可以点将,可以在武将一览里查询到
|
|
|
|
|
---@field public total_hidden boolean @ 完全隐藏
|
2022-03-25 04:28:07 +00:00
|
|
|
|
General = class("General")
|
|
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
|
---@alias Gender integer
|
2022-03-28 14:24:30 +00:00
|
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
|
General.Male = 1
|
|
|
|
|
General.Female = 2
|
2023-04-13 14:01:25 +00:00
|
|
|
|
General.Bigender = 3
|
|
|
|
|
General.Agender = 4
|
2022-04-01 12:51:01 +00:00
|
|
|
|
|
2023-04-12 05:28:01 +00:00
|
|
|
|
--- 构造函数,不可随意调用。
|
|
|
|
|
---@param package Package @ 武将所属包
|
|
|
|
|
---@param name string @ 武将名字
|
|
|
|
|
---@param kingdom string @ 武将所属势力
|
|
|
|
|
---@param hp integer @ 武将初始体力
|
|
|
|
|
---@param maxHp integer @ 武将初始最大体力
|
|
|
|
|
---@param gender Gender @ 武将性别
|
2022-04-01 12:51:01 +00:00
|
|
|
|
function General:initialize(package, name, kingdom, hp, maxHp, gender)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.package = package
|
|
|
|
|
self.name = name
|
2023-03-18 18:21:45 +00:00
|
|
|
|
local name_splited = name:split("__")
|
|
|
|
|
self.trueName = name_splited[#name_splited]
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.kingdom = kingdom
|
|
|
|
|
self.hp = hp
|
|
|
|
|
self.maxHp = maxHp or hp
|
|
|
|
|
self.gender = gender or General.Male
|
2023-08-24 13:37:06 +00:00
|
|
|
|
self.mainMaxHpAdjustedValue = 0
|
|
|
|
|
self.deputyMaxHpAdjustedValue = 0
|
2023-04-13 12:17:39 +00:00
|
|
|
|
self.shield = 0
|
2023-04-30 10:55:59 +00:00
|
|
|
|
self.subkingdom = nil
|
2022-03-25 04:28:07 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.skills = {} -- skills first added to this general
|
|
|
|
|
self.other_skills = {} -- skill belongs other general, e.g. "mashu" of pangde
|
2023-04-13 14:01:25 +00:00
|
|
|
|
self.related_skills = {} -- skills related to this general, but not first added to it, e.g. "jixi" of dengai
|
|
|
|
|
self.related_other_skills = {} -- skills related to this general and belong to other generals, e.g. "yingzi" of sunce
|
2023-01-04 06:21:29 +00:00
|
|
|
|
|
2023-08-24 13:37:06 +00:00
|
|
|
|
self.companions = {}
|
|
|
|
|
|
2023-01-04 06:21:29 +00:00
|
|
|
|
package:addGeneral(self)
|
2022-03-25 04:28:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-08 17:10:16 +00:00
|
|
|
|
function General:__tostring()
|
|
|
|
|
return string.format("<General %s>", self.name)
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-12 05:28:01 +00:00
|
|
|
|
--- 为武将增加技能,需要注意增加其他武将技能时的处理方式。
|
|
|
|
|
---@param skill Skill @ (单个)武将技能
|
2022-03-25 04:28:07 +00:00
|
|
|
|
function General:addSkill(skill)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if (type(skill) == "string") then
|
|
|
|
|
table.insert(self.other_skills, skill)
|
|
|
|
|
elseif (skill.class and skill.class:isSubclassOf(Skill)) then
|
|
|
|
|
table.insert(self.skills, skill)
|
2023-02-15 11:54:35 +00:00
|
|
|
|
skill.package = self.package
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-03-25 04:28:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-13 14:01:25 +00:00
|
|
|
|
--- 为武将增加相关技能,需要注意增加其他武将技能时的处理方式。
|
|
|
|
|
---@param skill Skill @ (单个)武将技能
|
|
|
|
|
function General:addRelatedSkill(skill)
|
|
|
|
|
if (type(skill) == "string") then
|
|
|
|
|
table.insert(self.related_other_skills, skill)
|
|
|
|
|
elseif (skill.class and skill.class:isSubclassOf(Skill)) then
|
|
|
|
|
table.insert(self.related_skills, skill)
|
|
|
|
|
Fk:addSkill(skill)
|
|
|
|
|
skill.package = self.package
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-03 15:59:04 +00:00
|
|
|
|
--- 获取武将所有技能。
|
2024-02-04 07:30:27 +00:00
|
|
|
|
---@param include_lord? boolean
|
|
|
|
|
---@return string[]
|
2023-04-23 13:10:07 +00:00
|
|
|
|
function General:getSkillNameList(include_lord)
|
2024-01-24 19:13:57 +00:00
|
|
|
|
local ret = {}
|
|
|
|
|
local other_skills = table.map(self.other_skills, Util.Name2SkillMapper)
|
|
|
|
|
local skills = table.connect(self.skills, other_skills)
|
|
|
|
|
for _, skill in ipairs(skills) do
|
|
|
|
|
if include_lord or not skill.lordSkill then
|
|
|
|
|
table.insert(ret, skill.name)
|
|
|
|
|
end
|
2023-04-23 13:10:07 +00:00
|
|
|
|
end
|
2024-01-24 19:13:57 +00:00
|
|
|
|
|
|
|
|
|
-- table.insertTable(ret, self.other_skills)
|
2023-04-23 13:10:07 +00:00
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-24 13:37:06 +00:00
|
|
|
|
--- 为武将增加珠联璧合关系武将(1个或多个),只需写trueName。
|
|
|
|
|
---@param name string[] @ 武将真名(表)
|
|
|
|
|
function General:addCompanions(name)
|
|
|
|
|
if type(name) == "table" then
|
|
|
|
|
table.insertTable(self.companions, name)
|
|
|
|
|
elseif type(name) == "string" then
|
|
|
|
|
table.insert(self.companions, name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-25 04:28:07 +00:00
|
|
|
|
return General
|