ClothingShopCfgManager.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections.Generic;
  2. namespace GFGGame
  3. {
  4. public class ClothingShopCfgManager : SingletonBase<ClothingShopCfgManager>
  5. {
  6. private bool _inited;
  7. private Dictionary<int, Dictionary<int, List<ClothingShopCfg>>> _dataDic = new Dictionary<int, Dictionary<int, List<ClothingShopCfg>>>();
  8. public List<ClothingShopCfg> GetList(int storeId, int typeIndex, int scoreType)
  9. {
  10. List<ClothingShopCfg> list = new List<ClothingShopCfg>();
  11. InitData();
  12. if (_dataDic.ContainsKey(storeId) && _dataDic[storeId].ContainsKey(typeIndex))
  13. {
  14. list = _dataDic[storeId][typeIndex];
  15. SortItemListByScore(list, scoreType);
  16. }
  17. return list;
  18. }
  19. private List<ClothingShopCfg> SortItemListByScore(List<ClothingShopCfg> arrayList, int scoreType)
  20. {
  21. arrayList.Sort((ClothingShopCfg a, ClothingShopCfg b) =>
  22. {
  23. int numA = ItemDataManager.GetItemNum(a.itemID);
  24. int numB = ItemDataManager.GetItemNum(b.itemID);
  25. bool hasA = numA > 0;
  26. bool hasB = numB > 0;
  27. if (hasA && !hasB)
  28. {
  29. return 1;
  30. }
  31. else if (!hasA && hasB)
  32. {
  33. return -1;
  34. }
  35. else if (scoreType > 0 && !hasA && !hasB)
  36. {
  37. int scoreA = DressUpMenuItemDataManager.GetItemScore(a.itemID, scoreType);
  38. int scoreB = DressUpMenuItemDataManager.GetItemScore(b.itemID, scoreType);
  39. if (scoreB > scoreA)
  40. {
  41. return 1;
  42. }
  43. else if (scoreB < scoreA)
  44. {
  45. return -1;
  46. }
  47. }
  48. return 0;
  49. });
  50. return arrayList;
  51. }
  52. private void InitData()
  53. {
  54. if (_inited)
  55. {
  56. return;
  57. }
  58. _inited = true;
  59. ClothingShopCfg[] clotiongDataArray = ClothingShopCfgArray.Instance.dataArray;
  60. foreach (ClothingShopCfg cfg in clotiongDataArray)
  61. {
  62. if (_dataDic.ContainsKey(ConstStoreId.CLOTHING_STORE_ID)==false){
  63. _dataDic[ConstStoreId.CLOTHING_STORE_ID] = new Dictionary<int, List<ClothingShopCfg>>();
  64. }
  65. if (_dataDic[ConstStoreId.CLOTHING_STORE_ID].ContainsKey(cfg.typeIndex)==false)
  66. {
  67. _dataDic[ConstStoreId.CLOTHING_STORE_ID][cfg.typeIndex] = new List<ClothingShopCfg>();
  68. }
  69. _dataDic[ConstStoreId.CLOTHING_STORE_ID][cfg.typeIndex].Add(cfg);
  70. }
  71. ClothingShopCfg[] clothingCJDataArray = ClothingShopCfgCJArray.Instance.dataArray;
  72. foreach (ClothingShopCfg cfg in clothingCJDataArray)
  73. {
  74. if (_dataDic.ContainsKey(ConstStoreId.LUCKY_BOX_STORE_ID) == false)
  75. {
  76. _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID] = new Dictionary<int, List<ClothingShopCfg>>();
  77. }
  78. if (_dataDic[ConstStoreId.LUCKY_BOX_STORE_ID].ContainsKey(cfg.typeIndex) == false)
  79. {
  80. _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID][cfg.typeIndex] = new List<ClothingShopCfg>();
  81. }
  82. _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID][cfg.typeIndex].Add(cfg);
  83. }
  84. ClothingShopCfg[] clothingCJADataArray = ClothingShopCfgCJArray.Instance.dataArray;
  85. foreach (ClothingShopCfg cfg in clothingCJADataArray)
  86. {
  87. if (_dataDic.ContainsKey(ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID) == false)
  88. {
  89. _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID] = new Dictionary<int, List<ClothingShopCfg>>();
  90. }
  91. if (_dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID].ContainsKey(cfg.typeIndex) == false)
  92. {
  93. _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID][cfg.typeIndex] = new List<ClothingShopCfg>();
  94. }
  95. _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID][cfg.typeIndex].Add(cfg);
  96. }
  97. }
  98. }
  99. }