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 return FormationData