local KingChallenge_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local king_challenge_pb = require('Proto/king_challenge_pb') local KING_CHALLENGE_BADGE_LIGHT_1V1 = "KING_CHALLENGE_BADGE_LIGHT_1V1" local KING_CHALLENGE_BADGE_LIGHT_3V3 = "KING_CHALLENGE_BADGE_LIGHT_3V3" KingChallenge_Model.KingChallengeRewardStatus = { RewardNotReach = king_challenge_pb.RewardNotReach, -- 未达成 RewardCanGet = king_challenge_pb.RewardCanGet, -- 可领取 RewardHasGet = king_challenge_pb.RewardHasGet -- 已领取 } function KingChallenge_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageOpenKingChallengePanel, private.OpenKingChallengePanelResponse) NetManager.RegisterMsgCB(MessageEnums.MessageKingChallengeReceiveReward, nil) private.curBigSeasonId = 0 -- 当前大赛季id private.lastBigSeasonId = 0 -- 上一次进入界面时的大赛季id private.rewardStatus = 0 -- 当赛季奖励状态 private.curLittleSeasonId = 1 -- 当前小赛季id private.curSeasonInfo = {} -- 当前大赛季信息 private.historySeasonInfo = {} -- 历史大赛季信息 end function KingChallenge_Model.GetCurBigSeasonId() return private.curBigSeasonId end function KingChallenge_Model.GetCurStartLittleSeasonId() return private.curSeasonInfo.startFairSeason end function KingChallenge_Model.GetCurLittleSeasonNum() return private.curSeasonInfo.seasonLong end function KingChallenge_Model.GetCurLittleSeasonId() return private.curLittleSeasonId end function KingChallenge_Model.GetCurSeasonInfo() return private.curSeasonInfo end function KingChallenge_Model.GetHistorySeasonInfo() return private.historySeasonInfo end function KingChallenge_Model.GetHistoryBigSeasonInfo(bigSeasonId) for _, seasonInfo in ipairs(private.historySeasonInfo) do if seasonInfo.seasonId == bigSeasonId then return seasonInfo end end logging.error(LTAG.ERROR," 未找到历史大赛季数据, 赛季Id为: ",bigSeasonId) return nil end function KingChallenge_Model.GetRewardStatus() return private.rewardStatus end --在当前大赛季中,某小赛季1v1是否达到王者 --return 是否达到王者,是否播放初次达到特效 function KingChallenge_Model.Is1V1ReachKingInCurBigSeason(littleSeasonId) for _, seasonId in ipairs(private.curSeasonInfo.successSoloSeasonIds) do if littleSeasonId == seasonId then if littleSeasonId ~= private.curLittleSeasonId then return true, false end local str = KING_CHALLENGE_BADGE_LIGHT_1V1 .. littleSeasonId if PersistentData.PlayerData:Get(str, false) then return true, false else PersistentData.PlayerData:Set(str, true, true) return true, true end end end return false, false end --在当前大赛季中,某小赛季3v3是否达到王者 --return 是否达到王者,是否播放初次达到特效 function KingChallenge_Model.Is3v3ReachKingInCurBigSeason(littleSeasonId) for _, seasonId in ipairs(private.curSeasonInfo.successTVTSeasonIds) do if littleSeasonId == seasonId then if littleSeasonId ~= private.curLittleSeasonId then return true, false end local str = KING_CHALLENGE_BADGE_LIGHT_3V3 .. littleSeasonId if PersistentData.PlayerData:Get(str, false) then return true, false else PersistentData.PlayerData:Set(str, true, true) return true, true end end end return false, false end --region ***************** 协议 ******************** function KingChallenge_Model.SyncSeasonInfo(info) logging.log(LTAG.LOG, "王者挑战enterWorld playerChange信息 ", info) private.curBigSeasonId = info.curSeason if private.curBigSeasonId == 0 then return end private.lastBigSeasonId = info.lastSeason if private.curLittleSeasonId ~= info.fairSeasonId then private.curLittleSeasonId = info.fairSeasonId if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIKingChallengeMainPanel) and private.curBigSeasonId == private.lastBigSeasonId then KingChallenge_Model.OpenKingChallengePanelRequest() end end if private.rewardStatus ~= info.rewardStatus then private.rewardStatus = info.rewardStatus EventSystem.Dispatch(EventID.UI_KingChallenge_RewardBoxRefresh) end if private.curBigSeasonId ~= private.lastBigSeasonId then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.FairPlay_KingChallenge) CTL.KingChallenge.CloseKingChallengeMainUI() elseif private.rewardStatus == KingChallenge_Model.KingChallengeRewardStatus.RewardCanGet then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.FairPlay_KingChallenge) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FairPlay_KingChallenge) end end -- 打开王者挑战主界面请求数据 function KingChallenge_Model.OpenKingChallengePanelRequest() local msg = NetManager.GetPB("king_challenge_op_pb").OpenKingChallengePanelReq() NetManager.SendMessage(MessageEnums.MessageOpenKingChallengePanel, msg) end function private.OpenKingChallengePanelResponse(msgResp) logging.log(LTAG.LOG, "打开王者挑战界面 ", msgResp) private.historySeasonInfo = msgResp.seasonInfo local bigSeasonCount = #private.historySeasonInfo if #private.historySeasonInfo > 0 then private.curSeasonInfo = table.remove(private.historySeasonInfo, bigSeasonCount) end EventSystem.Dispatch(EventID.UI_KingChallenge_MainRefresh) end -- 领奖 function KingChallenge_Model.KingChallengeReceiveRewardRequest() local msg = NetManager.GetPB("king_challenge_op_pb").KingChallengeReceiveRewardReq() NetManager.SendMessage(MessageEnums.MessageKingChallengeReceiveReward, msg) end return KingChallenge_Model