local Purchase_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local purchase_pb = require 'Proto.purchase_pb' function Purchase_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessagePurchaseNums, private.PurchaseNumsResp) NetManager.RegisterMsgCB(MessageEnums.MessagePurchaseItems, private.PurchaseItemsResp) end --可购买总次数:原系统配置的初始次数+其他收益增加的次数 function private.GetPurchaseTotalNums(type) local num = DataSheetManager.ActivityData:GetDataByID(type).DailyPayTimes --官职收益 local addValue = MDL.OfficialPosition.GetProfitBuyTimes(type) return num + addValue end --获取活动的剩余可购买次数 function Purchase_Model.GetAvailablePurchaseTimes(type) if type == LuaConst.ActivityType.GuildMine then local dataCount = DataSheetManager.MinePlunderCost:GetDataCount() local purchaseNums = MDL.GuildMine.GetMinePurchaseNum() return dataCount - purchaseNums else local hasPurchaseTimes = Purchase_Model.GetPurchaseNumsByType(type) local totalTimes = private.GetPurchaseTotalNums(type) return totalTimes - hasPurchaseTimes end end function Purchase_Model.GetPurchaseNumsByType(type) local hasPurchaseNums = 0 if type == LuaConst.ActivityType.HeroBiography then hasPurchaseNums = MDL.Biography.GetPurchaseNums() elseif type == LuaConst.ActivityType.OffLineSoloFight then hasPurchaseNums = MDL.SoloFight.GetPurchaseNums() elseif type == LuaConst.ActivityType.ThreeTeamFight then hasPurchaseNums = MDL.ThreeTeamFight.GetPurchaseNums() elseif type == LuaConst.ActivityType.WorldBoss then hasPurchaseNums = MDL.WorldBoss.PayRewardCount elseif type == LuaConst.ActivityType.CountryWorldBoss then hasPurchaseNums = MDL.CountryWorldBoss.GetPayRewardCount() elseif type == LuaConst.ActivityType.ResourcesChapterChild1 or type == LuaConst.ActivityType.ResourcesChapterChild2 or type == LuaConst.ActivityType.ResourcesChapterChild3 then local data = MDL.MaterialLevel.GetDataBychapterId(type) hasPurchaseNums = data and data.purchaseNums or 0 end return hasPurchaseNums end function Purchase_Model.PurchaseNumsReq(typeId, times) local msg = purchase_pb.PurchaseNumsReq() msg.type = typeId msg.nums = times NetManager.SendMessage(MessageEnums.MessagePurchaseNums, msg) end function private.PurchaseNumsResp(msgResp) if msgResp.Resp.Code == 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OfflineSoloFight_BuyTimes_BuySuccess"]) CTL.Sound.PlayGameSound("UI_jeweled_03") EventSystem.Dispatch(EventID.UI_PurchaseNumsSuccess) end end -- ----------------------购买道具数量----------------------- function Purchase_Model.PurchaseItemsReq(itemId, count, activityId, activityType) local msg = purchase_pb.PurchaseItemsReq() msg.activityId = activityId or 0 msg.activityType = activityType or 0 msg.itemId = itemId msg.nums = count NetManager.SendMessage(MessageEnums.MessagePurchaseItems, msg) end function private.PurchaseItemsResp(msgResp) if msgResp.Resp.Code == 0 then local itemId = msgResp.itemId CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_BuySuccess) EventSystem.Dispatch(EventID.UI_Shop_RefreshShopInfo, itemId) --EventSystem.Dispatch(EventID.UI_Shop_Buy_Success) --目前无用 先保留EventID EventSystem.Dispatch(EventID.UI_DrawCard_Refresh_MainUI) EventSystem.Dispatch(EventID.UI_Gacha_RefreshGet_CostInfo) EventSystem.Dispatch(EventID.UI_PayMall_RefreshMain) EventSystem.Dispatch(EventID.UI_PayMall_RefreshPopUp) EventSystem.Dispatch(EventID.UI_GachaShop_Refresh) EventSystem.Dispatch(EventID.UI_GachaShop_RefreshPopUp) EventSystem.Dispatch(EventID.UI_GachaLimit_Refresh) EventSystem.Dispatch(EventID.UI_GachaLimit_RefreshGet_CostInfo) EventSystem.Dispatch(EventID.Monopoly_Store_Refresh) EventSystem.Dispatch(EventID.UI_Monopoly_RefreshMain) EventSystem.Dispatch(EventID.UI_OACommon_StoreRefresh) end end return Purchase_Model