DressUpMenuItemDataManager.cs 17 KB

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