ArtifactData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. using FL.Network;
  2. using System;
  3. using System.Collections.Generic;
  4. using XGame.Database;
  5. using XGame.Framework.Data;
  6. using static FL.Network.ActArtifactFumo;
  7. namespace FL
  8. {
  9. public struct ArtifactEnchantParam
  10. {
  11. public int elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
  12. public int elementId; // 槽位附魔的元素id
  13. public int holePosition;// 部位id(孔位索引值)
  14. }
  15. public struct ElementInfoParam
  16. {
  17. public int elementId; // 元素id
  18. public int level; // 元素等级
  19. public int state; // 0_未出战 1_已出战(已附魔)
  20. public long power; // 元素拥有战力
  21. }
  22. /// <summary>
  23. /// 元素孔位数据
  24. /// </summary>
  25. public struct HolepositionParam
  26. {
  27. public EElementType elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
  28. public ArtifactEnchantParam enchantData;
  29. public bool bUpgradeUI; // 是否元素升级页签UI
  30. }
  31. public struct ElementPowerParam
  32. {
  33. public int holePosition; // 孔位(槽位)索引
  34. public long starPower; // 拥有效果的战力(受升级影响)
  35. public long wearPower; // 佩戴效果的战力(固定)
  36. }
  37. /// <summary>
  38. /// 神器数据
  39. /// </summary>
  40. public class ArtifactData : DataSingleton<ArtifactData>,IDisposable
  41. {
  42. /// <summary>
  43. /// 每个星级(黄|紫|红)最多拥有5个星星数量
  44. /// </summary>
  45. public const int MaxStarNum = 5;
  46. #region 神器附魔数据
  47. /// <summary>
  48. /// 每种元素拥有的最大附魔孔位
  49. /// </summary>
  50. public const int MaxHolePosition = 5;
  51. /// <summary>
  52. /// 每种元素最高级品质等级
  53. /// </summary>
  54. public const int MaxElementQuality = 6;
  55. /// <summary>
  56. /// 神器附魔数据
  57. /// key:元素枚举类型(火-毒-冰-雷-风)
  58. /// value:附魔的元素数据:key_孔位索引值
  59. /// </summary>
  60. private Dictionary<EElementType, Dictionary<int,ArtifactEnchantParam>> _enchantDataMap;
  61. public Dictionary<EElementType, Dictionary<int, ArtifactEnchantParam>> EnchantDataMap => _enchantDataMap ??= new Dictionary<EElementType, Dictionary<int, ArtifactEnchantParam>>();
  62. /// <summary>
  63. /// 升级(解锁)的元素信息(升级成功界面UI展示用数据)
  64. /// </summary>
  65. public List<ElementInfoParam> UpgradeElementList { set; get; }
  66. /// <summary>
  67. /// 已解锁的元素数据
  68. /// key:元素id
  69. /// value:元素信息
  70. /// </summary>
  71. private Dictionary<int, ElementInfoParam> _unlockElementMap;
  72. public Dictionary<int, ElementInfoParam> UnlockElementMap => _unlockElementMap ??= new Dictionary<int, ElementInfoParam>();
  73. /// <summary>
  74. /// 元素战力数据
  75. /// key:元素id
  76. /// </summary>
  77. private Dictionary<int, ElementPowerParam> _elementPowerMap = new Dictionary<int, ElementPowerParam>();
  78. /// <summary>
  79. /// 核心元素名字
  80. /// </summary>
  81. /// <param name="elementType"></param>
  82. /// <returns></returns>
  83. public string GetElementName(EElementType elementType)
  84. {
  85. switch (elementType)
  86. {
  87. case EElementType.Fire:
  88. return StringDefine.FireElement;
  89. case EElementType.Thunder:
  90. return StringDefine.ThunderElement;
  91. case EElementType.Ice:
  92. return StringDefine.IceElement;
  93. case EElementType.Poison:
  94. return StringDefine.PoisonElement;
  95. case EElementType.Wind:
  96. return StringDefine.WindElement;
  97. default:
  98. return string.Empty;
  99. }
  100. }
  101. /// <summary>
  102. /// 是否已解锁的元素id
  103. /// </summary>
  104. /// <param name="elementId"></param>
  105. /// <returns></returns>
  106. public bool IsUnlockElement(int elementId)
  107. {
  108. return UnlockElementMap.ContainsKey(elementId) ? true : false;
  109. }
  110. /// <summary>
  111. /// 获取核心元素数据(等级和穿戴信息)
  112. /// </summary>
  113. /// <param name="elementId"></param>
  114. /// <returns></returns>
  115. public ElementInfoParam GetElementUpgradeInfo(int elementId)
  116. {
  117. return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId] : new ElementInfoParam();
  118. }
  119. /// <summary>
  120. /// 获取某个元素的战力值
  121. /// </summary>
  122. /// <param name="elementId"></param>
  123. /// <returns></returns>
  124. public long GetElementPower(int elementId)
  125. {
  126. return UnlockElementMap.ContainsKey(elementId) ? _unlockElementMap[elementId].power : 0;
  127. }
  128. /// <summary>
  129. /// 获取元素的等级
  130. /// </summary>
  131. /// <param name="elementId"></param>
  132. /// <returns></returns>
  133. public int GetElementLevel(int elementId)
  134. {
  135. return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId].level : 0;
  136. }
  137. /// <summary>
  138. /// 获取元素类型的孔位上附魔的元素信息列表
  139. /// </summary>
  140. /// <returns></returns>
  141. public Dictionary<int,ArtifactEnchantParam> GetElementHolepositionData(EElementType elementType)
  142. {
  143. return EnchantDataMap.ContainsKey(elementType) ? EnchantDataMap[elementType] : new Dictionary<int, ArtifactEnchantParam>();
  144. }
  145. /// <summary>
  146. /// 获取某种元素类型的穿戴战力总值
  147. /// </summary>
  148. /// <param name="elementType"></param>
  149. /// <returns></returns>
  150. public long GetWearPower(EElementType elementType)
  151. {
  152. long wearPower = 0;
  153. if (EnchantDataMap.ContainsKey(elementType))
  154. {
  155. foreach (var item in EnchantDataMap[elementType])
  156. {
  157. if (_elementPowerMap.ContainsKey(item.Value.elementId))
  158. wearPower += _elementPowerMap[item.Value.elementId].wearPower;
  159. }
  160. }
  161. return wearPower;
  162. }
  163. /// <summary>
  164. /// 获取元素的穿戴战力值
  165. /// </summary>
  166. /// <param name="elementId"></param>
  167. /// <returns></returns>
  168. public long GetElementWearPower(int elementId)
  169. {
  170. return _elementPowerMap.ContainsKey(elementId) ? _elementPowerMap[elementId].wearPower : 0;
  171. }
  172. /// <summary>
  173. /// 获取元素类型孔位上附魔的元素信息
  174. /// </summary>
  175. /// <returns></returns>
  176. public ArtifactEnchantParam GetHolepositionElementInfo(EElementType elementType, int holePosition)
  177. {
  178. if (EnchantDataMap != null && EnchantDataMap.ContainsKey(elementType))
  179. {
  180. if (EnchantDataMap[elementType].ContainsKey(holePosition))
  181. return EnchantDataMap[elementType][holePosition];
  182. else
  183. new ArtifactEnchantParam();
  184. }
  185. return new ArtifactEnchantParam();
  186. }
  187. /// <summary>
  188. /// 获取元素表格信息(元素类型*1000+品质*100+孔位索引)
  189. /// </summary>
  190. /// <param name="elementType">元素类型</param>
  191. /// <param name="quality">品质</param>
  192. /// <param name="holePonsiton">孔位</param>
  193. /// <returns></returns>
  194. public artifactYuansuTable GetElementConfigInfo(int elementType, int quality, int holePonsiton)
  195. {
  196. return artifactYuansuTableRepo.Get(elementType * 1000 + quality * 100 + holePonsiton);
  197. }
  198. /// <summary>
  199. /// 获取元素附魔表格信息(元素核心id*1000+等级)
  200. /// </summary>
  201. /// <param name="elementTableId">元素表格信息id</param>
  202. /// <param name="level">等级</param>
  203. /// <returns></returns>
  204. public artifactFumoTable GetElementEnchantConfigInfo(int elementTableId, int level)
  205. {
  206. return artifactFumoTableRepo.Get(elementTableId * 1000 + level);
  207. }
  208. /// <summary>
  209. /// 5种元素类型在其5个孔位上的附魔数据
  210. /// </summary>
  211. /// <param name="enchantDataList"></param>
  212. public void OnchangeEnchantDataMap(List<ActArtifactFumo> enchantDataList)
  213. {
  214. foreach (var item in enchantDataList)
  215. {
  216. if (EnchantDataMap.ContainsKey((EElementType)item.type))
  217. {
  218. EnchantDataMap[(EElementType)item.type] = GetHolepositionEnchantMap(item.type, item.buwei);
  219. }
  220. else
  221. {
  222. EnchantDataMap.Add((EElementType)item.type, GetHolepositionEnchantMap(item.type, item.buwei));
  223. }
  224. }
  225. }
  226. private Dictionary<int, ArtifactEnchantParam> GetHolepositionEnchantMap(int elementType, List<ActArtifactBuWei> dataList)
  227. {
  228. var artifactEnchantMap = new Dictionary<int, ArtifactEnchantParam>();
  229. foreach (var item in dataList)
  230. {
  231. var enchantParam = new ArtifactEnchantParam()
  232. {
  233. elementType = elementType,
  234. holePosition = item.bwId,
  235. elementId = item.elementId
  236. };
  237. artifactEnchantMap.Add(item.bwId, enchantParam);
  238. }
  239. return artifactEnchantMap;
  240. }
  241. /// <summary>
  242. /// 元素的战力值变化
  243. /// </summary>
  244. /// <param name="elementId"></param>
  245. /// <param name="starPower"></param>
  246. private void OnchangElementPowerData(int elementId, long starPower)
  247. {
  248. if (_elementPowerMap.ContainsKey(elementId))
  249. {
  250. var elementPowerData = _elementPowerMap[elementId];
  251. elementPowerData.starPower = starPower;
  252. }
  253. else
  254. {
  255. var elementPowerData = new ElementPowerParam();
  256. elementPowerData.starPower = starPower;
  257. var elementConfig = artifactYuansuTableRepo.Get(elementId);
  258. if (elementConfig?.Trunk > 0)
  259. elementPowerData.holePosition = elementConfig.Trunk;
  260. if (elementConfig?.Wear_attr?.Length > 1)
  261. {
  262. elementPowerData.wearPower = AttrDescTableRepo.GetAttributePower(elementConfig.Wear_attr[0], elementConfig.Wear_attr[1]);
  263. }
  264. _elementPowerMap.Add(elementId, elementPowerData);
  265. }
  266. }
  267. /// <summary>
  268. /// 解锁的元素数据
  269. /// </summary>
  270. /// <param name="unlockElementList"></param>
  271. public void OnchangeUnlockElementMap(List<ActArtifactElementList> unlockElementList)
  272. {
  273. foreach (var item in unlockElementList)
  274. {
  275. var elementInfo = new ElementInfoParam()
  276. {
  277. elementId = item.elementId,
  278. level = item.level,
  279. state = item.status,
  280. power = item.power,
  281. };
  282. if (UnlockElementMap.ContainsKey(item.elementId))
  283. {
  284. UnlockElementMap[item.elementId] = elementInfo;
  285. }
  286. else
  287. {
  288. UnlockElementMap.Add(item.elementId, elementInfo);
  289. }
  290. OnchangElementPowerData(item.elementId,item.power);
  291. }
  292. }
  293. /// <summary>
  294. /// (激活)升级的元素列表
  295. /// </summary>
  296. /// <param name="unlockElementList"></param>
  297. public void SetUpgradeElementList(List<ActArtifactElementList> unlockElementList)
  298. {
  299. if (UpgradeElementList == null)UpgradeElementList = new List<ElementInfoParam>();
  300. foreach (var item in unlockElementList)
  301. {
  302. var elementInfo = new ElementInfoParam()
  303. {
  304. elementId = item.elementId,
  305. level = item.level,
  306. state = item.status
  307. };
  308. UpgradeElementList.Add(elementInfo);
  309. }
  310. }
  311. #endregion
  312. #region 普通神器数据
  313. /// <summary>
  314. /// 普通神器当前升级到的星级信息id(artifactInfo分表序号ID)
  315. /// </summary>
  316. public int ArtifactInfoId { get; set; }
  317. /// <summary>
  318. /// 普通神器当前升星经验
  319. /// </summary>
  320. public int ArtifactExp { get; set; }
  321. #endregion
  322. #region 高级神器数据
  323. /// <summary>
  324. /// 启用技能的高级神器的id
  325. /// </summary>
  326. public int UsingAdvanceArtifactId { set; get; }
  327. /// <summary>
  328. /// 已解锁的神器星级数据
  329. /// key:artifactBase.id
  330. /// value:star(星级)
  331. /// </summary>
  332. private Dictionary<int, int> _advancedArtifactMap;
  333. public Dictionary<int, int> AdvancedArtifactMap => _advancedArtifactMap ??= new Dictionary<int, int>();
  334. /// <summary>
  335. /// 高级神器是否已解锁状态
  336. /// </summary>
  337. /// <param name="artifactId"></param>
  338. /// <returns></returns>
  339. public bool IsUnLock(int artifactId)
  340. {
  341. return _advancedArtifactMap.ContainsKey(artifactId);
  342. }
  343. /// <summary>
  344. /// 获取高级神器的星级
  345. /// </summary>
  346. /// <param name="artifactId"></param>
  347. public int GetAdvancedArtifactLevel(int artifactId)
  348. {
  349. return _advancedArtifactMap.ContainsKey(artifactId) ? _advancedArtifactMap[artifactId] : 0;
  350. }
  351. /// <summary>
  352. /// 根据神器id和星级获取星级表id
  353. /// </summary>
  354. /// <param name="artifactId"></param>
  355. /// <param name="level"></param>
  356. /// <returns>10000*秘宝id+星级</returns>
  357. public int GetArtifactStarId(int artifactId, int level)
  358. {
  359. return artifactId*10000 + level;
  360. }
  361. /// <summary>
  362. /// 根据神器id和星级获取通用神器信息表id
  363. /// </summary>
  364. /// <param name="artifactId"></param>
  365. /// <param name="level"></param>
  366. /// <returns>秘宝id*10000+阶级*100+星级</returns>
  367. public int GetArtifactInfoId(int artifactId, int step, int starLv)
  368. {
  369. return artifactId * 10000 + step *100 + starLv;
  370. }
  371. #endregion
  372. /// <summary>
  373. /// 当前使用的神器外观模型id(通用神器用的是artifactInfo表格,高级神器对应的是artifactBase表格)
  374. /// 此字段只在神器内部使用,如果外部需要使用神器外观,请使用GetWearAppearance()
  375. /// </summary>
  376. public int AppearanceId { set; get; }
  377. /// <summary>
  378. /// 获取当前穿戴的神器外观
  379. /// </summary>
  380. /// <returns></returns>
  381. public string GetWearAppearance()
  382. {
  383. if (AppearanceId == 0) return string.Empty;
  384. var artifactBaseInfo = artifactBaseTableRepo.Get(AppearanceId);
  385. if (artifactBaseInfo != null) return artifactBaseInfo.Spine;
  386. var artifactInfo = artifactInfoTableRepo.Get(AppearanceId);
  387. return artifactInfo == null ? string.Empty : artifactInfo.Spine;
  388. }
  389. void IDisposable.Dispose()
  390. {
  391. _elementPowerMap.Clear();
  392. _advancedArtifactMap?.Clear();
  393. _advancedArtifactMap = null;
  394. _enchantDataMap?.Clear();
  395. _enchantDataMap = null;
  396. }
  397. }
  398. }