DressUpMenuItemDataManager.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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.GetGroup1ByItemTypeAndSubType(ConstItemType.DRESS_UP,
  713. dressUpGuideSubType[i]));
  714. }
  715. // 饰品
  716. for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  717. {
  718. itemCfgs.AddRange(
  719. CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(ConstItemType.DRESS_UP,
  720. dressUpGuideAccessoriesType[i]));
  721. }
  722. // 特殊
  723. var itemTypeCfg = CommonDataManager.Tables.TblItemTypeCfg.DataList;
  724. for (int i = 0; i < itemTypeCfg.Count; i++)
  725. {
  726. if (itemTypeCfg[i].Type > ConstDressUpItemType.TE_SHU)
  727. {
  728. itemCfgs.AddRange(
  729. CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(ConstItemType.DRESS_UP,
  730. itemTypeCfg[i].Type));
  731. }
  732. }
  733. }
  734. // 指定子类型
  735. else
  736. {
  737. if (subType == ConstDressUpItemType.TE_SHU)
  738. {
  739. var itemTypeCfg = CommonDataManager.Tables.TblItemTypeCfg.DataList;
  740. for (int i = 0; i < itemTypeCfg.Count; i++)
  741. {
  742. if (itemTypeCfg[i].Type > ConstDressUpItemType.TE_SHU)
  743. {
  744. itemCfgs.AddRange(
  745. CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(
  746. ConstItemType.DRESS_UP, itemTypeCfg[i].Type));
  747. }
  748. }
  749. }
  750. else
  751. {
  752. itemCfgs = CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(ConstItemType.DRESS_UP,
  753. subType);
  754. }
  755. }
  756. if (sorted)
  757. {
  758. itemCfgs.Sort((a, b) =>
  759. {
  760. bool haveA = CheckHasItem(a.Id);
  761. bool haveB = CheckHasItem(b.Id);
  762. if (haveB && !haveA)
  763. {
  764. return 1;
  765. }
  766. else if (!haveB && haveA)
  767. {
  768. return -1;
  769. }
  770. if (a.Rarity != b.Rarity)
  771. {
  772. return a.Rarity > b.Rarity ? -1 : 1;
  773. }
  774. return a.Res.CompareTo(b.Res);
  775. });
  776. }
  777. for (int i = 0; i < itemCfgs.Count; i++)
  778. {
  779. if (CanShow(itemCfgs[i]))
  780. {
  781. result.Add(itemCfgs[i].Id);
  782. }
  783. }
  784. return result;
  785. }
  786. // 默认的不显示
  787. public static List<int> defaultID = new List<int> { 10000, 20000, 30000, 50000, 60000 };
  788. private static bool CanShow(ItemCfg item)
  789. {
  790. if (defaultID.Contains(item.Id))
  791. {
  792. return false;
  793. }
  794. return item.IsHide <= 0;
  795. }
  796. public static List<int> GetAllDressUpGuideIdListBySubTypes(List<int> subTypes)
  797. {
  798. List<int> result = new List<int>();
  799. List<ItemCfg> itemCfgs = new List<ItemCfg>();
  800. for (int j = 0; j < subTypes.Count; j++)
  801. {
  802. int subType = subTypes[j];
  803. if (subType == ConstDressUpItemType.TE_SHU)
  804. {
  805. var itemTypeCfg = CommonDataManager.Tables.TblItemTypeCfg.DataList;
  806. for (int i = 0; i < itemTypeCfg.Count; i++)
  807. {
  808. if (itemTypeCfg[i].Type > ConstDressUpItemType.TE_SHU)
  809. {
  810. itemCfgs.AddRange(
  811. CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(
  812. ConstItemType.DRESS_UP, itemTypeCfg[i].Type));
  813. }
  814. }
  815. }
  816. else
  817. {
  818. itemCfgs.AddRange(
  819. CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemTypeAndSubType(ConstItemType.DRESS_UP,
  820. subType));
  821. }
  822. }
  823. itemCfgs.Sort((a, b) =>
  824. {
  825. bool haveA = CheckHasItem(a.Id);
  826. bool haveB = CheckHasItem(b.Id);
  827. if (haveB && !haveA)
  828. {
  829. return 1;
  830. }
  831. else if (!haveB && haveA)
  832. {
  833. return -1;
  834. }
  835. if (a.Rarity != b.Rarity)
  836. {
  837. return a.Rarity > b.Rarity ? -1 : 1;
  838. }
  839. return a.Res.CompareTo(b.Res);
  840. });
  841. for (int i = 0; i < itemCfgs.Count; i++)
  842. {
  843. if (CanShow(itemCfgs[i]))
  844. {
  845. result.Add(itemCfgs[i].Id);
  846. }
  847. }
  848. return result;
  849. }
  850. public static bool isLoading = false;
  851. public static async Task GetAllDressUpGuideIdListBySubTypeAsync()
  852. {
  853. isLoading = true;
  854. // // 除饰品外的散件
  855. // for (int i = 0; i < dressUpGuideSubType.Length; i++)
  856. // {
  857. // await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, dressUpGuideSubType[i]);
  858. // }
  859. //
  860. // // 饰品
  861. // for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  862. // {
  863. // await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, dressUpGuideAccessoriesType[i]);
  864. // }
  865. // 特殊
  866. // ItemTypeCfg[] itemTypeCfg = ItemTypeCfgArray.Instance.dataArray;
  867. // for (int i = 0; i < itemTypeCfg.Length; i++)
  868. // {
  869. // if (itemTypeCfg[i].type > ConstDressUpItemType.TE_SHU)
  870. // {
  871. // await ItemCfgArray.Instance.GetCfgsByitemTypeAndsubTypeAsync(ConstItemType.DRESS_UP, itemTypeCfg[i].type);
  872. // }
  873. // }
  874. isLoading = false;
  875. EventAgent.DispatchEvent(ConstMessage.DRESS_PART_LOAD_FINISHED);
  876. }
  877. public static void SortDressUpGuideIdList(List<int> list)
  878. {
  879. list.Sort((a, b) =>
  880. {
  881. ItemCfg itemA = CommonDataManager.Tables.TblItemCfg.GetOrDefault(a);
  882. ItemCfg itemB = CommonDataManager.Tables.TblItemCfg.GetOrDefault(b);
  883. bool haveA = CheckHasItem(itemA.Id);
  884. bool haveB = CheckHasItem(itemB.Id);
  885. if (haveB && !haveA)
  886. {
  887. return 1;
  888. }
  889. else if (!haveB && haveA)
  890. {
  891. return -1;
  892. }
  893. if (itemA.Rarity != itemB.Rarity)
  894. {
  895. return itemA.Rarity > itemB.Rarity ? -1 : 1;
  896. }
  897. return itemA.Res.CompareTo(itemB.Res);
  898. });
  899. }
  900. public static void GetTotalProgress(out int haveCount, out int totalCount)
  901. {
  902. totalCount = CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemType(ConstItemType.DRESS_UP).Count(a => a.SuitId == 0);
  903. haveCount = 0;
  904. // 除饰品外的散件
  905. for (int i = 0; i < dressUpGuideSubType.Length; i++)
  906. {
  907. if (_itemDatasBySubTypeDic.ContainsKey(dressUpGuideSubType[i]))
  908. {
  909. haveCount += _itemDatasBySubTypeDic[dressUpGuideSubType[i]].Count;
  910. }
  911. }
  912. // 饰品
  913. for (int i = 0; i < dressUpGuideAccessoriesType.Length; i++)
  914. {
  915. if (_itemDatasBySubTypeDic.ContainsKey(dressUpGuideAccessoriesType[i]))
  916. {
  917. haveCount += _itemDatasBySubTypeDic[dressUpGuideAccessoriesType[i]].Count;
  918. }
  919. }
  920. // 特殊
  921. if (_itemDatasBySubTypeDic.ContainsKey(ConstDressUpItemType.TE_SHU))
  922. {
  923. haveCount += _itemDatasBySubTypeDic[ConstDressUpItemType.TE_SHU].Count;
  924. }
  925. }
  926. }
  927. }