CardDataManager.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. 
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using ET;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class CardDataManager
  11. {
  12. private static Dictionary<int, Dictionary<int, CardData>> _cardDicByType = new Dictionary<int, Dictionary<int, CardData>>();
  13. public static Dictionary<int, Dictionary<int, int>> _selectList = new Dictionary<int, Dictionary<int, int>>();
  14. public static List<int> _selectRoleList = new List<int>();
  15. public static List<int> _selectRarityList = new List<int>();
  16. public static List<int> _selectFosterList = new List<int>();
  17. public static bool isFilter = false;//是否筛选中
  18. private static Dictionary<int, List<CardStoryCfg>> _cardStoryCfgDic = new Dictionary<int, List<CardStoryCfg>>();
  19. public static void Clear()
  20. {
  21. _cardDicByType.Clear();
  22. }
  23. public static void Add(CardInfoProto cardInfoProto)
  24. {
  25. CardData cardData = new CardData();
  26. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardInfoProto.CardId);
  27. cardData.id = cardInfoProto.CardId;
  28. cardData.lv = cardInfoProto.Lvl;
  29. cardData.exp = cardInfoProto.Exp;
  30. cardData.star = cardInfoProto.Star;
  31. cardData.itemCfg = itemCfg;
  32. cardData.resIndex = cardInfoProto.ResIndex;
  33. cardData.scores = new Dictionary<int, int>();
  34. for (int j = 0; j < cardInfoProto.KsAttribute.Count; j++)
  35. {
  36. cardData.scores.Add(cardInfoProto.KsAttribute[j], cardInfoProto.VsAttribute[j]);
  37. }
  38. cardData.mainScore = itemCfg.mainScore;
  39. cardData.resources = CardDataManager.GetCardResources(itemCfg);
  40. if (_cardDicByType.ContainsKey(0) == false)
  41. {
  42. _cardDicByType[0] = new Dictionary<int, CardData>();
  43. }
  44. if (_cardDicByType.ContainsKey(cardData.itemCfg.mainScore) == false)
  45. {
  46. _cardDicByType[cardData.itemCfg.mainScore] = new Dictionary<int, CardData>();
  47. }
  48. _cardDicByType[0][cardData.id] = cardData;
  49. _cardDicByType[cardData.itemCfg.mainScore][cardData.id] = cardData;
  50. }
  51. private static List<string> GetCardResources(ItemCfg itemCfg)
  52. {
  53. List<string> resources = new List<string>();
  54. resources.Add(itemCfg.res);
  55. if (itemCfg.cardRes != "")
  56. {
  57. resources.Add(itemCfg.cardRes);
  58. }
  59. return resources;
  60. }
  61. private static List<CardData> SortItemList(List<CardData> arrayList)
  62. {
  63. arrayList.Sort((CardData a, CardData b) =>
  64. {
  65. int rarityA = a.itemCfg.rarity;
  66. int rarityB = b.itemCfg.rarity;
  67. if (rarityA < rarityB)
  68. {
  69. return 1;
  70. }
  71. else if (rarityA > rarityB)
  72. {
  73. return -1;
  74. }
  75. return string.Compare(a.itemCfg.res, b.itemCfg.res);
  76. });
  77. return arrayList;
  78. }
  79. /// <summary>
  80. /// 根据卡牌Id获取卡牌升级升星数据,无数据返回null
  81. /// </summary>
  82. /// <param name="cardId"></param>
  83. /// <returns></returns>
  84. public static CardData GetCardDataById(int cardId)
  85. {
  86. return _cardDicByType[0].ContainsKey(cardId) ? _cardDicByType[0][cardId] : null;
  87. }
  88. /// <summary>
  89. /// 根据男主类型获取卡牌列表
  90. /// </summary>
  91. public static List<CardData> GetCardListByRarity(int mainScore)
  92. {
  93. if (_cardDicByType.ContainsKey(mainScore))
  94. {
  95. Dictionary<int, CardData> cardDic = _cardDicByType[mainScore];
  96. CardData[] cardArray = new CardData[cardDic.Count];
  97. cardDic.Values.CopyTo(cardArray, 0);
  98. List<CardData> cardList = new List<CardData>(cardArray);
  99. cardList = CardDataManager.SortItemList(cardList);
  100. return cardList;
  101. }
  102. return new List<CardData>();
  103. }
  104. public static bool isFullLv(int cardId, int lv, bool showTips = true)
  105. {
  106. CardData cardData = _cardDicByType[0][cardId];
  107. if (lv >= CardRarityCfgArray.Instance.GetCfg(cardData.itemCfg.rarity).maxCardLvl && cardData.exp >= CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(lv, cardData.itemCfg.rarity).needExp)
  108. {
  109. if (showTips == true)
  110. {
  111. PromptController.Instance.ShowFloatTextPrompt("已达到最大等级");
  112. }
  113. return true;
  114. }
  115. else
  116. {
  117. return false;
  118. }
  119. }
  120. public static bool isFullStar(int cardId, int star, bool showTips = true)
  121. {
  122. CardData cardData = _cardDicByType[0][cardId];
  123. if (CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(cardData.id, star + 1) == null)
  124. {
  125. if (showTips == true)
  126. {
  127. PromptController.Instance.ShowFloatTextPrompt("已达到最大星级");
  128. }
  129. return true;
  130. }
  131. else
  132. {
  133. return false;
  134. }
  135. }
  136. public static void GetPreViewLvAndExp(int rarity, int curLv, int curExp, int hasExp, out int showLv, out int showExp)
  137. {
  138. showLv = curLv;
  139. showExp = curExp + hasExp;
  140. int maxLv = CardRarityCfgArray.Instance.GetCfg(rarity).maxCardLvl;
  141. CardLvlCfg tCurCfg = CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(showLv, rarity);
  142. while (showExp >= tCurCfg.needExp && showLv <= maxLv)
  143. {
  144. showExp -= tCurCfg.needExp;
  145. if (showLv + 1 > maxLv)
  146. {
  147. //满级
  148. // showLv = showLv - 1;
  149. showExp = tCurCfg.needExp;
  150. break;
  151. }
  152. showLv++;
  153. tCurCfg = CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(showLv, rarity);
  154. // if (showExp < tCurCfg.needExp)
  155. // {
  156. // showLv = showLv - 1;
  157. // break;
  158. // }
  159. }
  160. }
  161. public static List<CardData> FilterCardList(List<CardData> cardList)
  162. {
  163. List<CardData> _cardList = new List<CardData>();
  164. for (int i = 0; i < cardList.Count; i++)
  165. {
  166. CardData cardData = cardList[i];
  167. bool isRole = _selectRoleList.Count == 0 || _selectRoleList.IndexOf(cardData.itemCfg.subType) >= 0;
  168. bool isRarity = _selectRarityList.Count == 0 || _selectRarityList.IndexOf(cardData.itemCfg.rarity) >= 0;
  169. int maxLv = CardRarityCfgArray.Instance.GetCfg(cardList[i].itemCfg.rarity).maxCardLvl;
  170. bool isFoster = _selectFosterList.Count == 0 ||
  171. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_LV) >= 0 && cardList[i].lv == maxLv ||
  172. _selectFosterList.IndexOf(ConstCardState.STATE_LV) >= 0 && cardList[i].lv < maxLv ||
  173. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_STAR) >= 0 && isFullStar(cardList[i].id, cardList[i].star, false) ||
  174. _selectFosterList.IndexOf(ConstCardState.STATE_STAR) >= 0 && !isFullStar(cardList[i].id, cardList[i].star, false);
  175. if (isRole && isRarity && isFoster)
  176. {
  177. _cardList.Add(cardData);
  178. }
  179. }
  180. return _cardList;
  181. }
  182. public static List<CardStoryCfg> GetStoryCfgsById(int cardId)
  183. {
  184. if (_cardStoryCfgDic.Keys.Count == 0)
  185. {
  186. CardStoryCfg[] cardStoryCfgs = CardStoryCfgArray.Instance.dataArray;
  187. for (int i = 0; i < cardStoryCfgs.Length; i++)
  188. {
  189. int _cardId = cardStoryCfgs[i].cardId;
  190. if (_cardStoryCfgDic.ContainsKey(_cardId) == false)
  191. {
  192. _cardStoryCfgDic.Add(_cardId, new List<CardStoryCfg>());
  193. }
  194. _cardStoryCfgDic[_cardId].Add(cardStoryCfgs[i]);
  195. }
  196. }
  197. return _cardStoryCfgDic.ContainsKey(cardId) ? _cardStoryCfgDic[cardId] : new List<CardStoryCfg>();
  198. }
  199. }
  200. }