using System; using System.Collections.Generic; using FL.Network; using UnityEngine; using XGame; using XGame.Framework; using XGame.Framework.Data; namespace FL.Data { public class EpigraphData : DataSingleton, IDisposable { #region 铭文库 private Dictionary _epiMap = new(); private Dictionary _epiUIDMap = new(); public List EpiList { get { var list = new List(); foreach (var epi in _epiMap.Values) { list.Add(epi); } return list; } } public int UpModeSelect = 0; public void UpdateEpiInfo(List mingwen) { foreach (var mw in mingwen) { var attr = GetEpigraphAttrByTableId(mw.mwId); if (attr != null) { attr.SetData(mw.mwId, mw.star, mw.shengbing); } else { var epiAttr = CreateEpigraphAttr(mw); _epiMap.Add(mw.mwId, epiAttr); _epiUIDMap.Add(epiAttr.UID, epiAttr); } } } public void InitEpiInfo(List mingwen) { var list = new List(); foreach (var mw in mingwen) { var epiAttr = CreateEpigraphAttr(mw); epiAttr.SetData(mw.mwId, mw.star, mw.shengbing); list.Add(epiAttr); } SetEpiInfo(list); } private EpigraphAttributes CreateEpigraphAttr(ActMingWenList mw) { var epiAttr = new EpigraphAttributes(); epiAttr.UID = UIDDefine.New(); epiAttr.SetData(mw.mwId, mw.star, mw.shengbing); return epiAttr; } public EpigraphAttributes GetEpigraphAttrByTableId(int id) { return _epiMap.GetValueOrDefault(id); } public bool TryGetEpigraphAttrByTableId(int id, out EpigraphAttributes epiAttr) { return _epiMap.TryGetValue(id, out epiAttr); } public EpigraphAttributes GetEpigraphAttrByUID(long UID) { return _epiUIDMap.GetValueOrDefault(UID); } public bool TryGetEpigraphAttrByUID(long UID, out EpigraphAttributes epigraphAttributes) { return _epiUIDMap.TryGetValue(UID, out epigraphAttributes); } public void SetEpiInfo(List data) { ClearEpiInfo(); foreach (var epiAttr in data) { _epiMap.Add(epiAttr.TableId, epiAttr); _epiUIDMap.Add(epiAttr.UID, epiAttr); } } #endregion #region 羁绊 public readonly Dictionary JibanMap = new Dictionary(); public void ClearJibanActive() { JibanMap.Clear(); } public void SetJibanActiveState(int jibanId, int level) { var id = 100000 + jibanId * 1000 + level; if (JibanMap.ContainsKey(jibanId)) { JibanMap.Remove(id); } JibanMap.Add(id, true); } public bool GetJibaIsActive(int jibanId, int level) { var id = 100000 + jibanId * 1000 + level; return JibanMap.GetValueOrDefault(id, false); } #endregion /// /// 获取铭文当前的阶级 /// /// 当前星级 /// public int GetStarStep(int starLv) { return Mathf.FloorToInt(starLv / 5) + 1; } /// /// 获取铭文当前阶级的星级 /// /// 当前星级 /// public int GetCurCtepStarLv(int starLv) { var lv = starLv % 5; if (lv == 0) lv = 5; return lv; } private void ClearEpiInfo() { foreach (var epiAttr in _epiMap.Values) { ObjectPool.Recycle(epiAttr); } _epiMap.Clear(); } void IDisposable.Dispose() { ClearEpiInfo(); } } }