DressUpMenuItemDataManager.cs 17 KB

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