local TreasureBowl_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local activity_treasure_bowl_pb = require('Proto.activity_treasure_bowl_pb') function TreasureBowl_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageActivityTreasureBowl, private.TreasureBowlResp) NetManager.RegisterMsgCB(MessageEnums.MessageGetTreasureBowlHistory, private.GetTreasureBowlHistoryResp) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushTreasureBowlHistory, private.TreasureBowlHistoryPush) private.drawCount = {} private.rechargeNum = {} private.drawBowlPlayerInfo = {} private.activityId = 0 end function TreasureBowl_Model.GetActivityId() return private.activityId end function TreasureBowl_Model.GetDrawCount(activityId) return private.drawCount[activityId] or 0 end function TreasureBowl_Model.GetRechargeNum(activityId) return private.rechargeNum[activityId] or 0 end function TreasureBowl_Model.GetPlayerInfo(activityId) return private.drawBowlPlayerInfo[activityId] or {} end function TreasureBowl_Model.SetBowlInfo(treasureBowlInfo) for i, v in ipairs(treasureBowlInfo) do private.activityId = v.activityId private.drawCount[private.activityId] = v.drawCount private.rechargeNum[private.activityId] = v.rechargeNum end EventSystem.Dispatch(EventID.UI_TreasureBowl_SelfInfoUpdate) end function TreasureBowl_Model.TreasureBowlReq(activityId, treasureBowlId) local msg = activity_treasure_bowl_pb.ActivityTreasureBowlReq() msg.activityId = activityId msg.treasureBowlId = treasureBowlId MDL.Reward.SetCloseRewardTipShow(true) NetManager.SendMessage(MessageEnums.MessageActivityTreasureBowl, msg) end function private.TreasureBowlResp(msgResp) if msgResp.Resp.Code == 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureBowlReward, {reward = msgResp.rewardItems[1]}) MDL.Reward.SetCloseRewardTipShow(false) end end function TreasureBowl_Model.GetTreasureBowlHistoryReq(activityId) local msg = activity_treasure_bowl_pb.GetTreasureBowlHistoryReq() msg.activityId = activityId NetManager.SendMessage(MessageEnums.MessageGetTreasureBowlHistory, msg) end function private.GetTreasureBowlHistoryResp(msgResp) if msgResp.Resp.Code == 0 then private.SetDrawBowlPlayerInfo(msgResp.activityId, msgResp.drawBowlPlayerInfo) end end function private.TreasureBowlHistoryPush(msg) private.SetDrawBowlPlayerInfo(msg.activityId, msg.drawBowlPlayerInfo) end function private.SetDrawBowlPlayerInfo(activityId, info) private.drawBowlPlayerInfo[activityId] = info EventSystem.Dispatch(EventID.UI_TreasureBowl_PlayerDrawInfoUpdate) end -- 可用次数 function TreasureBowl_Model.GetTreasureBowlAvailableCount() local rechargeNum = TreasureBowl_Model.GetRechargeNum(private.activityId) local availableCount = 0 for i, v in MDL.OperationActivity.TreasureBowlReward:GetEnumeratorByActivityID(private.activityId) do if rechargeNum >= v.NeedRecharge then availableCount = availableCount + 1 end end return availableCount - TreasureBowl_Model.GetDrawCount(private.activityId) end return TreasureBowl_Model