98 lines
2.6 KiB
Lua
98 lines
2.6 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:startFight(params, callback)
|
|
local result = {
|
|
status = 1
|
|
}
|
|
local cost = GFunc.getConstReward("chapter_cost")
|
|
if cost == nil then
|
|
if callback then
|
|
callback(result)
|
|
end
|
|
return
|
|
end
|
|
local vitCostNum = GFunc.getRewardNum(cost)
|
|
local ServerGameData = ServerDataManager:getServerGameData()
|
|
if vitCostNum > ServerGameData.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) then
|
|
if callback then
|
|
callback(result)
|
|
end
|
|
return
|
|
end
|
|
ServerGameData.ChapterData:enterFight(params.id)
|
|
result.cost = ServerGameData:addCosts({cost})
|
|
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)
|
|
ServerGameData.HeroData:tryUnlockHeroByChapterId(ServerGameData.ChapterData:getMaxChapterId())
|
|
result.rewards = ServerGameData:addRewards(rewards)
|
|
result.chapterData = ServerGameData.ChapterData:getCloneData()
|
|
result.status = 0
|
|
|
|
if callback then
|
|
callback(result)
|
|
end
|
|
end
|
|
|
|
return ServerChapterManager |