DressUpMenuItemDataManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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)
  123. {
  124. return 1;
  125. }
  126. else if (scoreB < scoreA)
  127. {
  128. return -1;
  129. }
  130. return 0;
  131. });
  132. return arrayList;
  133. }
  134. public static List<int> SortItemListByLowScore(List<int> arrayList)
  135. {
  136. arrayList.Sort((int a, int b) =>
  137. {
  138. bool isNewA = CheckIsDressUpItemNew(a);
  139. bool isNewB = CheckIsDressUpItemNew(b);
  140. if (isNewA != isNewB)
  141. {
  142. if (isNewA) return -1;
  143. if (isNewB) return 1;
  144. }
  145. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  146. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  147. if (scoreB < scoreA)
  148. {
  149. return 1;
  150. }
  151. else if (scoreB > scoreA)
  152. {
  153. return -1;
  154. }
  155. return 0;
  156. });
  157. return arrayList;
  158. }
  159. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  160. {
  161. arrayList.Sort((int a, int b) =>
  162. {
  163. int typeA = ItemUtilCS.GetItemSubType(a);
  164. int typeB = ItemUtilCS.GetItemSubType(b);
  165. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  166. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  167. if (typeB < typeA)
  168. {
  169. return -1;
  170. }
  171. else if (typeB > typeA)
  172. {
  173. return 1;
  174. }
  175. else if (scoreB > scoreA)
  176. {
  177. return 1;
  178. }
  179. else if (scoreB < scoreA)
  180. {
  181. return -1;
  182. }
  183. return 0;
  184. });
  185. return arrayList;
  186. }
  187. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  188. {
  189. arrayList.Sort((int a, int b) =>
  190. {
  191. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  192. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  193. bool isNewA = CheckIsDressUpItemNew(a);
  194. bool isNewB = CheckIsDressUpItemNew(b);
  195. if (isNewA != isNewB)
  196. {
  197. if (isNewA) return -1;
  198. if (isNewB) return 1;
  199. }
  200. if (itemCfgB.rarity > itemCfgA.rarity)
  201. {
  202. return 1;
  203. }
  204. else if (itemCfgB.rarity < itemCfgA.rarity)
  205. {
  206. return -1;
  207. }
  208. return 0;
  209. });
  210. return arrayList;
  211. }
  212. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  213. {
  214. arrayList.Sort((int a, int b) =>
  215. {
  216. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  217. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  218. bool isNewA = CheckIsDressUpItemNew(a);
  219. bool isNewB = CheckIsDressUpItemNew(b);
  220. if (isNewA != isNewB)
  221. {
  222. if (isNewA) return -1;
  223. if (isNewB) return 1;
  224. }
  225. if (itemCfgB.rarity < itemCfgA.rarity)
  226. {
  227. return 1;
  228. }
  229. else if (itemCfgB.rarity > itemCfgA.rarity)
  230. {
  231. return -1;
  232. }
  233. return 0;
  234. });
  235. return arrayList;
  236. }
  237. public static List<int> GetRecommendItemList(bool toSort = true)
  238. {
  239. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  240. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  241. List<int> recommendTypeList = new List<int>();
  242. List<int> recommendList = new List<int>();
  243. List<int> recommendSpecialList = new List<int>();
  244. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  245. if (toSort)
  246. {
  247. SortItemListByScoreByType(tempAllList);
  248. }
  249. foreach (int itemID in tempAllList)
  250. {
  251. int subType = ItemUtilCS.GetItemSubType(itemID);
  252. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  253. {
  254. if (!recommendTypeList.Contains(subType))
  255. {
  256. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  257. if (isNeed || fightCfg.needItemId <= 0)
  258. {
  259. if (subType < ConstDressUpItemType.TE_SHU)
  260. {
  261. recommendList.Add(itemID);
  262. }
  263. recommendTypeList.Add(subType);
  264. }
  265. }
  266. }
  267. }
  268. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  269. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  270. List<int> specialSubList = new List<int>();
  271. List<int> specialIdList = new List<int>();
  272. foreach (int itemID in recommendSpecialList)
  273. {
  274. int subType = ItemUtilCS.GetItemSubType(itemID);
  275. if (subType > ConstDressUpItemType.TE_SHU)
  276. {
  277. if (specialSubList.Count >= 3) continue;
  278. if (specialSubList.IndexOf(subType) < 0)
  279. {
  280. specialSubList.Add(subType);
  281. specialIdList.Add(itemID);
  282. }
  283. }
  284. }
  285. recommendList.AddRange(specialIdList);
  286. return recommendList;
  287. }
  288. // public static int GetRecommendCount()
  289. // {
  290. // List<int> recommendTypeList = GetRecommendItemList(false);
  291. // return recommendTypeList.Count;
  292. // }
  293. // public static int GetItemScore(int itemId)
  294. // {
  295. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  296. // }
  297. public static List<int> DressSearch(List<int> list)
  298. {
  299. List<int> searchList = new List<int>();
  300. for (int i = 0; i < list.Count; i++)
  301. {
  302. bool isSearch = true;
  303. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  304. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  305. string name = itemCfg != null ? itemCfg.name : suitCfg.name;
  306. for (int j = 0; j < dressSearchTxt.Length; j++)
  307. {
  308. if (name.IndexOf(dressSearchTxt[j]) < 0)
  309. {
  310. isSearch = false;
  311. break;
  312. }
  313. }
  314. if (isSearch)
  315. {
  316. searchList.Add(list[i]);
  317. }
  318. }
  319. return searchList;
  320. }
  321. public static List<int> DressFilter(List<int> list)
  322. {
  323. List<int> filterList = new List<int>();
  324. for (int i = 0; i < list.Count; i++)
  325. {
  326. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  327. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  328. bool isRarity = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  329. bool isScore = cfg == null ? true : FilterScore(cfg);
  330. bool isTag = cfg == null ? true : FilterTag(cfg);
  331. if (isRarity && isScore && isTag)
  332. {
  333. filterList.Add(list[i]);
  334. }
  335. }
  336. if (filterList.Count == 0)
  337. {
  338. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  339. }
  340. return filterList;
  341. }
  342. private static bool FilterRarity(ItemCfg 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 FilterRarity(SuitCfg cfg)
  363. {
  364. bool isRarity = false;
  365. if (selectRarityList.Count > 0)
  366. {
  367. for (int j = 0; j < selectRarityList.Count; j++)
  368. {
  369. if (cfg != null && cfg.rarity == selectRarityList[j])
  370. {
  371. isRarity = true;
  372. break;
  373. }
  374. }
  375. }
  376. else
  377. {
  378. isRarity = true;
  379. }
  380. return isRarity;
  381. }
  382. private static bool FilterScore(ItemCfg cfg)
  383. {
  384. bool isScore = false;
  385. if (selectScoreList.Count > 0)
  386. {
  387. if (cfg != null)
  388. {
  389. for (int j = 0; j < selectScoreList.Count; j++)
  390. {
  391. if (cfg.mainScore == selectScoreList[j])
  392. {
  393. isScore = true;
  394. break;
  395. }
  396. }
  397. }
  398. }
  399. else
  400. {
  401. isScore = true;
  402. }
  403. return isScore;
  404. }
  405. private static bool FilterTag(ItemCfg cfg)
  406. {
  407. bool isTag = false;
  408. if (selectTagList.Count > 0)
  409. {
  410. if (cfg != null)
  411. {
  412. for (int j = 0; j < selectTagList.Count; j++)
  413. {
  414. if (isTag == true)
  415. {
  416. break;
  417. }
  418. for (int k = 0; k < cfg.tagsArr.Length; k++)
  419. {
  420. if (cfg.tagsArr[k][0] == selectTagList[j])
  421. {
  422. isTag = true;
  423. break;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. else
  430. {
  431. isTag = true;
  432. }
  433. return isTag;
  434. }
  435. public static void AddNewDressItem(int value)
  436. {
  437. int subType = ItemUtilCS.GetItemSubType(value);
  438. if (!_newItemdata.ContainsKey(subType))
  439. {
  440. _newItemdata.Add(subType, new List<int>());
  441. }
  442. _newItemdata[subType].Add(value);
  443. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  444. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  445. // {
  446. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  447. // }
  448. }
  449. public static void RemoveNewDressItem(int itemId)
  450. {
  451. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  452. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  453. {
  454. _newItemdata[subType].Remove(itemId);
  455. }
  456. }
  457. //检测一级菜单是否有展示新增
  458. public static bool CheckIsFirstMenuNew(int menuId)
  459. {
  460. if (_newItemdata.Count == 0) return false;
  461. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  462. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  463. {
  464. foreach (int id2 in cfg1.subMenusArr)
  465. {
  466. if (CheckIsSecondMenuNew(id2)) return true;
  467. }
  468. }
  469. else
  470. {
  471. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  472. }
  473. return false;
  474. }
  475. //检测二级菜单是否有展示新增
  476. public static bool CheckIsSecondMenuNew(int subMenuId)
  477. {
  478. if (_newItemdata.Count == 0) return false;
  479. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  480. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  481. {
  482. return true;
  483. }
  484. return false;
  485. }
  486. //检测服装部件是否为新增
  487. public static bool CheckIsDressUpItemNew(int itemId)
  488. {
  489. if (_newItemdata.Count == 0) return false;
  490. int subType = ItemUtilCS.GetItemSubType(itemId);
  491. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  492. }
  493. }
  494. }