| | |
| | | //初始创建(0725),后续跟随背包事件增加删除 key = guid |
| | | protected Dictionary<string, HeroInfo> heroInfoDict = new Dictionary<string, HeroInfo>(); |
| | | |
| | | //武将列表界面 |
| | | public List<string> heroSortList = new List<string>(); |
| | | |
| | | //武将红点 |
| | | //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() |
| | | { |
| | | base.Init(); |
| | | |
| | | PackManager.Instance.refrechPackEvent += refrechPackEvent; |
| | | PackManager.Instance.ChangeItemEvent += ChangeHero; |
| | | PackManager.Instance.DeleteItemEvent += DeleteHero; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; |
| | |
| | | public override void Release() |
| | | { |
| | | base.Release(); |
| | | PackManager.Instance.refrechPackEvent -= refrechPackEvent; |
| | | PackManager.Instance.ChangeItemEvent -= ChangeHero; |
| | | PackManager.Instance.DeleteItemEvent -= DeleteHero; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; |
| | |
| | | |
| | | void OnBeforePlayerDataInitialize() |
| | | { |
| | | heroSortList.Clear(); |
| | | |
| | | heroInfoDict.Clear(); |
| | | } |
| | | |
| | | void refrechPackEvent(PackType packType) |
| | | { |
| | | if (packType == PackType.Hero) |
| | | { |
| | | InitHerosInfo(); |
| | | } |
| | | } |
| | | |
| | | // isCreate bool:true代表创建 false 刷新触发 |
| | | void ChangeHero(PackType packType, string guid, bool isCreate) |
| | |
| | | } |
| | | } |
| | | |
| | | void DeleteHero(PackType packType, string guid) |
| | | void DeleteHero(PackType packType, string guid, int itemID, int index, int clearType) |
| | | { |
| | | if (packType == PackType.Hero) |
| | | { |
| | |
| | | heroInfoDict.TryGetValue(guid, out heroInfo); |
| | | |
| | | heroInfoDict.Remove(guid); |
| | | |
| | | if (null != heroInfo) |
| | | onHeroDeleteEvent?.Invoke(heroInfo); |
| | | |
| | | onHeroDeleteEvent?.Invoke(itemID); |
| | | } |
| | | } |
| | | |
| | |
| | | return heroInfoDict.Values.ToList(); |
| | | } |
| | | |
| | | public List<string> GetHeroGuidList(int job = 0, int country = 0) |
| | | { |
| | | if (job == 0 && country == 0) |
| | | return heroInfoDict.Keys.ToList(); |
| | | |
| | | void InitHerosInfo() |
| | | { |
| | | heroInfoDict.Clear(); |
| | | SinglePack heroPack = PackManager.Instance.GetSinglePack(PackType.Hero); |
| | | Dictionary<int, ItemModel> heroes = heroPack.GetAllItems(); |
| | | |
| | | foreach (ItemModel hero in heroes.Values) |
| | | List<string> retGuidList = new List<string>(); |
| | | foreach (string guid in heroInfoDict.Keys) |
| | | { |
| | | ChangeHero(hero.packType, hero.guid, true); |
| | | 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() |
| | |
| | | |
| | | heroList.Sort((a, b) => |
| | | { |
| | | int power1 = a.CalculatePower(); |
| | | int power2 = b.CalculatePower(); |
| | | long power1 = a.CalculateFightPower(false); |
| | | long power2 = b.CalculateFightPower(false); |
| | | |
| | | if (power1 == power2) |
| | | { |
| | |
| | | return retList; |
| | | } |
| | | |
| | | public bool waitResortHeroList = false; |
| | | |
| | | |
| | | //刷新时机, 打开武将界面 或者 关闭功能界面 |
| | | public void SortHeroList() |
| | | public int GetHeroCount() |
| | | { |
| | | heroSortList = heroInfoDict.Keys.ToList(); |
| | | heroSortList.Sort(CmpHero); |
| | | return heroInfoDict.Count; |
| | | } |
| | | |
| | | |
| | | int CmpHero(string guidA, string guidB) |
| | | public bool HasHero(int heroID) |
| | | { |
| | | HeroInfo heroA = heroInfoDict[guidA]; |
| | | HeroInfo heroB = heroInfoDict[guidB]; |
| | | if (heroA == null || heroB == null) |
| | | { |
| | | return 0; |
| | | } |
| | | // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID |
| | | if (heroA.isInMainBattle != heroB.isInMainBattle) |
| | | { |
| | | return heroA.isInMainBattle ? -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); |
| | | return PackManager.Instance.GetSinglePack(PackType.Hero).HasItem(heroID); |
| | | } |
| | | |
| | | public int GetHeroCountByID(int heroID) |
| | | { |
| | | return (int)PackManager.Instance.GetSinglePack(PackType.Hero).GetCountById(heroID); |
| | | } |
| | | } |