Browse Source

商店购买

zhaoyang 3 năm trước cách đây
mục cha
commit
f2c688833e

+ 49 - 55
GameClient/Assets/Game/HotUpdate/ExcelConfig/Manager/ClothingShopCfgManager.cs

@@ -4,21 +4,64 @@ namespace GFGGame
 {
     public class ClothingShopCfgManager : SingletonBase<ClothingShopCfgManager>
     {
-        private bool _inited;
+
         private Dictionary<int, Dictionary<int, List<ShopCfg>>> _dataDic = new Dictionary<int, Dictionary<int, List<ShopCfg>>>();
 
         public List<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
         {
-            List<ShopCfg> list = new List<ShopCfg>();
-            InitData();
-            if (_dataDic.ContainsKey(storeId) && _dataDic[storeId].ContainsKey(typeIndex))
+            ShopCfg[] shopCfgs = null;
+            switch (storeId)
             {
-                list = _dataDic[storeId][typeIndex];
-                SortItemListByScore(list, scoreType);
+                case ConstStoreId.CLOTHING_STORE_ID:
+                    shopCfgs = ShopCfgClothingArray.Instance.GetCfgs(typeIndex);
+                    break;
+                case ConstStoreId.LUCKY_BOX_STORE_ID:
+                    shopCfgs = ShopCfgCJArray.Instance.GetCfgs(typeIndex);
+
+                    break;
+                case ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID:
+                    shopCfgs = ShopCfgCJAArray.Instance.GetCfgs(typeIndex);
+                    break;
             }
+            List<ShopCfg> list = new List<ShopCfg>(shopCfgs);
+            SortItemListByScore(list, scoreType);
             return list;
         }
 
+        private List<ShopCfg> ShopCfgs(int storeId)
+        {
+            ShopCfg[] shopCfgs = null;
+            switch (storeId)
+            {
+                case ConstStoreId.CLOTHING_STORE_ID:
+                    shopCfgs = ShopCfgClothingArray.Instance.dataArray;
+                    break;
+                case ConstStoreId.LUCKY_BOX_STORE_ID:
+                    shopCfgs = ShopCfgCJArray.Instance.dataArray;
+
+                    break;
+                case ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID:
+                    shopCfgs = ShopCfgCJAArray.Instance.dataArray;
+                    break;
+            }
+            return new List<ShopCfg>(shopCfgs);
+        }
+        public ShopCfg GetShopCfg(int buyId, int shopType)
+        {
+            switch (shopType)
+            {
+                case ConstStoreId.CLOTHING_STORE_ID:
+                    return ShopCfgClothingArray.Instance.GetCfg(buyId);
+
+                case ConstStoreId.LUCKY_BOX_STORE_ID:
+
+                    return ShopCfgCJArray.Instance.GetCfg(buyId);
+                case ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID:
+                    return ShopCfgCJAArray.Instance.GetCfg(buyId);
+            }
+            return null;
+        }
+
         private List<ShopCfg> SortItemListByScore(List<ShopCfg> arrayList, int scoreType)
         {
             arrayList.Sort((ShopCfg a, ShopCfg b) =>
@@ -52,54 +95,5 @@ namespace GFGGame
             });
             return arrayList;
         }
-
-        private void InitData()
-        {
-            if (_inited)
-            {
-                return;
-            }
-            _inited = true;
-            ShopCfg[] clotiongDataArray = ShopCfgClothingArray.Instance.dataArray;
-            foreach (ShopCfg cfg in clotiongDataArray)
-            {
-                if (_dataDic.ContainsKey(ConstStoreId.CLOTHING_STORE_ID)==false){
-                    _dataDic[ConstStoreId.CLOTHING_STORE_ID] = new Dictionary<int, List<ShopCfg>>();
-                }
-                if (_dataDic[ConstStoreId.CLOTHING_STORE_ID].ContainsKey(cfg.typeIndex)==false)
-                {
-                    _dataDic[ConstStoreId.CLOTHING_STORE_ID][cfg.typeIndex] = new List<ShopCfg>();
-                }
-                _dataDic[ConstStoreId.CLOTHING_STORE_ID][cfg.typeIndex].Add(cfg);
-            }
-
-            ShopCfg[] clothingCJDataArray = ShopCfgCJArray.Instance.dataArray;
-            foreach (ShopCfg cfg in clothingCJDataArray)
-            {
-                if (_dataDic.ContainsKey(ConstStoreId.LUCKY_BOX_STORE_ID) == false)
-                {
-                    _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID] = new Dictionary<int, List<ShopCfg>>();
-                }
-                if (_dataDic[ConstStoreId.LUCKY_BOX_STORE_ID].ContainsKey(cfg.typeIndex) == false)
-                {
-                    _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID][cfg.typeIndex] = new List<ShopCfg>();
-                }
-                _dataDic[ConstStoreId.LUCKY_BOX_STORE_ID][cfg.typeIndex].Add(cfg);
-            }
-
-            ShopCfg[] clothingCJADataArray = ShopCfgCJArray.Instance.dataArray;
-            foreach (ShopCfg cfg in clothingCJADataArray)
-            {
-                if (_dataDic.ContainsKey(ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID) == false)
-                {
-                    _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID] = new Dictionary<int, List<ShopCfg>>();
-                }
-                if (_dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID].ContainsKey(cfg.typeIndex) == false)
-                {
-                    _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID][cfg.typeIndex] = new List<ShopCfg>();
-                }
-                _dataDic[ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID][cfg.typeIndex].Add(cfg);
-            }
-        }
     }
 }

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Views/ClothingShop/ClothingShopView.cs

