using System; 
 | 
using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
  
 | 
using UnityEngine; 
 | 
  
 | 
public partial class HeroUIManager : GameSystemManager<HeroUIManager> 
 | 
{ 
 | 
  
 | 
  
 | 
    #region 布阵界面 
 | 
    public List<string> heroOnTeamSortList { get; private set; } = new List<string>();    //不同上阵的列表排序 
 | 
  
 | 
    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<List<int>, int, Vector3> OnTeamPosChangeEvent; //布阵变化 位置,列表的起飞索引,起飞坐标 
 | 
  
 | 
  
 | 
    // 【阵容属性】 - 该阵容所有武将有效 
 | 
    // 初始加成    lineupInitAddPer 
 | 
    // 升级加成    lineupLVAddPer 
 | 
    // 突破加成    lineupBreakLVAddPer 
 | 
    // 吞噬加成    lineupStarAddPer 
 | 
    // 阵容光环    lineupHaloValue 、 lineupHaloPer 
 | 
  
 | 
    /// <summary> 
 | 
    /// 按队伍汇总上阵属性 
 | 
    /// </summary> 
 | 
    /// <param name="type"></param> 
 | 
    /// <param name="isPreview">true 客户端预览阵容,默认false 服务器阵容</param> 
 | 
    /// <returns></returns> 
 | 
    public Dictionary<string, int> GetLineupPer(TeamType type, bool isPreview = false) 
 | 
    { 
 | 
        Dictionary<string, int> lineUPPer = new Dictionary<string, int>() 
 | 
        { 
 | 
            {"lineupInitAddPer", 0}, 
 | 
            {"lineupLVAddPer", 0}, 
 | 
            {"lineupBreakLVAddPer", 0}, 
 | 
            {"lineupStarAddPer", 0}, 
 | 
        }; 
 | 
  
 | 
        var team = TeamManager.Instance.GetTeam(type); 
 | 
        if (team == null) 
 | 
        { 
 | 
            return lineUPPer; 
 | 
        } 
 | 
        TeamHero[] teamHeroes = isPreview ? team.tempHeroes : team.serverHeroes; 
 | 
  
 | 
        foreach (var teamHero in teamHeroes) 
 | 
        { 
 | 
            if (teamHero == null) 
 | 
            { 
 | 
                continue; 
 | 
            } 
 | 
            var config = HeroQualityConfig.Get(HeroConfig.Get(teamHero.heroId).Quality); 
 | 
            lineUPPer["lineupInitAddPer"] += config.InitAddPer; 
 | 
  
 | 
            HeroInfo hero = HeroManager.Instance.GetHero(teamHero.guid); 
 | 
            if (hero == null) continue; 
 | 
            lineUPPer["lineupLVAddPer"] += hero.GetLineupLVAddPer(); 
 | 
            lineUPPer["lineupBreakLVAddPer"] += hero.GetLineupBreakLVAddPer(); 
 | 
            lineUPPer["lineupStarAddPer"] += hero.GetLineupStarAddPer(); 
 | 
  
 | 
        } 
 | 
        return lineUPPer; 
 | 
    } 
 | 
  
 | 
    /// <summary> 
 | 
    /// 按队伍获得阵型(国家光环)属性 
 | 
    /// </summary> 
 | 
    /// <param name="teamType"></param> 
 | 
    /// <param name="isPreview">true 客户端预览阵容,默认false 服务器阵容</param> 
 | 
    /// <returns></returns> 
 | 
    public Dictionary<int, int> GetCountryAttrs(TeamType teamType, bool isPreview = false) 
 | 
    { 
 | 
        Dictionary<int, int> countryAttrs = new Dictionary<int, int>(); 
 | 
        Int2 result = GetMaxCountHeroCountry(teamType, isPreview); 
 | 
        var lineupconfig = HeroLineupHaloConfig.GetConfig(result.x, result.y); 
 | 
        if (lineupconfig != null) 
 | 
        { 
 | 
            for (int i = 0; i < lineupconfig.AttrIDList.Length; i++) 
 | 
            { 
 | 
                countryAttrs[lineupconfig.AttrIDList[i]] = lineupconfig.AttrValueList[i]; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        return countryAttrs; 
 | 
    } 
 | 
  
 | 
    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; 
 | 
        } 
 | 
  
 | 
        var team = TeamManager.Instance.GetTeam(selectTeamType); 
 | 
        // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID 
 | 
        bool isInTeamA = team.HasHeroInServer(guidA); 
 | 
        bool isInTeamB = team.HasHeroInServer(guidB); 
 | 
        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 != heroB.heroStar) 
 | 
        { 
 | 
            return heroA.heroStar > heroB.heroStar ? -1 : 1; 
 | 
        } 
 | 
  
 | 
        return heroA.heroId.CompareTo(heroB.heroId); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
    /// <summary> 
 | 
    /// 上阵队伍中各个国家的武将数量 
 | 
    /// </summary> 
 | 
    /// <param name="teamType"></param> 
 | 
    /// <param name="isPreview">true 客户端预览阵容,默认false 服务器阵容</param> 
 | 
    /// <returns></returns> 
 | 
    public Dictionary<HeroCountry, int> GetCountryHeroCountByTeamType(TeamType teamType, bool isPreview = false) 
 | 
    { 
 | 
        Dictionary<HeroCountry, int> heroCountryCount = new Dictionary<HeroCountry, int>(); 
 | 
  
 | 
        var team = TeamManager.Instance.GetTeam(teamType); 
 | 
        if (team == null) 
 | 
        { 
 | 
            return heroCountryCount; 
 | 
        } 
 | 
        TeamHero[] teamHeroes = isPreview ? team.tempHeroes : team.serverHeroes; 
 | 
  
 | 
        for (int i = 0; i < teamHeroes.Length; i++) 
 | 
        { 
 | 
            if (teamHeroes[i] == null) 
 | 
                continue; 
 | 
            var country = teamHeroes[i].Country; 
 | 
  
 | 
            if (!heroCountryCount.ContainsKey(country)) 
 | 
            { 
 | 
                heroCountryCount.Add(country, 1); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                heroCountryCount[country] += 1; 
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
  
 | 
        return heroCountryCount; 
 | 
    } 
 | 
  
 | 
    /// <summary> 
 | 
    /// 获得自定义队伍中各个国家的武将数量 
 | 
    /// </summary> 
 | 
    public Dictionary<HeroCountry, int> GetCountryHeroCountByTeamHeroList(List<TeamHero> teamHeroes) 
 | 
    { 
 | 
        Dictionary<HeroCountry, int> heroCountryCount = new Dictionary<HeroCountry, int>(); 
 | 
        if (teamHeroes == null) 
 | 
        { 
 | 
            return heroCountryCount; 
 | 
        } 
 | 
        for (int i = 0; i < teamHeroes.Count; i++) 
 | 
        { 
 | 
            if (teamHeroes[i] == null) 
 | 
                continue; 
 | 
            var country = teamHeroes[i].Country; 
 | 
  
 | 
            if (!heroCountryCount.ContainsKey(country)) 
 | 
            { 
 | 
                heroCountryCount.Add(country, 1); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                heroCountryCount[country] += 1; 
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
  
 | 
        return heroCountryCount; 
 | 
    } 
 | 
  
 | 
    /// <summary> 
 | 
    /// 获得上阵中武将数量最大的国家和数量 
 | 
    /// </summary> 
 | 
    /// <param name="teamType"></param> 
 | 
    /// <param name="isPreview">true 客户端预览阵容,默认false 服务器阵容</param> 
 | 
    /// <returns></returns> 
 | 
    public Int2 GetMaxCountHeroCountry(TeamType teamType, bool isPreview = false) 
 | 
    { 
 | 
        var countryCountDict = GetCountryHeroCountByTeamType(teamType, isPreview); 
 | 
        //找到最大的国家和数量 
 | 
        HeroCountry country = HeroCountry.None; 
 | 
        int maxValue = 0; 
 | 
        foreach (var data in countryCountDict) 
 | 
        { 
 | 
            if (data.Value > maxValue) 
 | 
            { 
 | 
                country = data.Key; 
 | 
                maxValue = data.Value; 
 | 
            } 
 | 
        } 
 | 
        return new Int2((int)country, maxValue); 
 | 
    } 
 | 
  
 | 
    /// <summary> 
 | 
    /// 获得自定义队伍中武将数量最大的国家和数量 
 | 
    /// </summary> 
 | 
    public Int2 GetMaxCountHeroCountry(List<TeamHero> teamType) 
 | 
    { 
 | 
        var countryCountDict = GetCountryHeroCountByTeamHeroList(teamType); 
 | 
        //找到最大的国家和数量 
 | 
        HeroCountry country = HeroCountry.None; 
 | 
        int maxValue = 0; 
 | 
        foreach (var data in countryCountDict) 
 | 
        { 
 | 
            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<int> posList, int flyIndex, Vector3 startPos) 
 | 
    { 
 | 
        OnTeamPosChangeEvent?.Invoke(posList, flyIndex, startPos); 
 | 
    } 
 | 
  
 | 
    //推荐阵容 
 | 
    public List<string> SelectRecommend() 
 | 
    { 
 | 
        var tmpList = HeroManager.Instance.GetHeroGuidList(); 
 | 
        tmpList.Sort(CmpHeroRecommend); 
 | 
        //推荐最多6个,存在相同heroid,则跳过 
 | 
        List<string> selectHeroList = new List<string>(); 
 | 
        List<int> selectHeroIDList = new List<int>(); 
 | 
        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); 
 | 
        } 
 | 
  
 | 
        // 再按 肉盾>控制>输出>辅助 
 | 
        selectHeroList.Sort(CmpByJob); 
 | 
  
 | 
        return selectHeroList; 
 | 
    } 
 | 
  
 | 
    //!!!新排序规则 
 | 
    //若在新手引导(引导ID)中,如果5号位为空,则优先放置5号位 
 | 
    //按战力排序  
 | 
    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 != heroB.heroStar) 
 | 
        // { 
 | 
        //     return heroA.heroStar > heroB.heroStar ? -1 : 1; 
 | 
        // } 
 | 
  
 | 
  
 | 
  
 | 
        return heroB.CalculateFightPower(false).CompareTo(heroA.CalculateFightPower(false)); 
 | 
    } 
 | 
  
 | 
    int CmpByJob(string guidA, string guidB) 
 | 
    { 
 | 
        HeroInfo heroA = HeroManager.Instance.GetHero(guidA); 
 | 
        HeroInfo heroB = HeroManager.Instance.GetHero(guidB); 
 | 
        if (heroA == null || heroB == null) 
 | 
        { 
 | 
            return 0; 
 | 
        } 
 | 
         
 | 
        int indexA = Array.IndexOf(teamSortByJob, heroA.heroConfig.Class); 
 | 
        int indexB = Array.IndexOf(teamSortByJob, heroB.heroConfig.Class); 
 | 
  
 | 
        return indexA.CompareTo(indexB); 
 | 
    } 
 | 
  
 | 
  
 | 
    #endregion 
 | 
  
 | 
    #region 主界面上的武将上阵解锁显示 和 解锁规则 
 | 
  
 | 
    public int[][] lockHeroCountLimit; 
 | 
    public List<int> lockIndexList = new List<int>(); 
 | 
  
 | 
    public int[] teamSortByJob; 
 | 
    public int onekeyGuideID; 
 | 
    public int onekeyGuideFirstPos; //一键上阵在引导下的最优先推荐位置 
 | 
  
 | 
    public Action OnUnLockHeroCountEvent; 
 | 
    public int lockState 
 | 
    { 
 | 
        get 
 | 
        { 
 | 
            return QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.HeroCountLock, 0); 
 | 
        } 
 | 
        set 
 | 
        { 
 | 
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.HeroCountLock, value, 0); 
 | 
            QuickSetting.Instance.SendPackage(); 
 | 
            RefreshServerLockIndex(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    //解锁上阵英雄的数量限制, 解锁条件在界面上是按顺序排序的,但是锁定的位置是动态变化的 
 | 
    //比如 第4,5,6格子锁住了,但第6个的锁先完成了解锁条件,解锁后锁住的位置往后顺推 
 | 
    //则 第4的位置显示为解锁状态,5和6是锁住状态,5的解锁条件按配置列表的顺序解锁(即为原4的解锁条件) 
 | 
  
 | 
    // 模拟服务端 这里的index 对应的是配表的 
 | 
    public bool IsUnLock(int configIndex) 
 | 
    { 
 | 
        //按lockState的位判断 
 | 
        return (lockState & (1 << configIndex)) != 0; 
 | 
    } 
 | 
  
 | 
    public bool SetUnLock(int configIndex) 
 | 
    { 
 | 
        if (!CanUnLock(configIndex, true)) 
 | 
        { 
 | 
            return false; 
 | 
        } 
 | 
        lockState |= 1 << configIndex; 
 | 
        return true; 
 | 
    } 
 | 
  
 | 
    // 解锁类型 
 | 
    // 1.主公等级达X级开启; 
 | 
    // 2.通关主线X-X开启;同任务配法 
 | 
    // 3.开服时间达到X天开启; 
 | 
    public bool CanUnLock(int configIndex, bool notify = false) 
 | 
    { 
 | 
        int type = lockHeroCountLimit[configIndex][0]; 
 | 
        int value = lockHeroCountLimit[configIndex][1]; 
 | 
        if (type == 1) 
 | 
        { 
 | 
            if (PlayerDatas.Instance.baseData.LV < value) 
 | 
            { 
 | 
                if (notify) 
 | 
                    SysNotifyMgr.Instance.ShowTip("HeroCountUnLock1", value); 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
        else if (type == 2) 
 | 
        { 
 | 
            //如ExAttr1值为20103代表当前已经过了第2章第1关第3波; value为201 
 | 
            if (PlayerDatas.Instance.baseData.ExAttr1 / 100 <= value) 
 | 
            { 
 | 
                if (notify) 
 | 
                    SysNotifyMgr.Instance.ShowTip("HeroCountUnLock2", value / 100, value % 100); 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
        else if (type == 3) 
 | 
        { 
 | 
            if (TimeUtility.OpenDay < value - 1) 
 | 
            { 
 | 
                if (notify) 
 | 
                    SysNotifyMgr.Instance.ShowTip("HeroCountUnLock3", value); 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        return true; 
 | 
    } 
 | 
  
 | 
  
 | 
    public void ShowUnLockTip(int configIndex) 
 | 
    { 
 | 
        int type = lockHeroCountLimit[configIndex][0]; 
 | 
        int value = lockHeroCountLimit[configIndex][1]; 
 | 
        if (type == 1) 
 | 
        { 
 | 
            if (PlayerDatas.Instance.baseData.LV < value) 
 | 
            { 
 | 
                SysNotifyMgr.Instance.ShowTip("HeroCountUnLock1", value); 
 | 
                return; 
 | 
            } 
 | 
        } 
 | 
        else if (type == 2) 
 | 
        { 
 | 
            //如ExAttr1值为20103代表当前已经过了第2章第1关第3波; value为201 
 | 
            if (PlayerDatas.Instance.baseData.ExAttr1 / 100 <= value) 
 | 
            { 
 | 
                SysNotifyMgr.Instance.ShowTip("HeroCountUnLock2", value / 100, value % 100); 
 | 
                return; 
 | 
            } 
 | 
        } 
 | 
        else if (type == 3) 
 | 
        { 
 | 
            if (TimeUtility.OpenDay < value - 1) 
 | 
            { 
 | 
                SysNotifyMgr.Instance.ShowTip("HeroCountUnLock3", value); 
 | 
                return; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        //可以解锁,但未解锁 
 | 
        if (!IsUnLock(configIndex)) 
 | 
        { 
 | 
            SysNotifyMgr.Instance.ShowTip("HeroCountUnLock4"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    // 刷新未解锁武将上限的配置索引列表 
 | 
    public void RefreshServerLockIndex() 
 | 
    { 
 | 
        lockIndexList.Clear(); 
 | 
        for (int i = 0; i < lockHeroCountLimit.Length; i++) 
 | 
        { 
 | 
            if (!IsUnLock(i)) 
 | 
            { 
 | 
                lockIndexList.Add(i); 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public bool UnLockHeroCnt(int lockIndex) 
 | 
    { 
 | 
        if (lockIndex < 0 || lockIndex >= lockIndexList.Count) 
 | 
        { 
 | 
            return false; 
 | 
        } 
 | 
  
 | 
        return SetUnLock(lockIndexList[lockIndex]); 
 | 
  
 | 
    } 
 | 
  
 | 
    void OnQuickSettingUpdate() 
 | 
    { 
 | 
        RefreshServerLockIndex(); 
 | 
    } 
 | 
    #endregion 
 | 
  
 | 
} 
 |