------ 彩金将-抽奖 local SuperGoldLottery_Controller = {} local private = {} local EventSystem = require("Event/EventSystem") function SuperGoldLottery_Controller.OnStartup() EventSystem.Regist(EventID.UI_SuperGoldLottery_RefreshRedPoint, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_RefreshCurrency, private.RefreshRedPoint) private.ActivityType = MDL.OperationActivity.ActivityType.SuperGold end --是否可以抽奖 function SuperGoldLottery_Controller.IsCanLottery(activityId) local currentTurnTableID = MDL.SuperGoldLottery.GetCurrentTurnTableID(activityId) local data = MDL.SuperGoldLottery.GetTurnTableInfo(activityId) for i,v in ipairs(data) do --代币数量满足消耗 且还有可以抽的 local isEnough = UTL.Item.GetItemStockCount(v.MoneyID) >= v.MoneyNum local isLock = v.TurnTableID > currentTurnTableID if SuperGoldLottery_Controller.IsHasLeftRewardInLayer(activityId,v.TurnTableID) and isEnough and not isLock then return true end end return false end --按奖池是否可以抽奖 function SuperGoldLottery_Controller.IsCanLotteryByTurnTableID(activityId,turnTableID) local currentTurnTableID = MDL.SuperGoldLottery.GetCurrentTurnTableID(activityId) local data = MDL.SuperGoldLottery.GetTurnTableInfo(activityId) for i,v in ipairs(data) do --代币数量满足消耗 且还有可以抽的 if v.TurnTableID == turnTableID then local isEnough = UTL.Item.GetItemStockCount(v.MoneyID) >= v.MoneyNum local isLock = turnTableID > currentTurnTableID if SuperGoldLottery_Controller.IsHasLeftRewardInLayer(activityId,v.TurnTableID) and isEnough and not isLock then return true end end end return false end --指定的奖池还有可以抽取的奖励 function SuperGoldLottery_Controller.IsHasLeftRewardInLayer(activityId,id) local hasGetReward = MDL.SuperGoldLottery.GetHasGetRewardInfoByLayer(activityId,id) local data = MDL.SuperGoldLottery.GetRewardByTurnTableID(id) if not hasGetReward then return true end if data and #data > #hasGetReward then return true end return false end --获取指定奖池剩余抽取次数 function SuperGoldLottery_Controller.GetRemainDrawCountByTurnTable(activityId,turnTableId) local hasGetReward = MDL.SuperGoldLottery.GetHasGetRewardInfoByLayer(activityId,turnTableId) local data = MDL.SuperGoldLottery.GetRewardByTurnTableID(turnTableId) if not hasGetReward then return #data end return #data - #hasGetReward end --奖励是否已经领取 function SuperGoldLottery_Controller.IsHasGetReward(activityId,turnTableID,rewardID) local hasGetReward = MDL.SuperGoldLottery.GetHasGetRewardInfoByLayer(activityId,turnTableID) if not hasGetReward then return false end for i,v in ipairs(hasGetReward) do if v == rewardID then return true end end return false end --是否显示奖励UI (这里先不显示通用的奖励UI,稍后再显示) function SuperGoldLottery_Controller.IsDelayDisplayReward() if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISuperGoldLotteryMain) then return true end return false end --获取奖励数据 function SuperGoldLottery_Controller.GetRewardData(turnTableID,rewardID) local data = DataSheetManager.SuperGoldTurntableReward:GetDataByTurnTableID_RewardID(turnTableID,rewardID) return data end function SuperGoldLottery_Controller.OpenMainPanel(activityId) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISuperGoldLotteryMain,{activityId = activityId}) end --获取概率预览数据 function SuperGoldLottery_Controller.GetProbabilityData(turnTableID) local rewardList = MDL.SuperGoldLottery.GetRewardByTurnTableID(turnTableID) local result = {} --计算总概率 local totalWeight = 0 for i,v in ipairs(rewardList) do totalWeight = totalWeight + v.Weight end --填充概率数据 for i,v in ipairs(rewardList) do local data = {Item = v.Item, Num = v.Num, Weight = v.Weight, Probability = v.Weight/totalWeight} table.insert(result,data) end table.sort(result,private.SortByWeight) return result end --权重从小到大排序 function private.SortByWeight(a,b) return a.Weight < b.Weight end function private.RefreshRedPoint() if MDL.OperationActivity.HotControlInfo then local info = MDL.OperationActivity.HotControlInfo:GetDataByActivityType_ActivityID(private.ActivityType) if info then for i, v in pairs(info) do local activityId = v.ActivityID if not MDL.SuperGoldMain.GetHeroTypeByActivityId(activityId) then return end local rpEventId = CTL.SuperGoldMain.RpEventId[activityId] if rpEventId then local isCanLottery = SuperGoldLottery_Controller.IsCanLottery(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(isCanLottery, rpEventId.TownHome, rpEventId.SuperGoldLottery) else CTL.SuperGoldMain.InitLotteryRedPointTreeByActivityId(v.ActivityID) end end end end end return SuperGoldLottery_Controller