DressUpMenuItemDataManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType); ;
  98. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType); ;
  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 = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType); ;
  123. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType); ;
  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 = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType); ;
  143. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType); ;
  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. // }
  292. public static List<int> DressSearch(List<int> list, bool isTaoZhuang)
  293. {
  294. List<int> searchList = new List<int>();
  295. for (int i = 0; i < list.Count; i++)
  296. {
  297. bool isSearch = true;
  298. string name = isTaoZhuang ? SuitCfgArray.Instance.GetCfg(list[i]).name : ItemCfgArray.Instance.GetCfg(list[i]).name;
  299. for (int j = 0; j < dressSearchTxt.Length; j++)
  300. {
  301. if (name.IndexOf(dressSearchTxt[j]) < 0)
  302. {
  303. isSearch = false;
  304. break;
  305. }
  306. }
  307. if (isSearch)
  308. {
  309. searchList.Add(list[i]);
  310. }
  311. }
  312. return searchList;
  313. }
  314. public static List<int> DressFilter(List<int> list, bool isTaoZhuang)
  315. {
  316. List<int> filterList = new List<int>();
  317. for (int i = 0; i < list.Count; i++)
  318. {
  319. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  320. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  321. bool isRarity = isTaoZhuang ? FilterRarity(tzCfg) : FilterRarity(cfg);
  322. bool isScore = isTaoZhuang ? true : FilterScore(cfg);
  323. bool isTag = isTaoZhuang ? true : FilterTag(cfg);
  324. if (isRarity && isScore && isTag)
  325. {
  326. filterList.Add(list[i]);
  327. }
  328. }
  329. if (filterList.Count == 0)
  330. {
  331. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  332. }
  333. return filterList;
  334. }
  335. private static bool FilterRarity(ItemCfg cfg)
  336. {
  337. bool isRarity = false;
  338. if (selectRarityList.Count > 0)
  339. {
  340. for (int j = 0; j < selectRarityList.Count; j++)
  341. {
  342. if (cfg != null && cfg.rarity == selectRarityList[j])
  343. {
  344. isRarity = true;
  345. break;
  346. }
  347. }
  348. }
  349. else
  350. {
  351. isRarity = true;
  352. }
  353. return isRarity;
  354. }
  355. private static bool FilterRarity(SuitCfg cfg)
  356. {
  357. bool isRarity = false;
  358. if (selectRarityList.Count > 0)
  359. {
  360. for (int j = 0; j < selectRarityList.Count; j++)
  361. {
  362. if (cfg != null && cfg.rarity == selectRarityList[j])
  363. {
  364. isRarity = true;
  365. break;
  366. }
  367. }
  368. }
  369. else
  370. {
  371. isRarity = true;
  372. }
  373. return isRarity;
  374. }
  375. private static bool FilterScore(ItemCfg cfg)
  376. {
  377. bool isScore = false;
  378. if (selectScoreList.Count > 0)
  379. {
  380. if (cfg != null)
  381. {
  382. for (int j = 0; j < selectScoreList.Count; j++)
  383. {
  384. if (cfg.mainScore == selectScoreList[j])
  385. {
  386. isScore = true;
  387. break;
  388. }
  389. }
  390. }
  391. }
  392. else
  393. {
  394. isScore = true;
  395. }
  396. return isScore;
  397. }
  398. private static bool FilterTag(ItemCfg cfg)
  399. {
  400. bool isTag = false;
  401. if (selectTagList.Count > 0)
  402. {
  403. if (cfg != null)
  404. {
  405. for (int j = 0; j < selectTagList.Count; j++)
  406. {
  407. if (isTag == true)
  408. {
  409. break;
  410. }
  411. for (int k = 0; k < cfg.tagsArr.Length; k++)
  412. {
  413. if (cfg.tagsArr[k] == selectTagList[j])
  414. {
  415. isTag = true;
  416. break;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. else
  423. {
  424. isTag = true;
  425. }
  426. return isTag;
  427. }
  428. public static void AddNewDressItem(int value)
  429. {
  430. int subType = ItemUtilCS.GetItemSubType(value);
  431. if (!_newItemdata.ContainsKey(subType))
  432. {
  433. _newItemdata.Add(subType, new List<int>());
  434. }
  435. _newItemdata[subType].Add(value);
  436. }
  437. public static void RemoveNewDressItem(int itemId)
  438. {
  439. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  440. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  441. {
  442. _newItemdata[subType].Remove(itemId);
  443. }
  444. }
  445. //检测一级菜单是否有展示新增
  446. public static bool CheckIsFirstMenuNew(int menuId)
  447. {
  448. if (_newItemdata.Count == 0) return false;
  449. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  450. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  451. {
  452. foreach (int id2 in cfg1.subMenusArr)
  453. {
  454. if (CheckIsSecondMenuNew(id2)) return true;
  455. }
  456. }
  457. else
  458. {
  459. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  460. }
  461. return false;
  462. }
  463. //检测二级菜单是否有展示新增
  464. public static bool CheckIsSecondMenuNew(int subMenuId)
  465. {
  466. if (_newItemdata.Count == 0) return false;
  467. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  468. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  469. {
  470. return true;
  471. }
  472. return false;
  473. }
  474. //检测服装部件是否为新增
  475. public static bool CheckIsDressUpItemNew(int itemId)
  476. {
  477. if (_newItemdata.Count == 0) return false;
  478. int subType = ItemUtilCS.GetItemSubType(itemId);
  479. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  480. }
  481. }
  482. }