123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- using FL.Network;
- using System;
- using System.Collections.Generic;
- using XGame.Database;
- using XGame.Framework.Data;
- using static FL.Network.ActArtifactFumo;
- namespace FL
- {
- public struct ArtifactEnchantParam
- {
- public int elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
- public int elementId; // 槽位附魔的元素id
- public int holePosition;// 部位id(孔位索引值)
- }
- public struct ElementInfoParam
- {
- public int elementId; // 元素id
- public int level; // 元素等级
- public int state; // 0_未出战 1_已出战(已附魔)
- public long power; // 元素拥有战力
- }
- /// <summary>
- /// 元素孔位数据
- /// </summary>
- public struct HolepositionParam
- {
- public EElementType elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
- public ArtifactEnchantParam enchantData;
- public bool bUpgradeUI; // 是否元素升级页签UI
- }
- public struct ElementPowerParam
- {
- public int holePosition; // 孔位(槽位)索引
- public long starPower; // 拥有效果的战力(受升级影响)
- public long wearPower; // 佩戴效果的战力(固定)
- }
- /// <summary>
- /// 神器数据
- /// </summary>
- public class ArtifactData : DataSingleton<ArtifactData>,IDisposable
- {
- /// <summary>
- /// 每个星级(黄|紫|红)最多拥有5个星星数量
- /// </summary>
- public const int MaxStarNum = 5;
- #region 神器附魔数据
- /// <summary>
- /// 每种元素拥有的最大附魔孔位
- /// </summary>
- public const int MaxHolePosition = 5;
- /// <summary>
- /// 每种元素最高级品质等级
- /// </summary>
- public const int MaxElementQuality = 6;
- /// <summary>
- /// 神器附魔数据
- /// key:元素枚举类型(火-毒-冰-雷-风)
- /// value:附魔的元素数据:key_孔位索引值
- /// </summary>
- private Dictionary<EElementType, Dictionary<int,ArtifactEnchantParam>> _enchantDataMap;
- public Dictionary<EElementType, Dictionary<int, ArtifactEnchantParam>> EnchantDataMap => _enchantDataMap ??= new Dictionary<EElementType, Dictionary<int, ArtifactEnchantParam>>();
- /// <summary>
- /// 升级(解锁)的元素信息(升级成功界面UI展示用数据)
- /// </summary>
- public List<ElementInfoParam> UpgradeElementList { set; get; }
- /// <summary>
- /// 已解锁的元素数据
- /// key:元素id
- /// value:元素信息
- /// </summary>
- private Dictionary<int, ElementInfoParam> _unlockElementMap;
- public Dictionary<int, ElementInfoParam> UnlockElementMap => _unlockElementMap ??= new Dictionary<int, ElementInfoParam>();
- /// <summary>
- /// 元素战力数据
- /// key:元素id
- /// </summary>
- private Dictionary<int, ElementPowerParam> _elementPowerMap = new Dictionary<int, ElementPowerParam>();
- /// <summary>
- /// 核心元素名字
- /// </summary>
- /// <param name="elementType"></param>
- /// <returns></returns>
- public string GetElementName(EElementType elementType)
- {
- switch (elementType)
- {
- case EElementType.Fire:
- return StringDefine.FireElement;
- case EElementType.Thunder:
- return StringDefine.ThunderElement;
- case EElementType.Ice:
- return StringDefine.IceElement;
- case EElementType.Poison:
- return StringDefine.PoisonElement;
- case EElementType.Wind:
- return StringDefine.WindElement;
- default:
- return string.Empty;
- }
- }
- /// <summary>
- /// 是否已解锁的元素id
- /// </summary>
- /// <param name="elementId"></param>
- /// <returns></returns>
- public bool IsUnlockElement(int elementId)
- {
- return UnlockElementMap.ContainsKey(elementId) ? true : false;
- }
- /// <summary>
- /// 获取核心元素数据(等级和穿戴信息)
- /// </summary>
- /// <param name="elementId"></param>
- /// <returns></returns>
- public ElementInfoParam GetElementUpgradeInfo(int elementId)
- {
- return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId] : new ElementInfoParam();
- }
- /// <summary>
- /// 获取某个元素的战力值
- /// </summary>
- /// <param name="elementId"></param>
- /// <returns></returns>
- public long GetElementPower(int elementId)
- {
- return UnlockElementMap.ContainsKey(elementId) ? _unlockElementMap[elementId].power : 0;
- }
- /// <summary>
- /// 获取元素的等级
- /// </summary>
- /// <param name="elementId"></param>
- /// <returns></returns>
- public int GetElementLevel(int elementId)
- {
- return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId].level : 0;
- }
- /// <summary>
- /// 获取元素类型的孔位上附魔的元素信息列表
- /// </summary>
- /// <returns></returns>
- public Dictionary<int,ArtifactEnchantParam> GetElementHolepositionData(EElementType elementType)
- {
- return EnchantDataMap.ContainsKey(elementType) ? EnchantDataMap[elementType] : new Dictionary<int, ArtifactEnchantParam>();
- }
- /// <summary>
- /// 获取某种元素类型的穿戴战力总值
- /// </summary>
- /// <param name="elementType"></param>
- /// <returns></returns>
- public long GetWearPower(EElementType elementType)
- {
- long wearPower = 0;
- if (EnchantDataMap.ContainsKey(elementType))
- {
- foreach (var item in EnchantDataMap[elementType])
- {
- if (_elementPowerMap.ContainsKey(item.Value.elementId))
- wearPower += _elementPowerMap[item.Value.elementId].wearPower;
- }
- }
- return wearPower;
- }
- /// <summary>
- /// 获取元素的穿戴战力值
- /// </summary>
- /// <param name="elementId"></param>
- /// <returns></returns>
- public long GetElementWearPower(int elementId)
- {
- return _elementPowerMap.ContainsKey(elementId) ? _elementPowerMap[elementId].wearPower : 0;
- }
- /// <summary>
- /// 获取元素类型孔位上附魔的元素信息
- /// </summary>
- /// <returns></returns>
- public ArtifactEnchantParam GetHolepositionElementInfo(EElementType elementType, int holePosition)
- {
- if (EnchantDataMap != null && EnchantDataMap.ContainsKey(elementType))
- {
- if (EnchantDataMap[elementType].ContainsKey(holePosition))
- return EnchantDataMap[elementType][holePosition];
- else
- new ArtifactEnchantParam();
- }
- return new ArtifactEnchantParam();
- }
- /// <summary>
- /// 获取元素表格信息(元素类型*1000+品质*100+孔位索引)
- /// </summary>
- /// <param name="elementType">元素类型</param>
- /// <param name="quality">品质</param>
- /// <param name="holePonsiton">孔位</param>
- /// <returns></returns>
- public artifactYuansuTable GetElementConfigInfo(int elementType, int quality, int holePonsiton)
- {
- return artifactYuansuTableRepo.Get(elementType * 1000 + quality * 100 + holePonsiton);
- }
- /// <summary>
- /// 获取元素附魔表格信息(元素核心id*1000+等级)
- /// </summary>
- /// <param name="elementTableId">元素表格信息id</param>
- /// <param name="level">等级</param>
- /// <returns></returns>
- public artifactFumoTable GetElementEnchantConfigInfo(int elementTableId, int level)
- {
- return artifactFumoTableRepo.Get(elementTableId * 1000 + level);
- }
- /// <summary>
- /// 5种元素类型在其5个孔位上的附魔数据
- /// </summary>
- /// <param name="enchantDataList"></param>
- public void OnchangeEnchantDataMap(List<ActArtifactFumo> enchantDataList)
- {
- foreach (var item in enchantDataList)
- {
- if (EnchantDataMap.ContainsKey((EElementType)item.type))
- {
- EnchantDataMap[(EElementType)item.type] = GetHolepositionEnchantMap(item.type, item.buwei);
- }
- else
- {
- EnchantDataMap.Add((EElementType)item.type, GetHolepositionEnchantMap(item.type, item.buwei));
- }
- }
- }
- private Dictionary<int, ArtifactEnchantParam> GetHolepositionEnchantMap(int elementType, List<ActArtifactBuWei> dataList)
- {
- var artifactEnchantMap = new Dictionary<int, ArtifactEnchantParam>();
- foreach (var item in dataList)
- {
- var enchantParam = new ArtifactEnchantParam()
- {
- elementType = elementType,
- holePosition = item.bwId,
- elementId = item.elementId
- };
- artifactEnchantMap.Add(item.bwId, enchantParam);
- }
- return artifactEnchantMap;
- }
- /// <summary>
- /// 元素的战力值变化
- /// </summary>
- /// <param name="elementId"></param>
- /// <param name="starPower"></param>
- private void OnchangElementPowerData(int elementId, long starPower)
- {
- if (_elementPowerMap.ContainsKey(elementId))
- {
- var elementPowerData = _elementPowerMap[elementId];
- elementPowerData.starPower = starPower;
- }
- else
- {
- var elementPowerData = new ElementPowerParam();
- elementPowerData.starPower = starPower;
- var elementConfig = artifactYuansuTableRepo.Get(elementId);
- if (elementConfig?.Trunk > 0)
- elementPowerData.holePosition = elementConfig.Trunk;
- if (elementConfig?.Wear_attr?.Length > 1)
- {
- elementPowerData.wearPower = AttrDescTableRepo.GetAttributePower(elementConfig.Wear_attr[0], elementConfig.Wear_attr[1]);
- }
- _elementPowerMap.Add(elementId, elementPowerData);
- }
- }
- /// <summary>
- /// 解锁的元素数据
- /// </summary>
- /// <param name="unlockElementList"></param>
- public void OnchangeUnlockElementMap(List<ActArtifactElementList> unlockElementList)
- {
- foreach (var item in unlockElementList)
- {
- var elementInfo = new ElementInfoParam()
- {
- elementId = item.elementId,
- level = item.level,
- state = item.status,
- power = item.power,
- };
- if (UnlockElementMap.ContainsKey(item.elementId))
- {
- UnlockElementMap[item.elementId] = elementInfo;
- }
- else
- {
- UnlockElementMap.Add(item.elementId, elementInfo);
- }
- OnchangElementPowerData(item.elementId,item.power);
- }
- }
- /// <summary>
- /// (激活)升级的元素列表
- /// </summary>
- /// <param name="unlockElementList"></param>
- public void SetUpgradeElementList(List<ActArtifactElementList> unlockElementList)
- {
- if (UpgradeElementList == null)UpgradeElementList = new List<ElementInfoParam>();
- foreach (var item in unlockElementList)
- {
- var elementInfo = new ElementInfoParam()
- {
- elementId = item.elementId,
- level = item.level,
- state = item.status
- };
- UpgradeElementList.Add(elementInfo);
- }
- }
- #endregion
- #region 普通神器数据
- /// <summary>
- /// 普通神器当前升级到的星级信息id(artifactInfo分表序号ID)
- /// </summary>
- public int ArtifactInfoId { get; set; }
- /// <summary>
- /// 普通神器当前升星经验
- /// </summary>
- public int ArtifactExp { get; set; }
- #endregion
- #region 高级神器数据
- /// <summary>
- /// 启用技能的高级神器的id
- /// </summary>
- public int UsingAdvanceArtifactId { set; get; }
- /// <summary>
- /// 已解锁的神器星级数据
- /// key:artifactBase.id
- /// value:star(星级)
- /// </summary>
- private Dictionary<int, int> _advancedArtifactMap;
- public Dictionary<int, int> AdvancedArtifactMap => _advancedArtifactMap ??= new Dictionary<int, int>();
- /// <summary>
- /// 高级神器是否已解锁状态
- /// </summary>
- /// <param name="artifactId"></param>
- /// <returns></returns>
- public bool IsUnLock(int artifactId)
- {
- return _advancedArtifactMap.ContainsKey(artifactId);
- }
- /// <summary>
- /// 获取高级神器的星级
- /// </summary>
- /// <param name="artifactId"></param>
- public int GetAdvancedArtifactLevel(int artifactId)
- {
- return _advancedArtifactMap.ContainsKey(artifactId) ? _advancedArtifactMap[artifactId] : 0;
- }
- /// <summary>
- /// 根据神器id和星级获取星级表id
- /// </summary>
- /// <param name="artifactId"></param>
- /// <param name="level"></param>
- /// <returns>10000*秘宝id+星级</returns>
- public int GetArtifactStarId(int artifactId, int level)
- {
- return artifactId*10000 + level;
- }
- /// <summary>
- /// 根据神器id和星级获取通用神器信息表id
- /// </summary>
- /// <param name="artifactId"></param>
- /// <param name="level"></param>
- /// <returns>秘宝id*10000+阶级*100+星级</returns>
- public int GetArtifactInfoId(int artifactId, int step, int starLv)
- {
- return artifactId * 10000 + step *100 + starLv;
- }
- #endregion
- /// <summary>
- /// 当前使用的神器外观模型id(通用神器用的是artifactInfo表格,高级神器对应的是artifactBase表格)
- /// 此字段只在神器内部使用,如果外部需要使用神器外观,请使用GetWearAppearance()
- /// </summary>
- public int AppearanceId { set; get; }
- /// <summary>
- /// 获取当前穿戴的神器外观
- /// </summary>
- /// <returns></returns>
- public string GetWearAppearance()
- {
- if (AppearanceId == 0) return string.Empty;
- var artifactBaseInfo = artifactBaseTableRepo.Get(AppearanceId);
- if (artifactBaseInfo != null) return artifactBaseInfo.Spine;
- var artifactInfo = artifactInfoTableRepo.Get(AppearanceId);
- return artifactInfo == null ? string.Empty : artifactInfo.Spine;
- }
- void IDisposable.Dispose()
- {
- _elementPowerMap.Clear();
- _advancedArtifactMap?.Clear();
- _advancedArtifactMap = null;
- _enchantDataMap?.Clear();
- _enchantDataMap = null;
- }
- }
- }
|