84 lines
1.6 KiB
Lua
84 lines
1.6 KiB
Lua
local BattleTeam = class("BattleTeam")
|
|
|
|
function BattleTeam:init(side)
|
|
self.side = side
|
|
self.unitList = {}
|
|
self.unitMap = {}
|
|
end
|
|
|
|
function BattleTeam:addUnit(unit, isMainUnit)
|
|
self.unitMap[unit:getMatchType()] = unit
|
|
table.insert(self.unitList, unit)
|
|
if isMainUnit then
|
|
self.mainUnit = unit
|
|
end
|
|
end
|
|
|
|
function BattleTeam:getMainUnit()
|
|
return self.mainUnit
|
|
end
|
|
|
|
function BattleTeam:removeAllUnits()
|
|
for k, v in pairs(self.unitMap) do
|
|
self.unitMap[k] = nil
|
|
end
|
|
local count = #self.unitList
|
|
for i = 1, count do
|
|
self.unitList[i]:recycle()
|
|
table.remove(self.unitList)
|
|
end
|
|
self.mainUnit = nil
|
|
end
|
|
|
|
function BattleTeam:useNormalSkill(matchType, count, callback)
|
|
local unit = nil
|
|
if matchType == nil then
|
|
unit = self.unitList[1]
|
|
else
|
|
unit = self.unitMap[matchType]
|
|
end
|
|
if unit == nil then
|
|
return callback()
|
|
end
|
|
self.mainUnit = unit
|
|
unit:useNormalSkill(count, callback)
|
|
end
|
|
|
|
function BattleTeam:useSkill(matchType, callback)
|
|
local unit = nil
|
|
if matchType == nil then
|
|
unit = self.unitList[1]
|
|
else
|
|
unit = self.unitMap[matchType]
|
|
end
|
|
if unit == nil then
|
|
return callback()
|
|
end
|
|
self.mainUnit = unit
|
|
unit:useSkill(1, callback)
|
|
end
|
|
|
|
function BattleTeam:mainUnitUseAllSkills(callback)
|
|
self.mainUnit:useAllSkills(callback)
|
|
end
|
|
|
|
function BattleTeam:changeMainUnit(matchType)
|
|
if self.mainUnit and matchType == self.mainUnit:getMatchType() then
|
|
return
|
|
end
|
|
local unit = self.unitMap[matchType]
|
|
if unit == nil then
|
|
return
|
|
end
|
|
self.mainUnit:playSwitchOut()
|
|
self.mainUnit = unit
|
|
unit:playSwitchIn()
|
|
end
|
|
|
|
function BattleTeam:tick(dt)
|
|
for k, v in ipairs(self.unitList) do
|
|
v:tick(dt)
|
|
end
|
|
end
|
|
|
|
return BattleTeam |