DressUpMenuItemDataManager.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. using FairyGUI;
  7. namespace GFGGame
  8. {
  9. public enum DressFilterType
  10. {
  11. None,
  12. Search,
  13. Filter
  14. }
  15. public class DressUpMenuItemDataManager
  16. {
  17. public static string dressSearchTxt = "";
  18. public static DressFilterType dressFilterType = DressFilterType.None;
  19. public static List<int> selectRarityList = new List<int>();
  20. public static List<int> selectScoreList = new List<int>();
  21. public static List<string> selectTagList = new List<string>();
  22. private static List<int> _itemDatas = new List<int>();
  23. private static Dictionary<int, List<int>> _itemDatasBySubTypeDic = new Dictionary<int, List<int>>();
  24. public static Dictionary<int, List<int>> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } }
  25. private static Dictionary<int, List<int>> _newItemdata = new Dictionary<int, List<int>>();
  26. private static Dictionary<int, List<int>> _itemDatasByRarityDic = new Dictionary<int, List<int>>();
  27. //存储初始化时的衣服,用于性能优化,逐帧加载配置
  28. public static List<int> itemIDListInited = new List<int>();
  29. public static void InitData()
  30. {
  31. _itemDatas.Clear();
  32. _newItemdata.Clear();
  33. _itemDatasBySubTypeDic.Clear();
  34. _itemDatasByRarityDic.Clear();
  35. }
  36. public static void Clear()
  37. {
  38. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  39. selectRarityList.Clear();
  40. selectScoreList.Clear();
  41. selectTagList.Clear();
  42. dressSearchTxt = "";
  43. }
  44. public static void Add(ItemInfoProto itemInfoProto)
  45. {
  46. var value = itemInfoProto.ConfigId;
  47. //初始化时禁止使用物品配置,会造成卡顿!!!
  48. if (!_itemDatas.Contains(value))
  49. {
  50. _itemDatas.Add(value);
  51. int subType = itemInfoProto.SubType;
  52. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  53. if (!_itemDatasBySubTypeDic.ContainsKey(subType))
  54. {
  55. _itemDatasBySubTypeDic.Add(subType, new List<int>());
  56. }
  57. _itemDatasBySubTypeDic[subType].Add(value);
  58. if (!_itemDatasByRarityDic.ContainsKey(itemInfoProto.Rarity))
  59. {
  60. _itemDatasByRarityDic.Add(itemInfoProto.Rarity, new List<int>());
  61. }
  62. _itemDatasByRarityDic[itemInfoProto.Rarity].Add(value);
  63. if (GameGlobal.DataInited)
  64. {
  65. AddNewDressItem(value);
  66. DressUpMenuSuitDataManager.CheckItemInSuit(value);
  67. }
  68. else
  69. {
  70. itemIDListInited.Add(value);
  71. }
  72. }
  73. }
  74. public static bool CheckHasItem(int itemID)
  75. {
  76. return _itemDatas.Contains(itemID);
  77. }
  78. public static void Remove(int value)
  79. {
  80. if (_itemDatas == null)
  81. {
  82. return;
  83. }
  84. if (_itemDatas.Contains(value))
  85. {
  86. _itemDatas.Remove(value);
  87. }
  88. int subType = ItemUtilCS.GetItemSubType(value);
  89. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  90. if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0)
  91. {
  92. _itemDatasBySubTypeDic[subType].Remove(value);
  93. }
  94. int rarity = ItemCfgArray.Instance.GetCfg(value).rarity;
  95. if (_itemDatasByRarityDic.ContainsKey(rarity) && _itemDatasByRarityDic[rarity].IndexOf(value) >= 0)
  96. {
  97. _itemDatasByRarityDic[rarity].Remove(value);
  98. }
  99. }
  100. public static List<int> getItemDatasByType(int type)
  101. {
  102. List<int> arrayList = new List<int>();
  103. if (_itemDatasBySubTypeDic.ContainsKey(type))
  104. {
  105. arrayList.AddRange(_itemDatasBySubTypeDic[type]);
  106. }
  107. // for (int i = 0; i < _itemDatas.Count; i++)
  108. // {
  109. // int itemID = (int)_itemDatas[i];
  110. // int subType = ItemUtilCS.GetItemSubType(itemID);
  111. // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type)
  112. // {
  113. // arrayList.Add(itemID);
  114. // }
  115. // else if (subType == type)
  116. // {
  117. // arrayList.Add(itemID);
  118. // }
  119. // }
  120. return arrayList;
  121. }
  122. public static List<int> SortItemListByHighScore(List<int> arrayList, bool checkNew = false)
  123. {
  124. arrayList.Sort((int a, int b) =>
  125. {
  126. if (checkNew)
  127. {
  128. bool isNewA = CheckIsDressUpItemNew(a);
  129. bool isNewB = CheckIsDressUpItemNew(b);
  130. if (isNewA != isNewB)
  131. {
  132. if (isNewA) return -1;
  133. if (isNewB) return 1;
  134. }
  135. }
  136. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  137. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  138. if (scoreB > scoreA) return 1;
  139. if (scoreB < scoreA) return -1;
  140. return a - b;
  141. });
  142. return arrayList;
  143. }
  144. public static List<int> SortItemListByLowScore(List<int> arrayList, bool checkNew = false)
  145. {
  146. arrayList.Sort((int a, int b) =>
  147. {
  148. if (checkNew)
  149. {
  150. bool isNewA = CheckIsDressUpItemNew(a);
  151. bool isNewB = CheckIsDressUpItemNew(b);
  152. if (isNewA != isNewB)
  153. {
  154. if (isNewA) return -1;
  155. if (isNewB) return 1;
  156. }
  157. }
  158. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  159. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  160. if (scoreB < scoreA)
  161. {
  162. return 1;
  163. }
  164. else if (scoreB > scoreA)
  165. {
  166. return -1;
  167. }
  168. return 0;
  169. });
  170. return arrayList;
  171. }
  172. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  173. {
  174. arrayList.Sort((int a, int b) =>
  175. {
  176. int typeA = ItemUtilCS.GetItemSubType(a);
  177. int typeB = ItemUtilCS.GetItemSubType(b);
  178. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  179. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  180. if (typeB < typeA)
  181. {
  182. return -1;
  183. }
  184. else if (typeB > typeA)
  185. {
  186. return 1;
  187. }
  188. else if (scoreB > scoreA)
  189. {
  190. return 1;
  191. }
  192. else if (scoreB < scoreA)
  193. {
  194. return -1;
  195. }
  196. return 0;
  197. });
  198. return arrayList;
  199. }
  200. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  201. {
  202. arrayList.Sort((int a, int b) =>
  203. {
  204. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  205. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  206. bool isNewA = CheckIsDressUpItemNew(a);
  207. bool isNewB = CheckIsDressUpItemNew(b);
  208. if (isNewA != isNewB)
  209. {
  210. if (isNewA) return -1;
  211. if (isNewB) return 1;
  212. }
  213. if (itemCfgB.rarity > itemCfgA.rarity)
  214. {
  215. return 1;
  216. }
  217. else if (itemCfgB.rarity < itemCfgA.rarity)
  218. {
  219. return -1;
  220. }
  221. return 0;
  222. });
  223. return arrayList;
  224. }
  225. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  226. {
  227. arrayList.Sort((int a, int b) =>
  228. {
  229. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  230. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  231. bool isNewA = CheckIsDressUpItemNew(a);
  232. bool isNewB = CheckIsDressUpItemNew(b);
  233. if (isNewA != isNewB)
  234. {
  235. if (isNewA) return -1;
  236. if (isNewB) return 1;
  237. }
  238. if (itemCfgB.rarity < itemCfgA.rarity)
  239. {
  240. return 1;
  241. }
  242. else if (itemCfgB.rarity > itemCfgA.rarity)
  243. {
  244. return -1;
  245. }
  246. return 0;
  247. });
  248. return arrayList;
  249. }
  250. public static List<int> GetRecommendItemList(bool toSort = true)
  251. {
  252. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  253. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  254. List<int> recommendTypeList = new List<int>();
  255. List<int> recommendList = new List<int>();
  256. List<int> recommendSpecialList = new List<int>();
  257. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  258. if (toSort)
  259. {
  260. SortItemListByScoreByType(tempAllList);
  261. }
  262. foreach (int itemID in tempAllList)
  263. {
  264. int subType = ItemUtilCS.GetItemSubType(itemID);
  265. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  266. {
  267. if (!recommendTypeList.Contains(subType))
  268. {
  269. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  270. if (isNeed || fightCfg.needItemId <= 0)
  271. {
  272. if (subType < ConstDressUpItemType.TE_SHU)
  273. {
  274. recommendList.Add(itemID);
  275. }
  276. recommendTypeList.Add(subType);
  277. }
  278. }
  279. }
  280. }
  281. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  282. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  283. List<int> specialSubList = new List<int>();
  284. List<int> specialIdList = new List<int>();
  285. foreach (int itemID in recommendSpecialList)
  286. {
  287. int subType = ItemUtilCS.GetItemSubType(itemID);
  288. if (subType > ConstDressUpItemType.TE_SHU)
  289. {
  290. if (specialSubList.Count >= 3) continue;
  291. if (specialSubList.IndexOf(subType) < 0)
  292. {
  293. specialSubList.Add(subType);
  294. specialIdList.Add(itemID);
  295. }
  296. }
  297. }
  298. recommendList.AddRange(specialIdList);
  299. return recommendList;
  300. }
  301. // public static int GetRecommendCount()
  302. // {
  303. // List<int> recommendTypeList = GetRecommendItemList(false);
  304. // return recommendTypeList.Count;
  305. // }
  306. // public static int GetItemScore(int itemId)
  307. // {
  308. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  309. // }
  310. public static List<int> DressSearch(bool includeScene = true)
  311. {
  312. List<int> searchList = new List<int>();
  313. for (int i = 0; i < _itemDatas.Count; i++)
  314. {
  315. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  316. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  317. if (itemCfg.name.IndexOf(dressSearchTxt) >= 0 && searchList.IndexOf(itemCfg.id) < 0)
  318. {
  319. searchList.Add(itemCfg.id);
  320. }
  321. }
  322. return searchList;
  323. }
  324. public static List<int> DressFilter(bool includeScene = true)
  325. {
  326. List<int> filterList = new List<int>();
  327. for (int i = 0; i < _itemDatas.Count; i++)
  328. {
  329. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  330. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  331. bool isTag = selectTagList.Count == 0;
  332. if (selectTagList.Count > 0)
  333. {
  334. for (int j = 0; j < itemCfg.tagsArr.Length; j++)
  335. {
  336. if (selectTagList.IndexOf(itemCfg.tagsArr[j][0]) >= 0)
  337. {
  338. isTag = true;
  339. break;
  340. }
  341. }
  342. }
  343. if (!isTag) continue;
  344. if (selectRarityList.Count > 0 && selectRarityList.IndexOf(itemCfg.rarity) < 0) continue;
  345. if (selectScoreList.Count > 0 && selectScoreList.IndexOf(itemCfg.mainScore) < 0) continue;
  346. filterList.Add(itemCfg.id);
  347. }
  348. return filterList;
  349. }
  350. public static List<int> DressSearch(List<int> list)
  351. {
  352. List<int> searchList = new List<int>();
  353. for (int i = 0; i < list.Count; i++)
  354. {
  355. bool isSearch = true;
  356. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  357. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  358. string name = itemCfg != null ? itemCfg.name : suitCfg.name;
  359. for (int j = 0; j < dressSearchTxt.Length; j++)
  360. {
  361. if (name.IndexOf(dressSearchTxt[j]) < 0)
  362. {
  363. isSearch = false;
  364. break;
  365. }
  366. }
  367. if (isSearch)
  368. {
  369. searchList.Add(list[i]);
  370. }
  371. }
  372. return searchList;
  373. }
  374. public static List<int> DressFilter(List<int> list)
  375. {
  376. List<int> filterList = new List<int>();
  377. for (int i = 0; i < list.Count; i++)
  378. {
  379. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  380. SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  381. bool isRarity = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg);
  382. bool isScore = cfg == null ? true : FilterScore(cfg);
  383. bool isTag = cfg == null ? true : FilterTag(cfg);
  384. if (isRarity && isScore && isTag)
  385. {
  386. filterList.Add(list[i]);
  387. }
  388. }
  389. if (filterList.Count == 0)
  390. {
  391. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  392. }
  393. return filterList;
  394. }
  395. private static bool FilterRarity(ItemCfg cfg)
  396. {
  397. bool isRarity = false;
  398. if (selectRarityList.Count > 0)
  399. {
  400. for (int j = 0; j < selectRarityList.Count; j++)
  401. {
  402. if (cfg != null && cfg.rarity == selectRarityList[j])
  403. {
  404. isRarity = true;
  405. break;
  406. }
  407. }
  408. }
  409. else
  410. {
  411. isRarity = true;
  412. }
  413. return isRarity;
  414. }
  415. private static bool FilterRarity(SuitCfg cfg)
  416. {
  417. bool isRarity = false;
  418. if (selectRarityList.Count > 0)
  419. {
  420. for (int j = 0; j < selectRarityList.Count; j++)
  421. {
  422. if (cfg != null && cfg.rarity == selectRarityList[j])
  423. {
  424. isRarity = true;
  425. break;
  426. }
  427. }
  428. }
  429. else
  430. {
  431. isRarity = true;
  432. }
  433. return isRarity;
  434. }
  435. private static bool FilterScore(ItemCfg cfg)
  436. {
  437. bool isScore = false;
  438. if (selectScoreList.Count > 0)
  439. {
  440. if (cfg != null)
  441. {
  442. for (int j = 0; j < selectScoreList.Count; j++)
  443. {
  444. if (cfg.mainScore == selectScoreList[j])
  445. {
  446. isScore = true;
  447. break;
  448. }
  449. }
  450. }
  451. }
  452. else
  453. {
  454. isScore = true;
  455. }
  456. return isScore;
  457. }
  458. private static bool FilterTag(ItemCfg cfg)
  459. {
  460. bool isTag = false;
  461. if (selectTagList.Count > 0)
  462. {
  463. if (cfg != null)
  464. {
  465. for (int j = 0; j < selectTagList.Count; j++)
  466. {
  467. if (isTag == true)
  468. {
  469. break;
  470. }
  471. for (int k = 0; k < cfg.tagsArr.Length; k++)
  472. {
  473. if (cfg.tagsArr[k][0] == selectTagList[j])
  474. {
  475. isTag = true;
  476. break;
  477. }
  478. }
  479. }
  480. }
  481. }
  482. else
  483. {
  484. isTag = true;
  485. }
  486. return isTag;
  487. }
  488. public static void AddNewDressItem(int value)
  489. {
  490. int subType = ItemDataManager.GetItemSubType(value);
  491. if (!_newItemdata.ContainsKey(subType))
  492. {
  493. _newItemdata.Add(subType, new List<int>());
  494. }
  495. _newItemdata[subType].Add(value);
  496. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  497. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  498. // {
  499. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  500. // }
  501. }
  502. public static void RemoveNewDressItem(int itemId)
  503. {
  504. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  505. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  506. {
  507. _newItemdata[subType].Remove(itemId);
  508. }
  509. }
  510. //检测一级菜单是否有展示新增
  511. public static bool CheckIsFirstMenuNew(int menuId)
  512. {
  513. if (_newItemdata.Count == 0) return false;
  514. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  515. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  516. {
  517. foreach (int id2 in cfg1.subMenusArr)
  518. {
  519. if (CheckIsSecondMenuNew(id2)) return true;
  520. }
  521. }
  522. else
  523. {
  524. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  525. }
  526. return false;
  527. }
  528. //检测二级菜单是否有展示新增
  529. public static bool CheckIsSecondMenuNew(int subMenuId)
  530. {
  531. if (_newItemdata.Count == 0) return false;
  532. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  533. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  534. {
  535. return true;
  536. }
  537. return false;
  538. }
  539. //检测服装部件是否为新增
  540. public static bool CheckIsDressUpItemNew(int itemId)
  541. {
  542. if (_newItemdata.Count == 0) return false;
  543. int subType = ItemUtilCS.GetItemSubType(itemId);
  544. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  545. }
  546. //预加载服装配置
  547. public static void StartPreLoadItemCfg()
  548. {
  549. Timers.inst.AddUpdate(updateOnPreLoad);
  550. }
  551. private static void updateOnPreLoad(object param = null)
  552. {
  553. for(var i = 0; i < 3; i++)
  554. {
  555. PreLoadOneItemCfg();
  556. }
  557. if (itemIDListInited.Count <= 0)
  558. {
  559. Timers.inst.Remove(updateOnPreLoad);
  560. }
  561. }
  562. private static void PreLoadOneItemCfg()
  563. {
  564. var itemIDListInited = DressUpMenuItemDataManager.itemIDListInited;
  565. if (itemIDListInited.Count > 0)
  566. {
  567. int lasetIndex = itemIDListInited.Count - 1;
  568. int itemId = itemIDListInited[lasetIndex];
  569. itemIDListInited.RemoveAt(lasetIndex);
  570. ItemCfgArray.Instance.GetCfg(itemId);
  571. }
  572. }
  573. }
  574. }