DressUpMenuItemDataManager.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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>> _itemDatasBySubTypeDic = new Dictionary<int, List<int>>();
  22. public static Dictionary<int, List<int>> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } }
  23. private static Dictionary<int, List<int>> _newItemdata = new Dictionary<int, List<int>>();
  24. private static List<int> _newSuitData = new List<int>();
  25. public static void InitData()
  26. {
  27. _itemDatas.Clear();
  28. _newItemdata.Clear();
  29. _itemDatasBySubTypeDic.Clear();
  30. }
  31. public static void Clear()
  32. {
  33. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  34. selectRarityList.Clear();
  35. selectScoreList.Clear();
  36. selectTagList.Clear();
  37. dressSearchTxt = "";
  38. }
  39. public static void Add(int value)
  40. {
  41. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  42. if (itemCfg == null)
  43. {
  44. Debug.LogError("添加了一个不存在的物品" + value);
  45. }
  46. else
  47. {
  48. if (!_itemDatas.Contains(value))
  49. {
  50. _itemDatas.Add(value);
  51. int subType = ItemUtilCS.GetItemSubType(value);
  52. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  53. if (!_itemDatasBySubTypeDic.ContainsKey(subType))
  54. {
  55. _itemDatasBySubTypeDic.Add(subType, new List<int>());
  56. }
  57. _itemDatasBySubTypeDic[subType].Add(value);
  58. if (GameGlobal.DataInited)
  59. {
  60. AddNewDressItem(value);
  61. }
  62. DressUpMenuSuitDataManager.CheckItemInSuit(value);
  63. }
  64. }
  65. }
  66. public static bool CheckHasItem(int itemID)
  67. {
  68. return _itemDatas.Contains(itemID);
  69. }
  70. public static void Remove(int value)
  71. {
  72. if (_itemDatas == null)
  73. {
  74. return;
  75. }
  76. if (_itemDatas.Contains(value))
  77. {
  78. _itemDatas.Remove(value);
  79. }
  80. int subType = ItemUtilCS.GetItemSubType(value);
  81. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  82. if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0)
  83. {
  84. _itemDatasBySubTypeDic[subType].Remove(value);
  85. }
  86. }
  87. public static List<int> getItemDatasByType(int type)
  88. {
  89. List<int> arrayList = new List<int>();
  90. if (_itemDatasBySubTypeDic.ContainsKey(type))
  91. {
  92. arrayList.AddRange(_itemDatasBySubTypeDic[type]);
  93. }
  94. // for (int i = 0; i < _itemDatas.Count; i++)
  95. // {
  96. // int itemID = (int)_itemDatas[i];
  97. // int subType = ItemUtilCS.GetItemSubType(itemID);
  98. // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type)
  99. // {
  100. // arrayList.Add(itemID);
  101. // }
  102. // else if (subType == type)
  103. // {
  104. // arrayList.Add(itemID);
  105. // }
  106. // }
  107. return arrayList;
  108. }
  109. public static List<int> SortItemListByHighScore(List<int> arrayList)
  110. {
  111. arrayList.Sort((int a, int b) =>
  112. {
  113. bool isNewA = CheckIsDressUpItemNew(a);
  114. bool isNewB = CheckIsDressUpItemNew(b);
  115. if (isNewA != isNewB)
  116. {
  117. if (isNewA) return -1;
  118. if (isNewB) return 1;
  119. }
  120. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  121. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  122. if (scoreB > scoreA) return 1;
  123. if (scoreB < scoreA) return -1;
  124. return a - b;
  125. });
  126. return arrayList;
  127. }
  128. public static List<int> SortItemListByLowScore(List<int> arrayList)
  129. {
  130. arrayList.Sort((int a, int b) =>
  131. {
  132. bool isNewA = CheckIsDressUpItemNew(a);
  133. bool isNewB = CheckIsDressUpItemNew(b);
  134. if (isNewA != isNewB)
  135. {
  136. if (isNewA) return -1;
  137. if (isNewB) return 1;
  138. }
  139. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  140. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  141. if (scoreB < scoreA)
  142. {
  143. return 1;
  144. }
  145. else if (scoreB > scoreA)
  146. {
  147. return -1;
  148. }
  149. return 0;
  150. });
  151. return arrayList;
  152. }
  153. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  154. {
  155. arrayList.Sort((int a, int b) =>
  156. {
  157. int typeA = ItemUtilCS.GetItemSubType(a);
  158. int typeB = ItemUtilCS.GetItemSubType(b);
  159. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  160. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  161. if (typeB < typeA)
  162. {
  163. return -1;
  164. }
  165. else if (typeB > typeA)
  166. {
  167. return 1;
  168. }
  169. else if (scoreB > scoreA)
  170. {
  171. return 1;
  172. }
  173. else if (scoreB < scoreA)
  174. {
  175. return -1;
  176. }
  177. return 0;
  178. });
  179. return arrayList;
  180. }
  181. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  182. {
  183. arrayList.Sort((int a, int b) =>
  184. {
  185. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  186. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  187. bool isNewA = CheckIsDressUpItemNew(a);
  188. bool isNewB = CheckIsDressUpItemNew(b);
  189. if (isNewA != isNewB)
  190. {
  191. if (isNewA) return -1;
  192. if (isNewB) return 1;
  193. }
  194. if (itemCfgB.rarity > itemCfgA.rarity)
  195. {
  196. return 1;
  197. }
  198. else if (itemCfgB.rarity < itemCfgA.rarity)
  199. {
  200. return -1;
  201. }
  202. return 0;
  203. });
  204. return arrayList;
  205. }
  206. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  207. {
  208. arrayList.Sort((int a, int b) =>
  209. {
  210. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  211. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  212. bool isNewA = CheckIsDressUpItemNew(a);
  213. bool isNewB = CheckIsDressUpItemNew(b);
  214. if (isNewA != isNewB)
  215. {
  216. if (isNewA) return -1;
  217. if (isNewB) return 1;
  218. }
  219. if (itemCfgB.rarity < itemCfgA.rarity)
  220. {
  221. return 1;
  222. }
  223. else if (itemCfgB.rarity > itemCfgA.rarity)
  224. {
  225. return -1;
  226. }
  227. return 0;
  228. });
  229. return arrayList;
  230. }
  231. public static List<int> GetRecommendItemList(bool toSort = true)
  232. {
  233. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  234. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  235. List<int> recommendTypeList = new List<int>();
  236. List<int> recommendList = new List<int>();
  237. List<int> recommendSpecialList = new List<int>();
  238. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  239. if (toSort)
  240. {
  241. SortItemListByScoreByType(tempAllList);
  242. }
  243. foreach (int itemID in tempAllList)
  244. {
  245. int subType = ItemUtilCS.GetItemSubType(itemID);
  246. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  247. {
  248. if (!recommendTypeList.Contains(subType))
  249. {
  250. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  251. if (isNeed || fightCfg.needItemId <= 0)
  252. {
  253. if (subType < ConstDressUpItemType.TE_SHU)
  254. {
  255. recommendList.Add(itemID);
  256. }
  257. recommendTypeList.Add(subType);
  258. }
  259. }
  260. }
  261. }
  262. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  263. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  264. List<int> specialSubList = new List<int>();
  265. List<int> specialIdList = new List<int>();
  266. foreach (int itemID in recommendSpecialList)
  267. {
  268. int subType = ItemUtilCS.GetItemSubType(itemID);
  269. if (subType > ConstDressUpItemType.TE_SHU)
  270. {
  271. if (specialSubList.Count >= 3) continue;
  272. if (specialSubList.IndexOf(subType) < 0)
  273. {
  274. specialSubList.Add(subType);
  275. specialIdList.Add(itemID);
  276. }
  277. }
  278. }
  279. recommendList.AddRange(specialIdList);
  280. return recommendList;
  281. }
  282. // public static int GetRecommendCount()
  283. // {
  284. // List<int> recommendTypeList = GetRecommendItemList(false);
  285. // return recommendTypeList.Count;
  286. // }
  287. // public static int GetItemScore(int itemId)
  288. // {
  289. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  290. // }
  291. public static List<int> DressSearch(List<int> list)
  292. {
  293. List<int> searchList = new List<int>();
  294. for (int i = 0; i < list.Count; i++)
  295. {
  296. bool isSearch = true;
  297. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  298. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  299. string name = itemCfg != null ? itemCfg.name : suitCfg.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)
  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 = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  323. bool isScore = cfg == null ? true : FilterScore(cfg);
  324. bool isTag = cfg == null ? 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][0] == 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. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  438. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  439. // {
  440. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  441. // }
  442. }
  443. public static void RemoveNewDressItem(int itemId)
  444. {
  445. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  446. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  447. {
  448. _newItemdata[subType].Remove(itemId);
  449. }
  450. }
  451. //检测一级菜单是否有展示新增
  452. public static bool CheckIsFirstMenuNew(int menuId)
  453. {
  454. if (_newItemdata.Count == 0) return false;
  455. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  456. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  457. {
  458. foreach (int id2 in cfg1.subMenusArr)
  459. {
  460. if (CheckIsSecondMenuNew(id2)) return true;
  461. }
  462. }
  463. else
  464. {
  465. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  466. }
  467. return false;
  468. }
  469. //检测二级菜单是否有展示新增
  470. public static bool CheckIsSecondMenuNew(int subMenuId)
  471. {
  472. if (_newItemdata.Count == 0) return false;
  473. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  474. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  475. {
  476. return true;
  477. }
  478. return false;
  479. }
  480. //检测服装部件是否为新增
  481. public static bool CheckIsDressUpItemNew(int itemId)
  482. {
  483. if (_newItemdata.Count == 0) return false;
  484. int subType = ItemUtilCS.GetItemSubType(itemId);
  485. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  486. }
  487. }
  488. }