DressUpMenuItemDataManager.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public enum DressFilterType
  9. {
  10. None,
  11. Search,
  12. Filter
  13. }
  14. public class DressUpMenuItemDataManager
  15. {
  16. public static string dressSearchTxt = "";
  17. public static DressFilterType dressFilterType = DressFilterType.None;
  18. public static List<int> selectRarityList = new List<int>();
  19. public static List<int> selectScoreList = new List<int>();
  20. public static List<string> selectTagList = new List<string>();
  21. private static List<int> _itemDatas = new List<int>();
  22. private static Dictionary<int, List<int>> _itemDatasBySubTypeDic = new Dictionary<int, List<int>>();
  23. public static Dictionary<int, List<int>> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } }
  24. private static Dictionary<int, List<int>> _newItemdata = new Dictionary<int, List<int>>();
  25. private static List<int> _newSuitData = new List<int>();
  26. public static void InitData()
  27. {
  28. _itemDatas.Clear();
  29. _newItemdata.Clear();
  30. _itemDatasBySubTypeDic.Clear();
  31. }
  32. public static void Clear()
  33. {
  34. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  35. selectRarityList.Clear();
  36. selectScoreList.Clear();
  37. selectTagList.Clear();
  38. dressSearchTxt = "";
  39. }
  40. public static void Add(ItemInfoProto itemInfoProto)
  41. {
  42. var value = itemInfoProto.ConfigId;
  43. //游戏初始化禁止使用ItemCfg
  44. if (!_itemDatas.Contains(value))
  45. {
  46. _itemDatas.Add(value);
  47. int subType = itemInfoProto.SubType;
  48. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  49. if (!_itemDatasBySubTypeDic.ContainsKey(subType))
  50. {
  51. _itemDatasBySubTypeDic.Add(subType, new List<int>());
  52. }
  53. _itemDatasBySubTypeDic[subType].Add(value);
  54. if (GameGlobal.DataInited)
  55. {
  56. AddNewDressItem(value);
  57. DressUpMenuSuitDataManager.CheckItemInSuit(value);
  58. }
  59. }
  60. }
  61. public static bool CheckHasItem(int itemID)
  62. {
  63. return _itemDatas.Contains(itemID);
  64. }
  65. public static void Remove(int value)
  66. {
  67. if (_itemDatas == null)
  68. {
  69. return;
  70. }
  71. if (_itemDatas.Contains(value))
  72. {
  73. _itemDatas.Remove(value);
  74. }
  75. int subType = ItemUtilCS.GetItemSubType(value);
  76. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  77. if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0)
  78. {
  79. _itemDatasBySubTypeDic[subType].Remove(value);
  80. }
  81. }
  82. public static List<int> getItemDatasByType(int type)
  83. {
  84. List<int> arrayList = new List<int>();
  85. if (_itemDatasBySubTypeDic.ContainsKey(type))
  86. {
  87. arrayList.AddRange(_itemDatasBySubTypeDic[type]);
  88. }
  89. // for (int i = 0; i < _itemDatas.Count; i++)
  90. // {
  91. // int itemID = (int)_itemDatas[i];
  92. // int subType = ItemUtilCS.GetItemSubType(itemID);
  93. // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type)
  94. // {
  95. // arrayList.Add(itemID);
  96. // }
  97. // else if (subType == type)
  98. // {
  99. // arrayList.Add(itemID);
  100. // }
  101. // }
  102. return arrayList;
  103. }
  104. public static List<int> SortItemListByHighScore(List<int> arrayList)
  105. {
  106. arrayList.Sort((int a, int b) =>
  107. {
  108. bool isNewA = CheckIsDressUpItemNew(a);
  109. bool isNewB = CheckIsDressUpItemNew(b);
  110. if (isNewA != isNewB)
  111. {
  112. if (isNewA) return -1;
  113. if (isNewB) return 1;
  114. }
  115. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  116. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  117. if (scoreB > scoreA) return 1;
  118. if (scoreB < scoreA) return -1;
  119. return a - b;
  120. });
  121. return arrayList;
  122. }
  123. public static List<int> SortItemListByLowScore(List<int> arrayList)
  124. {
  125. arrayList.Sort((int a, int b) =>
  126. {
  127. bool isNewA = CheckIsDressUpItemNew(a);
  128. bool isNewB = CheckIsDressUpItemNew(b);
  129. if (isNewA != isNewB)
  130. {
  131. if (isNewA) return -1;
  132. if (isNewB) return 1;
  133. }
  134. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  135. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  136. if (scoreB < scoreA)
  137. {
  138. return 1;
  139. }
  140. else if (scoreB > scoreA)
  141. {
  142. return -1;
  143. }
  144. return 0;
  145. });
  146. return arrayList;
  147. }
  148. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  149. {
  150. arrayList.Sort((int a, int b) =>
  151. {
  152. int typeA = ItemUtilCS.GetItemSubType(a);
  153. int typeB = ItemUtilCS.GetItemSubType(b);
  154. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  155. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  156. if (typeB < typeA)
  157. {
  158. return -1;
  159. }
  160. else if (typeB > typeA)
  161. {
  162. return 1;
  163. }
  164. else if (scoreB > scoreA)
  165. {
  166. return 1;
  167. }
  168. else if (scoreB < scoreA)
  169. {
  170. return -1;
  171. }
  172. return 0;
  173. });
  174. return arrayList;
  175. }
  176. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  177. {
  178. arrayList.Sort((int a, int b) =>
  179. {
  180. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  181. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  182. bool isNewA = CheckIsDressUpItemNew(a);
  183. bool isNewB = CheckIsDressUpItemNew(b);
  184. if (isNewA != isNewB)
  185. {
  186. if (isNewA) return -1;
  187. if (isNewB) return 1;
  188. }
  189. if (itemCfgB.rarity > itemCfgA.rarity)
  190. {
  191. return 1;
  192. }
  193. else if (itemCfgB.rarity < itemCfgA.rarity)
  194. {
  195. return -1;
  196. }
  197. return 0;
  198. });
  199. return arrayList;
  200. }
  201. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  202. {
  203. arrayList.Sort((int a, int b) =>
  204. {
  205. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  206. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  207. bool isNewA = CheckIsDressUpItemNew(a);
  208. bool isNewB = CheckIsDressUpItemNew(b);
  209. if (isNewA != isNewB)
  210. {
  211. if (isNewA) return -1;
  212. if (isNewB) return 1;
  213. }
  214. if (itemCfgB.rarity < itemCfgA.rarity)
  215. {
  216. return 1;
  217. }
  218. else if (itemCfgB.rarity > itemCfgA.rarity)
  219. {
  220. return -1;
  221. }
  222. return 0;
  223. });
  224. return arrayList;
  225. }
  226. public static List<int> GetRecommendItemList(bool toSort = true)
  227. {
  228. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  229. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  230. List<int> recommendTypeList = new List<int>();
  231. List<int> recommendList = new List<int>();
  232. List<int> recommendSpecialList = new List<int>();
  233. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  234. if (toSort)
  235. {
  236. SortItemListByScoreByType(tempAllList);
  237. }
  238. foreach (int itemID in tempAllList)
  239. {
  240. int subType = ItemUtilCS.GetItemSubType(itemID);
  241. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  242. {
  243. if (!recommendTypeList.Contains(subType))
  244. {
  245. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  246. if (isNeed || fightCfg.needItemId <= 0)
  247. {
  248. if (subType < ConstDressUpItemType.TE_SHU)
  249. {
  250. recommendList.Add(itemID);
  251. }
  252. recommendTypeList.Add(subType);
  253. }
  254. }
  255. }
  256. }
  257. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  258. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  259. List<int> specialSubList = new List<int>();
  260. List<int> specialIdList = new List<int>();
  261. foreach (int itemID in recommendSpecialList)
  262. {
  263. int subType = ItemUtilCS.GetItemSubType(itemID);
  264. if (subType > ConstDressUpItemType.TE_SHU)
  265. {
  266. if (specialSubList.Count >= 3) continue;
  267. if (specialSubList.IndexOf(subType) < 0)
  268. {
  269. specialSubList.Add(subType);
  270. specialIdList.Add(itemID);
  271. }
  272. }
  273. }
  274. recommendList.AddRange(specialIdList);
  275. return recommendList;
  276. }
  277. // public static int GetRecommendCount()
  278. // {
  279. // List<int> recommendTypeList = GetRecommendItemList(false);
  280. // return recommendTypeList.Count;
  281. // }
  282. // public static int GetItemScore(int itemId)
  283. // {
  284. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  285. // }
  286. public static List<int> DressSearch(List<int> list)
  287. {
  288. List<int> searchList = new List<int>();
  289. for (int i = 0; i < list.Count; i++)
  290. {
  291. bool isSearch = true;
  292. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  293. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  294. string name = itemCfg != null ? itemCfg.name : suitCfg.name;
  295. for (int j = 0; j < dressSearchTxt.Length; j++)
  296. {
  297. if (name.IndexOf(dressSearchTxt[j]) < 0)
  298. {
  299. isSearch = false;
  300. break;
  301. }
  302. }
  303. if (isSearch)
  304. {
  305. searchList.Add(list[i]);
  306. }
  307. }
  308. return searchList;
  309. }
  310. public static List<int> DressFilter(List<int> list)
  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 = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  318. bool isScore = cfg == null ? true : FilterScore(cfg);
  319. bool isTag = cfg == null ? 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. for (int j = 0; j < selectScoreList.Count; j++)
  379. {
  380. if (cfg.mainScore == selectScoreList[j])
  381. {
  382. isScore = true;
  383. break;
  384. }
  385. }
  386. }
  387. }
  388. else
  389. {
  390. isScore = true;
  391. }
  392. return isScore;
  393. }
  394. private static bool FilterTag(ItemCfg cfg)
  395. {
  396. bool isTag = false;
  397. if (selectTagList.Count > 0)
  398. {
  399. if (cfg != null)
  400. {
  401. for (int j = 0; j < selectTagList.Count; j++)
  402. {
  403. if (isTag == true)
  404. {
  405. break;
  406. }
  407. for (int k = 0; k < cfg.tagsArr.Length; k++)
  408. {
  409. if (cfg.tagsArr[k][0] == selectTagList[j])
  410. {
  411. isTag = true;
  412. break;
  413. }
  414. }
  415. }
  416. }
  417. }
  418. else
  419. {
  420. isTag = true;
  421. }
  422. return isTag;
  423. }
  424. public static void AddNewDressItem(int value)
  425. {
  426. int subType = ItemDataManager.GetItemSubType(value);
  427. if (!_newItemdata.ContainsKey(subType))
  428. {
  429. _newItemdata.Add(subType, new List<int>());
  430. }
  431. _newItemdata[subType].Add(value);
  432. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  433. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  434. // {
  435. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  436. // }
  437. }
  438. public static void RemoveNewDressItem(int itemId)
  439. {
  440. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  441. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  442. {
  443. _newItemdata[subType].Remove(itemId);
  444. }
  445. }
  446. //检测一级菜单是否有展示新增
  447. public static bool CheckIsFirstMenuNew(int menuId)
  448. {
  449. if (_newItemdata.Count == 0) return false;
  450. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  451. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  452. {
  453. foreach (int id2 in cfg1.subMenusArr)
  454. {
  455. if (CheckIsSecondMenuNew(id2)) return true;
  456. }
  457. }
  458. else
  459. {
  460. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  461. }
  462. return false;
  463. }
  464. //检测二级菜单是否有展示新增
  465. public static bool CheckIsSecondMenuNew(int subMenuId)
  466. {
  467. if (_newItemdata.Count == 0) return false;
  468. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  469. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  470. {
  471. return true;
  472. }
  473. return false;
  474. }
  475. //检测服装部件是否为新增
  476. public static bool CheckIsDressUpItemNew(int itemId)
  477. {
  478. if (_newItemdata.Count == 0) return false;
  479. int subType = ItemUtilCS.GetItemSubType(itemId);
  480. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  481. }
  482. }
  483. }