local GoldenHeroBoss_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local Infrast = require("Infrast/Infrast") local LuaBit = require('bit') local DefaultSourceByte = LuaBit.bor(MDL.GoldenHeroBoss.BossShare.ShareFriend, MDL.GoldenHeroBoss.BossShare.ShareGuild, MDL.GoldenHeroBoss.BossShare.ShareWorld) local GoldenHeroBossFilterSettingFilePath = "LocalData/GoldenHeroBossFilterSetting" local LocalDataDir = "LocalData" local PowerRate = "SubjugateDataSpecialHero_PowerPointRate_" local SubjugateColorId = "SubjugateDataSpecialHero_SubjugateColor_" local SubjugateColorText = "SubjugateLevelColor_" function GoldenHeroBoss_Controller.OnStartup() EventSystem.Regist(EventID.UI_GoldenHeroBoss_AddNewBossRecord, private.RefreshFindRewardRedPoint) EventSystem.Regist(EventID.UI_GoldenHeroBoss_UpdateBossRecord, private.RefreshFindRewardRedPoint) EventSystem.Regist(EventID.UI_GoldenHeroBoss_RefreshDailyReward, private.RefreshDailyRewardRedPoint) EventSystem.Regist(EventID.UI_GoldenHeroBoss_RefreshDailyPoint, private.RefreshDailyRewardRedPoint) EventSystem.Regist(EventID.UI_GoldenHero_RefreshCurrency, private.RefreshItemEnoughRedPoint) EventSystem.Regist(EventID.UI_GoldenHeroBoss_SetAllInfo, private.RefreshItemEnoughRedPoint) private.ActivityType = MDL.OperationActivity.ActivityType.GoldenHero private.bossExpireTimerList = {} private.tempActivityId = nil private.tempBossId = nil private.myNewBoss = {} private.itemEnoughRp = {} private.constPowerRate = {} private.constSubjugateColorId = {} private.constSubjugateColorText = {} local index = 1 while DataSheetManager.ConstData:TryGetDataByID(PowerRate .. index) do private.constPowerRate[index] = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID(PowerRate .. index).FloatValue) private.constSubjugateColorId[index] = DataSheetManager.ConstData:GetDataByID(SubjugateColorId .. index).IntValue private.constSubjugateColorText[index] = DataSheetManager.ConstData:GetDataByID(SubjugateColorText .. index).StringValue index = index + 1 end end function GoldenHeroBoss_Controller.SetItemEnoughRedPoint(activityId) private.itemEnoughRp[activityId] = false MDL.RedPoint.UpdateNodeStateByLogicParams(false, CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].BossItemEnough) end function private.InitItemEnoughRedPoint() for i, v in pairs(MDL.OperationActivity.HotControlInfo:GetDataByActivityType_ActivityID(private.ActivityType)) do private.itemEnoughRp[v.ActivityID] = true end end function private.RefreshItemEnoughRedPoint() if MDL.OperationActivity.HotControlInfo then local info = MDL.OperationActivity.HotControlInfo:GetDataByActivityType_ActivityID(private.ActivityType) if info then if not next(private.itemEnoughRp) then private.InitItemEnoughRedPoint() end for i, v in pairs(info) do local activityId = v.ActivityID if not MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) then return end local rpEventId = CTL.GoldenHeroMain.RpEventId[activityId] if rpEventId then MDL.RedPoint.UpdateNodeStateByLogicParams(private.CheckItemEnoughRedPoint(activityId) and private.itemEnoughRp[activityId] , rpEventId.TownHome, rpEventId.BossItemEnough) end end end end end function private.RefreshDailyRewardRedPoint(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(GoldenHeroBoss_Controller.IsHasDailyRewardToCollect(activityId) , CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].BossPointReward) end function private.RefreshFindRewardRedPoint(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(GoldenHeroBoss_Controller.IsHasFindRewardToCollect(activityId) , CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].BossFindReward) end function GoldenHeroBoss_Controller.AddBossToNew(activityId, bossId) if not private.myNewBoss[activityId] then private.myNewBoss[activityId] = {} end private.myNewBoss[activityId][bossId] = true MDL.RedPoint.UpdateNodeStateByLogicParams(GoldenHeroBoss_Controller.CheckIfHasNewBoss(activityId), CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].BossNewOne) end function GoldenHeroBoss_Controller.RemoveBossFromNew(activityId, bossId) if private.myNewBoss[activityId] then private.myNewBoss[activityId][bossId] = nil end MDL.RedPoint.UpdateNodeStateByLogicParams(GoldenHeroBoss_Controller.CheckIfHasNewBoss(activityId), CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].BossNewOne) end function GoldenHeroBoss_Controller.CheckNewBossRedPoint(activityId, bossId) if private.myNewBoss[activityId] then return private.myNewBoss[activityId][bossId] or false end return false end --检查是否还有自己发现的新boss function GoldenHeroBoss_Controller.CheckIfHasNewBoss(activityId) if private.myNewBoss[activityId] then return next(private.myNewBoss[activityId]) and true or false end return false end --拥有讨伐体力是否大于等于上限 function private.CheckItemEnoughRedPoint(activityId) local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType) local hasNum = MDL.GoldenHeroMain.GetGoldHeroEnergyInfo(heroTypeData.BossEnergyType) local maxNum = heroTypeData.SynergyBossMaxEnergy return hasNum >= maxNum end --是否有boss发现奖励可领取 function GoldenHeroBoss_Controller.IsHasFindRewardToCollect(activityId) if MDL.GoldenHeroMain.IsActivityInFuncTime(activityId) then for i, v in ipairs(MDL.GoldenHeroBoss.GetSortedBossRecords(activityId)) do if v.rewardState then return true end end end return false end --是否有每日积分奖励可领取 function GoldenHeroBoss_Controller.IsHasDailyRewardToCollect(activityId) if MDL.GoldenHeroMain.IsActivityInFuncTime(activityId) then local point = MDL.GoldenHeroBoss.GetTodayScore(activityId) local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) for i, v in DataSheetManager.GoldHeroSynergyBossDailyReward[heroType]:GetEnumerator() do if point >= v.Integration and not GoldenHeroBoss_Controller.IsDailyRewardCollected(activityId, v.ID) then return true end end end return false end --dailyReward和2 ^ (rewardId - 1)进行按位与操作,如果为true则代表领过了 function GoldenHeroBoss_Controller.IsDailyRewardCollected(activityId, rewardId) local dailyReward = MDL.GoldenHeroBoss.GetDailyReward(activityId) return LuaBit.band(dailyReward, 2 ^ (rewardId - 1)) ~= 0 end function GoldenHeroBoss_Controller.IsBossCostItemEnough(activityId, bossId) local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType) local hasNum = MDL.GoldenHeroMain.GetGoldHeroEnergyInfo(heroTypeData.BossEnergyType) local bossInfo = MDL.GoldenHeroBoss.GetBossInfoByBossId(activityId, bossId) local bossData = DataSheetManager.GoldHeroSynergyBossData[heroType]:GetDataByID(bossInfo.bossCfgId) local needNum = bossData.EnergyNum return hasNum >= needNum end function GoldenHeroBoss_Controller.ShowBossFindView(activityId, bossId, bossConfigId, killerName) if killerName then --如果有击杀者名字则为击杀显示,直接显示即可 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroBossFind, {activityId = activityId, bossConfigId = bossConfigId, killerName = killerName}) else --如果没有击杀者名字则为发现显示,需要检测该boss是否还存在(存活或者没有过期) local bossInfo = MDL.GoldenHeroBoss.GetBossInfoByBossId(activityId, bossId) if bossInfo and bossInfo.hp > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroBossFind, {activityId = activityId, bossConfigId = bossConfigId, killerName = killerName}) end end end function GoldenHeroBoss_Controller.SaveTempData(activityId, bossId) private.tempActivityId = activityId private.tempBossId = bossId local bossInfo = MDL.GoldenHeroBoss.GetBossInfoByBossId(activityId, bossId) private.tempTabIndex = bossInfo.finder == BattleDataGetter.GetAcID() and 0 or 1 end function GoldenHeroBoss_Controller.LoadTempData() return private.tempActivityId, private.tempBossId, private.tempTabIndex end function GoldenHeroBoss_Controller.ClearTempData() private.tempActivityId = nil private.tempBossId = nil private.tempTabIndex = nil end function GoldenHeroBoss_Controller.ShowBattleSummary(msgResp) local msg = msgResp.goldHeroInfo local damage = msg.damage if damage and damage > 0 then local activityId = msg.activityId MDL.GoldenHeroBoss.SetMyRankInfo(activityId, msg.todayScore, msg.maxScore, msg.maxBossCfgId) end UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroBossBattleSummary, {battleResult = msg}) end function GoldenHeroBoss_Controller.ShowBossStar(groupComp, starNum) for i, v in ipairs(groupComp) do UIUtils.SetActive(v, starNum >= i) end end function GoldenHeroBoss_Controller.CheckMyRankAndOpenReward(activityId, heroType, rankType) for i, v in pairs(MDL.GoldenHeroBoss.BossRankType) do if v ~= rankType then MDL.GoldenHeroBoss.CheckBossRank(activityId, v) end end UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroBossRankReward, {activityId = activityId, heroType = heroType, rankType = rankType}) end --region -- **************** 轮询过期 ******************* -- function GoldenHeroBoss_Controller.AddBossExpireTimer(activityId, bossId, time) if not private.bossExpireTimerList[activityId] then private.bossExpireTimerList[activityId] = {} end private.bossExpireTimerList[activityId][bossId] = TimerUtil.Interval(function() private.CheckExpireBoss(activityId, bossId) end, time, 1) end function GoldenHeroBoss_Controller.RemoveBossExpireTimer(activityId, bossId) if private.bossExpireTimerList[activityId][bossId] then TimerUtil.Remove(private.bossExpireTimerList[activityId][bossId]) private.bossExpireTimerList[activityId][bossId] = nil end end function private.CheckExpireBoss(activityId, bossId) EventSystem.Dispatch(EventID.UI_GoldenHeroBoss_UpdateExpiredBoss, activityId, bossId) --boss已经过期 GoldenHeroBoss_Controller.RemoveBossFromNew(activityId, bossId) MDL.GoldenHeroBoss.RemoveBossInfo(activityId, bossId) end --endregion --region -- **************** 筛选 ******************* -- ---筛选功能分为星级和来源 ---星级存为一个list,如果list为空表明无筛选条件,list有值则list中有的星级才可以显示 ---来源存为一个数字,为所有来源的值的按位或的值,与这个值按位与可以判断是否有该途径 function GoldenHeroBoss_Controller.IsBossSuitFilter(activityId, bossId) local starList, sourceByte = GoldenHeroBoss_Controller.LoadFilterSetting(activityId) local bossInfo = MDL.GoldenHeroBoss.GetBossInfoByBossId(activityId, bossId) if bossInfo.finder == BattleDataGetter.GetAcID() then return true end if GoldenHeroBoss_Controller.IsShareTypeInclude(sourceByte, bossInfo.share) then local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) local bossData = DataSheetManager.GoldHeroSynergyBossData[heroType]:GetDataByID(bossInfo.bossCfgId) if table.containValue(starList, bossData.BossStar) then return true end end return false end function GoldenHeroBoss_Controller.SaveFilterSettingByActivityId(activityId, starList, sourceByte) logging.log(LTAG.LOG, "GoldenHeroBoss SaveFilterSettingByActivityId", activityId, sourceByte, starList) local acId = BattleDataGetter.GetAcID() private.filterSetup[acId][activityId] = {starList = starList, sourceByte = sourceByte} private.SaveFilterSettingData() end function GoldenHeroBoss_Controller.LoadFilterSetting(activityId) if not private.filterSetup then private.LoadFilterSettingData() end local acId = BattleDataGetter.GetAcID() local setup = private.filterSetup[acId][activityId] local starList = {} for i, v in pairs(setup.starList) do starList[i] = v end return starList, setup.sourceByte end function GoldenHeroBoss_Controller.DeleteFilterSettingByActivityId(activityId) private.filterSetup[BattleDataGetter.GetAcID()][activityId] = nil private.SaveFilterSettingData() end function GoldenHeroBoss_Controller.DeleteFilterSetting() LuaExt.FileDelete(GoldenHeroBossFilterSettingFilePath) end function private.SaveFilterSettingData() LuaExt.DirectoryCreate(LocalDataDir) LuaExt.FileWriteBytes(GoldenHeroBossFilterSettingFilePath, false, Infrast.EncodeToBytes(private.filterSetup)) end function private.LoadFilterSettingData() if not private.filterSetup then private.filterSetup = {} end local acId = BattleDataGetter.GetAcID() if not private.filterSetup[acId] then private.filterSetup[acId] = {} end --通过检测生成现在有效的数据的默认值 local typeInfoList = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if typeInfoList then for key, value in pairs(typeInfoList) do if type(value) == "table" then local activityId = value.activityId local isOpen = CTL.OperationActivity.IsOperationActivityOpen(value) local isStillGoing = CTL.OperationActivity.IsOperationActivityStillGoing(private.ActivityType, activityId) if isOpen and isStillGoing then local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) local starList = {} for i, v in ipairs(DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType).SynergyBossScreenStar) do starList[i] = v end private.filterSetup[acId][activityId] = {starList = starList, sourceByte = DefaultSourceByte} end end end end --通过现在有效的数据,使用存储在本地的数据进行覆盖 local bytes = LuaExt.FileReadBytes(GoldenHeroBossFilterSettingFilePath) if not string.isNilOrEmpty(bytes) then local localData = Infrast.DecodeFromBytes(bytes) if localData then local playerData = localData[acId] if playerData then for activityId, value in pairs(private.filterSetup[acId]) do local setting = playerData[activityId] if setting and next(setting) then local sourceByte = setting.sourceByte if sourceByte <= DefaultSourceByte and sourceByte > 0 then --如果保存的值大于默认最大值或者小于等于0,则说明数据有误,需要更正 value.sourceByte = setting.sourceByte end local starList = setting.starList if starList and #starList ~= 0 then value.starList = setting.starList end end end end end end ---存在一个问题,就是这样的操作没办法继续保存其他玩家账号的数据 ---解决方法就是除了这个玩家的其他的acid所属的value继续保存 private.SaveFilterSettingData() end function GoldenHeroBoss_Controller.IsShareTypeInclude(currentShare, shareType) return LuaBit.band(currentShare, shareType) ~= 0 end --endregion function GoldenHeroBoss_Controller.IsBossCanLocate(activityId, bossId) if not MDL.GoldenHeroBoss.GetBossInfoByBossId(activityId, bossId) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_SynergyBoss_Help_Hint16) return false end if not GoldenHeroBoss_Controller.IsBossSuitFilter(activityId, bossId) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_SynergyBoss_Help_Hint15) return false end return true end function GoldenHeroBoss_Controller.LocateShareBoss(activityId, bossId, tabIndex) if MDL.GoldenHeroMain.IsActivityInFuncTime(activityId) then local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGoldenHeroBossMain, {heroType = heroType, activityId = activityId, bossId = bossId, tabIndex = tabIndex}) EventSystem.Dispatch(EventID.UI_GoldenHeroBoss_LocateBoss, activityId, bossId) end end function private.GetSubjugateColorId(targetGs) local totalGs = MDL.Player.GetLineUpGs() local segmentIndex = 1 while private.constPowerRate[segmentIndex + 1] ~= nil do local rate = private.constPowerRate[segmentIndex] if totalGs < (targetGs * rate) then break end segmentIndex = segmentIndex + 1 end return private.constSubjugateColorId[segmentIndex] end function GoldenHeroBoss_Controller.GetSubjugateGsText(targetGs) local subjugateColorId = private.GetSubjugateColorId(targetGs) return UTL.Color.FormatTextByColor(private.constSubjugateColorText[subjugateColorId], targetGs) end return GoldenHeroBoss_Controller