DressUpMenuItemDataManager.cs 18 KB

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