c1_lua/lua/app/server/manager/server_chapter_manager.lua
2023-04-15 14:45:42 +08:00

70 lines
1.8 KiB
Lua

local ServerChapterManager = {}
function ServerChapterManager:openBox(params, callback)
local result = {
status = 1
}
if params == nil or not params.id or not params.index then
if callback then
callback(result)
end
return
end
local ServerGameData = ServerDataManager:getServerGameData()
if not ServerGameData.ChapterData:openChapterBox(params.id, params.index) then
if callback then
callback(result)
end
return
end
local rewards = ServerGameData.ChapterData:getChapterBoxRewards(params.id, params.index)
result.rewards = ServerGameData:addRewards(rewards)
result.chapterData = ServerGameData.ChapterData:getCloneData()
result.status = 0
if callback then
callback(result)
end
end
function ServerChapterManager:endFight(params, callback)
local result = {
status = 1
}
if params == nil or not params.id or not params.combatReport then
if callback then
callback(result)
end
return
end
local cfg = ConfigManager:getConfig("chapter")[params.id]
local rewards = {}
for i = 1, params.combatReport.wave do
for _, reward in ipairs(cfg.wave_reward) do
table.insert(rewards, reward)
end
end
if params.combatReport.victory then
for _, reward in ipairs(cfg.finish_reward) do
table.insert(rewards, reward)
end
end
rewards = GFunc.mergeRewards(rewards)
local ServerGameData = ServerDataManager:getServerGameData()
ServerGameData.ChapterData:fightChapter(params.id, params.combatReport.victory, params.combatReport.wave)
result.rewards = ServerGameData:addRewards(rewards)
result.chapterData = ServerGameData.ChapterData:getCloneData()
result.status = 0
if callback then
callback(result)
end
end
return ServerChapterManager