DressUpMenuItemDataManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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, bool checkNew = false)
  105. {
  106. arrayList.Sort((int a, int b) =>
  107. {
  108. if (checkNew)
  109. {
  110. bool isNewA = CheckIsDressUpItemNew(a);
  111. bool isNewB = CheckIsDressUpItemNew(b);
  112. if (isNewA != isNewB)
  113. {
  114. if (isNewA) return -1;
  115. if (isNewB) return 1;
  116. }
  117. }
  118. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  119. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  120. if (scoreB > scoreA) return 1;
  121. if (scoreB < scoreA) return -1;
  122. return a - b;
  123. });
  124. return arrayList;
  125. }
  126. public static List<int> SortItemListByLowScore(List<int> arrayList, bool checkNew = false)
  127. {
  128. arrayList.Sort((int a, int b) =>
  129. {
  130. if (checkNew)
  131. {
  132. bool isNewA = CheckIsDressUpItemNew(a);
  133. bool isNewB = CheckIsDressUpItemNew(b);
  134. if (isNewA != isNewB)
  135. {
  136. if (isNewA) return -1;
  137. if (isNewB) return 1;
  138. }
  139. }
  140. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  141. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  142. if (scoreB < scoreA)
  143. {
  144. return 1;
  145. }
  146. else if (scoreB > scoreA)
  147. {
  148. return -1;
  149. }
  150. return 0;
  151. });
  152. return arrayList;
  153. }
  154. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  155. {
  156. arrayList.Sort((int a, int b) =>
  157. {
  158. int typeA = ItemUtilCS.GetItemSubType(a);
  159. int typeB = ItemUtilCS.GetItemSubType(b);
  160. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  161. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  162. if (typeB < typeA)
  163. {
  164. return -1;
  165. }
  166. else if (typeB > typeA)
  167. {
  168. return 1;
  169. }
  170. else if (scoreB > scoreA)
  171. {
  172. return 1;
  173. }
  174. else if (scoreB < scoreA)
  175. {
  176. return -1;
  177. }
  178. return 0;
  179. });
  180. return arrayList;
  181. }
  182. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  183. {
  184. arrayList.Sort((int a, int b) =>
  185. {
  186. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  187. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  188. bool isNewA = CheckIsDressUpItemNew(a);
  189. bool isNewB = CheckIsDressUpItemNew(b);
  190. if (isNewA != isNewB)
  191. {
  192. if (isNewA) return -1;
  193. if (isNewB) return 1;
  194. }
  195. if (itemCfgB.rarity > itemCfgA.rarity)
  196. {
  197. return 1;
  198. }
  199. else if (itemCfgB.rarity < itemCfgA.rarity)
  200. {
  201. return -1;
  202. }
  203. return 0;
  204. });
  205. return arrayList;
  206. }
  207. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  208. {
  209. arrayList.Sort((int a, int b) =>
  210. {
  211. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  212. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  213. bool isNewA = CheckIsDressUpItemNew(a);
  214. bool isNewB = CheckIsDressUpItemNew(b);
  215. if (isNewA != isNewB)
  216. {
  217. if (isNewA) return -1;
  218. if (isNewB) return 1;
  219. }
  220. if (itemCfgB.rarity < itemCfgA.rarity)
  221. {
  222. return 1;
  223. }
  224. else if (itemCfgB.rarity > itemCfgA.rarity)
  225. {
  226. return -1;
  227. }
  228. return 0;
  229. });
  230. return arrayList;
  231. }
  232. public static List<int> GetRecommendItemList(bool toSort = true)
  233. {
  234. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  235. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  236. List<int> recommendTypeList = new List<int>();
  237. List<int> recommendList = new List<int>();
  238. List<int> recommendSpecialList = new List<int>();
  239. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  240. if (toSort)
  241. {
  242. SortItemListByScoreByType(tempAllList);
  243. }
  244. foreach (int itemID in tempAllList)
  245. {
  246. int subType = ItemUtilCS.GetItemSubType(itemID);
  247. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  248. {
  249. if (!recommendTypeList.Contains(subType))
  250. {
  251. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  252. if (isNeed || fightCfg.needItemId <= 0)
  253. {
  254. if (subType < ConstDressUpItemType.TE_SHU)
  255. {
  256. recommendList.Add(itemID);
  257. }
  258. recommendTypeList.Add(subType);
  259. }
  260. }
  261. }
  262. }
  263. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  264. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  265. List<int> specialSubList = new List<int>();
  266. List<int> specialIdList = new List<int>();
  267. foreach (int itemID in recommendSpecialList)
  268. {
  269. int subType = ItemUtilCS.GetItemSubType(itemID);
  270. if (subType > ConstDressUpItemType.TE_SHU)
  271. {
  272. if (specialSubList.Count >= 3) continue;
  273. if (specialSubList.IndexOf(subType) < 0)
  274. {
  275. specialSubList.Add(subType);
  276. specialIdList.Add(itemID);
  277. }
  278. }
  279. }
  280. recommendList.AddRange(specialIdList);
  281. return recommendList;
  282. }
  283. // public static int GetRecommendCount()
  284. // {
  285. // List<int> recommendTypeList = GetRecommendItemList(false);
  286. // return recommendTypeList.Count;
  287. // }
  288. // public static int GetItemScore(int itemId)
  289. // {
  290. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  291. // }
  292. public static List<int> DressSearch(List<int> list)
  293. {
  294. List<int> searchList = new List<int>();
  295. for (int i = 0; i < list.Count; i++)
  296. {
  297. bool isSearch = true;
  298. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  299. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  300. string name = itemCfg != null ? itemCfg.name : suitCfg.name;
  301. for (int j = 0; j < dressSearchTxt.Length; j++)
  302. {
  303. if (name.IndexOf(dressSearchTxt[j]) < 0)
  304. {
  305. isSearch = false;
  306. break;
  307. }
  308. }
  309. if (isSearch)
  310. {
  311. searchList.Add(list[i]);
  312. }
  313. }
  314. return searchList;
  315. }
  316. public static List<int> DressFilter(List<int> list)
  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 = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  324. bool isScore = cfg == null ? true : FilterScore(cfg);
  325. bool isTag = cfg == null ? 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. for (int j = 0; j < selectScoreList.Count; j++)
  385. {
  386. if (cfg.mainScore == selectScoreList[j])
  387. {
  388. isScore = true;
  389. break;
  390. }
  391. }
  392. }
  393. }
  394. else
  395. {
  396. isScore = true;
  397. }
  398. return isScore;
  399. }
  400. private static bool FilterTag(ItemCfg cfg)
  401. {
  402. bool isTag = false;
  403. if (selectTagList.Count > 0)
  404. {
  405. if (cfg != null)
  406. {
  407. for (int j = 0; j < selectTagList.Count; j++)
  408. {
  409. if (isTag == true)
  410. {
  411. break;
  412. }
  413. for (int k = 0; k < cfg.tagsArr.Length; k++)
  414. {
  415. if (cfg.tagsArr[k][0] == selectTagList[j])
  416. {
  417. isTag = true;
  418. break;
  419. }
  420. }
  421. }
  422. }
  423. }
  424. else
  425. {
  426. isTag = true;
  427. }
  428. return isTag;
  429. }
  430. public static void AddNewDressItem(int value)
  431. {
  432. int subType = ItemDataManager.GetItemSubType(value);
  433. if (!_newItemdata.ContainsKey(subType))
  434. {
  435. _newItemdata.Add(subType, new List<int>());
  436. }
  437. _newItemdata[subType].Add(value);
  438. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  439. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  440. // {
  441. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  442. // }
  443. }
  444. public static void RemoveNewDressItem(int itemId)
  445. {
  446. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  447. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  448. {
  449. _newItemdata[subType].Remove(itemId);
  450. }
  451. }
  452. //检测一级菜单是否有展示新增
  453. public static bool CheckIsFirstMenuNew(int menuId)
  454. {
  455. if (_newItemdata.Count == 0) return false;
  456. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  457. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  458. {
  459. foreach (int id2 in cfg1.subMenusArr)
  460. {
  461. if (CheckIsSecondMenuNew(id2)) return true;
  462. }
  463. }
  464. else
  465. {
  466. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  467. }
  468. return false;
  469. }
  470. //检测二级菜单是否有展示新增
  471. public static bool CheckIsSecondMenuNew(int subMenuId)
  472. {
  473. if (_newItemdata.Count == 0) return false;
  474. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  475. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  476. {
  477. return true;
  478. }
  479. return false;
  480. }
  481. //检测服装部件是否为新增
  482. public static bool CheckIsDressUpItemNew(int itemId)
  483. {
  484. if (_newItemdata.Count == 0) return false;
  485. int subType = ItemUtilCS.GetItemSubType(itemId);
  486. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  487. }
  488. }
  489. }