CardDataManager.cs 9.7 KB

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