DressUpMenuItemDataManager.cs 32 KB

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