DressUpMenuItemDataManager.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. using FairyGUI;
  7. using System.Threading.Tasks;
  8. namespace GFGGame
  9. {
  10. public enum DressFilterType
  11. {
  12. None,
  13. Search,
  14. Filter
  15. }
  16. public enum DressFilterItemType
  17. {
  18. ALL,
  19. DressUpItem, // 散件
  20. Suit // 套装
  21. }
  22. public class DressUpMenuItemDataManager
  23. {
  24. public static string dressSearchTxt = "";
  25. public static DressFilterType dressFilterType = DressFilterType.None;
  26. public static List<int> selectRarityList = new List<int>();
  27. public static List<int> selectScoreList = new List<int>();
  28. public static List<string> selectTagList = new List<string>();
  29. private static List<int> _itemDatas = new List<int>();
  30. private static Dictionary<int, List<int>> _itemDatasBySubTypeDic = new Dictionary<int, List<int>>();
  31. public static Dictionary<int, List<int>> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } }
  32. private static Dictionary<int, List<int>> _newItemdata = new Dictionary<int, List<int>>();
  33. private static Dictionary<int, List<int>> _itemDatasByRarityDic = new Dictionary<int, List<int>>();
  34. //存储初始化时的衣服,用于性能优化,逐帧加载配置
  35. public static List<int> itemIDListInited = new List<int>();
  36. public static void InitData()
  37. {
  38. _itemDatas.Clear();
  39. _newItemdata.Clear();
  40. _itemDatasBySubTypeDic.Clear();
  41. _itemDatasByRarityDic.Clear();
  42. }
  43. public static void Clear()
  44. {
  45. DressUpMenuItemDataManager.dressFilterType = DressFilterType.None;
  46. selectRarityList.Clear();
  47. selectScoreList.Clear();
  48. selectTagList.Clear();
  49. dressSearchTxt = "";
  50. }
  51. public static void Add(ItemInfoProto itemInfoProto)
  52. {
  53. var value = itemInfoProto.ConfigId;
  54. //初始化时禁止使用物品配置,会造成卡顿!!!
  55. if (!_itemDatas.Contains(value))
  56. {
  57. _itemDatas.Add(value);
  58. int subType = itemInfoProto.SubType;
  59. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  60. if (!_itemDatasBySubTypeDic.ContainsKey(subType))
  61. {
  62. _itemDatasBySubTypeDic.Add(subType, new List<int>());
  63. }
  64. _itemDatasBySubTypeDic[subType].Add(value);
  65. if (!_itemDatasByRarityDic.ContainsKey(itemInfoProto.Rarity))
  66. {
  67. _itemDatasByRarityDic.Add(itemInfoProto.Rarity, new List<int>());
  68. }
  69. _itemDatasByRarityDic[itemInfoProto.Rarity].Add(value);
  70. if (GameGlobal.PreDataInited)
  71. {
  72. AddNewDressItem(value);
  73. DressUpMenuSuitDataManager.CheckItemInSuit(value);
  74. PreDownloadManager.Instance.PreDownloadDressUpRes(value, ResType.Both);
  75. }
  76. else
  77. {
  78. itemIDListInited.Add(value);
  79. }
  80. }
  81. }
  82. public static bool CheckHasItem(int itemID)
  83. {
  84. return _itemDatas.Contains(itemID);
  85. }
  86. public static List<int> GetDressUpItemDatas()
  87. {
  88. return _itemDatas;
  89. }
  90. public static void Remove(int value)
  91. {
  92. if (_itemDatas == null)
  93. {
  94. return;
  95. }
  96. if (_itemDatas.Contains(value))
  97. {
  98. _itemDatas.Remove(value);
  99. }
  100. int subType = ItemUtilCS.GetItemSubType(value);
  101. subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType;
  102. if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0)
  103. {
  104. _itemDatasBySubTypeDic[subType].Remove(value);
  105. }
  106. int rarity = ItemCfgArray.Instance.GetCfg(value).rarity;
  107. if (_itemDatasByRarityDic.ContainsKey(rarity) && _itemDatasByRarityDic[rarity].IndexOf(value) >= 0)
  108. {
  109. _itemDatasByRarityDic[rarity].Remove(value);
  110. }
  111. }
  112. public static List<int> getItemDatasByType(int type)
  113. {
  114. List<int> arrayList = new List<int>();
  115. if (_itemDatasBySubTypeDic.ContainsKey(type))
  116. {
  117. arrayList.AddRange(_itemDatasBySubTypeDic[type]);
  118. }
  119. // for (int i = 0; i < _itemDatas.Count; i++)
  120. // {
  121. // int itemID = (int)_itemDatas[i];
  122. // int subType = ItemUtilCS.GetItemSubType(itemID);
  123. // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type)
  124. // {
  125. // arrayList.Add(itemID);
  126. // }
  127. // else if (subType == type)
  128. // {
  129. // arrayList.Add(itemID);
  130. // }
  131. // }
  132. return arrayList;
  133. }
  134. public static List<int> SortItemListByHighScore(List<int> arrayList, bool checkNew = false)
  135. {
  136. arrayList.Sort((int a, int b) =>
  137. {
  138. if (checkNew)
  139. {
  140. bool isNewA = CheckIsDressUpItemNew(a);
  141. bool isNewB = CheckIsDressUpItemNew(b);
  142. if (isNewA != isNewB)
  143. {
  144. if (isNewA) return -1;
  145. if (isNewB) return 1;
  146. }
  147. }
  148. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  149. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  150. if (scoreB > scoreA) return 1;
  151. if (scoreB < scoreA) return -1;
  152. return a - b;
  153. });
  154. return arrayList;
  155. }
  156. public static List<int> SortItemTeaPartyByHighScore(List<int> arrayList)
  157. {
  158. arrayList.Sort((int a, int b) =>
  159. {
  160. int scoreA = ItemDataManager.GetItemAddTeaPartyTagsScore(a);
  161. int scoreB = ItemDataManager.GetItemAddTeaPartyTagsScore(b);
  162. if (scoreB > scoreA) return 1;
  163. if (scoreB < scoreA) return -1;
  164. return a - b;
  165. });
  166. return arrayList;
  167. }
  168. public static List<int> SortItemListByLowScore(List<int> arrayList, bool checkNew = false)
  169. {
  170. arrayList.Sort((int a, int b) =>
  171. {
  172. if (checkNew)
  173. {
  174. bool isNewA = CheckIsDressUpItemNew(a);
  175. bool isNewB = CheckIsDressUpItemNew(b);
  176. if (isNewA != isNewB)
  177. {
  178. if (isNewA) return -1;
  179. if (isNewB) return 1;
  180. }
  181. }
  182. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  183. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  184. if (scoreB < scoreA)
  185. {
  186. return 1;
  187. }
  188. else if (scoreB > scoreA)
  189. {
  190. return -1;
  191. }
  192. return 0;
  193. });
  194. return arrayList;
  195. }
  196. public static List<int> SortItemTeaPartyByLowsore(List<int> arrayList)
  197. {
  198. arrayList.Sort((int a, int b) =>
  199. {
  200. int scoreA = ItemDataManager.GetItemAddTeaPartyTagsScore(a);
  201. int scoreB = ItemDataManager.GetItemAddTeaPartyTagsScore(b);
  202. if (scoreB < scoreA) return 1;
  203. if (scoreB > scoreA) return -1;
  204. return a - b;
  205. });
  206. return arrayList;
  207. }
  208. private static List<int> SortItemListByScoreByType(List<int> arrayList)
  209. {
  210. arrayList.Sort((int a, int b) =>
  211. {
  212. int typeA = ItemUtilCS.GetItemSubType(a);
  213. int typeB = ItemUtilCS.GetItemSubType(b);
  214. int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  215. int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ;
  216. if (typeB < typeA)
  217. {
  218. return -1;
  219. }
  220. else if (typeB > typeA)
  221. {
  222. return 1;
  223. }
  224. else if (scoreB > scoreA)
  225. {
  226. return 1;
  227. }
  228. else if (scoreB < scoreA)
  229. {
  230. return -1;
  231. }
  232. return 0;
  233. });
  234. return arrayList;
  235. }
  236. public static List<int> SortItemListByHighRarity(List<int> arrayList)
  237. {
  238. arrayList.Sort((int a, int b) =>
  239. {
  240. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  241. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  242. bool isNewA = CheckIsDressUpItemNew(a);
  243. bool isNewB = CheckIsDressUpItemNew(b);
  244. if (isNewA != isNewB)
  245. {
  246. if (isNewA) return -1;
  247. if (isNewB) return 1;
  248. }
  249. if (itemCfgB.rarity > itemCfgA.rarity)
  250. {
  251. return 1;
  252. }
  253. else if (itemCfgB.rarity < itemCfgA.rarity)
  254. {
  255. return -1;
  256. }
  257. return 0;
  258. });
  259. return arrayList;
  260. }
  261. public static List<int> SortItemListByLowRarity(List<int> arrayList)
  262. {
  263. arrayList.Sort((int a, int b) =>
  264. {
  265. ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a);
  266. ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b);
  267. bool isNewA = CheckIsDressUpItemNew(a);
  268. bool isNewB = CheckIsDressUpItemNew(b);
  269. if (isNewA != isNewB)
  270. {
  271. if (isNewA) return -1;
  272. if (isNewB) return 1;
  273. }
  274. if (itemCfgB.rarity < itemCfgA.rarity)
  275. {
  276. return 1;
  277. }
  278. else if (itemCfgB.rarity > itemCfgA.rarity)
  279. {
  280. return -1;
  281. }
  282. return 0;
  283. });
  284. return arrayList;
  285. }
  286. public static List<int> GetRecommendItemList(bool toSort = true)
  287. {
  288. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  289. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  290. List<int> recommendTypeList = new List<int>();
  291. List<int> recommendList = new List<int>();
  292. List<int> recommendSpecialList = new List<int>();
  293. List<int> tempAllList = _itemDatas.GetRange(0, _itemDatas.Count);
  294. if (toSort)
  295. {
  296. SortItemListByScoreByType(tempAllList);
  297. }
  298. foreach (int itemID in tempAllList)
  299. {
  300. int subType = ItemUtilCS.GetItemSubType(itemID);
  301. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING)
  302. {
  303. if (!recommendTypeList.Contains(subType))
  304. {
  305. bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID);
  306. if (isNeed || fightCfg.needItemId <= 0)
  307. {
  308. if (subType < ConstDressUpItemType.TE_SHU)
  309. {
  310. recommendList.Add(itemID);
  311. }
  312. recommendTypeList.Add(subType);
  313. }
  314. }
  315. }
  316. }
  317. recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU);
  318. recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList);
  319. List<int> specialSubList = new List<int>();
  320. List<int> specialIdList = new List<int>();
  321. foreach (int itemID in recommendSpecialList)
  322. {
  323. int subType = ItemUtilCS.GetItemSubType(itemID);
  324. if (subType > ConstDressUpItemType.TE_SHU)
  325. {
  326. if (specialSubList.Count >= 3) continue;
  327. if (specialSubList.IndexOf(subType) < 0)
  328. {
  329. specialSubList.Add(subType);
  330. specialIdList.Add(itemID);
  331. }
  332. }
  333. }
  334. recommendList.AddRange(specialIdList);
  335. return recommendList;
  336. }
  337. // public static int GetRecommendCount()
  338. // {
  339. // List<int> recommendTypeList = GetRecommendItemList(false);
  340. // return recommendTypeList.Count;
  341. // }
  342. // public static int GetItemScore(int itemId)
  343. // {
  344. // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType);
  345. // }
  346. public static List<int> DressSearch(bool includeScene = true)
  347. {
  348. List<int> searchList = new List<int>();
  349. for (int i = 0; i < _itemDatas.Count; i++)
  350. {
  351. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  352. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  353. if (itemCfg.name.IndexOf(dressSearchTxt) >= 0 && searchList.IndexOf(itemCfg.id) < 0)
  354. {
  355. searchList.Add(itemCfg.id);
  356. }
  357. }
  358. return searchList;
  359. }
  360. public static List<int> DressFilter(bool includeScene = true)
  361. {
  362. List<int> filterList = new List<int>();
  363. for (int i = 0; i < _itemDatas.Count; i++)
  364. {
  365. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemDatas[i]);
  366. if (!includeScene && DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(_itemDatas[i])) continue;
  367. bool isTag = selectTagList.Count == 0;
  368. if (selectTagList.Count > 0)
  369. {
  370. for (int j = 0; j < itemCfg.tagsArr.Length; j++)
  371. {
  372. if (selectTagList.IndexOf(itemCfg.tagsArr[j][0]) >= 0)
  373. {
  374. isTag = true;
  375. break;
  376. }
  377. }
  378. }
  379. if (!isTag) continue;
  380. if (selectRarityList.Count > 0 && selectRarityList.IndexOf(itemCfg.rarity) < 0) continue;
  381. if (selectScoreList.Count > 0 && selectScoreList.IndexOf(itemCfg.mainScore) < 0) continue;
  382. filterList.Add(itemCfg.id);
  383. }
  384. return filterList;
  385. }
  386. public static List<int> DressSearch(List<int> list, DressFilterItemType type = DressFilterItemType.ALL)
  387. {
  388. List<int> searchList = new List<int>();
  389. for (int i = 0; i < list.Count; i++)
  390. {
  391. bool isSearch = true;
  392. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]);
  393. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  394. // 散件优先于套装
  395. if (type == DressFilterItemType.ALL)
  396. {
  397. if (itemCfg == null)
  398. {
  399. type = DressFilterItemType.Suit;
  400. }
  401. else
  402. {
  403. type = DressFilterItemType.DressUpItem;
  404. }
  405. }
  406. string name = (type == DressFilterItemType.DressUpItem) ? itemCfg.name : suitCfg.name;
  407. for (int j = 0; j < dressSearchTxt.Length; j++)
  408. {
  409. if (name.IndexOf(dressSearchTxt[j]) < 0)
  410. {
  411. isSearch = false;
  412. break;
  413. }
  414. }
  415. if (isSearch)
  416. {
  417. searchList.Add(list[i]);
  418. }
  419. }
  420. return searchList;
  421. }
  422. public static List<int> DressFilter(List<int> list, DressFilterItemType type = DressFilterItemType.ALL)
  423. {
  424. List<int> filterList = new List<int>();
  425. for (int i = 0; i < list.Count; i++)
  426. {
  427. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]);
  428. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]);
  429. // 散件优先于套装
  430. if(type == DressFilterItemType.ALL)
  431. {
  432. if(cfg == null)
  433. {
  434. type = DressFilterItemType.Suit;
  435. }
  436. else
  437. {
  438. type = DressFilterItemType.DressUpItem;
  439. }
  440. }
  441. ItemCfg suitItemCfg = (suitCfg != null) ? ItemCfgArray.Instance.GetCfg(suitCfg.partsArr[0]) : null;
  442. bool isRarity = (type == DressFilterItemType.Suit) ? FilterRarity(suitCfg) : FilterRarity(cfg);
  443. bool isScore = FilterScore((type == DressFilterItemType.Suit) ? suitItemCfg : cfg);
  444. bool isTag = FilterTag((type == DressFilterItemType.Suit) ? suitItemCfg : cfg);
  445. if (isRarity && isScore && isTag)
  446. {
  447. filterList.Add(list[i]);
  448. }
  449. }
  450. if (filterList.Count == 0)
  451. {
  452. PromptController.Instance.ShowFloatTextPrompt("无满足条件物品");
  453. }
  454. return filterList;
  455. }
  456. private static bool FilterRarity(ItemCfg cfg)
  457. {
  458. bool isRarity = false;
  459. if (selectRarityList.Count > 0)
  460. {
  461. for (int j = 0; j < selectRarityList.Count; j++)
  462. {
  463. if (cfg != null && cfg.rarity == selectRarityList[j])
  464. {
  465. isRarity = true;
  466. break;
  467. }
  468. }
  469. }
  470. else
  471. {
  472. isRarity = true;
  473. }
  474. return isRarity;
  475. }
  476. private static bool FilterRarity(SuitCfg cfg)
  477. {
  478. bool isRarity = false;
  479. if (selectRarityList.Count > 0)
  480. {
  481. for (int j = 0; j < selectRarityList.Count; j++)
  482. {
  483. if (cfg != null && cfg.rarity == selectRarityList[j])
  484. {
  485. isRarity = true;
  486. break;
  487. }
  488. }
  489. }
  490. else
  491. {
  492. isRarity = true;
  493. }
  494. return isRarity;
  495. }
  496. private static bool FilterScore(ItemCfg cfg)
  497. {
  498. bool isScore = false;
  499. if (selectScoreList.Count > 0)
  500. {
  501. if (cfg != null)
  502. {
  503. for (int j = 0; j < selectScoreList.Count; j++)
  504. {
  505. if (cfg.mainScore == selectScoreList[j])
  506. {
  507. isScore = true;
  508. break;
  509. }
  510. }
  511. }
  512. }
  513. else
  514. {
  515. isScore = true;
  516. }
  517. return isScore;
  518. }
  519. private static bool FilterScore(SuitCfg suitCfg)
  520. {
  521. bool isScore = false;
  522. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(suitCfg.partsArr[0]);
  523. if (selectScoreList.Count > 0)
  524. {
  525. if (cfg != null)
  526. {
  527. for (int j = 0; j < selectScoreList.Count; j++)
  528. {
  529. if (cfg.mainScore == selectScoreList[j])
  530. {
  531. isScore = true;
  532. break;
  533. }
  534. }
  535. }
  536. }
  537. else
  538. {
  539. isScore = true;
  540. }
  541. return isScore;
  542. }
  543. private static bool FilterTag(ItemCfg cfg)
  544. {
  545. bool isTag = false;
  546. if (selectTagList.Count > 0)
  547. {
  548. if (cfg != null)
  549. {
  550. for (int j = 0; j < selectTagList.Count; j++)
  551. {
  552. if (isTag == true)
  553. {
  554. break;
  555. }
  556. for (int k = 0; k < cfg.tagsArr.Length; k++)
  557. {
  558. if (cfg.tagsArr[k][0] == selectTagList[j])
  559. {
  560. isTag = true;
  561. break;
  562. }
  563. }
  564. }
  565. }
  566. }
  567. else
  568. {
  569. isTag = true;
  570. }
  571. return isTag;
  572. }
  573. public static void AddNewDressItem(int value)
  574. {
  575. int subType = ItemDataManager.GetItemSubType(value);
  576. if (!_newItemdata.ContainsKey(subType))
  577. {
  578. _newItemdata.Add(subType, new List<int>());
  579. }
  580. _newItemdata[subType].Add(value);
  581. // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value);
  582. // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId))
  583. // {
  584. // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId);
  585. // }
  586. }
  587. public static void RemoveNewDressItem(int itemId)
  588. {
  589. int subType = ItemCfgArray.Instance.GetCfg(itemId).subType;
  590. if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0)
  591. {
  592. _newItemdata[subType].Remove(itemId);
  593. }
  594. }
  595. //检测一级菜单是否有展示新增
  596. public static bool CheckIsFirstMenuNew(int menuId)
  597. {
  598. if (_newItemdata.Count == 0) return false;
  599. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId);
  600. if (cfg1.subMenusArr.Length > 0)//有二级菜单
  601. {
  602. foreach (int id2 in cfg1.subMenusArr)
  603. {
  604. if (CheckIsSecondMenuNew(id2)) return true;
  605. }
  606. }
  607. else
  608. {
  609. if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true;
  610. }
  611. return false;
  612. }
  613. //检测二级菜单是否有展示新增
  614. public static bool CheckIsSecondMenuNew(int subMenuId)
  615. {
  616. if (_newItemdata.Count == 0) return false;
  617. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId);
  618. if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0)
  619. {
  620. return true;
  621. }
  622. return false;
  623. }
  624. //检测服装部件是否为新增
  625. public static bool CheckIsDressUpItemNew(int itemId)
  626. {
  627. if (_newItemdata.Count == 0) return false;
  628. int subType = ItemUtilCS.GetItemSubType(itemId);
  629. return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0;
  630. }
  631. //预加载服装配置
  632. public static void StartPreLoadItemCfg()
  633. {
  634. Timers.inst.AddUpdate(updateOnPreLoad);
  635. }
  636. private static void updateOnPreLoad(object param = null)
  637. {
  638. for(var i = 0; i < 3; i++)
  639. {
  640. PreLoadOneItemCfg();
  641. }
  642. if (itemIDListInited.Count <= 0)
  643. {
  644. Timers.inst.Remove(updateOnPreLoad);
  645. }
  646. }
  647. private static void PreLoadOneItemCfg()
  648. {
  649. var itemIDListInited = DressUpMenuItemDataManager.itemIDListInited;
  650. if (itemIDListInited.Count > 0)
  651. {
  652. int lasetIndex = itemIDListInited.Count - 1;
  653. int itemId = itemIDListInited[lasetIndex];
  654. itemIDListInited.RemoveAt(lasetIndex);
  655. ItemCfgArray.Instance.GetCfg(itemId);
  656. }
  657. }
  658. public static int[] dressUpGuideSubType = {
  659. ConstDressUpItemType.FA_XING, ConstDressUpItemType.LIAN_YI_QUN , ConstDressUpItemType.NEI_DA,
  660. ConstDressUpItemType.WAI_TAO,ConstDressUpItemType.SHANG_YI,ConstDressUpItemType.XIA_ZHUANG,ConstDressUpItemType.WA_ZI,
  661. ConstDressUpItemType.XIE_ZI,ConstDressUpItemType.SHOU_CHI_WU, ConstDressUpItemType.ZHUANG_RONG};
  662. public static int[] dressUpGuideAccessoriesType = {
  663. ConstDressUpItemType.TOU_SHI, ConstDressUpItemType.ER_SHI , ConstDressUpItemType.JING_SHI,
  664. ConstDressUpItemType.MIAN_BU,ConstDressUpItemType.YAO_SHI,ConstDressUpItemType.SHOU_SHI,ConstDressUpItemType.PI_BO};
  665. /// <summary>
  666. /// 根据主属性获取有序服装散件ID列表(排序规则: 已获得按稀有度从高到低 > 未获得按稀有度从高到低 > 名字拼音)
  667. /// 包含已获得和未获得
  668. /// </summary>
  669. /// <param name="subType">0-全部</param>
  670. /// <param name="sorted">true-有序</param>
  671. /// <returns></returns>
  672. public static List<int> GetAllDressUpGuideIdListBySubType(int subType, bool sorted = true)
  673. {
  674. List<int> result = new List<int>();
  675. List<ItemCfg> itemCfgs = new List<ItemCfg>();
  676. // 全部
  677. if (subType == 0)
  678. {
  679. // 除饰品外的散件
  680. for (int i = 0; i < dressUpGuideSubType.Length; i++)
  681. {
  682. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, dressUpGuideSubType[i]));
  683. }
  684. // 饰品
  685. for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  686. {
  687. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, dressUpGuideAccessoriesType[i]));
  688. }
  689. // 特殊
  690. ItemTypeCfg[] itemTypeCfg = ItemTypeCfgArray.Instance.dataArray;
  691. for (int i = 0; i < itemTypeCfg.Length; i++)
  692. {
  693. if (itemTypeCfg[i].type > ConstDressUpItemType.TE_SHU)
  694. {
  695. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, itemTypeCfg[i].type));
  696. }
  697. }
  698. }
  699. // 指定子类型
  700. else
  701. {
  702. if(subType == ConstDressUpItemType.TE_SHU)
  703. {
  704. ItemTypeCfg[] itemTypeCfg = ItemTypeCfgArray.Instance.dataArray;
  705. for(int i = 0;i< itemTypeCfg.Length; i++)
  706. {
  707. if(itemTypeCfg[i].type > ConstDressUpItemType.TE_SHU)
  708. {
  709. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, itemTypeCfg[i].type));
  710. }
  711. }
  712. }
  713. else
  714. {
  715. itemCfgs = ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, subType);
  716. }
  717. }
  718. if (sorted)
  719. {
  720. itemCfgs.Sort((a, b) =>
  721. {
  722. bool haveA = CheckHasItem(a.id);
  723. bool haveB = CheckHasItem(b.id);
  724. if (haveB && !haveA)
  725. {
  726. return 1;
  727. }
  728. else if (!haveB && haveA)
  729. {
  730. return -1;
  731. }
  732. if (a.rarity != b.rarity)
  733. {
  734. return a.rarity > b.rarity ? -1 : 1;
  735. }
  736. return a.res.CompareTo(b.res);
  737. });
  738. }
  739. for (int i = 0; i < itemCfgs.Count; i++)
  740. {
  741. if(CanShow(itemCfgs[i]))
  742. {
  743. result.Add(itemCfgs[i].id);
  744. }
  745. }
  746. return result;
  747. }
  748. // 默认的不显示
  749. public static List<int> defaultID = new List<int> { 10000, 20000, 30000, 50000, 60000 };
  750. private static bool CanShow(ItemCfg item)
  751. {
  752. if (defaultID.Contains(item.id))
  753. {
  754. return false;
  755. }
  756. return item.isHide <= 0;
  757. }
  758. public static List<int> GetAllDressUpGuideIdListBySubTypes(List<int> subTypes)
  759. {
  760. List<int> result = new List<int>();
  761. List<ItemCfg> itemCfgs = new List<ItemCfg>();
  762. for (int j = 0; j < subTypes.Count; j++)
  763. {
  764. int subType = subTypes[j];
  765. if (subType == ConstDressUpItemType.TE_SHU)
  766. {
  767. ItemTypeCfg[] itemTypeCfg = ItemTypeCfgArray.Instance.dataArray;
  768. for (int i = 0; i < itemTypeCfg.Length; i++)
  769. {
  770. if (itemTypeCfg[i].type > ConstDressUpItemType.TE_SHU)
  771. {
  772. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, itemTypeCfg[i].type));
  773. }
  774. }
  775. }
  776. else
  777. {
  778. itemCfgs.AddRange(ItemCfgArray.Instance.GetCfgsByitemTypeAndsubType(ConstItemType.DRESS_UP, subType));
  779. }
  780. }
  781. itemCfgs.Sort((a, b) =>
  782. {
  783. bool haveA = CheckHasItem(a.id);
  784. bool haveB = CheckHasItem(b.id);
  785. if (haveB && !haveA)
  786. {
  787. return 1;
  788. }
  789. else if (!haveB && haveA)
  790. {
  791. return -1;
  792. }
  793. if (a.rarity != b.rarity)
  794. {
  795. return a.rarity > b.rarity ? -1 : 1;
  796. }
  797. return a.res.CompareTo(b.res);
  798. });
  799. for (int i = 0; i < itemCfgs.Count; i++)
  800. {
  801. if (CanShow(itemCfgs[i]))
  802. {
  803. result.Add(itemCfgs[i].id);
  804. }
  805. }
  806. return result;
  807. }
  808. public static bool isLoading = false;
  809. public static async Task GetAllDressUpGuideIdListBySubTypeAsync()
  810. {
  811. isLoading = true;
  812. // 除饰品外的散件
  813. for (int i = 0; i < dressUpGuideSubType.Length; i++)
  814. {
  815. await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, dressUpGuideSubType[i]);
  816. }
  817. // 饰品
  818. for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  819. {
  820. await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, dressUpGuideAccessoriesType[i]);
  821. }
  822. // 特殊
  823. ItemTypeCfg[] itemTypeCfg = ItemTypeCfgArray.Instance.dataArray;
  824. for (int i = 0; i < itemTypeCfg.Length; i++)
  825. {
  826. if (itemTypeCfg[i].type > ConstDressUpItemType.TE_SHU)
  827. {
  828. await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, itemTypeCfg[i].type);
  829. }
  830. }
  831. isLoading = false;
  832. EventAgent.DispatchEvent(ConstMessage.DRESS_PART_LOAD_FINISHED);
  833. }
  834. public static void SortDressUpGuideIdList(List<int> list)
  835. {
  836. list.Sort((a, b) =>
  837. {
  838. ItemCfg itemA = ItemCfgArray.Instance.GetCfg(a);
  839. ItemCfg itemB = ItemCfgArray.Instance.GetCfg(b);
  840. bool haveA = CheckHasItem(itemA.id);
  841. bool haveB = CheckHasItem(itemB.id);
  842. if (haveB && !haveA)
  843. {
  844. return 1;
  845. }
  846. else if (!haveB && haveA)
  847. {
  848. return -1;
  849. }
  850. if (itemA.rarity != itemB.rarity)
  851. {
  852. return itemA.rarity > itemB.rarity ? -1 : 1;
  853. }
  854. return itemA.res.CompareTo(itemB.res);
  855. });
  856. }
  857. public static void GetTotalProgress(out int haveCount, out int totalCount)
  858. {
  859. totalCount = GlobalCfgArray.globalCfg.ClothingPartsCount;
  860. haveCount = 0;
  861. // 除饰品外的散件
  862. for (int i = 0; i < dressUpGuideSubType.Length; i++)
  863. {
  864. if (_itemDatasBySubTypeDic.ContainsKey(dressUpGuideSubType[i]))
  865. {
  866. haveCount += _itemDatasBySubTypeDic[dressUpGuideSubType[i]].Count;
  867. }
  868. }
  869. // 饰品
  870. for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  871. {
  872. if (_itemDatasBySubTypeDic.ContainsKey(dressUpGuideAccessoriesType[i]))
  873. {
  874. haveCount += _itemDatasBySubTypeDic[dressUpGuideAccessoriesType[i]].Count;
  875. }
  876. }
  877. // 特殊
  878. if (_itemDatasBySubTypeDic.ContainsKey(ConstDressUpItemType.TE_SHU))
  879. {
  880. haveCount += _itemDatasBySubTypeDic[ConstDressUpItemType.TE_SHU].Count;
  881. }
  882. }
  883. }
  884. }