DressUpMenuItemDataManager.cs 33 KB

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