DressUpMenuItemDataManager.cs 20 KB

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