using System; using System.Collections.Generic; using UnityEngine; //仙盟徽章 解锁途径类型 public enum FairyEmblemUnlockMethodType { Custom, // 0 - 定制 LV, // 1 - 等级自动解锁 Active, // 2 - 活动获得 } public class GuildEmblemModel : GameSystemManager { public readonly int MaxItemRowCount = 6; // 一行展示x个徽章 public readonly int FamilyActionsType = 15; // 徽章类型15 public readonly int FuncId = 237; public int defaultFamilyEmblemId; // 默认徽章ID public bool isSendA408Pack = false; private int m_NowChooseEmblemId; public int nowChooseEmblemId { get { return m_NowChooseEmblemId; } set { m_NowChooseEmblemId = value; ChooseEmblemIdChangeEvent?.Invoke(); } } public event Action ChooseEmblemIdChangeEvent; //切换标签页 Redpoint entranceRedPoint = new Redpoint(10702, MainRedDot.FairyEmbleManageRepoint); //仙盟管理面板入口红点 public override void Init() { PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo; defaultFamilyEmblemId = int.Parse(FuncConfigConfig.Get("FairyEmblem").Numerical1); } public override void Release() { PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo; } private void OnRefreshFairyInfo() { UpdateRedPoint(); } public void UpdateRedPoint() { entranceRedPoint.state = RedPointState.None; // 仅盟主能看到 if (!IsCaptain()) return; // 仙盟2级出现 if (PlayerDatas.Instance.fairyData == null || PlayerDatas.Instance.fairyData.fairy.FamilyLV != 2) return; // 只出现一次 if (GetRedPointShow()) return; entranceRedPoint.state = RedPointState.Simple; } string localStr = "FairyEmblemEntranceRedPoint_"; public bool GetRedPointShow() { return LocalSave.GetBool(localStr + PlayerDatas.Instance.PlayerId); } public void SetRedPointShow() { LocalSave.SetBool(localStr + PlayerDatas.Instance.PlayerId, true); } public bool TryGetNowEmblemID(out int nowID) { nowID = 0; int emblemID = (int)PlayerDatas.Instance.fairyData.fairy.EmblemID; if (FamilyEmblemConfig.HasKey(emblemID) && IsUnLock(emblemID)) { nowID = (int)emblemID; return true; } if (FamilyEmblemConfig.HasKey(defaultFamilyEmblemId)) { nowID = defaultFamilyEmblemId; return true; } nowID = 0; return false; } // 展示指定徽章 表中找不到徽章就显示默认的 public void ShowEmblem(int emblemID, ImageEx imgTitle, float scale = 1.0f) { int nowEmblemID = emblemID; if (!FamilyEmblemConfig.HasKey(nowEmblemID)) { nowEmblemID = defaultFamilyEmblemId; } FamilyEmblemConfig config = FamilyEmblemConfig.Get(nowEmblemID); UIFrame frame = imgTitle.GetComponent(); if (UIFrameMgr.Inst.ContainsDynamicImage(config.Image)) { if (frame == null) frame = imgTitle.gameObject.AddComponent(); List spriteList = UIFrameMgr.Inst.GetDynamicImage(config.Image); if (!spriteList.IsNullOrEmpty()) { imgTitle.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height); } imgTitle.raycastTarget = false; frame.ResetFrame(config.Image); frame.enabled = true; } else { if (frame != null) frame.enabled = false; imgTitle.SetSprite(config.Image); imgTitle.SetNativeSize(); } imgTitle.rectTransform.localScale = new Vector3(scale, scale, scale); } public List GetShowList() { List showList = new List(); List keys = FamilyEmblemConfig.GetKeys(); for (int i = 0; i < keys.Count; i++) { showList.Add(keys[i]); } showList.Sort(Cmp); return showList; } // 已激活>未激活 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) { if (!FamilyEmblemConfig.HasKey(emblemID)) return 0; 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: //所在仙盟等级小于徽章要求等级 未解锁 if (PlayerDatas.Instance.fairyData.fairy.FamilyLV < 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; } } public bool IsUsing(int emblemId) { if (!TryGetNowEmblemID(out int Id)) { return false; } return emblemId == Id; } 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 (int)PlayerDatas.Instance.fairyData.mine.FmLV == 3; } // 尝试从封包中得到指定的徽章时效信息(活动途径获取的徽章,定制徽章) 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; if (!FamilyEmblemConfig.HasKey(emblemId)) return false; FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId); if (!EffectConfig.HasKey(config.EffectID)) return false; effectID = config.EffectID; return true; } } public class EmblemModel { public int emblemID { get; private set; } public int emblemUIEffectID { get; private set; } public EmblemModel(int emblemID, int emblemUIEffectID) { this.emblemID = emblemID; this.emblemUIEffectID = emblemUIEffectID; } }