local Monopoly_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local monopoly_pb = require 'Proto/monopoly_pb' local DiceStoreIdLimit = 9901 local DiceStoreId = 9902 local DiceItemID = 31 local SuperDiceItemID = 231 local CoinItemID = 32 local SuperCoinItemID = 232 Monopoly_Controller.PointType = { ZeroPoint = 1, TopRewardPoint = 2, NormalRewardPoint = 3, LowerRewardPoint = 4 } Monopoly_Controller.TaskStateType = { UnDone = monopoly_pb.UnDone, Done = monopoly_pb.Done, Claimed = monopoly_pb.Commit } --------------------------------------- 系统函数 ------------------------------------------ function Monopoly_Controller.OnStartup() EventSystem.Regist(EventID.UI_OperationActivity_DataChanged, private.OnAllGoodsDataChanged) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.RefreshInfoByFunction) private.ActivityType = MDL.OperationActivity.ActivityType.Monopoly private.rewardParams = { passRewards = nil, stepRewards = nil, roundRewards = nil } private.triggerParams = { UnlockCondition = 0, UnlockConditionParamA = "", UnlockConditionParamB = "", UnlockConditionDes = "", ItemSourceID = 0 } Monopoly_Controller.RpEventId = {} private.pointCfgs = {} private.pointCount = {} private.taskInfos = {} private.taskInfoDict = {} private.TabID = {} private.goods = {} end function Monopoly_Controller.OnShutdown() private.rewardParams = nil private.pointCfgs = nil private.goods = nil private.taskInfos = nil private.taskInfoDict = nil private.limitDiceStoreData = nil private.diceStoreData = nil end ------------------------------------------------------------------------------------------- --------------------------------- 对外接口 ------------------------------------------------- -- 获取地图点的配置 function Monopoly_Controller.GetMapPointInfo(activityId,index) return private.pointCfgs[activityId][index] end function Monopoly_Controller:GetMapPointCount(activityId) return private.pointCount[activityId] end function Monopoly_Controller:GetLoopRewardCount(activityId) if not MDL.OperationActivity.MonopolyLoopReward or MDL.OperationActivity.MonopolyLoopReward:GetDataLengthByActivityID(activityId) == 0 then logging.error(LTAG.ERROR, "大富翁活动的圈数奖励配置不存在") return 0 end return MDL.OperationActivity.MonopolyLoopReward:GetDataLengthByActivityID(activityId) end function Monopoly_Controller:GetLoopRewardCfg(loopID, activityId) if not MDL.OperationActivity.MonopolyLoopReward or Monopoly_Controller:GetLoopRewardCount(activityId) == 0 then logging.error(LTAG.ERROR, "大富翁活动的圈数奖励配置不存在") return nil end if loopID then return MDL.OperationActivity.MonopolyLoopReward:GetDataByActivityID_LoopID(activityId, loopID) end return nil end function Monopoly_Controller.GetNextLoopRewardCfg(activityId) if not MDL.OperationActivity.MonopolyLoopReward or Monopoly_Controller:GetLoopRewardCount(activityId) == 0 then logging.error(LTAG.ERROR, "大富翁活动的圈数奖励配置不存在") return nil end local curRound = MDL.Monopoly.GetCurMapRound() for i = 1, Monopoly_Controller:GetLoopRewardCount(activityId) do local cfg = Monopoly_Controller:GetLoopRewardCfg(i, activityId) if curRound < cfg.LoopNum then return cfg end end local finalLoopRewardCfg = Monopoly_Controller:GetLoopRewardCfg(Monopoly_Controller:GetLoopRewardCount(activityId),activityId) return curRound >= finalLoopRewardCfg.LoopNum and finalLoopRewardCfg or Monopoly_Controller:GetLoopRewardCfg(1,activityId) end --------------------------------------------------------------------------------------------- --- function Monopoly_Controller.InitMonoplyHotDatas(activityId) if not private.limitDiceStoreData then private.limitDiceStoreData = MDL.OperationActivity.StoreGoodsData:GetDataByID(DiceStoreIdLimit) end if not private.diceStoreData then private.diceStoreData = MDL.OperationActivity.StoreGoodsData:GetDataByID(DiceStoreId) end if activityId == 0 then return end -- 更新大富翁点位奖励相关 if MDL.OperationActivity.MonopolyPointType and MDL.OperationActivity.MonopolyPointReward then if not private.pointCfgs[activityId] then private.pointCount[activityId] = MDL.OperationActivity.MonopolyPointType:GetDataLengthByActivityID(activityId) private.pointCfgs[activityId] = LuaExt.CreateTable(private.pointCount[activityId]) for _, v in MDL.OperationActivity.MonopolyPointType:GetEnumeratorByActivityID(activityId) do private.pointCfgs[activityId][v.PointID] = { type = v.PointType, StopReward = nil, PassReward = nil } local pointRewardCfg = MDL.OperationActivity.MonopolyPointReward:GetDataByActivityID_PointType(activityId, v.PointType) if pointRewardCfg.PassRewardID > 0 then private.pointCfgs[activityId][v.PointID].PassReward = {ItemID = pointRewardCfg.PassRewardID, ItemNum = pointRewardCfg.PassRewardNum} end end else for pointID, v in pairs (private.pointCfgs[activityId]) do -- 更新类型 local pointCfg = MDL.OperationActivity.MonopolyPointType:GetDataByActivityID_PointID(activityId, pointID) v.type = pointCfg.PointType -- 更新奖励 local pointRewardCfg = MDL.OperationActivity.MonopolyPointReward:GetDataByActivityID_PointType(activityId, v.type) if pointRewardCfg.PassRewardID > 0 then if v.PassReward then v.PassReward.ItemID = pointRewardCfg.PassRewardID v.PassReward.ItemNum = pointRewardCfg.PassRewardNum else v.PassReward = {ItemID = pointRewardCfg.PassRewardID, ItemNum = pointRewardCfg.PassRewardNum} end else v.PassReward = nil end end end EventSystem.Dispatch(EventID.Monopoly_Point_Refresh, activityId) end -- 更新圈数奖励 EventSystem.Dispatch(EventID.Monopoly_LoopReward_Refresh, activityId) -- 更新任务 if MDL.OperationActivity.TaskRewardData[private.ActivityType] then if not private.taskInfos[activityId] then private.taskInfos[activityId] = {} private.taskInfoDict[activityId] = {} else table.clearArray(private.taskInfos[activityId]) table.clearArray(private.taskInfoDict[activityId]) end local taskInfos, taskInfoDict = private.taskInfos[activityId], private.taskInfoDict[activityId] for _, v in pairs (MDL.OperationActivity.TaskRewardData[private.ActivityType]:GetDataByActivityID_ID(activityId)) do if not taskInfos[v.TaskType] then taskInfos[v.TaskType] = {} end local taskInfo = setmetatable({taskState = Monopoly_Controller.TaskStateType.UnDone, triggerData = MDL.OperationActivity.HotGenCondID:GetDataByCondID(v.CondID)}, {__index = v}) table.insert(taskInfos[v.TaskType], taskInfo) taskInfoDict[v.ID] = taskInfo end EventSystem.Dispatch(EventID.UI_Monopoly_RefreshTasks, activityId, true) end -- 更新商品 if MDL.OperationActivity.ActivityBaseData[private.ActivityType] then local backgroundCfg = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) if backgroundCfg then if private.TabID[activityId] ~= backgroundCfg.StoreID then private.TabID[activityId] = backgroundCfg.StoreID private.OnGoodsDataChanged(activityId) end end end end function private.OnGoodsDataChanged(activityId) if private.TabID[activityId] ~= 0 then if private.goods[activityId] then table.clearArray(private.goods[activityId]) else private.goods[activityId] = {} end for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.TabID == private.TabID[activityId] then table.insert(private.goods[activityId], v) end end table.sort(private.goods[activityId], private.SortGoods) EventSystem.Dispatch(EventID.Monopoly_Store_Refresh, activityId, true) end end function private.OnAllGoodsDataChanged() local aidList = MDL.Monopoly.GetActivityIdList() for _, v in ipairs(aidList) do private.OnGoodsDataChanged(v) end end -- 显示奖励结果 function Monopoly_Controller.ShowPassAndStepRewardTips(optResult) if (optResult.passReward and #optResult.passReward > 0) or (optResult.stepReward and #optResult.stepReward > 0) then Monopoly_Controller.SetRewardParams(optResult.passReward, optResult.stepReward, nil) UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyRewardTip) else EventSystem.Dispatch(EventID.UI_Monopoly_PlayNewRoundRewardEffect) end end function Monopoly_Controller.ShowRoundRewardEft(optResult) if optResult.roundReward and #optResult.roundReward > 0 then Monopoly_Controller.SetRewardParams(nil, nil, optResult.roundReward) UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyRewardTip,{isRoundReward = true}) end end function Monopoly_Controller.SetRewardParams(passRewards, stepRewards, roundRewards) private.rewardParams.passRewards = passRewards private.rewardParams.stepRewards = stepRewards private.rewardParams.roundRewards = roundRewards end function Monopoly_Controller.GetRewardParams() return private.rewardParams end function Monopoly_Controller.GetGoodCount(activityId) return #private.goods[activityId] end function Monopoly_Controller.GetGoodByIndex(activityId, index) return private.goods[activityId][index] end function Monopoly_Controller.SortGoods(activityId) table.sort(private.goods[activityId], private.SortGoods) end function Monopoly_Controller.GetActivitySameQualityTreasure(activityId, treasureId) local sameQualityTreasure = {} local selectTreasureInfo = {} local curTreasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) for _, goodData in ipairs(private.goods[activityId]) do local itemData = DataSheetManager.ItemData:GetDataByID(goodData.ItemID) if itemData.FirstType == LuaConst.ItemType.Treasure and itemData.Color == curTreasureData.TreasureQuality then local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(itemData.BelongerID) if treasureData.TreasureID == treasureId then selectTreasureInfo = treasureData else table.insert(sameQualityTreasure, treasureData) end end end return sameQualityTreasure, selectTreasureInfo end function private.SortGoods(a, b) if a.IsRareItem == b.IsRareItem then if a.SortID == b.SortID then return a.ID < b.ID end return a.SortID > b.SortID end return a.IsRareItem == true and b.IsRareItem == false end function Monopoly_Controller.UpdateTaskInfos(activityId, taskParams) local taskInfoDict = private.taskInfoDict[activityId] if type(taskParams) == "number" then if taskInfoDict[taskParams] then taskInfoDict[taskParams].taskState = monopoly_pb.Commit end else for _, v in ipairs (taskParams) do if taskInfoDict[v.taskId] then taskInfoDict[v.taskId].taskState = v.taskState end end end -- 重新排序 for _, taskList in pairs (private.taskInfos[activityId]) do table.sort(taskList, private.SortTasks) end end function Monopoly_Controller.GetTaskInfos(activityId) return private.taskInfos[activityId] end function Monopoly_Controller.GetTaskListCountByType(activityId, taskType) if taskType and private.taskInfos[activityId] and private.taskInfos[activityId][taskType] then return #private.taskInfos[activityId][taskType] end return nil end function Monopoly_Controller.GetTaskInfoByTypeAndIndex(activityId, taskType, index) if taskType and private.taskInfos[activityId] and private.taskInfos[activityId][taskType] and index then local taskList = private.taskInfos[activityId][taskType] return taskList[index] end return nil end function Monopoly_Controller.GetFirstDoneTaskType(activityId) for taskType, _ in pairs (private.taskInfos[activityId]) do if Monopoly_Controller.HasTaskTypeRp(activityId, taskType) then return taskType end end return nil end function Monopoly_Controller.HasTaskTypeRp(activityId, taskType) if taskType and private.taskInfos[activityId][taskType] then local taskList = private.taskInfos[activityId][taskType] return taskList[1] and taskList[1].taskState == monopoly_pb.Done end return false end function Monopoly_Controller.HasGiftRp(activityId) for _, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.StageUnlock, activityId) do local sheetData = v.data or nil if sheetData and sheetData.IsFree and v.state == MDL.DirectGift.GiftStateEnum.Available and (sheetData.LimitType == LuaConst.LimitBuyType.NoLimit or sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(v.activityId, v.giftId) > 0) then return true end break end for _, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, activityId) do local sheetData = v.data or nil if sheetData and sheetData.IsFree and v.state == MDL.DirectGift.GiftStateEnum.Available and (sheetData.LimitType == LuaConst.LimitBuyType.NoLimit or sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(v.activityId, v.giftId) > 0) then return true end end return false end function private.SortTasks(a, b) if a.taskState == b.taskState then return a.ID < b.ID end return a.taskState < b.taskState end function Monopoly_Controller.CondData2TriggerParams(condData) if condData and condData[1] then local triggerType = DataSheetManager.TriggerType:GetDataByID(condData[1].Trigger) if triggerType then private.triggerParams.UnlockCondition = condData[1].Trigger private.triggerParams.UnlockConditionParamA = condData[1].Param1 private.triggerParams.UnlockConditionParamB = condData[1].Param2 private.triggerParams.UnlockConditionDes = triggerType.TaskDesText private.triggerParams.ItemSourceID = 0 end end end function Monopoly_Controller.GetTriggerParams() return private.triggerParams end function Monopoly_Controller.IsDice(activityId, itemID) local itemId = Monopoly_Controller.GetDiceItemID(activityId) return itemID == itemId end function Monopoly_Controller.GetDiceItemID(activityId) local _, itemId = MDL.Monopoly.GetMoneyAndItemShow(activityId) if itemId == nil then itemId = Monopoly_Controller.IsSuperGold(activityId) and SuperDiceItemID or DiceItemID end return itemId end function Monopoly_Controller.GetDiceStoreData() if CTL.PayMall.IsSoldOut(private.limitDiceStoreData) then return private.diceStoreData end return private.limitDiceStoreData end function Monopoly_Controller.TryUseItemByCfgId(cfgId) local data = DataSheetManager.ItemData:GetDataByID(cfgId) local isSuperGold = data.SecondType == LuaConst.ItemActivityType.SuperGoldMonopolyDice local activityId = MDL.Monopoly.GetActivityIdByQuality(isSuperGold) if MDL.Monopoly.IsOpenMonopolyActivity(activityId) then Monopoly_Controller.OpenMainPanel(activityId) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_TeamIn_OutOfTime"]) end end function Monopoly_Controller.HandleItemSourceJump(itemId) local superGoldAid = MDL.Monopoly.GetActivityIdByQuality(true) if superGoldAid and not MDL.Monopoly.IsOpenMonopolyActivity(superGoldAid) then superGoldAid = nil end local goldAid = MDL.Monopoly.GetActivityIdByQuality(false) if goldAid and not MDL.Monopoly.IsOpenMonopolyActivity(goldAid) then goldAid = nil end --上面两个活动id筛选好了,现在判断跳转哪个活动。如果是九州币或神州币,优先跳转自己对应的活动,然后跳转另一个秘宝,再未开启。 --否则优先跳转神州秘宝,再九州秘宝,再未开启 local targetAid if itemId == CoinItemID then targetAid = goldAid or superGoldAid else targetAid = superGoldAid or goldAid end if targetAid then Monopoly_Controller.OpenMainPanel(targetAid) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_GMS_ActivityClosed"]) end end --GMS开关变化时刷新 function private.RefreshInfoByFunction(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.Monopoly then if not isUnlock then Monopoly_Controller.CloseAllFuncPanel() end end end function Monopoly_Controller.OpenMainPanel(activityId) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIMonopolyMainPanel) then return end if Monopoly_Controller.IsSuperGold(activityId) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyMainPanel, { activityId = activityId }, "Monopoly/UIMonopolyMainPanelDarkGold") else UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyMainPanel, { activityId = activityId }) end end function Monopoly_Controller.IsSuperGold(activityId) local backgroundCfg = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) if backgroundCfg then local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(backgroundCfg.TreasureID) local isSuperGold = treasureData.TreasureQuality == LuaConst.QualityColor.DarkGold --彩金品质需要换皮 return isSuperGold end return false end function Monopoly_Controller.CloseAllFuncPanel() UIManager.CloseView(Const_UI_Lua.UIEnum.UICurrencyExchange) UIManager.CloseView(Const_UI_Lua.UIEnum.UIBagItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPreviewItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.OperationActivity.UIGetActivityItemPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonNoteView) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyTasks) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPayMallPopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyStore) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyRewardTip) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyRewardRecord) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyRecords) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyPackageWindow) EventSystem.Dispatch(EventID.UI_Monopoly_OnCloseActivity) end return Monopoly_Controller