| | |
| | | //初始创建(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.CreateItemEvent += CreateHero; |
| | | PackManager.Instance.ChangeItemEvent += ChangeHero; |
| | | PackManager.Instance.DeleteItemEvent += DeleteHero; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize; |
| | | } |
| | | |
| | | public override void Release() |
| | | { |
| | | base.Release(); |
| | | PackManager.Instance.refrechPackEvent -= refrechPackEvent; |
| | | PackManager.Instance.CreateItemEvent -= CreateHero; |
| | | PackManager.Instance.ChangeItemEvent -= ChangeHero; |
| | | PackManager.Instance.DeleteItemEvent -= DeleteHero; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize; |
| | | } |
| | | |
| | | void OnBeforePlayerDataInitialize() |
| | | { |
| | | heroSortList.Clear(); |
| | | |
| | | heroInfoDict.Clear(); |
| | | } |
| | | |
| | | void refrechPackEvent(PackType packType) |
| | | { |
| | | if (packType == PackType.Hero) |
| | | { |
| | | InitHerosInfo(); |
| | | } |
| | | } |
| | | |
| | | void CreateHero(PackType packType, string guid) |
| | | // isCreate bool:true代表创建 false 刷新触发 |
| | | void ChangeHero(PackType packType, string guid, bool isCreate) |
| | | { |
| | | if (packType == PackType.Hero) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | public HeroInfo GetHero(string guid) |
| | | { |
| | | if (heroInfoDict == null || guid == null) |
| | | { |
| | | Debug.LogError("HeroManager GetHero guid is null"); |
| | | return null; |
| | | } |
| | | if (!heroInfoDict.ContainsKey(guid)) |
| | | return null; |
| | | return heroInfoDict[guid]; |
| | |
| | | return heroInfoDict.Values.ToList(); |
| | | } |
| | | |
| | | public List<string> GetHeroGuidList() |
| | | { |
| | | return heroInfoDict.Keys.ToList(); |
| | | } |
| | | |
| | | void InitHerosInfo() |
| | | { |
| | | heroInfoDict.Clear(); |
| | | SinglePack heroPack = PackManager.Instance.GetSinglePack(PackType.Hero); |
| | | Dictionary<int, ItemModel> heroes = heroPack.GetAllItems(); |
| | | /// 参数: 职业,国家,伤害类型,6大战斗属性,特殊属性 |
| | | public List<string> GetHeroGuidList(List<int> selectList = null) |
| | | { |
| | | if (selectList.IsNullOrEmpty()) |
| | | return heroInfoDict.Keys.ToList(); |
| | | |
| | | foreach (ItemModel hero in heroes.Values) |
| | | int job = selectList[0]; |
| | | int country = selectList[1]; |
| | | int hurtType = selectList[2]; |
| | | int fightAttrType = selectList[3]; |
| | | int specialAttrType = selectList[4]; |
| | | |
| | | List<string> retGuidList = new List<string>(); |
| | | foreach (string guid in heroInfoDict.Keys) |
| | | { |
| | | CreateHero(hero.packType, hero.guid); |
| | | HeroInfo heroInfo = heroInfoDict[guid]; |
| | | |
| | | //0代表全部, 同级别是可复选,不同级别为且的关系 |
| | | bool isMatch = true; |
| | | if (job != 0) |
| | | { |
| | | isMatch = isMatch && (job & (1 << heroInfo.heroConfig.Class)) > 0; |
| | | } |
| | | if (country != 0) |
| | | { |
| | | isMatch = isMatch && (country & (1 << heroInfo.heroConfig.Country)) > 0; |
| | | } |
| | | if (hurtType != 0) |
| | | { |
| | | isMatch = isMatch && (hurtType & (1 << heroInfo.heroConfig.HurtType)) > 0; |
| | | } |
| | | if (fightAttrType != 0) |
| | | { |
| | | isMatch = isMatch && (fightAttrType & (1 << heroInfo.heroConfig.Specialty)) > 0; |
| | | } |
| | | if (specialAttrType != 0) |
| | | { |
| | | bool isMatch2 = false; |
| | | for (int i = 0; i < heroInfo.heroConfig.Specialty2.Length; i++) |
| | | { |
| | | isMatch2 = (specialAttrType & (1 << heroInfo.heroConfig.Specialty2[i])) > 0; |
| | | if (isMatch2) |
| | | break; |
| | | } |
| | | isMatch = isMatch && isMatch2; |
| | | } |
| | | if (isMatch) |
| | | { |
| | | 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 PackManager.Instance.GetSinglePack(PackType.Hero).HasItem(heroID); |
| | | } |
| | | |
| | | return heroA.heroId.CompareTo(heroB.heroId); |
| | | public int GetHeroCountByID(int heroID) |
| | | { |
| | | return (int)PackManager.Instance.GetSinglePack(PackType.Hero).GetCountById(heroID); |
| | | } |
| | | |
| | | //获得生效的武将数量 |
| | | public int GetAttrActiveHeroCount() |
| | | { |
| | | int count = 0; |
| | | foreach (HeroInfo heroInfo in heroInfoDict.Values) |
| | | { |
| | | if (heroInfo.isAttrActive) |
| | | { |
| | | count++; |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | //获得未生效的武将数量 |
| | | public int GetNotActiveHeroCount() |
| | | { |
| | | int count = 0; |
| | | foreach (HeroInfo heroInfo in heroInfoDict.Values) |
| | | { |
| | | if (!heroInfo.isAttrActive) |
| | | { |
| | | count++; |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | //获得指定ID且属性生效的武将 |
| | | public HeroInfo GetHeroByID(int heroID) |
| | | { |
| | | foreach (HeroInfo heroInfo in heroInfoDict.Values) |
| | | { |
| | | if (heroInfo.heroId == heroID && heroInfo.isAttrActive) |
| | | { |
| | | return heroInfo; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<HeroInfo> GetHeroListByID(int heroID) |
| | | { |
| | | List<HeroInfo> heroList = new List<HeroInfo>(); |
| | | foreach (HeroInfo heroInfo in heroInfoDict.Values) |
| | | { |
| | | if (heroInfo.heroId == heroID) |
| | | { |
| | | heroList.Add(heroInfo); |
| | | } |
| | | } |
| | | return heroList; |
| | | } |
| | | |
| | | } |