DressUpMenuItemDataManager.cs 18 KB

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