DressUpMenuItemDataManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. List<int> recommendTypeList = new List<int>();
  197. List<int> recommendList = new List<int>();
  198. List<int> recommendSpecialList = new List<int>();
  199. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  200. if (toSort)
  201. {
  202. SortItemListByScoreByType(tempAllList);
  203. }
  204. foreach (int itemID in tempAllList)
  205. {
  206. int subType = ItemUtilCS.GetItemSubType(itemID);
  207. if (!CheckIsSceneType(itemID))
  208. {
  209. if (!recommendTypeList.Contains(subType))
  210. {
  211. if (subType < ConstDressUpItemType.TE_SHU)
  212. {
  213. recommendList.Add(itemID);
  214. }
  215. recommendTypeList.Add(subType);
  216. }
  217. }
  218. }
  219. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  220. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  221. List<int> specialSubList = new List<int>();
  222. List<int> specialIdList = new List<int>();
  223. foreach (int itemID in recommendSpecialList)
  224. {
  225. int subType = ItemUtilCS.GetItemSubType(itemID);
  226. if (subType > ConstDressUpItemType.TE_SHU)
  227. {
  228. if (specialSubList.Count >= 3) continue;
  229. if (specialSubList.IndexOf(subType) < 0)
  230. {
  231. specialSubList.Add(subType);
  232. specialIdList.Add(itemID);
  233. }
  234. }
  235. }
  236. recommendList.AddRange(specialIdList);
  237. return recommendList;
  238. }
  239. public static int GetRecommendCount()
  240. {
  241. List<int> recommendTypeList = GetRecommendItemList(false);
  242. return recommendTypeList.Count;
  243. }
  244. public static bool CheckIsSceneType(int itemID)
  245. {
  246. int subType = ItemUtilCS.GetItemSubType(itemID);
  247. DressUpMenuItemCfg1 typeCfg = DressUpMenuItemCfg1Array.Instance.GetCfg(12);
  248. foreach (int temp in typeCfg.subMenusArr)
  249. {
  250. DressUpMenuItemCfg2 subTypeCfg = DressUpMenuItemCfg2Array.Instance.GetCfg(temp);
  251. if (subType == subTypeCfg.type)
  252. {
  253. return true;
  254. }
  255. }
  256. return false;
  257. }
  258. public static int GetItemScore(int itemId)
  259. {
  260. return GetItemScore(itemId, InstanceZonesDataManager.currentScoreType);
  261. }
  262. public static int GetItemScore(int itemId, int scoreType)
  263. {
  264. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  265. if (itemCfg == null) return 0;
  266. int score = itemCfg.baseScore;
  267. switch (scoreType)
  268. {
  269. case ConstDressUpScoreType.SCORE_FENG:
  270. score += itemCfg.score1;
  271. break;
  272. case ConstDressUpScoreType.SCORE_HUA:
  273. score += itemCfg.score2;
  274. break;
  275. case ConstDressUpScoreType.SCORE_XUE:
  276. score += itemCfg.score3;
  277. break;
  278. case ConstDressUpScoreType.SCORE_YUE:
  279. score += itemCfg.score4;
  280. break;
  281. }
  282. return score;
  283. }
  284. public static List<int> DressSearch(List<int> list, bool isTaoZhuang)
  285. {
  286. List<int> searchList = new List<int>();
  287. for (int i = 0; i < list.Count; i++)
  288. {
  289. bool isSearch = true;
  290. string name = isTaoZhuang ? SuitCfgArray.Instance.GetCfg(list[i]).name : ItemCfgArray.Instance.GetCfg(list[i]).name;
  291. for (int j = 0; j < dressSearchTxt.Length; j++)
  292. {
  293. if (name.IndexOf(dressSearchTxt[j]) < 0)
  294. {
  295. isSearch = false;
  296. break;
  297. }
  298. }
  299. if (isSearch)
  300. {
  301. searchList.Add(list[i]);
  302. }
  303. }
  304. // if (searchList.Count == 0)
  305. // {
  306. // PromptController.Instance.ShowFloatTextPrompt("搜索不到相关物品");
  307. // }
  308. return searchList;
  309. }
  310. public static List<int> DressFilter(List<int> list, bool isTaoZhuang)
  311. {
  312. List<int> filterList = new List<int>();
  313. for (int i = 0; i < list.Count; i++)
  314. {
  315. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  316. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  317. bool isRarity = isTaoZhuang ? FilterRarity(tzCfg) : FilterRarity(cfg);
  318. bool isScore = isTaoZhuang ? true : FilterScore(cfg);
  319. bool isTag = isTaoZhuang ? true : FilterTag(cfg);
  320. if (isRarity && isScore && isTag)
  321. {
  322. filterList.Add(list[i]);
  323. }
  324. }
  325. if (filterList.Count == 0)
  326. {
  327. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  328. }
  329. return filterList;
  330. }
  331. private static bool FilterRarity(ItemCfg cfg)
  332. {
  333. bool isRarity = false;
  334. if (selectRarityList.Count > 0)
  335. {
  336. for (int j = 0; j < selectRarityList.Count; j++)
  337. {
  338. if (cfg != null && cfg.rarity == selectRarityList[j])
  339. {
  340. isRarity = true;
  341. break;
  342. }
  343. }
  344. }
  345. else
  346. {
  347. isRarity = true;
  348. }
  349. return isRarity;
  350. }
  351. private static bool FilterRarity(SuitCfg cfg)
  352. {
  353. bool isRarity = false;
  354. if (selectRarityList.Count > 0)
  355. {
  356. for (int j = 0; j < selectRarityList.Count; j++)
  357. {
  358. if (cfg != null && cfg.rarity == selectRarityList[j])
  359. {
  360. isRarity = true;
  361. break;
  362. }
  363. }
  364. }
  365. else
  366. {
  367. isRarity = true;
  368. }
  369. return isRarity;
  370. }
  371. private static bool FilterScore(ItemCfg cfg)
  372. {
  373. bool isScore = false;
  374. if (selectScoreList.Count > 0)
  375. {
  376. if (cfg != null)
  377. {
  378. int mainScore;
  379. int mainScoreValue;
  380. ItemDataManager.GetMainScore(cfg.id, out mainScore, out mainScoreValue);
  381. for (int j = 0; j < selectScoreList.Count; j++)
  382. {
  383. if (mainScore == selectScoreList[j])
  384. {
  385. isScore = true;
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. else
  392. {
  393. isScore = true;
  394. }
  395. return isScore;
  396. }
  397. private static bool FilterTag(ItemCfg cfg)
  398. {
  399. bool isTag = false;
  400. if (selectTagList.Count > 0)
  401. {
  402. if (cfg != null)
  403. {
  404. for (int j = 0; j < selectTagList.Count; j++)
  405. {
  406. if (isTag == true)
  407. {
  408. break;
  409. }
  410. for (int k = 0; k < cfg.tagsArr.Length; k++)
  411. {
  412. if (cfg.tagsArr[k] == selectTagList[j])
  413. {
  414. isTag = true;
  415. break;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. else
  422. {
  423. isTag = true;
  424. }
  425. return isTag;
  426. }
  427. private static void AddNewDressItem(int value)
  428. {
  429. int subType = ItemUtilCS.GetItemSubType(value);
  430. if (!_newItemdata.ContainsKey(subType))
  431. {
  432. _newItemdata.Add(subType, new List<int>());
  433. }
  434. _newItemdata[subType].Add(value);
  435. }
  436. public static void RemoveNewDressItem(int subType, int itemId)
  437. {
  438. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  439. {
  440. _newItemdata[subType].Remove(itemId);
  441. }
  442. }
  443. public static bool CheckIsSubtypeNew(int subType)
  444. {
  445. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(subType);
  446. if (_newItemdata.ContainsKey(subType) && _newItemdata.Count > 0)
  447. {
  448. return true;
  449. }
  450. else if (cfg1.subMenusArr.Length > 0)
  451. {
  452. foreach (int id2 in cfg1.subMenusArr)
  453. {
  454. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  455. if (cfg2.type == subType && _newItemdata.ContainsKey(subType) && _newItemdata.Count > 0)
  456. {
  457. return true;
  458. }
  459. }
  460. }
  461. return false;
  462. }
  463. public static bool CheckIsDressItemNew(int itemId)
  464. {
  465. int subType = ItemUtilCS.GetItemSubType(itemId);
  466. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  467. }
  468. }
  469. }