@@ -162,7 +162,7 @@ namespace GFGGame
             if (_selectedItemId > 0)
             {
                 // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, _selectedItemCount, null, true, false, MAX_COUNT);
-                ShopDataManager.Instance.BuyItem(_cfgSelected.itemID, _selectedItemCount, _storeId, _cfgSelected);
+                ShopDataManager.Instance.BuyItem(_cfgSelected.id, _selectedItemCount, _storeId, _cfgSelected);
 
             }
             // GuideController.TryGuideClothingShopViewBtnBug(_ui.m_compItemInfo.m_btnBuy);
@@ -196,7 +196,7 @@ namespace GFGGame
         {
             int count = _selectedItemId > 0 && _cfgSelected.itemID == _selectedItemId ? _selectedItemCount : INIT_COUNT;
             // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
-            ShopDataManager.Instance.BuyItem(_cfgSelected.itemID, count, _storeId, _cfgSelected);
+            ShopDataManager.Instance.BuyItem(_cfgSelected.id, count, _storeId, _cfgSelected);
         }
         private void UpdateItemChange()
         {

+ 17 - 8
GameClient/Assets/Game/HotUpdate/Views/CommonGame/BuyCountView.cs

@@ -15,7 +15,7 @@ namespace GFGGame
         private float _delay = 300;
         private float longpress = 900;//大于900毫秒才算长按
 
-        private int _itemId;
+        private int _buyId;
         private int _costId;
         private int _perCount;
         private int _perCostCount;
@@ -25,6 +25,7 @@ namespace GFGGame
         private bool _showTips;
         private int _buyType;
         private int _shopType;
+        private int _itemId;
         private Action _onSuccess;
 
 
@@ -55,7 +56,7 @@ namespace GFGGame
         /// <summary>
         /// 
         /// </summary>
-        /// <param name="itemId">物品id</param>
+        /// <param name="buyId">购买物品对应的编号,非必须为物品Id</param>
         /// <param name="costId">消耗品id</param>
         /// <param name="perCount">单位兑换数量</param>
         /// <param name="perCostCount">单位消耗数量</param>
@@ -63,9 +64,17 @@ namespace GFGGame
         /// <param name="showTips">是否弹购买成功飘字,默认是</param>
         /// <param name="openSource">是否打开来源界面。默认否</param>
         /// <param name="count">兑换总量</param>
-        public void SetParams(int itemId, int costId, int perCount, int perCostCount, int count, int buyType, int shopType = 0, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
+        public void SetParams(int buyId, int costId, int perCount, int perCostCount, int count, int buyType, int shopType = 0, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
         {
-            _itemId = itemId;
+            if (buyType == ConstBuyType.TYPE_SHOP)
+            {
+                _itemId = ClothingShopCfgManager.Instance.GetShopCfg(buyId, shopType).itemID;
+            }
+            else
+            {
+                _itemId = buyId;
+            }
+            _buyId = buyId;
             _costId = costId;
             _perCount = perCount;
             _perCostCount = perCostCount;
@@ -232,7 +241,7 @@ namespace GFGGame
 
                     if (_openSource)
                     {
-                        if (_itemId == ConstItemID.DIAMOND_RED)
+                        if (_buyId == ConstItemID.DIAMOND_RED)
                         {
                             ItemUtil.AddDiamondPurple();
                         }
@@ -254,10 +263,10 @@ namespace GFGGame
                         case ConstBuyType.TYPE_NORMAL:
                             break;
                         case ConstBuyType.TYPE_ITEM:
-                            result = await ItemExchangeSProxy.ItemExchange(_itemId, count);
+                            result = await ItemExchangeSProxy.ItemExchange(_buyId, count);
                             break;
                         case ConstBuyType.TYPE_SHOP:
-                            result = await ShopSProxy.ShopBuy(_shopType, _itemId, count);
+                            result = await ShopSProxy.ShopBuy(_shopType, _buyId, count);
                             break;
                     }
                     if (_onSuccess != null)
@@ -288,7 +297,7 @@ namespace GFGGame
 
         public void Reset()
         {
-            _itemId = 0;
+            _buyId = 0;
             _costId = 0;
             _perCount = 0;
             _perCostCount = 0;