DressUpMenuItemDataManager.cs 33 KB

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