119 lines
4.4 KiB
Lua
119 lines
4.4 KiB
Lua
local ChapterManager = class("ChapterManager", BaseModule)
|
|
|
|
function ChapterManager:openBox(chapterId, index)
|
|
if DataManager.ChapterData:getChapterBoxRewardGot(chapterId, index) then
|
|
return
|
|
end
|
|
|
|
local parmas = {
|
|
chapter_id = chapterId,
|
|
wave = index,
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterBoxRewardReq, parmas, {}, self.openBoxFinish, BIReport.ITEM_GET_TYPE.CHAPTER_BOX)
|
|
end
|
|
|
|
function ChapterManager:openBoxFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
local reqData = result.reqData
|
|
GFunc.showRewardBox(result.rewards)
|
|
DataManager.ChapterData:openBox(reqData.chapter_id, reqData.wave)
|
|
|
|
BIReport:postChapterOpenBox(reqData.chapter_id, DataManager.ChapterData:getChapterBoxNum(reqData.chapter_id, reqData.wave), result.rewards)
|
|
end
|
|
end
|
|
|
|
function ChapterManager:startFight()
|
|
if not ModuleManager.FormationManager:formationIsFull() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_8))
|
|
return
|
|
end
|
|
local cost = DataManager.ChapterData:getFightCost()
|
|
local vitCostNum = 0
|
|
if cost then
|
|
vitCostNum = GFunc.getRewardNum(cost)
|
|
end
|
|
if vitCostNum > DataManager.BagData.ItemData:getVit() then -- 体力不足
|
|
GFunc.showItemNotEnough(GConst.ItemConst.ITEM_ID_VIT)
|
|
ModuleManager.CommerceManager:showBuyVitUI()
|
|
return
|
|
end
|
|
local parmas = {
|
|
chapter_id = DataManager.ChapterData:getChapterId()
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterStartReq, parmas, {}, self.startFightFinish, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_START)
|
|
end
|
|
|
|
function ChapterManager:startFightFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
|
|
end
|
|
end
|
|
|
|
function ChapterManager:endFight(id, combatReport, gotMysteryBoxIndexs, taskProgress)
|
|
local mystery_box_idx = {}
|
|
if gotMysteryBoxIndexs then
|
|
for index, _ in pairs(gotMysteryBoxIndexs) do
|
|
table.insert(mystery_box_idx, index)
|
|
end
|
|
end
|
|
local parmas = {
|
|
win = combatReport.victory,
|
|
chapter_id = id,
|
|
mystery_box_idx = mystery_box_idx,
|
|
pass_wave = combatReport.wave,
|
|
combatReport = combatReport,
|
|
}
|
|
for fieldName, value in pairs(taskProgress) do
|
|
parmas[fieldName] = value
|
|
end
|
|
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterSettlementReq, parmas, {}, self.endFightFinish, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_END)
|
|
end
|
|
|
|
function ChapterManager:endFightFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
local reqData = result.reqData
|
|
local maxChapter = DataManager.ChapterData:getNewChapterId()
|
|
local rewards = {}
|
|
local newRewards = {}
|
|
local mysteryBoxIdx = result.mystery
|
|
for i, reward in ipairs(result.rewards) do
|
|
if i <= mysteryBoxIdx then
|
|
table.insert(newRewards, reward)
|
|
else
|
|
table.insert(rewards, reward)
|
|
end
|
|
end
|
|
|
|
if rewards then
|
|
local mergeRewards = {}
|
|
GFunc.mergeRewards2(rewards, mergeRewards, true)
|
|
for _, unit in ipairs(mergeRewards) do
|
|
table.insert(newRewards, unit)
|
|
end
|
|
end
|
|
|
|
ModuleManager.BattleManager:showBattleResultUI(newRewards, reqData.combatReport, mysteryBoxIdx)
|
|
DataManager.ChapterData:fightChapter(reqData.chapter_id, result.max_chapter_id, result.max_wave, reqData.mystery_box_idx)
|
|
-- 处理金猪,要在章节更新之后
|
|
DataManager.GoldPigData:addGoldPigCount()
|
|
|
|
local newMaxChapter = DataManager.ChapterData:getNewChapterId()
|
|
if maxChapter ~= newMaxChapter then
|
|
local data = {}
|
|
data.max_chapter = newMaxChapter
|
|
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
|
|
-- 标记可弹出新手礼包
|
|
if newMaxChapter == 2 then
|
|
DataManager.ShopData:markPopUpGiftForBeginnerGift()
|
|
end
|
|
-- 章节通关 标记可弹出章节礼包
|
|
DataManager.ShopData:markPopUpGiftForActChapterStore(newMaxChapter - 1)
|
|
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_PASS_CHAPTER)
|
|
end
|
|
|
|
ModuleManager.TaskManager:addFightTaskProgress(reqData)
|
|
end
|
|
end
|
|
|
|
return ChapterManager |