DressUpMenuItemDataManager.cs 17 KB

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