2022-03-30 16:33:56 +08:00
|
|
|
---@class Player : Object
|
2022-04-01 20:51:01 +08:00
|
|
|
---@field hp integer
|
|
|
|
---@field maxHp integer
|
|
|
|
---@field kingdom string
|
|
|
|
---@field role string
|
|
|
|
---@field general string
|
|
|
|
---@field handcard_num integer
|
|
|
|
---@field seat integer
|
|
|
|
---@field phase Phase
|
|
|
|
---@field faceup boolean
|
|
|
|
---@field chained boolean
|
|
|
|
---@field dying boolean
|
|
|
|
---@field dead boolean
|
|
|
|
---@field state string
|
|
|
|
---@field player_skills Skill[]
|
2022-04-02 21:39:44 +08:00
|
|
|
---@field flag string[]
|
|
|
|
---@field tag table<string, any>
|
|
|
|
---@field mark table<string, integer>
|
2022-03-27 14:49:41 +08:00
|
|
|
local Player = class("Player")
|
2022-03-25 12:28:07 +08:00
|
|
|
|
2022-04-01 20:51:01 +08:00
|
|
|
---@alias Phase integer
|
|
|
|
|
|
|
|
Player.RoundStart = 1
|
|
|
|
Player.Start = 2
|
|
|
|
Player.Judge = 3
|
|
|
|
Player.Draw = 4
|
|
|
|
Player.Play = 5
|
|
|
|
Player.Discard = 6
|
|
|
|
Player.Finish = 7
|
|
|
|
Player.NotActive = 8
|
|
|
|
Player.PhaseNone = 9
|
|
|
|
|
2022-03-25 12:28:07 +08:00
|
|
|
function Player:initialize()
|
2022-03-28 22:24:30 +08:00
|
|
|
self.hp = 0
|
|
|
|
self.maxHp = 0
|
|
|
|
self.kingdom = "qun"
|
|
|
|
self.role = ""
|
|
|
|
self.general = ""
|
|
|
|
self.handcard_num = 0
|
|
|
|
self.seat = 0
|
|
|
|
self.phase = Player.PhaseNone
|
|
|
|
self.faceup = true
|
|
|
|
self.chained = false
|
2022-03-25 12:28:07 +08:00
|
|
|
self.dying = false
|
|
|
|
self.dead = false
|
2022-03-30 14:14:40 +08:00
|
|
|
self.state = ""
|
2022-04-01 20:51:01 +08:00
|
|
|
|
|
|
|
self.player_skills = {}
|
2022-04-02 21:39:44 +08:00
|
|
|
self.flag = {}
|
|
|
|
self.tag = {}
|
|
|
|
self.mark = {}
|
2022-03-25 12:28:07 +08:00
|
|
|
end
|
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
---@param general General
|
|
|
|
---@param setHp boolean
|
|
|
|
---@param addSkills boolean
|
2022-03-25 12:28:07 +08:00
|
|
|
function Player:setGeneral(general, setHp, addSkills)
|
|
|
|
self.general = general
|
|
|
|
if setHp then
|
|
|
|
self.maxHp = general.maxHp
|
2022-03-31 13:29:23 +08:00
|
|
|
self.hp = general.hp
|
2022-03-25 12:28:07 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if addSkills then
|
2022-04-02 21:39:44 +08:00
|
|
|
table.insertTable(self.player_skills, general.skills)
|
2022-03-25 12:28:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-02 21:39:44 +08:00
|
|
|
---@param flag string
|
|
|
|
function Player:hasFlag(flag)
|
|
|
|
return table.contains(self.flag, flag)
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param flag string
|
|
|
|
function Player:setFlag(flag)
|
|
|
|
if flag == "." then
|
|
|
|
self:clearFlags()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if flag:sub(1, 1) == "-" then
|
|
|
|
flag = flag:sub(2, #flag)
|
|
|
|
table.removeOne(self.flag, flag)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not self:hasFlag(flag) then
|
|
|
|
table.insert(self.flag, flag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:clearFlags()
|
|
|
|
self.flag = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:addMark(mark, count)
|
|
|
|
count = count or 1
|
|
|
|
local num = self.mark[mark]
|
|
|
|
num = num or 0
|
|
|
|
self:setMark(mark, math.max(num + count, 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:removeMark(mark, count)
|
|
|
|
count = count or 1
|
|
|
|
local num = self.mark[mark]
|
|
|
|
num = num or 0
|
|
|
|
self:setMark(mark, math.max(num - count, 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setMark(mark, count)
|
|
|
|
if self.mark[mark] ~= count then
|
|
|
|
self.mark[mark] = count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:getMark(mark)
|
|
|
|
return (self.mark[mark] or 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:getMarkNames()
|
|
|
|
local ret = {}
|
|
|
|
for k, _ in pairs(self.mark) do
|
|
|
|
table.insert(ret, k)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2022-03-27 14:49:41 +08:00
|
|
|
return Player
|