DressUpMenuItemDataManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. }
  26. public static void Clear()
  27. {
  28. selectRarityList.Clear();
  29. selectScoreList.Clear();
  30. selectTagList.Clear();
  31. _newItemdata.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. int scoreA = GetItemScore(a);
  91. int scoreB = GetItemScore(b);
  92. if (scoreB > scoreA)
  93. {
  94. return 1;
  95. }
  96. else if (scoreB < scoreA)
  97. {
  98. return -1;
  99. }
  100. return 0;
  101. });
  102. return arrayList;
  103. }
  104. public static List<int> SortItemListByLowScore(List<int> arrayList)
  105. {
  106. arrayList.Sort((int a, int b) =>
  107. {
  108. int scoreA = GetItemScore(a);
  109. int scoreB = GetItemScore(b);
  110. if (scoreB < scoreA)
  111. {
  112. return 1;
  113. }
  114. else if (scoreB > scoreA)
  115. {
  116. return -1;
  117. }
  118. return 0;
  119. });
  120. return arrayList;
  121. }
  122. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  123. {
  124. arrayList.Sort((int a, int b) =>
  125. {
  126. int typeA = ItemUtilCS.GetItemSubType(a);
  127. int typeB = ItemUtilCS.GetItemSubType(b);
  128. int scoreA = GetItemScore(a);
  129. int scoreB = GetItemScore(b);
  130. if (typeB < typeA)
  131. {
  132. return -1;
  133. }
  134. else if (typeB > typeA)
  135. {
  136. return 1;
  137. }
  138. else if (scoreB > scoreA)
  139. {
  140. return 1;
  141. }
  142. else if (scoreB < scoreA)
  143. {
  144. return -1;
  145. }
  146. return 0;
  147. });
  148. return arrayList;
  149. }
  150. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  151. {
  152. arrayList.Sort((int a, int b) =>
  153. {
  154. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  155. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  156. if (CheckIsDressItemNew(b) && !CheckIsDressItemNew(a))
  157. {
  158. return 1;
  159. }
  160. if (itemCfgB.rarity > itemCfgA.rarity)
  161. {
  162. return 1;
  163. }
  164. else if (itemCfgB.rarity < itemCfgA.rarity)
  165. {
  166. return -1;
  167. }
  168. return 0;
  169. });
  170. return arrayList;
  171. }
  172. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  173. {
  174. arrayList.Sort((int a, int b) =>
  175. {
  176. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  177. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  178. if (CheckIsDressItemNew(b) && !CheckIsDressItemNew(a))
  179. {
  180. return 1;
  181. }
  182. if (itemCfgB.rarity < itemCfgA.rarity)
  183. {
  184. return 1;
  185. }
  186. else if (itemCfgB.rarity > itemCfgA.rarity)
  187. {
  188. return -1;
  189. }
  190. return 0;
  191. });
  192. return arrayList;
  193. }
  194. public static List<int> GetRecommendItemList(bool toSort = true)
  195. {
  196. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  197. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  198. List<int> recommendTypeList = new List<int>();
  199. List<int> recommendList = new List<int>();
  200. List<int> recommendSpecialList = new List<int>();
  201. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  202. if (toSort)
  203. {
  204. SortItemListByScoreByType(tempAllList);
  205. }
  206. foreach (int itemID in tempAllList)
  207. {
  208. int subType = ItemUtilCS.GetItemSubType(itemID);
  209. if (!CheckIsSceneType(itemID))
  210. {
  211. if (!recommendTypeList.Contains(subType))
  212. {
  213. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  214. if (isNeed || fightCfg.needItemId <= 0)
  215. {
  216. if (subType < ConstDressUpItemType.TE_SHU)
  217. {
  218. recommendList.Add(itemID);
  219. }
  220. recommendTypeList.Add(subType);
  221. }
  222. }
  223. }
  224. }
  225. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  226. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  227. List<int> specialSubList = new List<int>();
  228. List<int> specialIdList = new List<int>();
  229. foreach (int itemID in recommendSpecialList)
  230. {
  231. int subType = ItemUtilCS.GetItemSubType(itemID);
  232. if (subType > ConstDressUpItemType.TE_SHU)
  233. {
  234. if (specialSubList.Count >= 3) continue;
  235. if (specialSubList.IndexOf(subType) < 0)
  236. {
  237. specialSubList.Add(subType);
  238. specialIdList.Add(itemID);
  239. }
  240. }
  241. }
  242. recommendList.AddRange(specialIdList);
  243. return recommendList;
  244. }
  245. public static int GetRecommendCount()
  246. {
  247. List<int> recommendTypeList = GetRecommendItemList(false);
  248. return recommendTypeList.Count;
  249. }
  250. public static bool CheckIsSceneType(int itemID)
  251. {
  252. int subType = ItemUtilCS.GetItemSubType(itemID);
  253. DressUpMenuItemCfg1 typeCfg = DressUpMenuItemCfg1Array.Instance.GetCfg(12);
  254. foreach (int temp in typeCfg.subMenusArr)
  255. {
  256. DressUpMenuItemCfg2 subTypeCfg = DressUpMenuItemCfg2Array.Instance.GetCfg(temp);
  257. if (subType == subTypeCfg.type)
  258. {
  259. return true;
  260. }
  261. }
  262. return false;
  263. }
  264. public static int GetItemScore(int itemId)
  265. {
  266. return GetItemScore(itemId, InstanceZonesDataManager.currentScoreType);
  267. }
  268. public static int GetItemScore(int itemId, int scoreType)
  269. {
  270. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  271. if (itemCfg == null) return 0;
  272. int score = itemCfg.baseScore;
  273. switch (scoreType)
  274. {
  275. case ConstDressUpScoreType.SCORE_FENG:
  276. score += itemCfg.score1;
  277. break;
  278. case ConstDressUpScoreType.SCORE_HUA:
  279. score += itemCfg.score2;
  280. break;
  281. case ConstDressUpScoreType.SCORE_XUE:
  282. score += itemCfg.score3;
  283. break;
  284. case ConstDressUpScoreType.SCORE_YUE:
  285. score += itemCfg.score4;
  286. break;
  287. }
  288. return score;
  289. }
  290. public static List<int> DressSearch(List<int> list, bool isTaoZhuang)
  291. {
  292. List<int> searchList = new List<int>();
  293. for (int i = 0; i < list.Count; i++)
  294. {
  295. bool isSearch = true;
  296. string name = isTaoZhuang ? SuitCfgArray.Instance.GetCfg(list[i]).name : ItemCfgArray.Instance.GetCfg(list[i]).name;
  297. for (int j = 0; j < dressSearchTxt.Length; j++)
  298. {
  299. if (name.IndexOf(dressSearchTxt[j]) < 0)
  300. {
  301. isSearch = false;
  302. break;
  303. }
  304. }
  305. if (isSearch)
  306. {
  307. searchList.Add(list[i]);
  308. }
  309. }
  310. // if (searchList.Count == 0)
  311. // {
  312. // PromptController.Instance.ShowFloatTextPrompt("搜索不到相关物品");
  313. // }
  314. return searchList;
  315. }
  316. public static List<int> DressFilter(List<int> list, bool isTaoZhuang)
  317. {
  318. List<int> filterList = new List<int>();
  319. for (int i = 0; i < list.Count; i++)
  320. {
  321. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  322. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  323. bool isRarity = isTaoZhuang ? FilterRarity(tzCfg) : FilterRarity(cfg);
  324. bool isScore = isTaoZhuang ? true : FilterScore(cfg);
  325. bool isTag = isTaoZhuang ? true : FilterTag(cfg);
  326. if (isRarity && isScore && isTag)
  327. {
  328. filterList.Add(list[i]);
  329. }
  330. }
  331. if (filterList.Count == 0)
  332. {
  333. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  334. }
  335. return filterList;
  336. }
  337. private static bool FilterRarity(ItemCfg cfg)
  338. {
  339. bool isRarity = false;
  340. if (selectRarityList.Count > 0)
  341. {
  342. for (int j = 0; j < selectRarityList.Count; j++)
  343. {
  344. if (cfg != null && cfg.rarity == selectRarityList[j])
  345. {
  346. isRarity = true;
  347. break;
  348. }
  349. }
  350. }
  351. else
  352. {
  353. isRarity = true;
  354. }
  355. return isRarity;
  356. }
  357. private static bool FilterRarity(SuitCfg 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 FilterScore(ItemCfg cfg)
  378. {
  379. bool isScore = false;
  380. if (selectScoreList.Count > 0)
  381. {
  382. if (cfg != null)
  383. {
  384. int mainScore;
  385. int mainScoreValue;
  386. ItemDataManager.GetMainScore(cfg.id, out mainScore, out mainScoreValue);
  387. for (int j = 0; j < selectScoreList.Count; j++)
  388. {
  389. if (mainScore == selectScoreList[j])
  390. {
  391. isScore = true;
  392. break;
  393. }
  394. }
  395. }
  396. }
  397. else
  398. {
  399. isScore = true;
  400. }
  401. return isScore;
  402. }
  403. private static bool FilterTag(ItemCfg cfg)
  404. {
  405. bool isTag = false;
  406. if (selectTagList.Count > 0)
  407. {
  408. if (cfg != null)
  409. {
  410. for (int j = 0; j < selectTagList.Count; j++)
  411. {
  412. if (isTag == true)
  413. {
  414. break;
  415. }
  416. for (int k = 0; k < cfg.tagsArr.Length; k++)
  417. {
  418. if (cfg.tagsArr[k] == selectTagList[j])
  419. {
  420. isTag = true;
  421. break;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. else
  428. {
  429. isTag = true;
  430. }
  431. return isTag;
  432. }
  433. private static void AddNewDressItem(int value)
  434. {
  435. int subType = ItemUtilCS.GetItemSubType(value);
  436. if (!_newItemdata.ContainsKey(subType))
  437. {
  438. _newItemdata.Add(subType, new List<int>());
  439. }
  440. _newItemdata[subType].Add(value);
  441. }
  442. public static void RemoveNewDressItem(int subType, int itemId)
  443. {
  444. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  445. {
  446. _newItemdata[subType].Remove(itemId);
  447. }
  448. }
  449. public static bool CheckIsSubtypeNew(int subType)
  450. {
  451. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(subType);
  452. if (_newItemdata.ContainsKey(subType) && _newItemdata.Count > 0)
  453. {
  454. return true;
  455. }
  456. else if (cfg1.subMenusArr.Length > 0)
  457. {
  458. foreach (int id2 in cfg1.subMenusArr)
  459. {
  460. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  461. if (cfg2.type == subType && _newItemdata.ContainsKey(subType) && _newItemdata.Count > 0)
  462. {
  463. return true;
  464. }
  465. }
  466. }
  467. return false;
  468. }
  469. public static bool CheckIsDressItemNew(int itemId)
  470. {
  471. int subType = ItemUtilCS.GetItemSubType(itemId);
  472. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  473. }
  474. }
  475. }