CardDataManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. cardData.id = cardInfoProto.CardId;
  28. cardData.lv = cardInfoProto.Lvl;
  29. cardData.exp = cardInfoProto.Exp;
  30. cardData.star = cardInfoProto.Star;
  31. cardData.mainScore = cardInfoProto.MainScore;
  32. cardData.resIndex = cardInfoProto.ResIndex;
  33. for (int i = 0; i < cardInfoProto.KsStarBonus.Count; i++)
  34. {
  35. cardData.starRewardsState[cardInfoProto.KsStarBonus[i]] = cardInfoProto.VsStarBonus[i];
  36. }
  37. cardData.scores = new Dictionary<int, int>();
  38. for (int j = 0; j < cardInfoProto.KsAttribute.Count; j++)
  39. {
  40. cardData.scores.Add(cardInfoProto.KsAttribute[j], cardInfoProto.VsAttribute[j]);
  41. }
  42. if (_cardDicByType.ContainsKey(0) == false)
  43. {
  44. _cardDicByType[0] = new Dictionary<int, CardData>();
  45. }
  46. if (_cardDicByType.ContainsKey(cardData.mainScore) == false)
  47. {
  48. _cardDicByType[cardData.mainScore] = new Dictionary<int, CardData>();
  49. }
  50. _cardDicByType[0][cardData.id] = cardData;
  51. _cardDicByType[cardData.mainScore][cardData.id] = cardData;
  52. }
  53. public static List<string> GetCardResources(ItemCfg itemCfg)
  54. {
  55. List<string> resources = new List<string>();
  56. resources.Add(itemCfg.res);
  57. if (itemCfg.cardRes != "")
  58. {
  59. resources.Add(itemCfg.cardRes);
  60. }
  61. return resources;
  62. }
  63. //默认词牌排序规则 :稀有度>星级>等级>种类(风>花>雪>月)
  64. public static List<CardData> SortItemList(List<CardData> arrayList)
  65. {
  66. arrayList.Sort((CardData a, CardData b) =>
  67. {
  68. int rarityA = a.itemCfg.rarity;
  69. int rarityB = b.itemCfg.rarity;
  70. if (rarityA < rarityB)
  71. {
  72. return 1;
  73. }
  74. else if (rarityA > rarityB)
  75. {
  76. return -1;
  77. }
  78. else
  79. {
  80. if (a.star < b.star)
  81. {
  82. return 1;
  83. }
  84. else if (a.star > b.star)
  85. {
  86. return -1;
  87. }
  88. else
  89. {
  90. if (a.lv < b.lv)
  91. return 1;
  92. else if (a.lv > b.lv)
  93. return -1;
  94. else
  95. {
  96. if (a.mainScore > b.mainScore)
  97. return 1;
  98. else if (a.mainScore < b.mainScore)
  99. return -1;
  100. }
  101. }
  102. }
  103. return string.Compare(a.itemCfg.res, b.itemCfg.res);
  104. });
  105. return arrayList;
  106. }
  107. /// <summary>
  108. /// 根据词牌Id获取词牌升级升星数据,无数据返回null
  109. /// </summary>
  110. /// <param name="cardId"></param>
  111. /// <returns></returns>
  112. public static CardData GetCardDataById(int cardId)
  113. {
  114. if (_cardDicByType.Count == 0 || !_cardDicByType.ContainsKey(0) || !_cardDicByType[0].ContainsKey(cardId))
  115. {
  116. return null;
  117. }
  118. return _cardDicByType[0][cardId];
  119. }
  120. /// <summary>
  121. /// 根据男主类型获取词牌列表
  122. /// </summary>
  123. public static List<CardData> GetCardListByRoleType(int mainScore)
  124. {
  125. if (_cardDicByType.ContainsKey(mainScore))
  126. {
  127. return _cardDicByType[mainScore].Values.ToList();
  128. }
  129. return new List<CardData>();
  130. }
  131. public static bool isFullLv(int cardId, int lv, bool showTips = true)
  132. {
  133. CardData cardData = _cardDicByType[0][cardId];
  134. int rarity = cardData.itemCfg.rarity;
  135. int maxLv = CardRarityCfgArray.Instance.GetCfg(rarity).maxCardLvl;
  136. if (lv >= maxLv && cardData.exp >= CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(rarity, maxLv).needExp)
  137. {
  138. if (showTips == true)
  139. {
  140. PromptController.Instance.ShowFloatTextPrompt("已达到最大等级");
  141. }
  142. return true;
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. public static bool isFullStar(int cardId, int star, bool showTips = true)
  150. {
  151. CardData cardData = _cardDicByType[0][cardId];
  152. if (CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(cardData.id, star + 1) == null)
  153. {
  154. if (showTips == true)
  155. {
  156. PromptController.Instance.ShowFloatTextPrompt("已达到最大星级");
  157. }
  158. return true;
  159. }
  160. else
  161. {
  162. return false;
  163. }
  164. }
  165. public static void GetPreViewLvAndExp(int cardId, int curLv, int curExp, int hasExp, out int showLv, out int showExp)
  166. {
  167. showLv = curLv;
  168. showExp = curExp + hasExp;
  169. CardData cardData = _cardDicByType[0][cardId];
  170. int rarity = cardData.itemCfg.rarity;
  171. int maxLv = CardRarityCfgArray.Instance.GetCfg(rarity).maxCardLvl;
  172. CardLvlCfg tCurCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(rarity, showLv);
  173. while (showExp >= tCurCfg.needExp && showLv <= maxLv)
  174. {
  175. showExp -= tCurCfg.needExp;
  176. if (showLv + 1 > maxLv)
  177. {
  178. //满级
  179. showExp = tCurCfg.needExp;
  180. break;
  181. }
  182. showLv++;
  183. tCurCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(rarity, showLv);
  184. }
  185. }
  186. public static List<CardData> FilterCardList(List<CardData> cardList)
  187. {
  188. List<CardData> _cardList = new List<CardData>();
  189. for (int i = 0; i < cardList.Count; i++)
  190. {
  191. CardData cardData = cardList[i];
  192. bool isRole = _selectRoleList.Count == 0 || _selectRoleList.IndexOf(cardData.itemCfg.subType) >= 0;
  193. bool isRarity = _selectRarityList.Count == 0 || _selectRarityList.IndexOf(cardData.itemCfg.rarity) >= 0;
  194. int maxLv = CardRarityCfgArray.Instance.GetCfg(cardData.itemCfg.rarity).maxCardLvl;
  195. bool isFoster = _selectFosterList.Count == 0 ||
  196. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_LV) >= 0 && cardList[i].lv == maxLv ||
  197. _selectFosterList.IndexOf(ConstCardState.STATE_LV) >= 0 && cardList[i].lv < maxLv ||
  198. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_STAR) >= 0 && isFullStar(cardList[i].id, cardList[i].star, false) ||
  199. _selectFosterList.IndexOf(ConstCardState.STATE_STAR) >= 0 && !isFullStar(cardList[i].id, cardList[i].star, false);
  200. if (isRole && isRarity && isFoster)
  201. {
  202. _cardList.Add(cardData);
  203. }
  204. }
  205. return _cardList;
  206. }
  207. public static List<CardStoryCfg> GetStoryCfgsById(int cardId)
  208. {
  209. if (_cardStoryCfgDic.Keys.Count == 0)
  210. {
  211. CardStoryCfg[] cardStoryCfgs = CardStoryCfgArray.Instance.dataArray;
  212. for (int i = 0; i < cardStoryCfgs.Length; i++)
  213. {
  214. int _cardId = cardStoryCfgs[i].cardId;
  215. if (_cardStoryCfgDic.ContainsKey(_cardId) == false)
  216. {
  217. _cardStoryCfgDic.Add(_cardId, new List<CardStoryCfg>());
  218. }
  219. _cardStoryCfgDic[_cardId].Add(cardStoryCfgs[i]);
  220. }
  221. }
  222. return _cardStoryCfgDic.ContainsKey(cardId) ? _cardStoryCfgDic[cardId] : new List<CardStoryCfg>();
  223. }
  224. //升星是否满足材料消耗
  225. public static bool GetUpStarEnoughMaterial(int cardId)
  226. {
  227. CardData cardData = CardDataManager.GetCardDataById(cardId);
  228. CardStarCfg starCfg = CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(cardId, cardData.star);
  229. for (int i = 0; i < starCfg.materiarsArr.Length; i++)
  230. {
  231. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.IsAutoSelect) == 0 &&
  232. ItemDataManager.GetItemNum(starCfg.materiarsArr[i][0]) < starCfg.materiarsArr[i][1])
  233. return false;
  234. else if (GameGlobal.myNumericComponent.GetAsInt(NumericType.IsAutoSelect) == 1 &&
  235. (i == 0 && (ItemDataManager.GetItemNum(6003001) + ItemDataManager.GetItemNum(starCfg.materiarsArr[i][0])) < starCfg.materiarsArr[i][1]) || (i == 1 && (ItemDataManager.GetItemNum(6003002) + ItemDataManager.GetItemNum(starCfg.materiarsArr[i][0])) < starCfg.materiarsArr[i][1]))
  236. return false;
  237. }
  238. return true;
  239. }
  240. /// <summary>
  241. /// 根据主属性获取有序牌ID列表(排序规则: 已获得词牌按稀有度从高到低 > 未获得词牌按稀有度从高到低 > 按词牌名字拼音)
  242. /// </summary>
  243. /// <param name="mainScore">
  244. /// 0 - 全部
  245. /// </param>
  246. /// <returns></returns>
  247. public static List<int> GetAllCardIdListByRoleType(int mainScore)
  248. {
  249. List<int> result = new List<int>();
  250. List<ItemCfg> itemCfgs = ItemCfgArray.Instance.GetCfgsByitemType(ConstItemType.CARD);
  251. itemCfgs.Sort((a, b) =>
  252. {
  253. bool haveA = GetCardDataById(a.id) != null;
  254. bool haveB = GetCardDataById(b.id) != null;
  255. if (haveB && !haveA)
  256. {
  257. return 1;
  258. }
  259. else if (!haveB && haveA)
  260. {
  261. return -1;
  262. }
  263. if (a.rarity != b.rarity)
  264. {
  265. return a.rarity > b.rarity ? -1 : 1;
  266. }
  267. return a.res.CompareTo(b.res);
  268. });
  269. for (int i = 0; i < itemCfgs.Count; i++)
  270. {
  271. if (itemCfgs[i].isHide > 0)
  272. {
  273. continue;
  274. }
  275. if (mainScore == 0 || itemCfgs[i].mainScore == mainScore)
  276. {
  277. result.Add(itemCfgs[i].id);
  278. }
  279. }
  280. return result;
  281. }
  282. public static void GetTotalProgress(out int haveCount, out int totalCount, int mainScore = 0)
  283. {
  284. totalCount = GlobalCfgArray.globalCfg.CardCount;
  285. if (mainScore != 0)
  286. {
  287. List<ItemCfg> itemCfgs = ItemCfgArray.Instance.GetCfgsByitemType(ConstItemType.CARD);
  288. totalCount = 0;
  289. for (int i = 0; i < itemCfgs.Count; i++)
  290. {
  291. if (itemCfgs[i].isHide > 0)
  292. {
  293. continue;
  294. }
  295. if (itemCfgs[i].mainScore == mainScore)
  296. {
  297. ++totalCount;
  298. }
  299. }
  300. }
  301. haveCount = _cardDicByType.ContainsKey(mainScore) ? _cardDicByType[mainScore].Count : 0;
  302. }
  303. }
  304. }