123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 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<EpigraphData>, IDisposable
- {
- #region 铭文库
- private Dictionary<int, EpigraphAttributes> _epiMap = new();
- private Dictionary<long, EpigraphAttributes> _epiUIDMap = new();
- public List<EpigraphAttributes> EpiList
- {
- get
- {
- var list = new List<EpigraphAttributes>();
- foreach (var epi in _epiMap.Values)
- {
- list.Add(epi);
- }
- return list;
- }
- }
- public int UpModeSelect = 0;
- public void UpdateEpiInfo(List<ActMingWenList> 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<ActMingWenList> mingwen)
- {
- var list = new List<EpigraphAttributes>();
- 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<EpigraphAttributes> data)
- {
- ClearEpiInfo();
- foreach (var epiAttr in data)
- {
- _epiMap.Add(epiAttr.TableId, epiAttr);
- _epiUIDMap.Add(epiAttr.UID, epiAttr);
- }
- }
- #endregion
- #region 羁绊
- public readonly Dictionary<int, bool> JibanMap = new Dictionary<int, bool>();
- 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
- /// <summary>
- /// 获取铭文当前的阶级
- /// </summary>
- /// <param name="starLv">当前星级</param>
- /// <returns></returns>
- public int GetStarStep(int starLv)
- {
- return Mathf.FloorToInt(starLv / 5) + 1;
- }
- /// <summary>
- /// 获取铭文当前阶级的星级
- /// </summary>
- /// <param name="starLv">当前星级</param>
- /// <returns></returns>
- 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();
- }
- }
- }
|