DressUpMenuItemDataManager.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public enum DressFilterType
  9. {
  10. None,
  11. Search,
  12. Filter
  13. }
  14. public class DressUpMenuItemDataManager
  15. {
  16. public static string dressSearchTxt = "";
  17. public static DressFilterType dressFilterType = DressFilterType.None;
  18. public static List<int> selectRarityList = new List<int>();
  19. public static List<int> selectScoreList = new List<int>();
  20. public static List<string> selectTagList = new List<string>();
  21. private static List<int> _itemDatas = new List<int>();
  22. private static Dictionary<int, List<int>> _itemDatasBySubTypeDic = new Dictionary<int, List<int>>();
  23. public static Dictionary<int, List<int>> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } }
  24. private static Dictionary<int, List<int>> _newItemdata = new Dictionary<int, List<int>>();
  25. private static Dictionary<int, List<int>> _itemDatasByRarityDic = new Dictionary<int, List<int>>();
  26. private static List<int> _newSuitData = new List<int>();
  27. public static void InitData()
  28. {
  29. _itemDatas.Clear();
  30. _newItemdata.Clear();
  31. _itemDatasBySubTypeDic.Clear();
  32. _itemDatasByRarityDic.Clear();
  33. }
  34. public static void Clear()
  35. {
  36. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  37. selectRarityList.Clear();
  38. selectScoreList.Clear();
  39. selectTagList.Clear();
  40. dressSearchTxt = "";
  41. }
  42. public static void Add(ItemInfoProto itemInfoProto)
  43. {
  44. var value = itemInfoProto.ConfigId;
  45. //游戏初始化禁止使用ItemCfg
  46. if (!_itemDatas.Contains(value))
  47. {
  48. _itemDatas.Add(value);
  49. int subType = itemInfoProto.SubType;
  50. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  51. if (!_itemDatasBySubTypeDic.ContainsKey(subType))
  52. {
  53. _itemDatasBySubTypeDic.Add(subType, new List<int>());
  54. }
  55. _itemDatasBySubTypeDic[subType].Add(value);
  56. if (!_itemDatasByRarityDic.ContainsKey(itemInfoProto.Rarity))
  57. {
  58. _itemDatasByRarityDic.Add(itemInfoProto.Rarity, new List<int>());
  59. }
  60. _itemDatasByRarityDic[itemInfoProto.Rarity].Add(value);
  61. if (GameGlobal.DataInited)
  62. {
  63. AddNewDressItem(value);
  64. DressUpMenuSuitDataManager.CheckItemInSuit(value);
  65. }
  66. }
  67. }
  68. public static bool CheckHasItem(int itemID)
  69. {
  70. return _itemDatas.Contains(itemID);
  71. }
  72. public static void Remove(int value)
  73. {
  74. if (_itemDatas == null)
  75. {
  76. return;
  77. }
  78. if (_itemDatas.Contains(value))
  79. {
  80. _itemDatas.Remove(value);
  81. }
  82. int subType = ItemUtilCS.GetItemSubType(value);
  83. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  84. if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0)
  85. {
  86. _itemDatasBySubTypeDic[subType].Remove(value);
  87. }
  88. int rarity = ItemCfgArray.Instance.GetCfg(value).rarity;
  89. if (_itemDatasByRarityDic.ContainsKey(rarity) && _itemDatasByRarityDic[rarity].IndexOf(value) >= 0)
  90. {
  91. _itemDatasByRarityDic[rarity].Remove(value);
  92. }
  93. }
  94. public static List<int> getItemDatasByType(int type)
  95. {
  96. List<int> arrayList = new List<int>();
  97. if (_itemDatasBySubTypeDic.ContainsKey(type))
  98. {
  99. arrayList.AddRange(_itemDatasBySubTypeDic[type]);
  100. }
  101. // for (int i = 0; i < _itemDatas.Count; i++)
  102. // {
  103. // int itemID = (int)_itemDatas[i];
  104. // int subType = ItemUtilCS.GetItemSubType(itemID);
  105. // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type)
  106. // {
  107. // arrayList.Add(itemID);
  108. // }
  109. // else if (subType == type)
  110. // {
  111. // arrayList.Add(itemID);
  112. // }
  113. // }
  114. return arrayList;
  115. }
  116. public static List<int> SortItemListByHighScore(List<int> arrayList, bool checkNew = false)
  117. {
  118. arrayList.Sort((int a, int b) =>
  119. {
  120. if (checkNew)
  121. {
  122. bool isNewA = CheckIsDressUpItemNew(a);
  123. bool isNewB = CheckIsDressUpItemNew(b);
  124. if (isNewA != isNewB)
  125. {
  126. if (isNewA) return -1;
  127. if (isNewB) return 1;
  128. }
  129. }
  130. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  131. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  132. if (scoreB > scoreA) return 1;
  133. if (scoreB < scoreA) return -1;
  134. return a - b;
  135. });
  136. return arrayList;
  137. }
  138. public static List<int> SortItemListByLowScore(List<int> arrayList, bool checkNew = false)
  139. {
  140. arrayList.Sort((int a, int b) =>
  141. {
  142. if (checkNew)
  143. {
  144. bool isNewA = CheckIsDressUpItemNew(a);
  145. bool isNewB = CheckIsDressUpItemNew(b);
  146. if (isNewA != isNewB)
  147. {
  148. if (isNewA) return -1;
  149. if (isNewB) return 1;
  150. }
  151. }
  152. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  153. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  154. if (scoreB < scoreA)
  155. {
  156. return 1;
  157. }
  158. else if (scoreB > scoreA)
  159. {
  160. return -1;
  161. }
  162. return 0;
  163. });
  164. return arrayList;
  165. }
  166. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  167. {
  168. arrayList.Sort((int a, int b) =>
  169. {
  170. int typeA = ItemUtilCS.GetItemSubType(a);
  171. int typeB = ItemUtilCS.GetItemSubType(b);
  172. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  173. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  174. if (typeB < typeA)
  175. {
  176. return -1;
  177. }
  178. else if (typeB > typeA)
  179. {
  180. return 1;
  181. }
  182. else if (scoreB > scoreA)
  183. {
  184. return 1;
  185. }
  186. else if (scoreB < scoreA)
  187. {
  188. return -1;
  189. }
  190. return 0;
  191. });
  192. return arrayList;
  193. }
  194. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  195. {
  196. arrayList.Sort((int a, int b) =>
  197. {
  198. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  199. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  200. bool isNewA = CheckIsDressUpItemNew(a);
  201. bool isNewB = CheckIsDressUpItemNew(b);
  202. if (isNewA != isNewB)
  203. {
  204. if (isNewA) return -1;
  205. if (isNewB) return 1;
  206. }
  207. if (itemCfgB.rarity > itemCfgA.rarity)
  208. {
  209. return 1;
  210. }
  211. else if (itemCfgB.rarity < itemCfgA.rarity)
  212. {
  213. return -1;
  214. }
  215. return 0;
  216. });
  217. return arrayList;
  218. }
  219. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  220. {
  221. arrayList.Sort((int a, int b) =>
  222. {
  223. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  224. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  225. bool isNewA = CheckIsDressUpItemNew(a);
  226. bool isNewB = CheckIsDressUpItemNew(b);
  227. if (isNewA != isNewB)
  228. {
  229. if (isNewA) return -1;
  230. if (isNewB) return 1;
  231. }
  232. if (itemCfgB.rarity < itemCfgA.rarity)
  233. {
  234. return 1;
  235. }
  236. else if (itemCfgB.rarity > itemCfgA.rarity)
  237. {
  238. return -1;
  239. }
  240. return 0;
  241. });
  242. return arrayList;
  243. }
  244. public static List<int> GetRecommendItemList(bool toSort = true)
  245. {
  246. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  247. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  248. List<int> recommendTypeList = new List<int>();
  249. List<int> recommendList = new List<int>();
  250. List<int> recommendSpecialList = new List<int>();
  251. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  252. if (toSort)
  253. {
  254. SortItemListByScoreByType(tempAllList);
  255. }
  256. foreach (int itemID in tempAllList)
  257. {
  258. int subType = ItemUtilCS.GetItemSubType(itemID);
  259. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  260. {
  261. if (!recommendTypeList.Contains(subType))
  262. {
  263. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  264. if (isNeed || fightCfg.needItemId <= 0)
  265. {
  266. if (subType < ConstDressUpItemType.TE_SHU)
  267. {
  268. recommendList.Add(itemID);
  269. }
  270. recommendTypeList.Add(subType);
  271. }
  272. }
  273. }
  274. }
  275. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  276. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  277. List<int> specialSubList = new List<int>();
  278. List<int> specialIdList = new List<int>();
  279. foreach (int itemID in recommendSpecialList)
  280. {
  281. int subType = ItemUtilCS.GetItemSubType(itemID);
  282. if (subType > ConstDressUpItemType.TE_SHU)
  283. {
  284. if (specialSubList.Count >= 3) continue;
  285. if (specialSubList.IndexOf(subType) < 0)
  286. {
  287. specialSubList.Add(subType);
  288. specialIdList.Add(itemID);
  289. }
  290. }
  291. }
  292. recommendList.AddRange(specialIdList);
  293. return recommendList;
  294. }
  295. // public static int GetRecommendCount()
  296. // {
  297. // List<int> recommendTypeList = GetRecommendItemList(false);
  298. // return recommendTypeList.Count;
  299. // }
  300. // public static int GetItemScore(int itemId)
  301. // {
  302. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  303. // }
  304. public static List<int> DressSearch(bool includeScene = true)
  305. {
  306. List<int> searchList = new List<int>();
  307. for (int i = 0; i < _itemDatas.Count; i++)
  308. {
  309. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  310. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  311. if (itemCfg.name.IndexOf(dressSearchTxt) >= 0 && searchList.IndexOf(itemCfg.id) < 0)
  312. {
  313. searchList.Add(itemCfg.id);
  314. }
  315. }
  316. return searchList;
  317. }
  318. public static List<int> DressFilter(bool includeScene = true)
  319. {
  320. List<int> filterList = new List<int>();
  321. for (int i = 0; i < _itemDatas.Count; i++)
  322. {
  323. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  324. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  325. bool isTag = selectTagList.Count == 0;
  326. if (selectTagList.Count > 0)
  327. {
  328. for (int j = 0; j < itemCfg.tagsArr.Length; j++)
  329. {
  330. if (selectTagList.IndexOf(itemCfg.tagsArr[j][0]) >= 0)
  331. {
  332. isTag = true;
  333. break;
  334. }
  335. }
  336. }
  337. if (!isTag) continue;
  338. if (selectRarityList.Count > 0 && selectRarityList.IndexOf(itemCfg.rarity) < 0) continue;
  339. if (selectScoreList.Count > 0 && selectScoreList.IndexOf(itemCfg.mainScore) < 0) continue;
  340. filterList.Add(itemCfg.id);
  341. }
  342. return filterList;
  343. }
  344. public static List<int> DressSearch(List<int> list)
  345. {
  346. List<int> searchList = new List<int>();
  347. for (int i = 0; i < list.Count; i++)
  348. {
  349. bool isSearch = true;
  350. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  351. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  352. string name = itemCfg != null ? itemCfg.name : suitCfg.name;
  353. for (int j = 0; j < dressSearchTxt.Length; j++)
  354. {
  355. if (name.IndexOf(dressSearchTxt[j]) < 0)
  356. {
  357. isSearch = false;
  358. break;
  359. }
  360. }
  361. if (isSearch)
  362. {
  363. searchList.Add(list[i]);
  364. }
  365. }
  366. return searchList;
  367. }
  368. public static List<int> DressFilter(List<int> list)
  369. {
  370. List<int> filterList = new List<int>();
  371. for (int i = 0; i < list.Count; i++)
  372. {
  373. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  374. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  375. bool isRarity = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  376. bool isScore = cfg == null ? true : FilterScore(cfg);
  377. bool isTag = cfg == null ? true : FilterTag(cfg);
  378. if (isRarity && isScore && isTag)
  379. {
  380. filterList.Add(list[i]);
  381. }
  382. }
  383. if (filterList.Count == 0)
  384. {
  385. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  386. }
  387. return filterList;
  388. }
  389. private static bool FilterRarity(ItemCfg cfg)
  390. {
  391. bool isRarity = false;
  392. if (selectRarityList.Count > 0)
  393. {
  394. for (int j = 0; j < selectRarityList.Count; j++)
  395. {
  396. if (cfg != null && cfg.rarity == selectRarityList[j])
  397. {
  398. isRarity = true;
  399. break;
  400. }
  401. }
  402. }
  403. else
  404. {
  405. isRarity = true;
  406. }
  407. return isRarity;
  408. }
  409. private static bool FilterRarity(SuitCfg cfg)
  410. {
  411. bool isRarity = false;
  412. if (selectRarityList.Count > 0)
  413. {
  414. for (int j = 0; j < selectRarityList.Count; j++)
  415. {
  416. if (cfg != null && cfg.rarity == selectRarityList[j])
  417. {
  418. isRarity = true;
  419. break;
  420. }
  421. }
  422. }
  423. else
  424. {
  425. isRarity = true;
  426. }
  427. return isRarity;
  428. }
  429. private static bool FilterScore(ItemCfg cfg)
  430. {
  431. bool isScore = false;
  432. if (selectScoreList.Count > 0)
  433. {
  434. if (cfg != null)
  435. {
  436. for (int j = 0; j < selectScoreList.Count; j++)
  437. {
  438. if (cfg.mainScore == selectScoreList[j])
  439. {
  440. isScore = true;
  441. break;
  442. }
  443. }
  444. }
  445. }
  446. else
  447. {
  448. isScore = true;
  449. }
  450. return isScore;
  451. }
  452. private static bool FilterTag(ItemCfg cfg)
  453. {
  454. bool isTag = false;
  455. if (selectTagList.Count > 0)
  456. {
  457. if (cfg != null)
  458. {
  459. for (int j = 0; j < selectTagList.Count; j++)
  460. {
  461. if (isTag == true)
  462. {
  463. break;
  464. }
  465. for (int k = 0; k < cfg.tagsArr.Length; k++)
  466. {
  467. if (cfg.tagsArr[k][0] == selectTagList[j])
  468. {
  469. isTag = true;
  470. break;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. else
  477. {
  478. isTag = true;
  479. }
  480. return isTag;
  481. }
  482. public static void AddNewDressItem(int value)
  483. {
  484. int subType = ItemDataManager.GetItemSubType(value);
  485. if (!_newItemdata.ContainsKey(subType))
  486. {
  487. _newItemdata.Add(subType, new List<int>());
  488. }
  489. _newItemdata[subType].Add(value);
  490. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  491. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  492. // {
  493. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  494. // }
  495. }
  496. public static void RemoveNewDressItem(int itemId)
  497. {
  498. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  499. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  500. {
  501. _newItemdata[subType].Remove(itemId);
  502. }
  503. }
  504. //检测一级菜单是否有展示新增
  505. public static bool CheckIsFirstMenuNew(int menuId)
  506. {
  507. if (_newItemdata.Count == 0) return false;
  508. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  509. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  510. {
  511. foreach (int id2 in cfg1.subMenusArr)
  512. {
  513. if (CheckIsSecondMenuNew(id2)) return true;
  514. }
  515. }
  516. else
  517. {
  518. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  519. }
  520. return false;
  521. }
  522. //检测二级菜单是否有展示新增
  523. public static bool CheckIsSecondMenuNew(int subMenuId)
  524. {
  525. if (_newItemdata.Count == 0) return false;
  526. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  527. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  528. {
  529. return true;
  530. }
  531. return false;
  532. }
  533. //检测服装部件是否为新增
  534. public static bool CheckIsDressUpItemNew(int itemId)
  535. {
  536. if (_newItemdata.Count == 0) return false;
  537. int subType = ItemUtilCS.GetItemSubType(itemId);
  538. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  539. }
  540. }
  541. }