DressUpMenuItemDataManager.cs 17 KB

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