238 lines
5.6 KiB
Lua
238 lines
5.6 KiB
Lua
local HeroEntity = require "app/userdata/hero/hero_entity"
|
|
local HeroData = class("HeroData", BaseData)
|
|
|
|
function HeroData:ctor()
|
|
self.heroes = {}
|
|
self.data.activeCount = 0
|
|
self.data.isDirty = false
|
|
self.matchActiveHeroMap = {}
|
|
self.maxHeroLvOnInit = 0
|
|
self.showHeroUnlockChapter = 0
|
|
self.heroChapterUnlockMap = {}
|
|
self.heroChapterUnlockMapBi = {}
|
|
end
|
|
|
|
function HeroData:clear()
|
|
self.heroes = {}
|
|
end
|
|
|
|
function HeroData:init(data)
|
|
self.heroes = {}
|
|
for k, v in pairs(self.heroChapterUnlockMap) do
|
|
self.heroChapterUnlockMap[k] = false
|
|
end
|
|
for k, v in pairs(self.heroChapterUnlockMapBi) do
|
|
self.heroChapterUnlockMapBi[k] = false
|
|
end
|
|
if data then
|
|
for id, heroInfo in pairs(data) do
|
|
self:addHero(heroInfo)
|
|
if self.maxHeroLvOnInit < heroInfo.level then
|
|
self.maxHeroLvOnInit = heroInfo.level
|
|
end
|
|
end
|
|
end
|
|
|
|
local heroCfg = ConfigManager:getConfig("hero")
|
|
for heroId, info in pairs(heroCfg) do
|
|
local entity = self:getHeroById(heroId)
|
|
if entity and entity:isActived() then
|
|
local matchType = entity:getMatchType()
|
|
if not self.matchActiveHeroMap[matchType] then
|
|
self.matchActiveHeroMap[matchType] = {}
|
|
end
|
|
self.matchActiveHeroMap[matchType][entity:getCfgId()] = true
|
|
end
|
|
if info.unlock_chapter and info.is_show == 1 then
|
|
self.heroChapterUnlockMap[info.unlock_chapter] = true
|
|
end
|
|
if info.unlock_chapter then
|
|
self.heroChapterUnlockMapBi[info.unlock_chapter] = true
|
|
end
|
|
end
|
|
self.showHeroUnlockChapter = 0
|
|
end
|
|
|
|
-- 是否是合法的英雄
|
|
function HeroData:isExistHeroById(id)
|
|
if not id or id == 0 then
|
|
return false
|
|
end
|
|
|
|
return ConfigManager:getConfig("hero")[id] ~= nil
|
|
end
|
|
|
|
function HeroData:addHero(heroStruct)
|
|
if self.heroes[heroStruct.id] then
|
|
return
|
|
end
|
|
self.heroes[heroStruct.id] = self:getEntity(heroStruct)
|
|
self.data.activeCount = self.data.activeCount + 1
|
|
end
|
|
|
|
function HeroData:getEntity(heroStruct)
|
|
return HeroEntity:create(heroStruct.id, heroStruct.level, heroStruct.collection_level)
|
|
end
|
|
|
|
function HeroData:getHeroById(id)
|
|
if not self:isExistHeroById(id) then
|
|
return
|
|
end
|
|
if not self.heroes[id] then
|
|
self.heroes[id] = self:getEntity({id = id, level = 0, collection_level = 0})
|
|
end
|
|
return self.heroes[id]
|
|
end
|
|
|
|
function HeroData:getAllHeroes()
|
|
return self.heroes
|
|
end
|
|
|
|
function HeroData:getActiveHeroCount()
|
|
return self.data.activeCount
|
|
end
|
|
|
|
function HeroData:getHeroIsActive(id)
|
|
local entity = self.heroes[id]
|
|
if entity == nil then
|
|
return false
|
|
end
|
|
return entity:isActived()
|
|
end
|
|
|
|
|
|
function HeroData:getHeroIsUnlock(id)
|
|
local entity = self.heroes[id]
|
|
if entity == nil then
|
|
return false
|
|
end
|
|
return entity:isUnlock()
|
|
end
|
|
|
|
function HeroData:getUnlockHeroCount()
|
|
local count = 0
|
|
for id, entity in pairs(self.heroes) do
|
|
if entity:isUnlock() then
|
|
count = count + 1
|
|
end
|
|
end
|
|
return count
|
|
end
|
|
|
|
function HeroData:setHeroLv(id, lv)
|
|
local entity = self:getHeroById(id)
|
|
local activeBefore = true
|
|
if not entity:isActived() then
|
|
self.data.activeCount = self.data.activeCount + 1
|
|
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_NEW_HERO_GOT)
|
|
ModuleManager.PlayerManager:checkUnlockAvatar(id)
|
|
activeBefore = false
|
|
BIReport:postFirstGetHero(self.data.activeCount)
|
|
end
|
|
local beforeLv = entity:getLv()
|
|
entity:setLv(lv)
|
|
if entity:isActived() then
|
|
local matchType = entity:getMatchType()
|
|
if not self.matchActiveHeroMap[matchType] then
|
|
self.matchActiveHeroMap[matchType] = {}
|
|
end
|
|
self.matchActiveHeroMap[matchType][entity:getCfgId()] = true
|
|
end
|
|
|
|
if activeBefore then
|
|
BIReport:postHeroOpt(id, BIReport.HERO_OPT_TYPE.LEVEL_UP)
|
|
else
|
|
if not entity:getUnlcokChapter() then
|
|
BIReport:postHeroOpt(id, BIReport.HERO_OPT_TYPE.UNLOCK)
|
|
end
|
|
BIReport:postHeroOpt(id, BIReport.HERO_OPT_TYPE.ACTIVE)
|
|
end
|
|
|
|
BIReport:postHeroLev(beforeLv, lv)
|
|
BIReport:postFirstDayHeroLevel(id)
|
|
end
|
|
|
|
function HeroData:getMatchActiveHeroMap()
|
|
return self.matchActiveHeroMap
|
|
end
|
|
|
|
function HeroData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function HeroData:getRp()
|
|
local formationMap = DataManager.FormationData:getStageFormation()
|
|
if not formationMap then
|
|
return false
|
|
end
|
|
local heroMap = {}
|
|
for _, heroId in pairs(formationMap) do
|
|
heroMap[heroId] = true
|
|
end
|
|
|
|
for id, entity in pairs(self.heroes) do
|
|
if entity:canLvUp() then
|
|
if heroMap[id] or not entity:isActived() then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
|
|
if DataManager.CollectionData:hasRedPoint(GConst.CollectionConst.TYPE.HERO) then
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function HeroData:getMaxHeroLvOnInit()
|
|
return self.maxHeroLvOnInit
|
|
end
|
|
|
|
function HeroData:getIfCanShowHeroUnlock()
|
|
return self.showHeroUnlockChapter > 0
|
|
end
|
|
|
|
function HeroData:markShowHeroUnlock()
|
|
self.showHeroUnlockChapter = 0
|
|
end
|
|
|
|
function HeroData:checkIfCanShowHeroUnlock(chapterId)
|
|
if self.heroChapterUnlockMapBi[chapterId] then -- 日志上报
|
|
for id, entity in pairs(self.heroes) do
|
|
if not entity:isActived() and entity:getUnlcokChapter() == chapterId then
|
|
BIReport:postHeroOpt(id, BIReport.HERO_OPT_TYPE.UNLOCK)
|
|
end
|
|
end
|
|
end
|
|
|
|
if not self.heroChapterUnlockMap[chapterId] then
|
|
return
|
|
end
|
|
self.showHeroUnlockChapter = chapterId
|
|
end
|
|
|
|
function HeroData:getHeroChapterUnlockList()
|
|
local list = {}
|
|
for id, entity in pairs(self.heroes) do
|
|
if not entity:isActived() and entity:getIsShowUnlcokChapter() and entity:getUnlcokChapter() == self.showHeroUnlockChapter then
|
|
table.insert(list, id)
|
|
end
|
|
end
|
|
return list
|
|
end
|
|
|
|
function HeroData:getAllHeroesBIStr()
|
|
local str
|
|
for heroId, entity in pairs(self:getAllHeroes()) do
|
|
if str then
|
|
str = str .. "|"
|
|
else
|
|
str = GConst.EMPTY_STRING
|
|
end
|
|
str = str .. heroId .. ":" .. entity:getLv()
|
|
end
|
|
return str
|
|
end
|
|
|
|
return HeroData |