DressUpMenuItemDataManager.cs 37 KB

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