164 lines
5.6 KiB
Lua
164 lines
5.6 KiB
Lua
local DailyChallengeManager = class("DailyChallengeManager", BaseModule)
|
|
|
|
function DailyChallengeManager:init()
|
|
self.sid = self:scheduleGlobal(function()
|
|
self:onDayChange()
|
|
end, DataManager.DailyChallengeData:getTodaySurplusTime())
|
|
end
|
|
|
|
function DailyChallengeManager:showBattleBuffUI()
|
|
UIManager:showUI("app/ui/battle/battle_daily_challenge_buff_ui")
|
|
end
|
|
|
|
function DailyChallengeManager:showBattleTaskUI()
|
|
UIManager:showUI("app/ui/daily_challenge/daily_challenge_task_ui")
|
|
end
|
|
|
|
function DailyChallengeManager:getBuffDesc(id)
|
|
local desc = I18N:getText("buff_daily_challenge", id, "desc")
|
|
return desc
|
|
end
|
|
|
|
-- 开始挑战
|
|
function DailyChallengeManager:startChallenge()
|
|
Logger.logHighlight("开始每日挑战")
|
|
-- 判断次数
|
|
if not DataManager.DailyChallengeData:isEnoughChallengeTime() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.DAILY_CHALLENGE_DESC_1))
|
|
return
|
|
end
|
|
|
|
-- 判断体力
|
|
if not DataManager.DailyChallengeData:isEnoughHp() then
|
|
GFunc.showItemNotEnough(GConst.ItemConst.ITEM_ID_VIT)
|
|
ModuleManager.CommerceManager:showBuyVitUI()
|
|
return
|
|
end
|
|
|
|
-- 检查阵容
|
|
if not ModuleManager.FormationManager:formationIsFull() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_8))
|
|
return
|
|
end
|
|
|
|
if not DataManager.DailyChallengeData:isMeetChallenge() then
|
|
return
|
|
end
|
|
|
|
local cost = DataManager.DailyChallengeData:getChallengeHpCost()
|
|
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 = {}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterDailyChallengeStartReq, parmas, {}, self.rspStartChallenge, BIReport.ITEM_GET_TYPE.DAILY_CHALLENGE)
|
|
end
|
|
|
|
function DailyChallengeManager:rspStartChallenge(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
DataManager.DailyChallengeData:setFixedChapterId(result.today_fixed_chapter_id)
|
|
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.DAILY_CHALLENGE)
|
|
end
|
|
end
|
|
|
|
-- 挑战结束
|
|
function DailyChallengeManager:endChallenge(chapterId, combatReport, taskProgress, heroInfo, lastBossRound)
|
|
local parmas = {
|
|
win = combatReport.victory,
|
|
chapter_id = chapterId,
|
|
pass_wave = combatReport.wave,
|
|
hero_info = heroInfo,
|
|
kills_boss_turn = lastBossRound,
|
|
combatReport = combatReport,
|
|
}
|
|
for fieldName, value in pairs(taskProgress) do
|
|
parmas[fieldName] = value
|
|
end
|
|
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterSettlementReq, parmas, {}, self.endChallengeFinish, BIReport.ITEM_GET_TYPE.DAILY_CHALLENGE_END)
|
|
end
|
|
|
|
function DailyChallengeManager:endChallengeFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
local reqData = result.reqData
|
|
local rewards = result.rewards
|
|
ModuleManager.BattleManager:showBattleResultUI(rewards, reqData.combatReport)
|
|
DataManager.DailyChallengeData:init(result.daily_challenge)
|
|
|
|
ModuleManager.TaskManager:addFightTaskProgress(reqData)
|
|
end
|
|
end
|
|
|
|
function DailyChallengeManager:onDayChange()
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterDailyChallengeResetReq, nil, {}, self.rspDayChange, BIReport.ITEM_GET_TYPE.DAILY_CHALLENGE_RESET)
|
|
end
|
|
|
|
function DailyChallengeManager:rspDayChange(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
DataManager.DailyChallengeData:init(result.daily_challenge)
|
|
end
|
|
end
|
|
|
|
-- 获取波次(战斗)奖励
|
|
function DailyChallengeManager:getWaveReward()
|
|
-- body
|
|
end
|
|
|
|
-- 获取任务(箱子)奖励
|
|
function DailyChallengeManager:getTaskReward(taskId)
|
|
-- 跨天通关时,不算完成第二天的任务
|
|
end
|
|
|
|
function DailyChallengeManager:dealTaskProgress(battleController)
|
|
local teamEntity = battleController.battleData:getAtkTeam()
|
|
local members = teamEntity:getAllMembers()
|
|
local heroInfo = {}
|
|
for k, v in pairs(members) do
|
|
heroInfo[v:getId()] = {
|
|
skill_cast = v:getActiveSkillReleaseCount(),
|
|
Damage = v:getDamageCount(),
|
|
}
|
|
end
|
|
|
|
local comboOver10Count = battleController.taskProgress[GConst.BattleConst.BATTLE_TASK_FIELD.COMBO_OVER_10]
|
|
local linkCountOver8Count = battleController.taskProgress[GConst.BattleConst.BATTLE_TASK_FIELD.LINK_COUNT_OVER_8]
|
|
|
|
local skillCountMap = {}
|
|
local damageMatchTypeMap = {}
|
|
local damageHeroMap = {}
|
|
local totalDmg = 0
|
|
for heroId, info in pairs(heroInfo) do
|
|
local entity = DataManager.HeroData:getHeroById(heroId)
|
|
if entity then
|
|
skillCountMap[entity:getMatchType()] = info.skill_cast
|
|
damageMatchTypeMap[entity:getMatchType()] = info.Damage
|
|
damageHeroMap[heroId] = info.Damage
|
|
totalDmg = totalDmg + info.Damage
|
|
end
|
|
end
|
|
|
|
for matchType, damage in pairs(damageMatchTypeMap) do
|
|
damageMatchTypeMap[matchType] = math.floor(damage / totalDmg * GConst.BattleConst.DEFAULT_FACTOR + 0.000001)
|
|
end
|
|
|
|
for heroId, damage in pairs(damageHeroMap) do
|
|
damageHeroMap[heroId] = math.floor(damage / totalDmg * GConst.BattleConst.DEFAULT_FACTOR + 0.000001)
|
|
end
|
|
|
|
local taskProgress = {
|
|
[3] = comboOver10Count,
|
|
[4] = linkCountOver8Count,
|
|
[5] = skillCountMap,
|
|
[7] = damageHeroMap,
|
|
[8] = damageMatchTypeMap
|
|
}
|
|
return taskProgress
|
|
end
|
|
|
|
return DailyChallengeManager |