| | |
| | | //--------------------------------------------------------
|
| | | // [Author]: YYL
|
| | | // [ Date ]: 2025年8月5日
|
| | | // [ Date ]: Wednesday, May 27, 2026
|
| | | //--------------------------------------------------------
|
| | |
|
| | | using System.Collections.Generic;
|
| | |
| | |
|
| | | public int Id;
|
| | | public int Country;
|
| | | public int Countrys;
|
| | | public int NeedHeroCount;
|
| | | public int[] AttrIDList;
|
| | | public int[] AttrValueList;
|
| | |
| | |
|
| | | int.TryParse(tables[1],out Country);
|
| | |
|
| | | int.TryParse(tables[2],out NeedHeroCount); |
| | | int.TryParse(tables[2],out Countrys); |
| | |
|
| | | if (tables[3].Contains("[")) |
| | | int.TryParse(tables[3],out NeedHeroCount); |
| | |
|
| | | if (tables[4].Contains("[")) |
| | | { |
| | | AttrIDList = JsonMapper.ToObject<int[]>(tables[3]); |
| | | AttrIDList = JsonMapper.ToObject<int[]>(tables[4]); |
| | | } |
| | | else |
| | | { |
| | | string[] AttrIDListStringArray = tables[3].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | string[] AttrIDListStringArray = tables[4].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | AttrIDList = new int[AttrIDListStringArray.Length]; |
| | | for (int i=0;i<AttrIDListStringArray.Length;i++) |
| | | { |
| | |
| | | } |
| | | }
|
| | |
|
| | | if (tables[4].Contains("[")) |
| | | if (tables[5].Contains("[")) |
| | | { |
| | | AttrValueList = JsonMapper.ToObject<int[]>(tables[4]); |
| | | AttrValueList = JsonMapper.ToObject<int[]>(tables[5]); |
| | | } |
| | | else |
| | | { |
| | | string[] AttrValueListStringArray = tables[4].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | string[] AttrValueListStringArray = tables[5].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries); |
| | | AttrValueList = new int[AttrValueListStringArray.Length]; |
| | | for (int i=0;i<AttrValueListStringArray.Length;i++) |
| | | { |
| | |
| | | // 国家 数量 |
| | | private static Dictionary<int, Dictionary<int, HeroLineupHaloConfig>> configDics = new Dictionary<int, Dictionary<int, HeroLineupHaloConfig>>(); |
| | | |
| | | // 混搭阵型索引:Key=Countrys, Value={NeedHeroCount→Config} |
| | | private static Dictionary<int, Dictionary<int, HeroLineupHaloConfig>> mixedConfigDics = new Dictionary<int, Dictionary<int, HeroLineupHaloConfig>>(); |
| | | |
| | | protected override void OnConfigParseCompleted() |
| | | { |
| | | |
| | | Dictionary<int, HeroLineupHaloConfig> tempDic = null; |
| | | if (!configDics.TryGetValue(Country, out tempDic)) |
| | | if (Country == 0 && Countrys > 0) |
| | | { |
| | | tempDic = new Dictionary<int, HeroLineupHaloConfig>(); |
| | | configDics.Add(Country, tempDic); |
| | | // 混搭阵型配置 |
| | | Dictionary<int, HeroLineupHaloConfig> tempDic = null; |
| | | if (!mixedConfigDics.TryGetValue(Countrys, out tempDic)) |
| | | { |
| | | tempDic = new Dictionary<int, HeroLineupHaloConfig>(); |
| | | mixedConfigDics.Add(Countrys, tempDic); |
| | | } |
| | | tempDic[NeedHeroCount] = this; |
| | | } |
| | | else |
| | | { |
| | | // 单国家配置 |
| | | Dictionary<int, HeroLineupHaloConfig> tempDic = null; |
| | | if (!configDics.TryGetValue(Country, out tempDic)) |
| | | { |
| | | tempDic = new Dictionary<int, HeroLineupHaloConfig>(); |
| | | configDics.Add(Country, tempDic); |
| | | } |
| | | |
| | | tempDic[NeedHeroCount] = this; |
| | | tempDic[NeedHeroCount] = this; |
| | | } |
| | | } |
| | | |
| | | public static HeroLineupHaloConfig GetConfig(int country, int count) |
| | |
| | | return configDics[country][count]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取所有混搭配置 |
| | | /// </summary> |
| | | public static Dictionary<int, Dictionary<int, HeroLineupHaloConfig>> GetAllMixedConfigs() |
| | | { |
| | | return mixedConfigDics; |
| | | } |
| | | |
| | | public static Dictionary<int, HeroLineupHaloConfig> GetAttrsByCountry(int country) |
| | | { |
| | | Dictionary<int, HeroLineupHaloConfig> attrs; |
| | |
| | | public void RefreshOnTeamCountry(List<TeamHero> teamHeroes, bool playEffect = false) |
| | | { |
| | | this.teamHeroes = teamHeroes; |
| | | |
| | | // 1. 先检查混搭阵型 |
| | | var mixedConfig = HeroUIManager.Instance.GetMixedFormationConfig(teamHeroes); |
| | | if (mixedConfig != null) |
| | | { |
| | | countryOnImg.SetSprite("heroTeamCountryHe"); |
| | | var participatingCountries = HeroUIManager.Instance.GetParticipatingCountriesByPriority(teamHeroes); |
| | | int totalPoints = mixedConfig.Countrys * mixedConfig.NeedHeroCount; |
| | | for (int i = 0; i < OnCountImgs.Count; i++) |
| | | { |
| | | if (i < totalPoints) |
| | | { |
| | | int countryIndex = i / mixedConfig.NeedHeroCount; |
| | | OnCountImgs[i].SetActive(true); |
| | | OnCountImgs[i].SetSprite("heroTeamCountryPoint" + participatingCountries[countryIndex]); |
| | | } |
| | | else |
| | | { |
| | | OnCountImgs[i].SetActive(false); |
| | | } |
| | | } |
| | | if (playEffect) |
| | | countryEffect.Play(); |
| | | return; |
| | | } |
| | | |
| | | Int2 result = HeroUIManager.Instance.GetMaxCountHeroCountry(teamHeroes); |
| | | |
| | | var config = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | |
| | | |
| | | public void Display(int index) |
| | | { |
| | | // 第5个格子为混搭阵型 |
| | | if (index == 4) |
| | | { |
| | | DisplayMixedFormation(); |
| | | return; |
| | | } |
| | | |
| | | Int2 result; |
| | | if (HeroUIManager.Instance.isCustonHeroFormation) |
| | | { |
| | |
| | | } |
| | | attrText.text = text; |
| | | } |
| | | |
| | | void DisplayMixedFormation() |
| | | { |
| | | // 获取当前激活的混搭配置 |
| | | HeroLineupHaloConfig activeMixedConfig; |
| | | List<TeamHero> teamHeroes = null; |
| | | if (HeroUIManager.Instance.isCustonHeroFormation) |
| | | teamHeroes = HeroUIManager.Instance.custonTeamHeroes; |
| | | |
| | | if (teamHeroes != null) |
| | | activeMixedConfig = HeroUIManager.Instance.GetMixedFormationConfig(teamHeroes); |
| | | else |
| | | activeMixedConfig = HeroUIManager.Instance.GetMixedFormationConfig(HeroUIManager.Instance.selectTeamType, true); |
| | | |
| | | bool hasActive = activeMixedConfig != null; |
| | | activeImg.SetActive(hasActive); |
| | | countryOnImg.SetSprite("heroTeamCountryHe"); |
| | | |
| | | // 激活点显示:使用当前激活配置的阵营颜色 |
| | | List<int> participatingCountries = null; |
| | | if (teamHeroes != null) |
| | | participatingCountries = HeroUIManager.Instance.GetParticipatingCountriesByPriority(teamHeroes); |
| | | else |
| | | participatingCountries = HeroUIManager.Instance.GetParticipatingCountriesByPriority(HeroUIManager.Instance.selectTeamType, true); |
| | | |
| | | if (activeMixedConfig != null && participatingCountries != null && participatingCountries.Count > 0) |
| | | { |
| | | int totalPoints = activeMixedConfig.Countrys * activeMixedConfig.NeedHeroCount; |
| | | for (int i = 0; i < OnCountImgs.Length; i++) |
| | | { |
| | | if (i < totalPoints) |
| | | { |
| | | int countryIndex = i / activeMixedConfig.NeedHeroCount; |
| | | OnCountImgs[i].SetActive(true); |
| | | OnCountImgs[i].SetSprite("heroTeamCountryPoint" + participatingCountries[countryIndex]); |
| | | } |
| | | else |
| | | { |
| | | OnCountImgs[i].SetActive(false); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < OnCountImgs.Length; i++) |
| | | OnCountImgs[i].SetActive(false); |
| | | } |
| | | |
| | | // 获取所有混搭配置并展平,按 Countrys 排序 |
| | | var allMixedConfigs = HeroLineupHaloConfig.GetAllMixedConfigs(); |
| | | List<HeroLineupHaloConfig> sortedConfigs = new List<HeroLineupHaloConfig>(); |
| | | if (allMixedConfigs != null) |
| | | { |
| | | foreach (var kvp in allMixedConfigs) |
| | | { |
| | | foreach (var innerKvp in kvp.Value) |
| | | { |
| | | sortedConfigs.Add(innerKvp.Value); |
| | | } |
| | | } |
| | | sortedConfigs.Sort((a, b) => |
| | | { |
| | | if (a.Countrys != b.Countrys) return a.Countrys.CompareTo(b.Countrys); |
| | | return a.NeedHeroCount.CompareTo(b.NeedHeroCount); |
| | | }); |
| | | } |
| | | |
| | | // 属性文本:遍历所有混搭配置,激活的高亮,未激活的灰色 |
| | | string text = string.Empty; |
| | | for (int k = 0; k < sortedConfigs.Count; k++) |
| | | { |
| | | var config = sortedConfigs[k]; |
| | | bool isActive = activeMixedConfig != null && activeMixedConfig.Id == config.Id; |
| | | string lineText = (k == 0 ? "" : "</r>") + Language.Get("herocard74", config.Countrys, config.NeedHeroCount); |
| | | |
| | | for (int i = 0; i < config.AttrIDList.Length; i++) |
| | | { |
| | | string format = !isActive ? "{0}+{1}" : "{0}+" + UIHelper.AppendColor(TextColType.Green, "{1}"); |
| | | lineText += " " + PlayerPropertyConfig.GetFullDescription(config.AttrIDList[i], config.AttrValueList[i], format); |
| | | } |
| | | |
| | | text += UIHelper.AppendColor(isActive ? TextColType.NavyBrown : TextColType.Gray, lineText); |
| | | } |
| | | attrText.text = text; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | scroller.OnRefreshCell += OnRefreshCell; |
| | | CreateScroller(); |
| | | Int2 result; |
| | | |
| | | // 优先检查混搭阵型 |
| | | HeroLineupHaloConfig activeConfig = null; |
| | | if (HeroUIManager.Instance.isCustonHeroFormation) |
| | | { |
| | | result = HeroUIManager.Instance.GetMaxCountHeroCountry(HeroUIManager.Instance.custonTeamHeroes);; |
| | | activeConfig = HeroUIManager.Instance.GetMixedFormationConfig(HeroUIManager.Instance.custonTeamHeroes); |
| | | if (activeConfig == null) |
| | | { |
| | | var result = HeroUIManager.Instance.GetMaxCountHeroCountry(HeroUIManager.Instance.custonTeamHeroes); |
| | | activeConfig = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result = HeroUIManager.Instance.GetMaxCountHeroCountry(HeroUIManager.Instance.selectTeamType, true); |
| | | activeConfig = HeroUIManager.Instance.GetMixedFormationConfig(HeroUIManager.Instance.selectTeamType, true); |
| | | if (activeConfig == null) |
| | | { |
| | | var result = HeroUIManager.Instance.GetMaxCountHeroCountry(HeroUIManager.Instance.selectTeamType, true); |
| | | activeConfig = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | | } |
| | | } |
| | | |
| | | |
| | | var config = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | | if (config == null) |
| | | if (activeConfig == null) |
| | | { |
| | | totalAttrText.text = ""; |
| | | } |
| | |
| | | { |
| | | string lineText = string.Empty; |
| | | |
| | | for (int i = 0; i < config.AttrIDList.Length; i++) |
| | | for (int i = 0; i < activeConfig.AttrIDList.Length; i++) |
| | | { |
| | | string format = "{0}+" + UIHelper.AppendColor(TextColType.Green, "{1}"); |
| | | lineText += " " + PlayerPropertyConfig.GetFullDescription(config.AttrIDList[i], config.AttrValueList[i], format); |
| | | lineText += " " + PlayerPropertyConfig.GetFullDescription(activeConfig.AttrIDList[i], activeConfig.AttrValueList[i], format); |
| | | } |
| | | totalAttrText.text = Language.Get("herocard36") + lineText.Trim(); |
| | | } |
| | |
| | | { |
| | | scroller.AddCell(ScrollerDataType.Header, i); |
| | | } |
| | | // 第5个为混搭阵型格子(显示在最后) |
| | | scroller.AddCell(ScrollerDataType.Header, 4); |
| | | scroller.Restart(); |
| | | } |
| | | |
| | |
| | | //上阵武将国家光环激活 |
| | | void RefreshOnTeamCountry(bool playEffect = false) |
| | | { |
| | | // 先检查混搭阵型 |
| | | var mixedConfig = HeroUIManager.Instance.GetMixedFormationConfig(HeroUIManager.Instance.selectTeamType, true); |
| | | if (mixedConfig != null) |
| | | { |
| | | countryOnImg.SetSprite("heroTeamCountryHe"); |
| | | var participatingCountries = HeroUIManager.Instance.GetParticipatingCountriesByPriority(HeroUIManager.Instance.selectTeamType, true); |
| | | int totalPoints = mixedConfig.Countrys * mixedConfig.NeedHeroCount; |
| | | for (int i = 0; i < OnCountImgs.Count; i++) |
| | | { |
| | | if (i < totalPoints) |
| | | { |
| | | int countryIndex = i / mixedConfig.NeedHeroCount; |
| | | OnCountImgs[i].SetActive(true); |
| | | OnCountImgs[i].SetSprite("heroTeamCountryPoint" + participatingCountries[countryIndex]); |
| | | } |
| | | else |
| | | { |
| | | OnCountImgs[i].SetActive(false); |
| | | } |
| | | } |
| | | if (playEffect) |
| | | countryEffect.Play(); |
| | | return; |
| | | } |
| | | |
| | | Int2 result = HeroUIManager.Instance.GetMaxCountHeroCountry(HeroUIManager.Instance.selectTeamType, true); |
| | | |
| | | var config = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | |
| | | // return lineUPPer; |
| | | // } |
| | | |
| | | #region 混搭阵型 |
| | | |
| | | /// <summary> |
| | | /// 检测是否满足混搭阵型条件(按队伍类型) |
| | | /// </summary> |
| | | public HeroLineupHaloConfig GetMixedFormationConfig(int teamType, bool isPreview = false) |
| | | { |
| | | var countryCountDict = GetCountryHeroCountByTeamType(teamType, isPreview); |
| | | return GetMixedFormationConfigByCountryDict(countryCountDict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测是否满足混搭阵型条件(按自定义队伍) |
| | | /// </summary> |
| | | public HeroLineupHaloConfig GetMixedFormationConfig(List<TeamHero> teamHeroes) |
| | | { |
| | | var countryCountDict = GetCountryHeroCountByTeamHeroList(teamHeroes); |
| | | return GetMixedFormationConfigByCountryDict(countryCountDict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据国家分布检测混搭阵型 |
| | | /// </summary> |
| | | HeroLineupHaloConfig GetMixedFormationConfigByCountryDict(Dictionary<HeroCountry, int> countryCountDict) |
| | | { |
| | | var mixedConfigs = HeroLineupHaloConfig.GetAllMixedConfigs(); |
| | | if (mixedConfigs == null || mixedConfigs.Count == 0) |
| | | return null; |
| | | |
| | | // 统计有武将上阵的不同国家数量 和 最小国家武将数 |
| | | int distinctCountryCount = 0; |
| | | int minHeroCount = int.MaxValue; |
| | | foreach (var data in countryCountDict) |
| | | { |
| | | if (data.Value > 0) |
| | | { |
| | | distinctCountryCount++; |
| | | if (data.Value < minHeroCount) |
| | | minHeroCount = data.Value; |
| | | } |
| | | } |
| | | |
| | | if (distinctCountryCount == 0) |
| | | return null; |
| | | |
| | | // 遍历混搭配置,检查是否匹配 |
| | | foreach (var kvp in mixedConfigs) |
| | | { |
| | | int countrys = kvp.Key; |
| | | if (countrys != distinctCountryCount) |
| | | continue; |
| | | |
| | | foreach (var innerKvp in kvp.Value) |
| | | { |
| | | int needHeroCount = innerKvp.Key; |
| | | if (minHeroCount >= needHeroCount) |
| | | return innerKvp.Value; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取上阵武将中所有参与的国家,按优先级排序(按队伍类型) |
| | | /// 优先级:魏(1) > 蜀(2) > 吴(3) > 群(4) |
| | | /// </summary> |
| | | public List<int> GetParticipatingCountriesByPriority(int teamType, bool isPreview = false) |
| | | { |
| | | var countryCountDict = GetCountryHeroCountByTeamType(teamType, isPreview); |
| | | return GetParticipatingCountriesByPriorityByDict(countryCountDict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取上阵武将中所有参与的国家,按优先级排序(按自定义队伍) |
| | | /// </summary> |
| | | public List<int> GetParticipatingCountriesByPriority(List<TeamHero> teamHeroes) |
| | | { |
| | | var countryCountDict = GetCountryHeroCountByTeamHeroList(teamHeroes); |
| | | return GetParticipatingCountriesByPriorityByDict(countryCountDict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据国家分布获取所有参与国家(按优先级排序) |
| | | /// </summary> |
| | | List<int> GetParticipatingCountriesByPriorityByDict(Dictionary<HeroCountry, int> countryCountDict) |
| | | { |
| | | List<int> result = new List<int>(); |
| | | // 优先级:魏(1) > 蜀(2) > 吴(3) > 群(4) |
| | | for (int i = 1; i <= 4; i++) |
| | | { |
| | | if (countryCountDict.ContainsKey((HeroCountry)i) && countryCountDict[(HeroCountry)i] > 0) |
| | | result.Add(i); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 按队伍获得阵型(国家光环)属性 |
| | | /// </summary> |
| | |
| | | public Dictionary<int, int> GetCountryAttrs(int teamType, bool isPreview = false) |
| | | { |
| | | Dictionary<int, int> countryAttrs = new Dictionary<int, int>(); |
| | | |
| | | // 1. 先检查混搭阵型 |
| | | var mixedConfig = GetMixedFormationConfig(teamType, isPreview); |
| | | if (mixedConfig != null) |
| | | { |
| | | for (int i = 0; i < mixedConfig.AttrIDList.Length; i++) |
| | | { |
| | | countryAttrs[mixedConfig.AttrIDList[i]] = mixedConfig.AttrValueList[i]; |
| | | } |
| | | return countryAttrs; |
| | | } |
| | | |
| | | // 2. 没有混搭则走单国家逻辑 |
| | | Int2 result = GetMaxCountHeroCountry(teamType, isPreview); |
| | | var lineupconfig = HeroLineupHaloConfig.GetConfig(result.x, result.y); |
| | | if (lineupconfig != null) |