CardDataManager.cs 14 KB

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