local FormationResonance_Controller = {} local private = {} local resonance_info = require 'Proto/resonance_info_pb' local PercentStr = "%.0f%%" local NotEnoughStr = "%d/%d" local EnoughStr = "%d/%d" local MainResonanceAttrType_1 = LuaConst.AttrType.pvpfindmg local MainResonanceAttrType_2 = LuaConst.AttrType.antipvpfindmg local NobelProgressLevel = "%s%d" local NobelProgressLevelVN = "%s %d" local NobilityMaxRankID = DataSheetManager.Nobility:GetDataCount() function FormationResonance_Controller.OnStartup() private.jumpSubTypeId = nil end function FormationResonance_Controller.OnShutdown() end function FormationResonance_Controller.GetPercentStr(floatValue) if not floatValue or floatValue == 0 then return "0%" end local percentValue = floatValue * 100 return string.format(PercentStr, percentValue) end function FormationResonance_Controller.GetConsumeText(curConsumeCount, needConsumeCount) if not curConsumeCount or not needConsumeCount then return "" end if curConsumeCount >= needConsumeCount then return string.format(EnoughStr, curConsumeCount, needConsumeCount) end return string.format(NotEnoughStr, curConsumeCount, needConsumeCount) end function FormationResonance_Controller.GetCompleteCondition(typeId, level) local infoCfg = MDL.FormationResonance.GetSubResonanceInfoCfg(typeId, level) if not infoCfg then return "", 0 end if private.IsCompleteConditionByExp(typeId) then return UIUtils.GetLocalizedTxt(Const_IDS[infoCfg.Des]), infoCfg.NeedExp elseif typeId == resonance_info.Equip_Enhance then -- 等级 return string.FormatByIdsId(Const_IDS[infoCfg.Des], infoCfg.EquipEnhanceNum, private.ChangeLevelToNobilityLevel(infoCfg.MinEquipEnhanceLevel)), infoCfg.EquipEnhanceNum elseif typeId == resonance_info.Hero_Advance then local heroAdvCfg = DataSheetManager.HeroAdvance:GetDataByAdvanceID(infoCfg.MinHeroAdv) return string.FormatByIdsId(Const_IDS[infoCfg.Des], infoCfg.HeroNum, heroAdvCfg.Stage, heroAdvCfg.LightStar), infoCfg.HeroNum elseif typeId == resonance_info.Hero_Level then -- 等级 return string.FormatByIdsId(Const_IDS[infoCfg.Des], infoCfg.HeroNum, private.ChangeLevelToNobilityLevel(infoCfg.MinHeroLevelLevel)), infoCfg.HeroNum elseif typeId == resonance_info.Jade_Insert then return string.FormatByIdsId(Const_IDS[infoCfg.Des], infoCfg.JadeNum, infoCfg.MinJadeLevel), infoCfg.JadeNum elseif typeId == resonance_info.Treasure_Soul then return string.FormatByIdsId(Const_IDS[infoCfg.Des], infoCfg.SoulNum, infoCfg.SoulColor), infoCfg.SoulNum elseif typeId == resonance_info.Horse_Soul then return UIUtils.GetLocalizedTxt(Const_IDS[infoCfg.Des]), infoCfg.NeedExp elseif typeId == resonance_info.GodBeast_Break then return UIUtils.GetLocalizedTxt(Const_IDS[infoCfg.Des]), infoCfg.NeedExp elseif typeId == resonance_info.GodBeast_Raise then local showYearStr = infoCfg.TotalLevel * 100 return string.FormatByIdsId(Const_IDS[infoCfg.Des], showYearStr), showYearStr elseif typeId == resonance_info.Horse_Equip then return UIUtils.GetLocalizedTxt(Const_IDS[infoCfg.Des]), infoCfg.NeedExp end return "", 0 end function FormationResonance_Controller.GetConditionShowParam(typeID, param) if typeID == resonance_info.GodBeast_Raise then return param * 100 else return param end end function private.IsCompleteConditionByExp(typeId) return typeId == resonance_info.Equip_Quality or typeId == resonance_info.Hero_Break or typeId == resonance_info.Horse_Break or typeId == resonance_info.Weapon_Break or typeId == resonance_info.Treasure_Break or typeId == resonance_info.Weapon_Foundry or typeId == resonance_info.Stratagem_Resonance end function FormationResonance_Controller.JumpToSpecificFunctionPanel(typeId) -- 记录跳转子共鸣ID private.jumpSubTypeId = typeId if typeId == resonance_info.Equip_Enhance or typeId == resonance_info.Equip_Quality or typeId == resonance_info.Jade_Insert then if typeId == resonance_info.Jade_Insert then local gemBagDatas = MDL.GemCompose.GetSortGemBagDatas() local count = #gemBagDatas if count <= 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Jade_NoOne"]) return end end -- 上阵武将默认穿戴的第一件装备 local heroIds = MDL.Player.GetHeroLinUpIds() for _, heroId in ipairs (heroIds) do if heroId == 0 or heroId == -1 then break end local equipInfos = MDL.Equipment.GetEquipmentsByHeroId(heroId) if equipInfos and #equipInfos > 0 then local subViewName = MDL.Equipment.DetailType.Base if typeId == resonance_info.Equip_Enhance then subViewName = MDL.Equipment.DetailType.Strengthen elseif typeId == resonance_info.Jade_Insert then subViewName = MDL.Equipment.DetailType.Compose end UIManager.CloseView(Const_UI_Lua.UIEnum.UIMedal) UIManager.CloseView(Const_UI_Lua.UIEnum.UIResonanceInfo) CTL.Equipment.OpenDetailByEquipInfo(equipInfos[1], subViewName) return end end CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Equipment_NoOne"]) elseif typeId == resonance_info.Hero_Advance or typeId == resonance_info.Hero_Break or typeId == resonance_info.Hero_Level then -- 默认拿排序第一个的武将 local heroIds = MDL.Formation.GetSlotHeroIds() MDL.HeroSelect.curSelectHeroID = heroIds[1] local subViewName = MDL.HeroSelect.ToggleViewNameList.Advanced if typeId == resonance_info.Hero_Break then subViewName = MDL.HeroSelect.ToggleViewNameList.Break elseif typeId == resonance_info.Hero_Level then subViewName = MDL.HeroSelect.ToggleViewNameList.LevelUp end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, {isFormation = true, subViewName = subViewName}) elseif typeId == resonance_info.Horse_Break then local activeHorses = MDL.WarHorse.GetActiveHorseInfoDic() if activeHorses then for _, v in pairs (activeHorses) do if v.HeroID then CTL.WarHorse.OpenSubPanel(CTL.WarHorse.Horse_EnterType.Formation, v.ConfigInfo, CTL.WarHorse.Horse_TabIndex.Break) return end end end CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Horse_NoOne"]) elseif typeId == resonance_info.Weapon_Break or typeId == resonance_info.Weapon_Foundry then local list = MDL.DivineWeapon.GetAllData() for _, v in ipairs (list) do local heroInfo = MDL.HeroSelect.GetHeroInfo(v.MagicWeaponID) if heroInfo then local toggleType if typeId == resonance_info.Weapon_Foundry then toggleType = UTL.Toggle.ToggleType.Forge end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel,{data = v, isFormation = true, toggleType = toggleType}) return end end elseif typeId == resonance_info.Treasure_Break then local treatures = MDL.Treasure.GetTreasureInfoList() if treatures then for _, v in pairs (treatures) do if v.EquipHeroId then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, {treasureId = v.TreasureID, isFormation = true}) return end end end CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Treasure_NoOne"]) elseif typeId == resonance_info.Treasure_Soul then CTL.Treasure.GotoTreasureSoul() elseif typeId == resonance_info.Stratagem_Resonance then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIStratagemMainPanel) elseif typeId == resonance_info.Horse_Soul then CTL.HorseSoul.GotoHorseSoul() elseif typeId == resonance_info.GodBeast_Raise or typeId == resonance_info.GodBeast_Break then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGodBeastMainPanel) elseif typeId == resonance_info.Horse_Equip then CTL.HorseEquip.GotoHorseEquip() end end function FormationResonance_Controller.SetSubResonanceImage(imageResonance, resonanceType, labTxt) if imageResonance and resonanceType then local subResonanceCfg = MDL.FormationResonance.GetSubResonanceCfg(resonanceType) if subResonanceCfg then UIUtils.SetImageByAssetBundle(imageResonance, subResonanceCfg.Icon) if labTxt then UIUtils.SetLabelText(labTxt, Const_IDS[subResonanceCfg.ResonanceChildName]) end end end end function FormationResonance_Controller.SetChangeMainResonanceAttrs(numTxt, nextLevel) if numTxt and nextLevel then local data = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(nextLevel) UIUtils.SetLabel(numTxt, FormationResonance_Controller.GetPercentStr(data.AttrNum)) if data then local mainLevel = nextLevel - 1 while (mainLevel ~= 0) do local temp = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(mainLevel) if temp.AttrType == data.AttrType then UIUtils.SetLabel(numTxt, FormationResonance_Controller.GetPercentStr(data.AttrNum - temp.AttrNum)) break end mainLevel = mainLevel - 1 end end end end function FormationResonance_Controller.OpenSubResonanceLevelUp() local subType = MDL.FormationResonance.GetSubResonanceOprType() local subInfo = MDL.FormationResonance.GetSubResonanceInfo(subType) if subInfo and subType == MDL.FormationResonance.GetLastUpdateSubType() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceLevelUp, subInfo) end end function private.ChangeLevelToNobilityLevel(level) local nobelCfg = private.GetNobilityCfgByProgress(level) if nobelCfg.RankID == 1 then return tostring(level) end local formerCfg = DataSheetManager.Nobility:GetDataByRankID(nobelCfg.RankID - 1) if GameAppInfo.IsVietnamPackage() then return string.format(NobelProgressLevelVN, UIUtils.GetLocalizedTxt(Const_IDS[nobelCfg.Name]), level - formerCfg.TeamLevelMax) else return string.format(NobelProgressLevel, UIUtils.GetLocalizedTxt(Const_IDS[nobelCfg.Name]), level - formerCfg.TeamLevelMax) end end function private.GetNobilityCfgByProgress(level) local nobelCfg = nil for _, v in DataSheetManager.Nobility:GetEnumerator() do if not nobelCfg and level <= v.TeamLevelMax then nobelCfg = v break end end return nobelCfg or DataSheetManager.Nobility:GetDataByRankID(NobilityMaxRankID) end function FormationResonance_Controller.FindUpdateAttrIndex(level) if level then local curResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(level) local nextResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(level + 1) if curResonanceCfg and nextResonanceCfg then for i, v in ipairs (curResonanceCfg.Attr_Table) do if nextResonanceCfg.Attr_Table[i].AttrNum > curResonanceCfg.Attr_Table[i].AttrNum then return i end end end end return 1 end function FormationResonance_Controller.RecoveryResonanceFunctionPanel() if private.jumpSubTypeId then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMedal) UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, {subResonanceID = private.jumpSubTypeId, isShowGoto = true}) end private.jumpSubTypeId = nil end function FormationResonance_Controller.ClearJumpSubTypeId() private.jumpSubTypeId = nil end return FormationResonance_Controller