local EventSystem = require('Event/EventSystem') local fundinfo_pb = require("Proto/fundinfo_pb") local fund_opt_pb = require("Proto/fund_opt_pb") local GrowthFund_Model = {} local private = {} GrowthFund_Model.BuyStateType = { No = 0, -- 未购买 Yes = 1 -- 已购买 } GrowthFund_Model.SubItemStateType = { Doing = 0, -- 为达成 Finished = 1, -- 达成可领取 AlreadyGet = 2, -- 已领取 } function GrowthFund_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageFundGetUIInfo, private.FundGetUIInfoResponse) -- 获取基金界面信息 NetManager.RegisterMsgCB(MessageEnums.MessageFundGetAward, private.FundGetAwardResponse) -- 基金-领取奖励 private.FundInfoList = {} -- 根据活动ID拆分关卡表 private.ActivitiesItemList = {} -- 根据活动ID拆分关卡表 private.SplitConfig() end function GrowthFund_Model.FundDataInited() return private.fundDataInited end --region 拆分奖励表 function private.SortFunction(a,b) return a.ID < b.ID end function private.SplitConfig() --按照类型拆分多人副本 for _,v in DataSheetManager.Fund:GetEnumerator() do if private.ActivitiesItemList[v.Type] == nil then private.ActivitiesItemList[v.Type] = {} end table.insert(private.ActivitiesItemList[v.Type], v) end for _,levelData in ipairs(private.ActivitiesItemList) do table.sort(levelData, private.SortFunction) end end --endregion --region 外部获取函数 ---@return 基金返利列表 function GrowthFund_Model.GetActivitiesItemListByID(fundID) local itemList = private.ActivitiesItemList[fundID] if itemList then return itemList else logging.error(LTAG.ERROR, "GetActivitiesItemListByID 基金ID不存在 ID:", fundID) return nil end end ---@return 基金返利列表 function GrowthFund_Model.GetAllRebateCountByFundID(fundID) local rebateCount = 0 local fundConfig = GrowthFund_Model.GetActivitiesItemListByID(fundID) for k,v in ipairs(fundConfig) do local rewardConfig = DataSheetManager.FundReward:GetDataByID(v.FundRewardID) rebateCount = rebateCount + rewardConfig.Item_Table[1].ItemNum end return rebateCount end ---@return 基金详情 function GrowthFund_Model.GetGrowFundByFundID(fundID) local foundInfo = private.FundInfoList[fundID] if foundInfo then return foundInfo else return nil end end ---@return 基金完成Trigger判断 function GrowthFund_Model.IsCompleteTrigger(fundType, fundID) if fundType and fundID then local foundInfo = private.FundInfoList[fundType] if foundInfo and foundInfo.FundSubInfos and #foundInfo.FundSubInfos > 0 then for _, v in ipairs (foundInfo.FundSubInfos) do if v.Id <= fundID and v.State ~= GrowthFund_Model.SubItemStateType.AlreadyGet then return false end end return true end end return false end --endregion --region -- **************** 协议部分 ******************* function private.RefreshFundInfo(msgResp) --logging.log(LTAG.LOG, "RefreshFundInfo", msgResp) for k,v in ipairs(msgResp) do private.FundInfoList[v.FundType] = v end private.fundDataInited = true EventSystem.Dispatch(EventID.UI_Fund_RefreshPanel) EventSystem.Dispatch(EventID.UI_Fund_RefreshRedPoint) end -- 登录、数据变化时同步基金数据 function GrowthFund_Model.SyncFundInfo(msgResp) --logging.log(LTAG.LOG, "SyncFundInfo", msgResp) if msgResp then private.RefreshFundInfo(msgResp) end end -- 请求界面信息 function GrowthFund_Model.FundGetUIInfoRequest(fundType) local msg = fund_opt_pb.FundGetUIInfoReq() msg.FundType = fundType NetManager.SendMessage(MessageEnums.MessageFundGetUIInfo, msg) end function private.FundGetUIInfoResponse(msgResp) --logging.log(LTAG.LOG, "FundGetUIInfoResponse", msgResp.FundInfo) if msgResp.FundInfo then private.RefreshFundInfo(msgResp.FundInfo) end end -- 领取阶段奖励 function GrowthFund_Model.FundGetAwardRequest(fundType, subId) local msg = fund_opt_pb.FundGetAwardReq() msg.FundType = fundType msg.SubId = subId NetManager.SendMessage(MessageEnums.MessageFundGetAward, msg) end function private.FundGetAwardResponse(msgResp) --logging.log(LTAG.LOG, "FundGetAwardResponse", msgResp.FundInfo) if msgResp.FundInfo then private.RefreshFundInfo({msgResp.FundInfo}) end end --endregion 协议部分 return GrowthFund_Model