c1_lua/lua/app/userdata/formation/formation_data.lua
2023-06-07 17:25:08 +08:00

78 lines
1.9 KiB
Lua

local FormationData = class("FormationData", BaseData)
function FormationData:init(data)
self.data.dirty = false
self.formations = {}
-- 目前只有主线关卡的
if data and data.heroes then
local clientFormation = {}
for matchType, heroId in pairs(data.heroes) do
clientFormation[tonumber(matchType)] = heroId
end
self.formations[GConst.BattleConst.BATTLE_TYPE.STAGE] = clientFormation
end
end
function FormationData:getStageFormation()
return self:getFormation(GConst.BattleConst.BATTLE_TYPE.STAGE)
end
function FormationData:getFormation(formationType)
local formation = self.formations[formationType]
if formation == nil then
formation = {}
self.formations[formationType] = formation
end
return formation
end
function FormationData:upHeroToFormation(formationType, matchType, heroId)
local formation = self:getFormation(formationType)
if formation[matchType] == heroId then
return
end
formation[matchType] = heroId
self:setDirty()
end
function FormationData:heroInFormation(formationType, heroId)
local formation = self:getFormation(formationType)
if not formation then
return false
end
for matchType, id in pairs(formation) do
if id == heroId then
return true
end
end
return false
end
function FormationData:setDirty()
self.data.dirty = not self.data.dirty
end
function FormationData:getStageFormationBIStr()
local str
local totalLevel = 0
local allAtk = 0
local allHp = 0
for matchType, heroId in pairs(self:getStageFormation()) do
local entity = DataManager.HeroData:getHeroById(heroId)
if entity then
if str then
str = str .. "|"
else
str = GConst.EMPTY_STRING
end
str = str .. heroId .. ":" .. entity:getLv()
totalLevel = totalLevel + entity:getLv()
allAtk = allAtk + entity:getAtk()
allHp = allHp + entity:getHp()
end
end
return str, totalLevel, allAtk, allHp
end
return FormationData