miduo_client/Assets/ManagedResources/~Lua/Modules/ArenaTopMatch/ArenaTopMatchManager.lua

653 lines
22 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

ArenaTopMatchManager = {};
local this = ArenaTopMatchManager
function this.Initialize()
this.baseInfo = {}
this.myBattleInfo = {}
this.battleHistoryInfo = {}
this.myTeamRankInfo = {}
--- 竞猜数据
this.isCanBet = false -- 是否可以竞猜
this.betBattleInfo = {}
this.betRateInfo = {}
this.myBetTarget = nil
this.betHistoryInfo = {}
this.coinNum=0 --竞猜币临时数据
-- this.isGuessTipView=false--是否打开竞猜提示面板
-- 淘汰赛数据
this.EliminationData_32 = {}
this.EliminationData_4 = {}
--奖励数据
this.rewardData={}
for k, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.ChampionshipReward)) do
table.insert(this.rewardData, v)
end
-- 拍脸完成,获取一次基础数据,判断是否需要弹出巅峰赛拍脸
Game.GlobalEvent:AddEvent(GameEvent.PatFace.PatFaceSendFinish, function()
this.RequestTopMatchBaseInfo()
end)
-- 赛季结束时获取下一赛季的数据
Game.GlobalEvent:AddEvent(GameEvent.FunctionCtrl.OnFunctionClose, function(typeId)
if typeId == FUNCTION_OPEN_TYPE.TOP_MATCH then
this.RequestTopMatchBaseInfo()
end
end)
end
--- 判断巅峰战是否激活
function this.IsTopMatchActive()
return ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.TOP_MATCH)
end
--- 获取时间
function this.GetTopMatchTime()
local serData = ActTimeCtrlManager.GetSerDataByTypeId(FUNCTION_OPEN_TYPE.TOP_MATCH)
if serData then
return serData.startTime, serData.endTime
end
return
end
---=============巅峰战基础信息========================
-- 向服务器请求基础信息
function this.RequestTopMatchBaseInfo(func)
-- 获取巅峰战信息
NetManager.GetTopMatchBaseInfo(function(msg)
if not this.baseInfo then
this.baseInfo = {}
end
this.baseInfo.joinState = msg.joinState
this.baseInfo.progress = msg.progress
this.baseInfo.endTime = msg.endTime
this.baseInfo.myrank = msg.myrank
this.baseInfo.maxRank = msg.maxRank
this.baseInfo.myscore = msg.myscore
this.myBattleInfo = msg.championBattleInfo
this.RefreshBaseInfo()
-- 发送更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnTopMatchDataUpdate)
Log(string.format("巅峰战基础信息 state = %s, progress = %s, endTime = %s, myrank = %s", msg.joinState, msg.progress, msg.endTime, msg.myrank))
if func then func() end
end)
end
-- 阶段信息刷新
function this.UpdateTopMatchStage(msg)
-- 没有数据或者未开启时重新获取数据
if not this.baseInfo or not this.baseInfo.progress or this.baseInfo.progress <= 0 then
this.RequestTopMatchBaseInfo()
return
end
-- 获取新的阶段信息
this.baseInfo.progress = msg.progress
this.baseInfo.endTime = msg.endTime
Log(string.format("巅峰战阶段刷新 state = %s, progress = %s, endTime = %s, myrank = %s",
this.baseInfo.joinState, this.baseInfo.progress, this.baseInfo.endTime, this.baseInfo.myrank))
-- 刷新基础信息
this.RefreshBaseInfo()
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnTopMatchDataUpdate)
--刷新排行信息
Game.GlobalEvent:DispatchEvent(GameEvent.ATM_RankView.OnRankChange)
-- 切换到准备阶段刷新一遍数据
if this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_READY then
this.RequestTopMatchBaseInfo()
--this.RequestBetBaseInfo()
-- 竞猜阶段刷新竞猜数据
elseif this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_GUESS then
this.RequestBetBaseInfo()
-- 战斗阶段不刷新
--elseif this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_GUESS then
-- 切换到结算阶段刷新一遍所有数据
elseif this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_END then
this.RequestTopMatchBaseInfo()
this.RequestBetBaseInfo()
end
end
-- 获取战斗记录
function this.RequestBattleHistory(func)
-- 获取巅峰赛战斗记录
NetManager.GetTopMatchHistoryBattle(function(msg)
this.battleHistoryInfo = msg.enemyPairInfo
-- 对历史记录排序
table.sort(this.battleHistoryInfo, function(a, b)
return a.roundTimes > b.roundTimes
end)
Log("获取历史战斗记录成功 == "..#this.battleHistoryInfo)
if func then func() end
end)
end
-- 获取选拔赛小组排名数据
function this.RequestMyTeamRank(func)
--
NetManager.GetTopMatchMyTeamRank(function(msg)
this.myTeamRankInfo = msg.rankInfos
-- 对历史记录排序
table.sort(this.myTeamRankInfo, function(a, b)
return a.personInfo.rank < b.personInfo.rank
end)
Log("获取小组排名数据成功 == "..#this.myTeamRankInfo)
if func then func() end
end)
end
-- 刷新基础信息
function this.RefreshBaseInfo()
if this.baseInfo.progress == -1 then -- 未开始
this.baseInfo.battleStage = TOP_MATCH_STAGE.CLOSE
this.baseInfo.battleTurn = -1
this.baseInfo.battleState = TOP_MATCH_TIME_STATE.CLOSE
elseif this.baseInfo.progress == -2 then -- 已结束
this.baseInfo.battleStage = TOP_MATCH_STAGE.OVER
this.baseInfo.battleTurn = -2
this.baseInfo.battleState = TOP_MATCH_TIME_STATE.OVER
elseif this.baseInfo.progress > 0 then
local oldState = this.baseInfo.battleState
this.baseInfo.battleStage = tonumber(string.sub(this.baseInfo.progress, 1, 1))
this.baseInfo.battleTurn = tonumber(string.sub(this.baseInfo.progress, 2, 2))
this.baseInfo.battleState = tonumber(string.sub(this.baseInfo.progress, 3, 3))
-- 判断阶段切换,并检测是否需要弹窗提示
if UIManager.IsOpen(UIName.ArenaTopMatchPanel) then return end
if not this.IsTopMatchActive() then return end
if oldState ~= this.baseInfo.battleState then
if this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_READY and this.baseInfo.joinState == 1 then
--检测拍脸
Log("准备阶段 拍脸")
Game.GlobalEvent:DispatchEvent(GameEvent.PatFace.PatFaceSend,FacePanelType.Championship)
elseif this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_GUESS then
--检测拍脸
Log("竞猜阶段 拍脸")
Game.GlobalEvent:DispatchEvent(GameEvent.PatFace.PatFaceSend,FacePanelType.Championship)
end
end
end
end
-- 获取巅峰战基础信息
function this.GetBaseData()
return this.baseInfo
end
-- 获取对战信息
function this.GetBattleInfo()
return this.myBattleInfo
end
-- 获取历史战斗记录
function this.GetBattleHistory()
return this.battleHistoryInfo
end
-- 获取小组赛排名
function this.GetMyTeamRankInfo()
return this.myTeamRankInfo
end
--- =================== end ==========================
--- ====================竞猜相关=======================
--- 获取竞猜基础数据
function this.RequestBetBaseInfo(func)
-- 未开启
if not this.IsTopMatchActive() then
this.isCanBet = false
if func then func() end
return
end
-- 第一个准备阶段无竞猜信息
if this.baseInfo.battleStage == TOP_MATCH_STAGE.CHOOSE
and this.baseInfo.battleTurn == 1
and this.baseInfo.battleState == TOP_MATCH_TIME_STATE.OPEN_IN_READY then
this.isCanBet = false
if func then func() end
return
end
-- 积分赛不设置竞猜环节 32强才显示
if this.baseInfo.battleStage~=TOP_MATCH_STAGE.ELIMINATION then
this.isCanBet = false
if func then func() end
return
end
-- 获取巅峰战信息
NetManager.GetBetMatchInfo(0, function(msg)
this.betBattleInfo = msg.championBattleInfo
this.betRateInfo = msg.championBetInfo
this.myBetTarget = msg.winUid
Log(string.format("巅峰战赔率信息 myBetTarget = %s, betId = %s, redCoins = %s, blueCoins = %s", msg.winUid, msg.championBetInfo.id, msg.championBetInfo.redCoins, msg.championBetInfo.blueCoins))
-- 可以竞猜了
this.isCanBet = true
--
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnGuessDataUpdate)
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnGuessRateUpdate)
if func then func() end
end)
end
-- 刷新赔率信息
function this.RequestBetRateInfo(func)
-- 未开启
if not this.IsTopMatchActive() then
return
end
-- 不在竞猜阶段不刷新
if this.baseInfo.battleState ~= TOP_MATCH_TIME_STATE.OPEN_IN_GUESS then
return
end
-- 积分赛不设置竞猜环节 32强才显示
if this.baseInfo.battleStage~=TOP_MATCH_STAGE.ELIMINATION then return end
-- 获取巅峰战信息
NetManager.GetBetMatchInfo(1, function(msg)
this.betRateInfo = msg.championBetInfo
Log(string.format("巅峰战赔率信息 betId = %s, redCoins = %s, blueCoins = %s", msg.championBetInfo.id, msg.championBetInfo.redCoins, msg.championBetInfo.blueCoins))
--
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnGuessRateUpdate)
if func then func() end
end)
end
-- 请求下注
function this.RequestBet(uid, coins, func)
-- 未开启
if not this.IsTopMatchActive() then
return
end
-- 第一个准备阶段无竞猜信息
if this.baseInfo.battleState ~= TOP_MATCH_TIME_STATE.OPEN_IN_GUESS then
PopupTipPanel.ShowTip("非竞猜阶段无法参与竞猜")
return
end
-- 判断竞猜币是否足够
if coins == 0 then
PopupTipPanel.ShowTip("竞猜币数量不能为0")
return
end
local guessCoinId = ArenaTopMatchManager.GetGuessCoinID()
local haveNum = BagManager.GetItemCountById(guessCoinId)
if coins > haveNum then
PopupTipPanel.ShowTip("竞猜币数量超出拥有数量")
return
end
-- 判断是否已经参与过竞猜
if this.myBetTarget and this.myBetTarget ~= 0 then
-- 已经参与过竞猜
PopupTipPanel.ShowTip("您已参与过本轮竞猜,下一轮再来吧")
return
end
-- 获取巅峰战信息
NetManager.RequestBet(uid, coins, function()
-- 保存下注对象
this.myBetTarget = uid
-- 刷新
Game.GlobalEvent:DispatchEvent(GameEvent.TopMatch.OnGuessDataUpdate)
if func then func() end
end)
end
-- 获取历史竞猜信息
function this.RequestBetHistory(func)
-- 获取我得竞猜信息
NetManager.GetBetHistoryInfo(function(msg)
this.betHistoryInfo = msg.championMyBetDetails
-- 对历史记录排序
table.sort(this.betHistoryInfo, function(a, b)
return a.enemyPairInfo.roundTimes > b.enemyPairInfo.roundTimes
end)
Log("获取历史竞猜记录成功 == "..#this.betHistoryInfo)
if func then func() end
end)
end
-- 竞猜成功回调
function this.OnGuessSuccess(msg)
if this.isLogin then return end--上来就弹新关卡界面 所以不弹
if MapManager.isInMap or UIManager.IsOpen(UIName.BattlePanel) then return end--在关卡里 副本里不弹
UIManager.OpenPanel(UIName.GuessCoinDropPopup, msg.roundTimes, msg.itemId, msg.itemNum)
end
-- 判断是否可以竞猜
function this.IsCanBet()
return this.isCanBet
end
--- 获取竞猜战斗信息
function this.GetBetBattleInfo()
return this.betBattleInfo
end
--- 获取赔率信息
function this.GetBetRateInfo()
return this.betRateInfo
end
--- 获取我下注的对象
function this.GetMyBetTarget()
return this.myBetTarget
end
-- 获取历史竞猜记录
function this.GetBetHistory()
return this.betHistoryInfo
end
-- 设置竞猜币数量
function this.SetCoinNum(num)
this.coinNum=num
end
-- 获取竞猜币数量
function this.GetCoinNum()
return this.coinNum
end
--- =================== end ==========================
--- ======================32强赛数据=====================
--- 请求淘汰赛数据(32强)
function this.Request_32_EliminationData(func)
-- 未开启
if not this.IsTopMatchActive() then return end
--
if this.baseInfo.battleStage ~= TOP_MATCH_STAGE.ELIMINATION and this.baseInfo.battleStage~= TOP_MATCH_STAGE.OVER then return end
NetManager.GetTopMatchEliminationInfo(1, function(msg)
this.EliminationData_32 = msg.championBattlePairInfo
-- Log("获取32强数据成功, 数据长度 = "..#this.EliminationData_32)
if func then func() end
end)
end
--- 请求淘汰赛数据4强
function this.Request_4_EliminationData(func)
-- 未开启
if not this.IsTopMatchActive() then return end
--
if this.baseInfo.battleStage ~= TOP_MATCH_STAGE.ELIMINATION and this.baseInfo.battleStage~= TOP_MATCH_STAGE.OVER then return end
NetManager.GetTopMatchEliminationInfo(2, function(msg)
this.EliminationData_4 = msg.championBattlePairInfo
-- Log("获取4强数据成功, 数据长度 = "..#this.EliminationData_4)
if func then func() end
end)
end
--- 获取32强数据
function this.Get_32_EliminationData()
-- body
return this.EliminationData_32
end
-- 获取4强数据
function this.Get_4_EliminationData()
-- body
return this.EliminationData_4
end
--- =================== end ==========================
-- ==================== 其他接口==========================
-- 请求回放数据
function this.RequestRecordFightData(result, fightId, nameStr, func)
NetManager.FightRePlayRequest(2, fightId, function(msg)
local fightData = msg.fightData
if not fightData then
PopupTipPanel.ShowTip("获取回放数据失败")
return
end
-- local nameStr = fight.attackName.."|"..fight.defName
this.RequestReplayRecord(result, fightData, nameStr, func)
end)
end
--- 请求开始播放回放
--- isWin 战斗结果 1 胜利 0 失败
--- fightData 战斗数据
--- nameStr 交战双方名称
--- doneFunc 战斗播放完成要回调的事件
function this.RequestReplayRecord(isWin, fightData, nameStr, doneFunc)
local fightData, seed, fightType, maxTime = BattleManager.GetBattleServerData({fightData = fightData}, 1)
UIManager.OpenPanel(UIName.BattlePanel, fightData, seed, fightType, maxTime, "back#"..tostring(isWin).."#"..nameStr, 51034, doneFunc)
end
-- 获取当前阶段名称
function this.GetCurTopMatchName()
local titleName = "逐胜之巅"
local stageName = ""
if this.baseInfo.progress == -1 then
return titleName, "未开始", "即将开始"
elseif this.baseInfo.progress == -2 then
return titleName, "已结束", "已结束"
end
if this.baseInfo.battleStage == TOP_MATCH_STAGE.CHOOSE then
stageName = "选拔赛"..NumToSimplenessFont[this.baseInfo.battleTurn]
else
local maxTurn = this.GetEliminationMaxRound()
local curTurn = this.baseInfo.battleTurn
local opTurn = maxTurn - curTurn + 1 --- 将服务器发过来的轮数倒序,方便计算
if opTurn == 1 then
stageName = "决赛"
else
stageName = math.pow(2, opTurn) .. ""
end
end
local stateName = TOP_MATCH_STATE_NAME[this.baseInfo.battleState] or "未知"
return titleName, stageName, stateName
end
-- 通过总轮数获取当前阶段名称
function this.GetTurnNameByRoundTimes(roundTimes)
if not roundTimes or roundTimes <= 0 then
return "未开始"
end
-- 选拔赛
local maxRound = this.GetChooseMaxRound()
if roundTimes <= maxRound then
return "选拔赛"..NumToSimplenessFont[roundTimes]
end
-- 淘汰赛
local curTurn = roundTimes - maxRound -- 当前淘汰赛轮数
local maxTurn = this.GetEliminationMaxRound()
local opTurn = maxTurn - curTurn + 1 --- 将服务器发过来的轮数倒序,方便计算
if opTurn == 1 then
return "决赛"
else
return math.pow(2, opTurn) .. ""
end
return "未知"
end
-- 获取选拔赛最大轮数
local CHOOSE_MAX_ROUND
function this.GetChooseMaxRound()
if not CHOOSE_MAX_ROUND then
CHOOSE_MAX_ROUND = ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1).TrialsGroup - 1--选拔赛最大轮数 = 每组人数 - 1
end
return CHOOSE_MAX_ROUND
end
-- 获取淘汰赛最大轮数
local ELIMINATION_MAX_ROUND
function this.GetEliminationMaxRound()
if not ELIMINATION_MAX_ROUND then
local config = ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1)
local eliminationNum = config.ChampionshipPlayer/config.TrialsGroup*config.TrialsGroupWinner -- 参与淘汰赛得人数
ELIMINATION_MAX_ROUND = math.log(eliminationNum, 2)
end
return ELIMINATION_MAX_ROUND
end
-- 获取选拔赛每场积分变化值常量
function this.GetMatchDeltaIntegral()
return ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1).WinnerIntegral
end
-- 通过排名获取相应的排名位置
function this.GetRankNameByRank(rank)
--
if rank <= 0 then return "未上榜" end
local curStage = this.baseInfo.battleStage
local curTurn = this.baseInfo.battleTurn
local curState = this.baseInfo.battleState
--- 未获取到数据
if curStage == -1 or curTurn == -1 or curState == -1 then
return "未上榜"
end
--- 选拔赛阶段都是相应得强数
if curStage == 1 then
local config = ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1)
return config.ChampionshipPlayer..""
end
--- 判断淘汰赛阶段的轮数
local maxTurn = this.GetEliminationMaxRound()
if curTurn <= 0 then curTurn = maxTurn end
local opTurn = maxTurn - curTurn + 1 --- 将服务器发过来的轮数倒序,方便计算
--- 如果是结算状态,按下一轮处理
if curState == TOP_MATCH_TIME_STATE.OPEN_IN_END or curState == TOP_MATCH_TIME_STATE.OVER then
opTurn = opTurn - 1
end
--- 轮数为0表示决赛的结算阶段
if opTurn == 0 then
if rank == 1 then
return "冠军"
elseif rank == 2 then
return "亚军"
end
end
--- 如果大于淘汰赛最大轮数的最大名次
if rank > math.pow(2, maxTurn) then
local config = ConfigManager.GetConfigData(ConfigName.ChampionshipSetting, 1)
return config.ChampionshipPlayer..""
end
--- 如果小于当前轮数的最大排名,则返回当前轮数的名称
local opTurnMaxRank = math.pow(2, opTurn)
if rank <= opTurnMaxRank then
return opTurnMaxRank..""
end
--- 如果大于当前的轮数,则可能已被淘汰,返回相应的被淘汰轮数的名称
for turn = opTurn + 1, maxTurn do
local turnMaxRank = math.pow(2, turn)
if rank <= turnMaxRank then
return turnMaxRank..""
end
end
-- 数据没错的情况下不会出现这种情况
return "未上榜"
end
-- 竞猜币ID
function this.GetGuessCoinID()
return 77
end
-- -- 是否可换阵容
function this.CanChangeTeam()
if this.myBattleInfo.result ~= -1 then
return false
end
local state = this.baseInfo.battleState -- 当前阶段状态
local isJoin = this.baseInfo.joinState == 1 -- 参与状态
if isJoin and state == TOP_MATCH_TIME_STATE.OPEN_IN_READY then
return true
end
return false
end
--- =================== end ==========================
-----淘汰赛相关-----
-------------------
-----巅峰战排名相关-----
this.rankData={}--排行滚动数据
this.myRankData={} --我的数据
this.requestCountDown=1--允许请求倒计时
this.requestTimer=nil--允许请求计时器
this.CurPage=0
--请求排名数据
function this.RequestRankData(page,func)
-- if this.CurPage >= page or #this.rankData>128 then return end
-- this.CurPage=page
--防连续切标签不断请求数据
--if this.requestTimer~=nil then return end
--this.requestTimer = Timer.New(function()
-- this.requestCountDown=this.requestCountDown-1
-- if this.requestCountDown<0 then
-- this.requestCountDown=0
-- this.requestTimer:Stop()
-- this.requestTimer=nil
-- this.requestCountDown=1
-- end
--end, 1,-1)
--this.requestTimer:Start()
--if this.baseInfo.battleStage== TOP_MATCH_STAGE.ELIMINATION
-- and this.baseInfo.battleTurn > 0
-- or this.baseInfo.battleStage == TOP_MATCH_STAGE.OVER then
NetManager.GetTopMatchRankInfo(page,function(msg)
this.myRankData=msg.myInfo.personInfo
if page==1 then
this.rankData={}
end
local length=#this.rankData
for i, v in ipairs(msg.rankInfos) do
if v.personInfo.rank<=8 then
this.rankData[length+i]=v.personInfo
end
end
if func then
func()
end
-- for i, v in pairs(this.rankData) do
-- Log(tostring(v))
-- end
-- Log("<color=green>排行请求成功 请求页签"..page.."</color>")
-- Game.GlobalEvent:DispatchEvent(GameEvent.ATM_RankView.OnRankChange)
end)
--end
end
--获取排行数据
function this.GetRankData()
return this.rankData,this.myRankData
end
--请求下页数据
-- function this.GetNextRankData()
-- Log("请求下一页数据")
-- --判断是否符合刷新条件
-- local MaxNum = 128
-- if #this.rankData >= MaxNum then return end
-- --上一页数据少于20条则没有下一页数不再刷新
-- if #this.rankData % 20 > 0 then
-- return
-- end
-- this.RequestRankData(this.CurPage + 1)
-- end
----------------------
-----巅峰战奖励相关-----
--获取奖励数据
function this.GetRewardData()
return this.rewardData
end
----------------------
return this