yyl
2025-10-17 c124d98bdf9659cf764bebb799bee42c30eb152f
Main/System/Hero/HeroManager.cs
@@ -10,16 +10,9 @@
    //初始创建(0725),后续跟随背包事件增加删除  key = guid
    protected Dictionary<string, HeroInfo> heroInfoDict = new Dictionary<string, HeroInfo>();
    //武将红点
    //MainRedDot.HeroCardRedpoint * 1000 + hero.itemHero.gridIndex;
    public Action<HeroInfo> onNewHeroEvent;
    public Action<HeroInfo> onHeroChangeEvent;
    public Action<HeroInfo> onHeroDeleteEvent;
    public Action<int> onHeroDeleteEvent;
    public override void Init()
    {
@@ -40,7 +33,7 @@
    void OnBeforePlayerDataInitialize()
    {
        heroInfoDict.Clear();
    }
@@ -65,7 +58,7 @@
        }
    }
    void DeleteHero(PackType packType, string guid)
    void DeleteHero(PackType packType, string guid, int itemID, int index, int clearType)
    {
        if (packType == PackType.Hero)
        {
@@ -73,9 +66,8 @@
            heroInfoDict.TryGetValue(guid, out heroInfo);
            heroInfoDict.Remove(guid);
            if (null != heroInfo)
                onHeroDeleteEvent?.Invoke(heroInfo);
            onHeroDeleteEvent?.Invoke(itemID);
        }
    }
@@ -95,12 +87,27 @@
    {
        if (job == 0 && country == 0)
            return heroInfoDict.Keys.ToList();
        return heroInfoDict.Keys.Where((x) =>
        List<string> retGuidList = new List<string>();
        foreach (string guid in heroInfoDict.Keys)
        {
            HeroInfo heroInfo = heroInfoDict[x];
            return heroInfo.heroConfig.Class == job && heroInfo.heroConfig.Country == country;
        }).ToList();
            HeroInfo heroInfo = heroInfoDict[guid];
            //0代表全部
            if (job == 0 || country == 0)
            {
                if (job != 0 && job == heroInfo.heroConfig.Class)
                    retGuidList.Add(guid);
                if (country != 0 && country == heroInfo.heroConfig.Country)
                    retGuidList.Add(guid);
            }
            else
            {
                if (job == heroInfo.heroConfig.Class && country == heroInfo.heroConfig.Country)
                    retGuidList.Add(guid);
            }
        }
        return retGuidList;
    }
    public List<HeroInfo> GetPowerfulHeroList()
@@ -109,8 +116,8 @@
        heroList.Sort((a, b) =>
        {
            int power1 = a.CalculatePower();
            int power2 = b.CalculatePower();
            long power1 = a.CalculatePower(false);
            long power2 = b.CalculatePower(false);
            if (power1 == power2)
            {
@@ -131,7 +138,18 @@
    }
    public int GetHeroCount()
    {
        return heroInfoDict.Count;
    }
    public bool HasHero(int heroID)
    {
        return PackManager.Instance.GetSinglePack(PackType.Hero).HasItem(heroID);
    }
    public int GetHeroCountByID(int heroID)
    {
        return (int)PackManager.Instance.GetSinglePack(PackType.Hero).GetCountById(heroID);
    }
}