CardDataManager.cs 13 KB

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