c1_lua/lua/app/module/chapter/chapter_manager.lua
2023-04-21 10:56:25 +08:00

64 lines
2.2 KiB
Lua

local ChapterManager = class("ChapterManager", BaseModule)
function ChapterManager:openBox(chapterId, index)
if DataManager.ChapterData:getChapterBoxRewardGot(chapterId, index) then
return
end
local parmas = {
id = chapterId,
index = index,
}
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX, parmas, function(result)
if result.status == 0 then
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.CHAPTER_BOX)
GFunc.showRewardBox(result.rewards)
DataManager.ChapterData:init(result.chapterData, true)
DataManager.ChapterData:setDirty()
end
end)
end
function ChapterManager:startFight()
if not ModuleManager.FormationManager:formationIsFull() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_8))
return
end
---- 通信
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
end
function ChapterManager:endFight(id, combatReport)
local cfg = ConfigManager:getConfig("chapter")[id]
local rewards = {}
for i = 1, combatReport.wave do
for _, reward in ipairs(cfg.wave_reward) do
table.insert(rewards, reward)
end
end
if combatReport.victory then
for _, reward in ipairs(cfg.finish_reward) do
table.insert(rewards, reward)
end
end
local parmas = {
id = id,
combatReport = combatReport,
rewards = GFunc.mergeRewards(rewards)
}
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT, parmas, function(result)
if result.status == 0 then
if combatReport.victory and DataManager.ChapterData:getChapterId() == DataManager.ChapterData:getMaxChapterId() + 1 then
DataManager.ChapterData:goNextChapter()
end
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.FIGHT_END)
ModuleManager.BattleManager:showBattleResultUI(result.rewards, combatReport)
DataManager.ChapterData:init(result.chapterData, true)
DataManager.ChapterData:setDirty()
end
end)
end
return ChapterManager