c1_lua/lua/app/userdata/formation/formation_data.lua
2023-04-11 20:05:03 +08:00

43 lines
1.1 KiB
Lua

local FormationData = class("FormationData", BaseData)
function FormationData:init(data)
self.data.dirty = false
self.formations = {}
if data and data.formations then
for formationType, formation in pairs(data.formations) do
local clientFormation = {}
self.formations[formationType] = clientFormation
for matchTypeStr, heroId in pairs(formation) do
clientFormation[tonumber(matchTypeStr)] = heroId
end
end
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:setDirty()
self.data.dirty = not self.data.dirty
end
return FormationData