using System; using System.Collections.Generic; using UnityEngine; //仙盟徽章 解锁途径类型 public enum FairyEmblemUnlockMethodType { Custom, // 0 - 定制 LV, // 1 - 等级自动解锁 Active, // 2 - 活动获得 } public class GuildEmblemModel : GameSystemManager { public readonly int FamilyActionsType = 15; // 公会记录徽章类型15 private int m_NowChooseEmblemId; public event Action ChooseEmblemIdChangeEvent; //切换徽章 public int nowChooseEmblemId { get { return m_NowChooseEmblemId; } set { m_NowChooseEmblemId = value; ChooseEmblemIdChangeEvent?.Invoke(); } } //创建公会时,选择的徽章 int m_CreateSelectEmblemId; public event Action CreateSelectEmblemIdChangeEvent; public int createSelectEmblemId { get { return m_CreateSelectEmblemId; } set { m_CreateSelectEmblemId = value; CreateSelectEmblemIdChangeEvent?.Invoke(); } } public string createEmblemWord = ""; //创建公会时,输入的旗号 Redpoint entranceRedPoint = new Redpoint(10702, MainRedDot.FairyEmbleManageRepoint); //仙盟管理面板入口红点 // 旧的显示列表,用于判断是否有变化, 对比红点显示 public List oldShowActiveList = new List(); // 旧的激活列表,点击新的徽章时会更新,或者关闭的时候更新 public List showList = new List(); public override void Init() { PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo; GuildManager.Instance.FamilyActionInfoEvent += OnFamilyActionInfoEvent; DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; } public override void Release() { PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo; GuildManager.Instance.FamilyActionInfoEvent -= OnFamilyActionInfoEvent; DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; } public void OnBeforePlayerDataInitialize() { m_NowChooseEmblemId = 0; m_CreateSelectEmblemId = 0; createEmblemWord = ""; oldShowActiveList.Clear(); showList.Clear(); } private void OnRefreshFairyInfo() { UpdateRedPoint(); } public void UpdateRedPoint() { entranceRedPoint.state = RedPointState.None; // 仅盟主能看到 if (!IsCaptain()) return; if (!GetRedPointShow()) return; entranceRedPoint.state = RedPointState.Simple; } // 新旧列表对比显示红点 public bool GetRedPointShow() { if (oldShowActiveList.IsNullOrEmpty()) return false; for (int i = 0; i < showList.Count; i++) { //已解锁的 if (!oldShowActiveList.Contains(showList[i]) && IsUnLock(showList[i])) { return true; } } return false; } public List SortShowList() { if (showList.IsNullOrEmpty()) { List keys = FamilyEmblemConfig.GetKeys(); for (int i = 0; i < keys.Count; i++) { showList.Add(keys[i]); } } showList.Sort(Cmp); if (oldShowActiveList.IsNullOrEmpty()) { // 初始化时,刷新旧的激活列表 RefreshOldShowActiveList(); } return showList; } // 刷新旧的激活列表,用于对比红点显示 public void RefreshOldShowActiveList() { for (int i = 0; i < showList.Count; i++) { //已解锁的 if (IsUnLock(showList[i])) { if (!oldShowActiveList.Contains(showList[i])) { oldShowActiveList.Add(showList[i]); } } } } // 已激活>未激活 private int Cmp(int a, int b) { bool isUnlock1 = IsUnLock(a); bool isUnlock2 = IsUnLock(b); if (isUnlock1 != isUnlock2) { return isUnlock2.CompareTo(isUnlock1); } // 如果激活状态相同,比较是否为限时:限时 (true) > 永久 (false) bool isLimitA = IsLimitTime(a, out var familyAction1); bool isLimitB = IsLimitTime(b, out var familyAction2); if (isLimitA != isLimitB) { return isLimitB.CompareTo(isLimitA); } // 限时状态相同,比较 SortNum int sortNumA = GetSortNum(a); int sortNumB = GetSortNum(b); if (sortNumA != sortNumB) { return sortNumA.CompareTo(sortNumB); } return a.CompareTo(b); } public int GetSortNum(int emblemID) { return FamilyEmblemConfig.Get(emblemID).SortNum; } // 获得徽章来源类型 public FairyEmblemUnlockMethodType GetFairyEmblemUnlockType(int emblemID) { FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemID); if (config == null) return FairyEmblemUnlockMethodType.LV; if (config.CustomFamilyID > 0) return FairyEmblemUnlockMethodType.Custom; return config.UnlockFamilyLV > 0 ? FairyEmblemUnlockMethodType.LV : FairyEmblemUnlockMethodType.Active; } // 徽章是否解锁,未加入公会的也可以调用判断 public bool IsUnLock(int emblemId) { FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId); FairyEmblemUnlockMethodType type = GetFairyEmblemUnlockType(emblemId); HA513_tagMCFamilyActionInfo.tagMCFamilyAction familyAction; switch (type) { case FairyEmblemUnlockMethodType.Custom: //所在仙盟不是指定的定制仙盟 未解锁 if (PlayerDatas.Instance.baseData.FamilyId != config.CustomFamilyID) return false; //封包中没有就算未解锁 if (!TryGetfamilyAction(emblemId, out familyAction)) return false; if (familyAction.Value2 > 0 && familyAction.Value2 < TimeUtility.AllSeconds) return false; return true; case FairyEmblemUnlockMethodType.LV: int lv = 1; //没有公会的情况 if (PlayerDatas.Instance.fairyData.fairy != null) { lv = PlayerDatas.Instance.fairyData.fairy.FamilyLV; } //所在仙盟等级小于徽章要求等级 未解锁 if (lv < config.UnlockFamilyLV) return false; return true; case FairyEmblemUnlockMethodType.Active: //封包中没有就算未解锁 if (!TryGetfamilyAction(emblemId, out familyAction)) return false; if (familyAction.Value2 > 0 && familyAction.Value2 < TimeUtility.AllSeconds) return false; return true; default: return false; } } void OnFamilyActionInfoEvent(int familyId, int actionType) { UpdateRedPoint(); } public bool IsLimitTime(int emblemId, out HA513_tagMCFamilyActionInfo.tagMCFamilyAction familyAction) { familyAction = new HA513_tagMCFamilyActionInfo.tagMCFamilyAction(); FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId); FairyEmblemUnlockMethodType type = GetFairyEmblemUnlockType(emblemId); switch (type) { case FairyEmblemUnlockMethodType.LV: return false; case FairyEmblemUnlockMethodType.Custom: case FairyEmblemUnlockMethodType.Active: if (config.ExpireMinutes <= 0) return false; if (!TryGetfamilyAction(emblemId, out familyAction)) return false; return true; default: return false; } } public bool IsCaptain() { return PlayerDatas.Instance.fairyData.mine.FmLV == 3; } // 获得徽章记录信息信息(活动途径获取的徽章,定制徽章),value1是徽章ID,value2是徽章到期时间 private bool TryGetfamilyAction(int emblemId, out HA513_tagMCFamilyActionInfo.tagMCFamilyAction familyAction) { familyAction = new HA513_tagMCFamilyActionInfo.tagMCFamilyAction(); if (GuildManager.Instance.TryGetFamilyActions(FamilyActionsType, out var actions)) { for (int i = 0; i < actions.Length; i++) { if (actions[i].Value1 == emblemId) { familyAction = actions[i]; return true; } } } return false; } public bool TryGetEffectID(int emblemId, out int effectID) { effectID = 0; FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId); if (!EffectConfig.HasKey(config.EffectID)) return false; effectID = config.EffectID; return true; } }