CardDataManager.cs 9.0 KB

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