c1_lua/lua/app/module/chapter/chapter_manager.lua
2023-05-05 18:27:33 +08:00

88 lines
3.2 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
GFunc.showRewardBox(result.rewards)
DataManager.ChapterData:openBox(result.reqData.chapter_id, result.reqData.wave)
BIReport:postChapterOpenBox(result.reqData.chapter_id, DataManager.ChapterData:getChapterBoxNum(chapterId, index), 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)
return
end
local parmas = {
id = DataManager.ChapterData:getChapterId()
}
-- self:sendMessage(ProtoMsgType.FromMsgEnum., parmas, {}, self.startFightFinish, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_START)
self:startFightFinish({err_code = "SUCCESS"})
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)
local parmas = {
chapter_id = id,
win = combatReport.victory,
pass_wave = combatReport.wave,
combatReport = combatReport,
}
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterSettlementReq, parmas, {}, self.startFightFinish, 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()
if reqData.combatReport.victory and DataManager.ChapterData:getChapterId() == DataManager.ChapterData:getMaxChapterId() + 1 then
DataManager.ChapterData:goNextChapter()
end
local newRewards = {}
if result.rewards then
GFunc.mergeRewards2(result.rewards, newRewards)
end
ModuleManager.BattleManager:showBattleResultUI(newRewards, reqData.combatReport)
-- DataManager.ChapterData:init(result.chapterData, true)
-- DataManager.ChapterData:setDirty()
-- 处理金猪
DataManager.GodPigData:addGoldPigCount()
local newMaxChapter = DataManager.ChapterData:getNewChapterId()
if maxChapter ~= newMaxChapter then
local data = {}
data.max_chapter = newMaxChapter
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
end
end
end
return ChapterManager