using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; //武将相关界面的操作数据管理 public class HeroUIManager : GameSystemManager { #region 武将列表界面 public List heroSortList { get; private set; } = new List(); //上阵为主线的列表 #endregion public void OnBeforePlayerDataInitialize() { heroSortList.Clear(); heroOnTeamSortList.Clear(); } public void OnPlayerLoginOk() { } public override void Init() { } public override void Release() { } public void QueryUnLockHeroPack() { //解锁更多的武将背包 int canBuyCnt = PackManager.Instance.GetCanBuyPackGirdCount(PackType.Hero); if (canBuyCnt <= 0) { return; } ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HeroPack1", GeneralDefine.MoneyDisplayModel[1],1, 1), (bool isOK)=> { }); } //刷新时机, 打开武将界面 或者 关闭功能界面 public void SortHeroList() { heroSortList = HeroManager.Instance.GetHeroGuidList(); heroSortList.Sort(CmpHero); } int CmpHero(string guidA, string guidB) { HeroInfo heroA = HeroManager.Instance.GetHero(guidA); HeroInfo heroB = HeroManager.Instance.GetHero(guidB); if (heroA == null || heroB == null) { return 0; } // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID bool isInTeamA = heroA.IsInTeamByTeamType(TeamType.Story); bool isInTeamB = heroB.IsInTeamByTeamType(TeamType.Story); if (isInTeamA != isInTeamB) { return isInTeamA ? -1 : 1; } if (heroA.heroLevel != heroB.heroLevel) { return heroA.heroLevel > heroB.heroLevel ? -1 : 1; } if (heroA.breakLevel != heroB.breakLevel) { return heroA.breakLevel > heroB.breakLevel ? -1 : 1; } if (heroA.awakeLevel != heroB.awakeLevel) { return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1; } if (heroA.Quality != heroB.Quality) { return heroA.Quality > heroB.Quality ? -1 : 1; } if (heroA.heroStar != heroA.heroStar) { return heroA.heroStar > heroB.heroStar ? -1 : 1; } return heroA.heroId.CompareTo(heroB.heroId); } #region 布阵界面 public List heroOnTeamSortList { get; private set; } = new List(); //不同上阵的列表排序 private TeamType m_SelectTeamType = TeamType.Story; //当前选中的是哪个阵容, 布阵相关逻辑使用 public TeamType selectTeamType { get { return m_SelectTeamType; } set { if (m_SelectTeamType == value) return; //上一个阵容需要恢复到原状态 if (m_SelectTeamType != TeamType.None) { TeamManager.Instance.GetTeam(m_SelectTeamType).RestoreTeam(); } m_SelectTeamType = value; } } public int selectTeamPosJob = 0; //布阵界面 筛选职业 public int selectTeamPosCountry = 0; //布阵界面 筛选国家 public const float clickFlyPosTime = 0.5f; //点击列表中的武将图标时, 飞入布阵的时间 public event Action, int, Vector3> OnTeamPosChangeEvent; //布阵变化 位置,列表的起飞索引,起飞坐标 public void SortHeroOnTeamList() { heroOnTeamSortList = HeroManager.Instance.GetHeroGuidList(selectTeamPosJob, selectTeamPosCountry); heroOnTeamSortList.Sort(CmpHeroByTeamType); } int CmpHeroByTeamType(string guidA, string guidB) { HeroInfo heroA = HeroManager.Instance.GetHero(guidA); HeroInfo heroB = HeroManager.Instance.GetHero(guidB); if (heroA == null || heroB == null) { return 0; } // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID bool isInTeamA = heroA.IsInTeamByTeamType(selectTeamType); bool isInTeamB = heroB.IsInTeamByTeamType(selectTeamType); if (isInTeamA != isInTeamB) { return isInTeamA ? -1 : 1; } if (heroA.heroLevel != heroB.heroLevel) { return heroA.heroLevel > heroB.heroLevel ? -1 : 1; } if (heroA.breakLevel != heroB.breakLevel) { return heroA.breakLevel > heroB.breakLevel ? -1 : 1; } if (heroA.awakeLevel != heroB.awakeLevel) { return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1; } if (heroA.Quality != heroB.Quality) { return heroA.Quality > heroB.Quality ? -1 : 1; } if (heroA.heroStar != heroA.heroStar) { return heroA.heroStar > heroB.heroStar ? -1 : 1; } return heroA.heroId.CompareTo(heroB.heroId); } //上阵队伍中各个国家的武将数量 public Dictionary GetCountryHeroCountByTeamType(TeamType teamType) { Dictionary heroCountryCount = new Dictionary(); var team = TeamManager.Instance.GetTeam(teamType); if (team != null) { for (int i = 0; i < team.tempHeroes.Length; i++) { if (team.tempHeroes[i] == null) continue; var country = (HeroCountry)team.tempHeroes[i].heroConfig.Country; if (!heroCountryCount.ContainsKey(country)) { heroCountryCount.Add(country, 1); } else { heroCountryCount[country] = heroCountryCount[country] + 1; } } } return heroCountryCount; } //获得上阵中武将数量最大的国家和数量 public Int2 GetMaxCountHeroCountry(TeamType teamType) { var countryCount = GetCountryHeroCountByTeamType(teamType); //找到最大的国家和数量 HeroCountry country = HeroCountry.None; int maxValue = 0; foreach (var data in countryCount) { if (data.Value > maxValue) { country = data.Key; maxValue = data.Value; } } return new Int2((int)country, maxValue); } //在不同页签下选AttackType 0 攻击阵容 1 防守阵容 public int GetSelectTeamTypeByAttackType(int AttackType) { if (selectTeamType == TeamType.Arena || selectTeamType == TeamType.ArenaDefense) { return AttackType == 0 ? (int)TeamType.Arena : (int)TeamType.ArenaDefense; } return (int)TeamType.Story; } public void NotifyOnTeamPosChangeEvent(List posList, int flyIndex, Vector3 startPos) { OnTeamPosChangeEvent?.Invoke(posList, flyIndex, startPos); } //推荐阵容 public List SelectRecommend() { //推荐阵容的算法逻辑 //自动选择优先级:武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID var tmpList = HeroManager.Instance.GetHeroGuidList(); tmpList.Sort(CmpHeroRecommend); //推荐最多6个,存在相同heroid,则跳过 List selectHeroList = new List(); List selectHeroIDList = new List(); for (int i = 0; i < tmpList.Count; i++) { if (selectHeroList.Count >= TeamConst.MaxTeamHeroCount) break; string guid = tmpList[i]; HeroInfo heroInfo = HeroManager.Instance.GetHero(guid); if (selectHeroIDList.Contains(heroInfo.heroId)) continue; //如果重复了,跳过 if (selectHeroList.Contains(guid)) continue; selectHeroList.Add(guid); selectHeroIDList.Add(heroInfo.heroId); } return selectHeroList; } int CmpHeroRecommend(string guidA, string guidB) { HeroInfo heroA = HeroManager.Instance.GetHero(guidA); HeroInfo heroB = HeroManager.Instance.GetHero(guidB); if (heroA == null || heroB == null) { return 0; } // 排序规则:武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID if (heroA.heroLevel != heroB.heroLevel) { return heroA.heroLevel > heroB.heroLevel ? -1 : 1; } if (heroA.breakLevel != heroB.breakLevel) { return heroA.breakLevel > heroB.breakLevel ? -1 : 1; } if (heroA.awakeLevel != heroB.awakeLevel) { return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1; } if (heroA.Quality != heroB.Quality) { return heroA.Quality > heroB.Quality ? -1 : 1; } if (heroA.heroStar != heroA.heroStar) { return heroA.heroStar > heroB.heroStar ? -1 : 1; } return heroA.heroId.CompareTo(heroB.heroId); } #endregion }