local GoldenHeroMain_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local fuben_pb = require 'Proto/fuben_pb' local gold_hero_secret_opt_pb = require('Proto.gold_hero_secret_opt_pb') local GoldHeroEnergyInfo = {} local GoldHeroEnergyMaxCountInfo = {} GoldenHeroMain_Model.EnergyType = { Story = 1, Boss = 2, } GoldenHeroMain_Model.HeroType = { GY = 1, -- 关羽 SSX = 2, -- 孙尚香 DC = 3, -- 貂蝉 CC = 4, -- 曹操 SJ = 5, -- 孙坚 ZL = 6, -- 张辽 TSC = 7, -- 太史慈 HYY = 8, -- 黄月英 ZJ = 9, -- 甄姬 GN = 10, -- 甘宁 JX = 11, -- 贾诩 LM = 12, -- 吕蒙 } GoldenHeroMain_Model.LevelType = { Story = 1, -- 秘闻 Anecdote = 2, -- 轶事 } function GoldenHeroMain_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageGoldHeroEnergyBuy, private.GoldHeroEnergyBuyResp) EventSystem.Regist(EventID.UI_OperationActivity_InfoChanged, private.SetGoldenHeroEndTimer) private.ActivityType = MDL.OperationActivity.ActivityType.GoldenHero private.isInActivityFuncTime = {} --是否在功能活动时间内(如果在展示时间则为false) private.activityEndTimerHandle = {} private.consumeList = {} private.energyBuyCount = {} private.templateIDAndActivityIDDic = {} private.InitEnergyData() end function GoldenHeroMain_Model.GetHeroTypeByActivityId(activityId) if MDL.OperationActivity.ActivityBaseData[private.ActivityType] then local goldHeroData = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) if goldHeroData then return goldHeroData.HeroType else logging.error(LTAG.ERROR, "金将活动找不到activityId:", activityId, "在hot4BackGround静态数据表数据!!!请服务器和策划检查!!!不要忽略!!!") end else logging.error(LTAG.ERROR, "金将活动没有hot4BackGround静态数据表数据!!!请服务器和策划检查!!!不要忽略!!!") end end function GoldenHeroMain_Model.GetLevelTypeByActivityId(activityId) if MDL.OperationActivity.ActivityBaseData[private.ActivityType] then local goldHeroData = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) if goldHeroData then local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(goldHeroData.HeroType) if heroTypeData then return heroTypeData.HeroLevelType else logging.error(LTAG.ERROR, "金将活动在GoldHeroActivityModeData表中找不到HeroType:", goldHeroData.HeroType, "的数据!!!请策划检查!!!不要忽略!!!") end else logging.error(LTAG.ERROR, "金将活动找不到activityId:", activityId, "在hot4BackGround静态数据表数据!!!请服务器和策划检查!!!不要忽略!!!") end else logging.error(LTAG.ERROR, "金将活动没有hot4BackGround静态数据表数据!!!请服务器和策划检查!!!不要忽略!!!") end end ---private 缓存正在进行中的金将活动的模板映射关系 function private.SetTemplateIDAndActivityID() local goldHeroInfoList = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if goldHeroInfoList then for i, v in pairs(goldHeroInfoList) do if v.startTime <= UTL.Time.GetServerTimestamp() and v.endTime >= UTL.Time.GetServerTimestamp() then local heroType = GoldenHeroMain_Model.GetHeroTypeByActivityId(i) if heroType then private.templateIDAndActivityIDDic[heroType] = i end end end end end function GoldenHeroMain_Model.GetActivityIDByHeroType(heroType) local activityId = private.templateIDAndActivityIDDic[heroType] if activityId and activityId > 0 then return activityId else return 0 end end function GoldenHeroMain_Model.IsActivityInFuncTime(activityId) if private.isInActivityFuncTime[activityId] == nil then private.SetEndTimerByActivityId(activityId) end return private.isInActivityFuncTime[activityId] end function GoldenHeroMain_Model.GetEndFuncTime(activityId) local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(GoldenHeroMain_Model.GetHeroTypeByActivityId(activityId)) local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType, activityId) return activityInfo.endTime - heroTypeData.DisplayTime * UTL.Time.TotalSecondsOneDay end function private.SetGoldenHeroEndTimer() local goldHeroInfoList = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if goldHeroInfoList then for i, v in pairs(goldHeroInfoList) do if GoldenHeroMain_Model.GetHeroTypeByActivityId(v.activityId) then private.SetEndTimerByActivityId(v.activityId) end end end private.SetTemplateIDAndActivityID() end function private.SetEndTimerByActivityId(activityId) if private.activityEndTimerHandle[activityId] then TimerUtil.Remove(private.activityEndTimerHandle[activityId]) end local heroType = GoldenHeroMain_Model.GetHeroTypeByActivityId(activityId) if heroType then local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType) local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType, activityId) if activityInfo and heroTypeData then local endFuncTime = activityInfo.endTime - heroTypeData.DisplayTime * UTL.Time.TotalSecondsOneDay local nowTime = UTL.Time.GetServerTimestamp() if endFuncTime > nowTime then private.isInActivityFuncTime[activityId] = true local deltaTime = endFuncTime - nowTime if deltaTime <= UTL.Time.TotalSecondsOneDay then private.activityEndTimerHandle[activityId] = TimerUtil.Interval(function() private.DispatchEndActivity(activityId) end, deltaTime - 1, 1) --时间减1s是为了防止有误差导致玩家点击出现报错 end else private.DispatchEndActivity(activityId) end end end end function private.DispatchEndActivity(activityId) logging.log(LTAG.LOG, "GoldenHero ActivityEnd, activityId: ", activityId) private.isInActivityFuncTime[activityId] = false EventSystem.Dispatch(EventID.UI_GoldenHero_ActivityEnd, activityId) end --region 金将体验商店消耗物品 function GoldenHeroMain_Model.GetItemConsumeNumByActivityId(activityId, itemId) if private.consumeList[activityId] then return private.consumeList[activityId][itemId] or 0 end return 0 end function GoldenHeroMain_Model.SetActivityConsumeList(activityStoreInfo) for i, v in ipairs(activityStoreInfo) do local activityId = v.activityId if not private.consumeList[activityId] then private.consumeList[activityId] = {} end private.consumeList[activityId][v.itemId] = v.itemNum end end --endregion --region 金将体验体力相关 function private.InitEnergyData() for k, v in DataSheetManager.GoldHeroActivityModeData:GetEnumerator() do GoldHeroEnergyMaxCountInfo[v.LevelEnergyType] = v.ActivityLevelMaxEnergy GoldHeroEnergyMaxCountInfo[v.BossEnergyType] = v.SynergyBossMaxEnergy end end function GoldenHeroMain_Model.GetEnergyBuyType(itemId, activityId) local heroType = GoldenHeroMain_Model.GetHeroTypeByActivityId(activityId) local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType) if itemId == heroTypeData.LevelEnergyType then return GoldenHeroMain_Model.EnergyType.Story elseif itemId == heroTypeData.BossEnergyType then return GoldenHeroMain_Model.EnergyType.Boss end end function GoldenHeroMain_Model.GetGoldHeroEnergyBuyCount(activityId, energyType) if not private.energyBuyCount[activityId] then private.energyBuyCount[activityId] = {} logging.error(LTAG.ERROR, "ActivityId为:", activityId, "的金将活动体力购买次数数据有问题,请服务器和客户端排查!!!") end return private.energyBuyCount[activityId][energyType] or 0 end function GoldenHeroMain_Model.SetGoldHeroEnergyBuyCount(activityId, buyInfo) if not private.energyBuyCount[activityId] then private.energyBuyCount[activityId] = {} end for i, v in ipairs(buyInfo) do private.energyBuyCount[activityId][v.energyType] = v.buyCount end end function GoldenHeroMain_Model.SetGoldHeroEnergyInfo(info) for k, v in ipairs(info) do GoldHeroEnergyInfo[v.itemId] = v.itemNum end EventSystem.Dispatch(EventID.UI_GoldenHero_RefreshCurrency) end ---@return number 体力值 function GoldenHeroMain_Model.GetGoldHeroEnergyInfo(currencyID) local currencyCount = GoldHeroEnergyInfo[currencyID] if currencyCount then return currencyCount end return 0 end ---@return number 体力值上限 function GoldenHeroMain_Model.GetGoldHeroEnergyMaxCount(currencyID) local count = GoldHeroEnergyMaxCountInfo[currencyID] if count then return count end return 0 end --endregion function GoldenHeroMain_Model.GoldHeroEnergyBuyReq(activityId, energyType, count) local msg = gold_hero_secret_opt_pb.GoldHeroEnergyBuyReq() msg.activityId = activityId msg.energyType = energyType msg.count = count NetManager.SendMessage(MessageEnums.MessageGoldHeroEnergyBuy, msg) end function private.GoldHeroEnergyBuyResp(msgResp) if msgResp.Resp.Code == 0 then GoldenHeroMain_Model.SetGoldHeroEnergyBuyCount(msgResp.activityId, msgResp.buyInfo) end end function GoldenHeroMain_Model.EnterHeroTry(activityId, levelId, mapId) if CTL.TeamMatch.IsCanGoOtherScene(LuaConst.LevelType.GoldHeroShow, mapId) == false then return end local msg = fuben_pb.EnterFubenReq() msg.id = levelId msg.mapType = LuaConst.LevelType.GoldHeroShow msg.mapID = mapId msg.goldHeroInfo.activityId = activityId NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) private.SaveTempData(activityId, levelId, mapId) CTL.GoldenHeroMain.SetIsOpenedActivity() end function private.SaveTempData(activityId, levelId, mapId) private.tempActivityId = activityId private.tempLevelId = levelId private.tempMapId = mapId end function GoldenHeroMain_Model.LoadTempData() return private.tempActivityId, private.tempLevelId, private.tempMapId end function GoldenHeroMain_Model.ClearTempData() private.tempActivityId = nil private.tempLevelId = nil private.tempMapId = nil end function GoldenHeroMain_Model.SetHeroTryFirstPassRp(state) private.heroTryFirstPassRp = state end function GoldenHeroMain_Model.GetHeroTryFirstPassRp() return private.heroTryFirstPassRp or false end return GoldenHeroMain_Model