2022-03-30 08:33:56 +00:00
|
|
|
---@class Package : Object
|
|
|
|
---@field name string
|
2022-04-01 12:51:01 +00:00
|
|
|
---@field type PackageType
|
|
|
|
---@field generals General[]
|
|
|
|
---@field extra_skills Skill[]
|
|
|
|
---@field related_skills table<string, string>
|
|
|
|
---@field cards Card[]
|
2022-03-28 14:24:30 +00:00
|
|
|
local Package = class("Package")
|
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
---@alias PackageType integer
|
|
|
|
|
|
|
|
Package.GeneralPack = 1
|
|
|
|
Package.CardPack = 2
|
|
|
|
Package.SpecialPack = 3
|
2022-03-28 14:24:30 +00:00
|
|
|
|
|
|
|
function Package:initialize(name, _type)
|
2022-04-30 07:27:56 +00:00
|
|
|
assert(type(name) == "string")
|
|
|
|
assert(type(_type) == "nil" or type(_type) == "number")
|
|
|
|
self.name = name
|
|
|
|
self.type = _type or Package.GeneralPack
|
|
|
|
|
|
|
|
self.generals = {}
|
|
|
|
self.extra_skills = {} -- skill not belongs to any generals, like "jixi"
|
|
|
|
self.related_skills = {}
|
|
|
|
self.cards = {}
|
2022-03-28 14:24:30 +00:00
|
|
|
end
|
|
|
|
|
2022-04-02 13:39:44 +00:00
|
|
|
---@return Skill[]
|
2022-03-28 14:24:30 +00:00
|
|
|
function Package:getSkills()
|
2022-04-30 07:27:56 +00:00
|
|
|
local ret = {table.unpack(self.related_skills)}
|
|
|
|
if self.type == Package.GeneralPack then
|
|
|
|
for _, g in ipairs(self.generals) do
|
|
|
|
for _, s in ipairs(g.skills) do
|
|
|
|
table.insert(ret, s)
|
|
|
|
end
|
2022-03-28 14:24:30 +00:00
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
end
|
|
|
|
return ret
|
2022-03-28 14:24:30 +00:00
|
|
|
end
|
|
|
|
|
2022-03-30 08:33:56 +00:00
|
|
|
---@param general General
|
2022-03-28 14:24:30 +00:00
|
|
|
function Package:addGeneral(general)
|
2022-04-30 07:27:56 +00:00
|
|
|
assert(general.class and general:isInstanceOf(General))
|
|
|
|
table.insert(self.generals, general)
|
2022-03-28 14:24:30 +00:00
|
|
|
end
|
|
|
|
|
2022-03-31 05:29:23 +00:00
|
|
|
---@param card Card
|
|
|
|
function Package:addCard(card)
|
2022-04-30 07:27:56 +00:00
|
|
|
assert(card.class and card:isInstanceOf(Card))
|
|
|
|
card.package = self
|
|
|
|
table.insert(self.cards, card)
|
2022-03-31 05:29:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---@param cards Card[]
|
|
|
|
function Package:addCards(cards)
|
2022-04-30 07:27:56 +00:00
|
|
|
for _, card in ipairs(cards) do
|
|
|
|
self:addCard(card)
|
|
|
|
end
|
2022-03-31 05:29:23 +00:00
|
|
|
end
|
|
|
|
|
2022-03-28 14:24:30 +00:00
|
|
|
return Package
|