123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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
- {
- 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);
- }
- }
- /// <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();
- }
- }
- }
|