CardDataManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. 
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using cfg.GfgCfg;
  7. using ET;
  8. using UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class CardDataManager
  12. {
  13. private static Dictionary<int, Dictionary<int, CardData>> _cardDicByType = 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, out int showExp)
  173. {
  174. showLv = curLv;
  175. showExp = curExp + hasExp;
  176. CardData cardData = _cardDicByType[0][cardId];
  177. int rarity = cardData.itemCfg.Rarity;
  178. int maxLv = CommonDataManager.Tables.TblCardRarityCfg.GetOrDefault(rarity).MaxCardLvl;
  179. CardLvlCfg tCurCfg = CommonDataManager.Tables.TblCardLvlCfg.Get(rarity, showLv);
  180. while (showExp >= tCurCfg.NeedExp && showLv <= maxLv)
  181. {
  182. showExp -= tCurCfg.NeedExp;
  183. if (showLv + 1 > maxLv)
  184. {
  185. //满级
  186. showExp = tCurCfg.NeedExp;
  187. break;
  188. }
  189. showLv++;
  190. tCurCfg = CommonDataManager.Tables.TblCardLvlCfg.Get(rarity, showLv);
  191. }
  192. }
  193. public static List<CardData> FilterCardList(List<CardData> cardList)
  194. {
  195. List<CardData> _cardList = new List<CardData>();
  196. for (int i = 0; i < cardList.Count; i++)
  197. {
  198. CardData cardData = cardList[i];
  199. bool isRole = _selectRoleList.Count == 0 || _selectRoleList.IndexOf(cardData.itemCfg.SubType) >= 0;
  200. bool isRarity = _selectRarityList.Count == 0 || _selectRarityList.IndexOf(cardData.itemCfg.Rarity) >= 0;
  201. int maxLv = CommonDataManager.Tables.TblCardRarityCfg.GetOrDefault(cardData.itemCfg.Rarity).MaxCardLvl;
  202. bool isFoster = _selectFosterList.Count == 0 ||
  203. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_LV) >= 0 && cardList[i].lv == maxLv ||
  204. _selectFosterList.IndexOf(ConstCardState.STATE_LV) >= 0 && cardList[i].lv < maxLv ||
  205. _selectFosterList.IndexOf(ConstCardState.STATE_FULL_STAR) >= 0 && isFullStar(cardList[i].id, cardList[i].star, false) ||
  206. _selectFosterList.IndexOf(ConstCardState.STATE_STAR) >= 0 && !isFullStar(cardList[i].id, cardList[i].star, false);
  207. if (isRole && isRarity && isFoster)
  208. {
  209. _cardList.Add(cardData);
  210. }
  211. }
  212. return _cardList;
  213. }
  214. public static List<CardStoryCfg> GetStoryCfgsById(int cardId)
  215. {
  216. if (_cardStoryCfgDic.Keys.Count == 0)
  217. {
  218. List<CardStoryCfg> cardStoryCfgs = CommonDataManager.Tables.TblCardStoryCfg.DataList ;
  219. for (int i = 0; i < cardStoryCfgs.Count; i++)
  220. {
  221. int _cardId = cardStoryCfgs[i].CardId;
  222. if (_cardStoryCfgDic.ContainsKey(_cardId) == false)
  223. {
  224. _cardStoryCfgDic.Add(_cardId, new List<CardStoryCfg>());
  225. }
  226. _cardStoryCfgDic[_cardId].Add(cardStoryCfgs[i]);
  227. }
  228. }
  229. return _cardStoryCfgDic.ContainsKey(cardId) ? _cardStoryCfgDic[cardId] : new List<CardStoryCfg>();
  230. }
  231. //升星是否满足材料消耗
  232. public static bool GetUpStarEnoughMaterial(int cardId)
  233. {
  234. CardData cardData = CardDataManager.GetCardDataById(cardId);
  235. CardStarCfg starCfg = CommonDataManager.Tables.TblCardStarCfg.Get(cardId, cardData.star);
  236. for (int i = 0; i < starCfg.Materiars.Count; i++)
  237. {
  238. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.IsAutoSelect) == 0 &&
  239. ItemDataManager.GetItemNum(starCfg.Materiars[i].ItemId) < starCfg.Materiars[i].Count)
  240. return false;
  241. else if (GameGlobal.myNumericComponent.GetAsInt(NumericType.IsAutoSelect) == 1 &&
  242. (i == 0 && (ItemDataManager.GetItemNum(6003001) + ItemDataManager.GetItemNum(starCfg.Materiars[i].ItemId)) < starCfg.Materiars[i].Count) || (i == 1 && (ItemDataManager.GetItemNum(6003002) + ItemDataManager.GetItemNum(starCfg.Materiars[i].ItemId)) < starCfg.Materiars[i].Count))
  243. return false;
  244. }
  245. return true;
  246. }
  247. /// <summary>
  248. /// 根据主属性获取有序牌ID列表(排序规则: 已获得词牌按稀有度从高到低 > 未获得词牌按稀有度从高到低 > 按词牌名字拼音)
  249. /// </summary>
  250. /// <param name="mainScore">
  251. /// 0 - 全部
  252. /// </param>
  253. /// <returns></returns>
  254. public static List<int> GetAllCardIdListByRoleType(int mainScore)
  255. {
  256. List<int> result = new List<int>();
  257. List<ItemCfg> itemCfgs = CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemType(ConstItemType.CARD);
  258. itemCfgs.Sort((a, b) =>
  259. {
  260. bool haveA = GetCardDataById(a.Id) != null;
  261. bool haveB = GetCardDataById(b.Id) != null;
  262. if (haveB && !haveA)
  263. {
  264. return 1;
  265. }
  266. else if (!haveB && haveA)
  267. {
  268. return -1;
  269. }
  270. if (a.Rarity != b.Rarity)
  271. {
  272. return a.Rarity > b.Rarity ? -1 : 1;
  273. }
  274. return a.Res.CompareTo(b.Res);
  275. });
  276. for (int i = 0; i < itemCfgs.Count; i++)
  277. {
  278. if (itemCfgs[i].IsHide > 0)
  279. {
  280. continue;
  281. }
  282. if (mainScore == 0 || itemCfgs[i].MainScore == mainScore)
  283. {
  284. result.Add(itemCfgs[i].Id);
  285. }
  286. }
  287. return result;
  288. }
  289. public static void GetTotalProgress(out int haveCount, out int totalCount, int mainScore = 0)
  290. {
  291. totalCount = CommonDataManager.Tables.TblGlobalCfg.CardCount;
  292. if (mainScore != 0)
  293. {
  294. List<ItemCfg> itemCfgs = CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemType(ConstItemType.CARD);
  295. totalCount = 0;
  296. for (int i = 0; i < itemCfgs.Count; i++)
  297. {
  298. if (itemCfgs[i].IsHide > 0)
  299. {
  300. continue;
  301. }
  302. if (itemCfgs[i].MainScore == mainScore)
  303. {
  304. ++totalCount;
  305. }
  306. }
  307. }
  308. haveCount = _cardDicByType.ContainsKey(mainScore) ? _cardDicByType[mainScore].Count : 0;
  309. }
  310. public static int GetNextUpCardNeedRoleLv(int cardLv) {
  311. int roleLv = RoleDataManager.lvl;
  312. for (int i = roleLv + 1; i< CommonDataManager.Tables.TblRoleLevelCfg.DataList.Count; i++)
  313. {
  314. int limit = CommonDataManager.Tables.TblRoleLevelCfg.GetOrDefault(i).CardLeverLimit;
  315. if (cardLv < limit)
  316. {
  317. roleLv = i;
  318. break;
  319. }
  320. }
  321. return roleLv;
  322. }
  323. }
  324. }