local AssistanceFight_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local math_floor = math.floor local ActiveFormationIcon = { [1] = "zz_Wei", [2] = "zz_Shu", [3] = "zz_Wu", [4] = "zz_Qun" } -------------------------- 系统函数 ------------------------------ function AssistanceFight_Controller.OnStartup() EventSystem.Regist(EventID.FunctionUnlockUpdate, private.OnFunctionUnlockUpdate) -- UI使用记录每次界面变化 需要播放特效的位置 private.teamworks = { [1] = 0, [2] = 0, [3] = 0 } -- 阵容变化记录 private.changeTeamWorks = { false, false, false, } private.isNeedOptimise = false private.teamBuffFormationIndex = 0 -- 所有需要查找并排序武将的都用这个集合 private.heroList = LuaExt.CreateTable(3) private.horseList = LuaExt.CreateTable(3) private.treasureList = LuaExt.CreateTable(3) for i = 1, 3 do local heroDatas = LuaExt.CreateTable(DataSheetManager.HeroNum:GetDataCount()) for i, v in DataSheetManager.HeroNum:GetEnumerator() do table.insert(heroDatas, v) end private.heroList[i] = heroDatas local horseDatas = LuaExt.CreateTable(DataSheetManager.HorseData:GetDataCount()) for i, v in DataSheetManager.HorseData:GetEnumerator() do horseDatas[v.HorseID] = v end private.horseList[i] = horseDatas local treasureDatas = LuaExt.CreateTable(DataSheetManager.TreasureData:GetDataCount()) for i, v in DataSheetManager.TreasureData:GetEnumerator() do treasureDatas[v.TreasureID] = v end private.treasureList[i] = treasureDatas end end function AssistanceFight_Controller.OnShutdown() private.teamworks = nil private.changeTeamWorks = nil private.heroList = nil private.horseList = nil private.treasureList = nil end ----------------------------------------------------------------- function AssistanceFight_Controller.OpenAssistancePanel(heroIndex, isOpenFromHeroFormationPanel) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.AssistanceFight) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIAssistanceFightPanel, {heroIndex = heroIndex, isOpenFromHeroFormationPanel = isOpenFromHeroFormationPanel}) end end function AssistanceFight_Controller.CheckSlotUnlockState(slotInfo) if not slotInfo then return false, false end return slotInfo.data.slotState > 0, UTL.Item.GetItemStockCount(slotInfo.config.UnlockItem_Table[1].UnlockItemID) >= slotInfo.config.UnlockItem_Table[1].UnlockItemNum end function AssistanceFight_Controller.IsPlayTeamworkEft(formationIndex, quality) local isPlay = private.teamworks[formationIndex] == 0 and quality > 0 private.teamworks[formationIndex] = quality return isPlay end function AssistanceFight_Controller.SetActiveFormationIcon(image, kingom) UTL.Item.SetAtlasSprite(image, "UI_Array", ActiveFormationIcon[kingom]) end --region ********************* 槽位下阵 ***************************** function AssistanceFight_Controller.OperateHeroLeave(slotId, heroId, assistanceType) private.slotId = slotId private.heroId = heroId local ids if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then ids = "IDS_AssistanceFight_ChooseHero_OutHint" elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then ids = "IDS_AssistanceFight_ChooseHorse_OutHint" elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then ids = "IDS_AssistanceFight_ChooseTreasure_OutHint" end UTL.MessageBox.ShowOKCancelBox("", UIUtils.GetLocalizedTxt(Const_IDS[ids]), private.RequestOptSlotOnLeave) end function private.RequestOptSlotOnLeave() MDL.AssistanceFight.RequestOptSlotOnLeave(private.slotId, private.heroId) end --endregion ********************* 槽位下阵 ***************************** --region ********************* 阵位交换 ***************************** function AssistanceFight_Controller.OperateSlotHeroChange(slotIdA, slotIdB, assistanceType) private.slotIdA = slotIdA private.slotIdB = slotIdB local ids if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then ids = "IDS_AssistanceFight_ChooseHero_ChangeHint" elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then ids = "IDS_AssistanceFight_ChooseHorse_ChangeHint" elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then ids = "IDS_AssistanceFight_ChooseTreasure_ChangeHint" end UTL.MessageBox.ShowOKCancelBox("", UIUtils.GetLocalizedTxt(Const_IDS[ids]), private.RequestExchangeSlotHero) end function private.RequestExchangeSlotHero() MDL.AssistanceFight.RequestExchangeSlotHero(private.slotIdA, private.slotIdB) end --endregion ********************* 阵位交换 ***************************** --region ********************* 红点 ***************************** ---@private 玩法解锁刷新红点 function private.OnFunctionUnlockUpdate(funcID, isComplete) if funcID == MDL.Unlock.FunctionType.AssistanceFight then AssistanceFight_Controller.SetRedPoint() end end ---@public 是否有最优布阵 function AssistanceFight_Controller.IsNeedOptimise() return private.isNeedOptimise end ---@public 一键布阵红点 function AssistanceFight_Controller.SetRedPoint() private.isNeedOptimise = false CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_AssistFight) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.AssistanceFight) then local curHeroId = 0 local hasBest = false for i = 1, 3 do for pos = 1, 8 do local slotInfo = MDL.AssistanceFight.GetSlotInfo(i, pos) if slotInfo.data.slotState == 2 then curHeroId = slotInfo.data.heroId hasBest = AssistanceFight_Controller.IsShowSlotRedPoint(slotInfo) if hasBest then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_AssistFight) private.isNeedOptimise = true break end else local isTriggerUnlock, itemUnlock = AssistanceFight_Controller.CheckSlotUnlockState(slotInfo) if isTriggerUnlock and itemUnlock then if pos >= 5 and pos < 7 then -- 坐骑要加一个坐骑助阵槽显隐条件判断 if CTL.AssistanceFight.ShowAssistanceHorse(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_AssistFight) end elseif pos >= 7 then -- 宝物要加一个宝物助阵槽显隐条件判断 if CTL.AssistanceFight.ShowAssistanceTreasure(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_AssistFight) end else CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_AssistFight) end end end end end end end ---@public 前中后军阵容红点 ---@param formationType 阵位ID function AssistanceFight_Controller.IsShowFormationRedPoint(formationType) local formationInfo = MDL.AssistanceFight.GetFormationInfo(formationType) if formationInfo then for _, v in pairs (formationInfo) do if AssistanceFight_Controller.IsShowSlotRedPoint(v) then return true end end end return false end ---@public 助阵槽位红点 ---@param slotInfo 槽位信息 function AssistanceFight_Controller.IsShowSlotRedPoint(slotInfo) local slotData = slotInfo.data if slotData.slotState == 2 then local formationIndex = slotInfo.formationIndex local assistanceType = slotInfo.config.AssistanceType local gSProportion = slotInfo.config.AssistanceGSProportion local data if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then data = private.heroList[formationIndex] elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then data = private.horseList[formationIndex] elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then data = private.treasureList[formationIndex] end if slotData.heroId == 0 then for _, v in ipairs (data) do local gs, data_ID if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then data_ID = v.ID gs = MDL.AssistanceFight.GetFormationSlotHeroGs(formationIndex, data_ID) if gs == 0 then return false end if not MDL.AssistanceFight.IsHeroOnAssistancePos(data_ID) then return true end elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then data_ID = v.HorseID gs = MDL.AssistanceFight.GetFormationSlotHorseGs(formationIndex, data_ID) if gs == 0 then return false end if not MDL.AssistanceFight.IsHorseOnAssistancePos(data_ID) then return true end elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then data_ID = v.TreasureID gs = MDL.AssistanceFight.GetFormationSlotTreasureGs(formationIndex, data_ID) if gs == 0 then return false end if not MDL.AssistanceFight.IsTreasureOnAssistancePos(data_ID) then return true end end end else -- 判断是否有战力更强的武将 for _, v in ipairs (data) do local gs, data_ID if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then data_ID = v.ID gs = MDL.AssistanceFight.GetFormationSlotHeroGs(formationIndex, data_ID) elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then data_ID = v.HorseID gs = MDL.AssistanceFight.GetFormationSlotHorseGs(formationIndex, data_ID) elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then data_ID = v.TreasureID gs = MDL.AssistanceFight.GetFormationSlotTreasureGs(formationIndex, data_ID) end if gs > 0 then if assistanceType == MDL.AssistanceFight.AssistanceType.Hero then if not MDL.Player.HeroIsLineUp(data_ID) and not MDL.AssistanceFight.IsHeroOnAssistancePos(data_ID) then local curGs = MDL.AssistanceFight.GetFormationSlotHeroGs(formationIndex, slotData.heroId) if gs * gSProportion > curGs * gSProportion then return true end end elseif assistanceType == MDL.AssistanceFight.AssistanceType.Horse then if MDL.WarHorse.GetEquippedHeroIDByHorseID(data_ID) <= 0 and not MDL.AssistanceFight.IsHorseOnAssistancePos(data_ID) then local curGs = MDL.AssistanceFight.GetFormationSlotHorseGs(formationIndex, slotData.heroId) if gs > curGs then return true end end elseif assistanceType == MDL.AssistanceFight.AssistanceType.Treasure then if MDL.Treasure.GetEquippedHeroIDByTreasureID(data_ID) <= 0 and not MDL.AssistanceFight.IsTreasureOnAssistancePos(data_ID) then local curGs = MDL.AssistanceFight.GetFormationSlotTreasureGs(formationIndex, slotData.heroId) if gs > curGs then return true end end end end end end else local isTriggerUnlock, itemUnlock = AssistanceFight_Controller.CheckSlotUnlockState(slotInfo) if isTriggerUnlock and itemUnlock then if slotInfo.slotIndex >= 5 and slotInfo.slotIndex < 7 then -- 坐骑要加一个坐骑助阵槽显隐条件判断 if CTL.AssistanceFight.ShowAssistanceHorse(slotInfo.formationIndex) then return true end elseif slotInfo.slotIndex >= 7 then -- 宝物要加一个宝物助阵槽显隐条件判断 if CTL.AssistanceFight.ShowAssistanceTreasure(slotInfo.formationIndex) then return true end else return true end else return false end end return false end --endregion ********************* 红点 ***************************** --region ********************* 连携 ***************************** function AssistanceFight_Controller.DelayRegistFunctionUnlockUpdate() EventSystem.Regist(EventID.FunctionUnlockUpdate, private.OnFormationTeamWorkUnlock) end function private.OnFormationTeamWorkUnlock(funcID, isComplete) -- 功能解锁 触发阵容连携解锁提示 if funcID == MDL.Unlock.FunctionType.FormationTeamWork then AssistanceFight_Controller.CalculateFormationBuffChanges() end end function AssistanceFight_Controller.CalculateFormationBuffLevel(mainHeroId, subHeroId) local mainHero = DataSheetManager.HeroNum:GetDataByID(mainHeroId or 0) local subHero = DataSheetManager.HeroNum:GetDataByID(subHeroId or 0) local qualityLevel = 0 if mainHero and subHero and mainHero.Kingdom == subHero.Kingdom then local minQuality = mainHero.HeroQuality <= subHero.HeroQuality and mainHero.HeroQuality or subHero.HeroQuality for _, v in DataSheetManager.HeroTeamBuffData:GetEnumerator() do if v.LowestQuality == minQuality then qualityLevel = v.TeamBuffID break end end end return qualityLevel end function AssistanceFight_Controller.CalculateFormationBuffChanges(formerLineups, lineups) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FormationTeamWork) then return false end for i, _ in ipairs (private.changeTeamWorks) do private.changeTeamWorks[i] = false end local isChange = false if formerLineups and lineups then if #formerLineups == 0 then return end -- 阵容变更 for i = 1, 3 do local formerQualityLevel = AssistanceFight_Controller.CalculateFormationBuffLevel(formerLineups[i * 2 - 1], formerLineups[i * 2]) local curQualityLevel = AssistanceFight_Controller.CalculateFormationBuffLevel(lineups[i * 2 - 1], lineups[i * 2]) if curQualityLevel > 0 and formerQualityLevel ~= curQualityLevel then private.changeTeamWorks[i] = true -- logging.error(LTAG.ERROR, "阵容变更", i) isChange = true end end else -- 功能解锁 lineups = MDL.Player.GetHeroLinUpIds() for i = 1, 3 do local curQualityLevel = AssistanceFight_Controller.CalculateFormationBuffLevel(lineups[i * 2 - 1], lineups[i * 2]) if curQualityLevel > 0 then private.changeTeamWorks[i] = true -- logging.error(LTAG.ERROR, "功能解锁", i) isChange = true end end end return isChange end function AssistanceFight_Controller.ShowTeamworkBuff() local formationIndex for i, _ in ipairs (private.changeTeamWorks) do if private.changeTeamWorks[i] then formationIndex = i private.changeTeamWorks[i] = false break end end if formationIndex then private.teamBuffFormationIndex = formationIndex UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroTeamBuff) else MDL.FormationResonance.CloseDelayResonanceShow() end end function AssistanceFight_Controller.GetTeamBuffFormationIndex() return private.teamBuffFormationIndex end function AssistanceFight_Controller.GetBuffTitleAndDes(id) local heroTeamBuffData = DataSheetManager.HeroTeamBuffData:GetDataByTeamBuffID(id) if not heroTeamBuffData then return nil, nil, nil end local qualityCfg = DataSheetManager.QualityColor:GetDataByID(heroTeamBuffData.LowestQuality) local devEftData = DataSheetManager.DevelopEffectData:GetDataByID(heroTeamBuffData.DevelopEffectID) local buffData = DataSheetManager.BuffData:GetDataByBuffID(devEftData.BuffIDs[1]) local title = UIUtils.GetLocalizedTxt(Const_IDS[buffData.BuffName]) if qualityCfg then local qualityStr = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[qualityCfg.ColorText]), heroTeamBuffData.LowestQuality) title = string.FormatByIdsId(Const_IDS[buffData.BuffName], qualityStr) end local idsCombineCfg = DataSheetManager.IDSCombine:GetDataByID(buffData.BuffDescribe) return title, UIUtils.GetLocalizedTxt(Const_IDS[idsCombineCfg.MainIDS]), heroTeamBuffData.NextLevelIDS end --endregion ********************* 连携 ***************************** function private.SortHeroListByPower(a, b) if not a then return false elseif not b then return true end -- 三军助战武将全部相同 且前军必然解锁 所以排序计算战力以前军为准就可以了 local a_ID, b_ID, aPower, bPower if a.ID then a_ID ,b_ID = a.ID, b.ID aPower = MDL.AssistanceFight.GetFormationSlotHeroGs(private.curHeroDataSortFormationIndex, a_ID) bPower = MDL.AssistanceFight.GetFormationSlotHeroGs(private.curHeroDataSortFormationIndex, b_ID) elseif a.HorseID then a_ID ,b_ID = a.HorseID, b.HorseID aPower = MDL.AssistanceFight.GetFormationSlotHorseGs(private.curHorseDataSortFormationIndex, a_ID) bPower = MDL.AssistanceFight.GetFormationSlotHorseGs(private.curHorseDataSortFormationIndex, b_ID) elseif a.TreasureID then a_ID ,b_ID = a.TreasureID, b.TreasureID aPower = MDL.AssistanceFight.GetFormationSlotTreasureGs(private.curTreasureDataSortFormationIndex, a_ID) bPower = MDL.AssistanceFight.GetFormationSlotTreasureGs(private.curTreasureDataSortFormationIndex, b_ID) end if aPower == bPower then return a_ID < b_ID end return aPower > bPower end --region ********************** 武将 ************************* function AssistanceFight_Controller.SortHeroList() -- 对阵容助战武将按照战力降序排序 for i, _ in ipairs (private.heroList) do private.curHeroDataSortFormationIndex = i table.sort(private.heroList[i], private.SortHeroListByPower) end end function AssistanceFight_Controller.GetAvailableHeroList(formationIndex) return private.heroList[formationIndex] end --endregion ********************** 武将 ************************* --region ********************** 坐骑 ************************* function AssistanceFight_Controller.SortHorseList() -- 对阵容助战坐骑按照战力降序排序 for i, _ in ipairs (private.horseList) do private.curHorseDataSortFormationIndex = i table.sort(private.horseList[i], private.SortHeroListByPower) end end function AssistanceFight_Controller.GetAvailableHorseList(formationIndex) return private.horseList[formationIndex] end ---@public 助阵坐骑显隐状态 ---@param fightPositionID 前中后军阵位ID ---@param position 槽位ID function AssistanceFight_Controller.ShowAssistanceHorse(fightPositionID, position) local isShow = false if MDL.Formation.GetSlotsCount() == 6 then for i, v in ipairs(MDL.Formation.GetSlotHeroIds()) do if not MDL.WarHorse.GetInfoByHeroID(v) then return false end end isShow = true if position then -- 可见条件 local assistanceData = DataSheetManager.HeroAssistanceData:GetDataByFightPosition_AssistancePosition(fightPositionID, position) if assistanceData.VisibleTriggerID > 0 then isShow = MDL.Unlock.IsTriggerIdComplete(assistanceData.VisibleTriggerID) end end else return false end return isShow end --endregion ********************** 坐骑 ************************* --region ********************** 宝物 ************************* function AssistanceFight_Controller.SortTreasureList() -- 对阵容助战坐骑按照战力降序排序 for i, _ in ipairs (private.treasureList) do private.curTreasureDataSortFormationIndex = i table.sort(private.treasureList[i], private.SortHeroListByPower) end end function AssistanceFight_Controller.GetAvailableTreasureList(formationIndex) return private.treasureList[formationIndex] end ---@public 助阵宝物显隐状态 ---@param fightPositionID 前中后军阵位ID ---@param position 槽位ID function AssistanceFight_Controller.ShowAssistanceTreasure(fightPositionID, position) local isShow = false if MDL.Formation.GetSlotsCount() == 6 then for i, v in ipairs(MDL.Formation.GetSlotHeroIds()) do if not MDL.Treasure.GetTreasureInfoByHeroId(v) then return false end end isShow = true if position then -- 可见条件 local assistanceData = DataSheetManager.HeroAssistanceData:GetDataByFightPosition_AssistancePosition(fightPositionID, position) if assistanceData.VisibleTriggerID > 0 then isShow = MDL.Unlock.IsTriggerIdComplete(assistanceData.VisibleTriggerID) end end else return false end return isShow end --endregion ********************** 宝物 ************************* return AssistanceFight_Controller