Browse Source

商店购买

zhaoyang 3 years ago
parent
commit
51cc5be0f3

+ 1 - 1
GameClient/Assets/Game/CSShare

@@ -1 +1 @@
-Subproject commit 15fb3465d54e5c1e635c70aeeda339cc5fb7ae64
+Subproject commit 2d147924ec65a6eae6137bc96c60814f90302cd4

+ 10 - 0
GameClient/Assets/Game/HotUpdate/Constant/ConstBuyType.cs

@@ -0,0 +1,10 @@
+namespace GFGGame
+{
+    public class ConstBuyType
+    {
+        public const int TYPE_NORMAL = 0;//无类型兑换,无表格
+        public const int TYPE_ITEM = 1;//物品兑换,对应兑换表
+        public const int TYPE_SHOP = 2;//商店兑换,对应商店表
+
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/Constant/ConstBuyType.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b23433def6fb3d647b0aed7d6b9ac45d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Constant/ConstMessage.cs

@@ -38,5 +38,7 @@ namespace GFGGame
 
         public const string NOTICE_MAINSTORY_BOXBONUS_STATE = "NOTICE_MAINSTORY_BOXBONUS_STATE";
 
+        public const string SHOP_BUY = "SHOP_BUY";
+
     }
 }

+ 15 - 15
GameClient/Assets/Game/HotUpdate/Constant/ConstStoreId.cs

@@ -5,10 +5,10 @@ namespace GFGGame
 {
     public class ConstStoreId
     {
+        public const int CLOTHING_STORE_ID = 1;//服装店
+        public const int LUCKY_BOX_STORE_ID = 2;//抽卡兑换商店
+        public const int LUCKY_BOX_ACTIVITY_STORE_ID = 3;//抽卡活动兑换商店
         public const int DIAMOND_STORE_ID = 1;//钻石商店
-        public const int CLOTHING_STORE_ID = 2;//服装店
-        public const int LUCKY_BOX_STORE_ID = 3;//抽卡兑换商店
-        public const int LUCKY_BOX_ACTIVITY_STORE_ID = 4;//抽卡活动兑换商店
 
         public const string DIAMOND_STORE_TITLE = "钻石商城";//钻石商店
         public const string CLOTHING_STORE_TITLE = "服装店";//服装店
@@ -17,18 +17,18 @@ namespace GFGGame
 
         private static SortedList _storeTitleList;
 
-        public static SortedList CardStateList()
-        {
-            if (ConstStoreId._storeTitleList == null)
-            {
-                ConstStoreId._storeTitleList = new SortedList();
-                ConstStoreId._storeTitleList.Add(ConstStoreId.DIAMOND_STORE_ID, ConstStoreId.DIAMOND_STORE_TITLE);
-                ConstStoreId._storeTitleList.Add(ConstStoreId.CLOTHING_STORE_ID, ConstStoreId.CLOTHING_STORE_TITLE);
-                ConstStoreId._storeTitleList.Add(ConstStoreId.LUCKY_BOX_STORE_ID, ConstStoreId.LUCKY_BOX_STORE_TITLE);
-                ConstStoreId._storeTitleList.Add(ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID, ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_TITLE);
+        // public static SortedList CardStateList()
+        // {
+        //     if (ConstStoreId._storeTitleList == null)
+        //     {
+        //         ConstStoreId._storeTitleList = new SortedList();
+        //         ConstStoreId._storeTitleList.Add(ConstStoreId.DIAMOND_STORE_ID, ConstStoreId.DIAMOND_STORE_TITLE);
+        //         ConstStoreId._storeTitleList.Add(ConstStoreId.CLOTHING_STORE_ID, ConstStoreId.CLOTHING_STORE_TITLE);
+        //         ConstStoreId._storeTitleList.Add(ConstStoreId.LUCKY_BOX_STORE_ID, ConstStoreId.LUCKY_BOX_STORE_TITLE);
+        //         ConstStoreId._storeTitleList.Add(ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID, ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_TITLE);
 
-            }
-            return ConstStoreId._storeTitleList;
-        }
+        //     }
+        //     return ConstStoreId._storeTitleList;
+        // }
     }
 }

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Controller/BuyItemConteoller.cs

@@ -20,14 +20,14 @@ namespace GFGGame
         /// <param name="showTips">是否弹购买成功飘字,默认是</param>
         /// <param name="openSource">是否打开来源界面。默认否</param>
         /// <param name="count">兑换总量</param>
-        public static void Show(int itemId, int costId, int perCount, int perCostCount, int count, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
+        public static void Show(int itemId, int costId, int perCount, int perCostCount, int count, int buyType = ConstBuyType.TYPE_NORMAL, int shopType = 0, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
         {
             if (_buyCountView == null)
             {
                 _buyCountView = new BuyCountView();
             }
             _buyCountView.Reset();
-            _buyCountView.SetParams(itemId, costId, perCount, perCostCount, count, onSuccess, showTips, openSource, maxCount);
+            _buyCountView.SetParams(itemId, costId, perCount, perCostCount, count, buyType, shopType, onSuccess, showTips, openSource, maxCount);
             _buyCountView.Show();
 
         }

+ 12 - 0
GameClient/Assets/Game/HotUpdate/Data/ShopDataManager.cs

@@ -0,0 +1,12 @@
+namespace GFGGame
+{
+    public class ShopDataManager : SingletonBase<ShopDataManager>
+    {
+        // public int SHOP_TYPE;
+
+        public void BuyItem(int itemId, int itemCount, int shopType, ShopCfg shopCfg)
+        {
+            BuyItemConteoller.Show(itemId, shopCfg.costID, 1, shopCfg.costNum, itemCount, ConstBuyType.TYPE_SHOP, shopType, null, true, false, GameConst.MAX_COUNT_TO_BUY_ITEMS);
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/Data/ShopDataManager.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d01673f1de485f74b92ab376a01aee7b
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 24 - 0
GameClient/Assets/Game/HotUpdate/ServerProxy/ItemExchangeSProxy.cs

@@ -0,0 +1,24 @@
+using ET;
+
+namespace GFGGame
+{
+    public class ItemExchangeSProxy
+    {
+        public static async ETTask<bool> ItemExchange(int buyId, int buyCount)
+        {
+            M2C_ItemExchange response = null;
+            response = (M2C_ItemExchange)await MessageHelper.SendToServer(new C2M_ItemExchange() { ItemId = buyId, times = buyCount });
+            if (response != null)
+            {
+                if (response.Error == ErrorCode.ERR_Success)
+                {
+
+                    EventAgent.DispatchEvent(ConstMessage.SHOP_BUY);
+                    return true;
+                }
+            }
+            return false;
+
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/ServerProxy/ItemExchangeSProxy.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8aa893b51b02934409834e12116af7d4
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 23 - 0
GameClient/Assets/Game/HotUpdate/ServerProxy/ShopSProxy.cs

@@ -0,0 +1,23 @@
+using ET;
+
+namespace GFGGame
+{
+    public class ShopSProxy
+    {
+        public static async ETTask<bool> ShopBuy(int shopType, int buyId, int buyCount)
+        {
+            M2C_ShopBuy response = null;
+            response = (M2C_ShopBuy)await MessageHelper.SendToServer(new C2M_ShopBuy() { ShopType = shopType, BuyId = buyId, BuyCount = buyCount });
+            if (response != null)
+            {
+                if (response.Error == ErrorCode.ERR_Success)
+                {
+
+                    EventAgent.DispatchEvent(ConstMessage.SHOP_BUY);
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/ServerProxy/ShopSProxy.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5c262a5856dc233469c89c4fdc475ca4
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 4
GameClient/Assets/Game/HotUpdate/Utils/ItemUtil.cs

@@ -8,7 +8,7 @@ namespace GFGGame
 {
     public class ItemUtil
     {
-        
+
         /// <param name="showTips">是否弹购买成功飘字,默认是</param>
         /// <param name="openSource">是否打开来源界面。默认否</param>
         /// <param name="showTxtBuyTips">是否显示购买提示</param>
@@ -25,7 +25,7 @@ namespace GFGGame
             }
             else
             {
-                BuyItemConteoller.Show(itemId, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, num, onSuccess, showTips, openSource, maxCount);
+                BuyItemConteoller.Show(itemId, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, num, ConstBuyType.TYPE_ITEM, 0, onSuccess, showTips, openSource, maxCount);
                 BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;
             }
         }
@@ -68,7 +68,7 @@ namespace GFGGame
             string showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买{0}/{1}次", lastBuyCount, currencyRatioCfg.maxLimit);
             BuyConfirmController.Show(ConstItemID.POWER, currencyRatioCfg.num, currencyRatioCfg.costId, currencyRatioCfg.costNum, () =>
             {
-                NumericHelper.RequestAddAttributePoint(GameGlobal.zoneScene , NumericType.PowerBuyTimes).Coroutine();
+                NumericHelper.RequestAddAttributePoint(GameGlobal.zoneScene, NumericType.PowerBuyTimes).Coroutine();
                 if (onSuccess != null)
                 {
                     onSuccess();
@@ -103,7 +103,7 @@ namespace GFGGame
         {
 
             ItemExchangeCfg currencyRatioCfg = GetCurrencyRatioCfgById(ConstItemID.DIAMOND_RED);
-            BuyItemConteoller.Show(currencyRatioCfg.id, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, value > 0 ? value : currencyRatioCfg.num, onSuccess, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
+            BuyItemConteoller.Show(currencyRatioCfg.id, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, value > 0 ? value : currencyRatioCfg.num, ConstBuyType.TYPE_ITEM, 0, onSuccess, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
             BuyItemConteoller.showTxtBuyTips = true;
         }
         /// <summary>

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

@@ -161,7 +161,9 @@ namespace GFGGame
             }
             if (_selectedItemId > 0)
             {
-                BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, _selectedItemCount, null, true, false, MAX_COUNT);
+                // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, _selectedItemCount, null, true, false, MAX_COUNT);
+                ShopDataManager.Instance.BuyItem(_cfgSelected.itemID, _selectedItemCount, _storeId, _cfgSelected);
+
             }
             // GuideController.TryGuideClothingShopViewBtnBug(_ui.m_compItemInfo.m_btnBuy);
         }
@@ -193,8 +195,8 @@ namespace GFGGame
         private void OnclickBtnBuy()
         {
             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);
-
+            // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
+            ShopDataManager.Instance.BuyItem(_cfgSelected.itemID, count, _storeId, _cfgSelected);
         }
         private void UpdateItemChange()
         {

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/CommonGame/BuyConfirmView.cs

@@ -87,7 +87,7 @@ namespace GFGGame
                                        {
                                            int costNeedCount = _costCount - ItemDataManager.GetItemNum(_costId);
                                            ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(_costId);
-                                           BuyItemConteoller.Show(_costId, (int)currencyRatioCfg.costId, (int)currencyRatioCfg.num, (int)currencyRatioCfg.costNum, costNeedCount, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
+                                           BuyItemConteoller.Show(_costId, (int)currencyRatioCfg.costId, (int)currencyRatioCfg.num, (int)currencyRatioCfg.costNum, costNeedCount, ConstBuyType.TYPE_ITEM, 0, null, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
                                        }));
                     OnClickBtnCancel();
                 }

+ 29 - 15
GameClient/Assets/Game/HotUpdate/Views/CommonGame/BuyCountView.cs

@@ -23,8 +23,11 @@ namespace GFGGame
         private int _maxCount;
         private bool _openSource;
         private bool _showTips;
+        private int _buyType;
+        private int _shopType;
         private Action _onSuccess;
 
+
         public override void Dispose()
         {
             base.Dispose();
@@ -60,7 +63,7 @@ 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, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
+        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)
         {
             _itemId = itemId;
             _costId = costId;
@@ -71,6 +74,8 @@ namespace GFGGame
             _maxCount = maxCount;
             _openSource = openSource;
             _showTips = showTips;
+            _buyType = buyType;
+            _shopType = shopType;
         }
         protected override void OnShown()
         {
@@ -105,8 +110,6 @@ namespace GFGGame
             int count = int.Parse(_ui.m_txtCount.text.Trim());
 
             int price = (int)Math.Ceiling((decimal)count / _perCount) * _perCostCount;
-            // int price = ItemUtil.CostItemCount(_itemId, count);
-
             _ui.m_txtPrice.text = "" + price;
             SetBtnState();
         }
@@ -216,7 +219,7 @@ namespace GFGGame
             }
 
         }
-        private void OnClickBtnSure()
+        private async void OnClickBtnSure()
         {
             int count = int.Parse(_ui.m_txtCount.text.Trim());
             int price = int.Parse(_ui.m_txtPrice.text.Trim());
@@ -243,13 +246,25 @@ namespace GFGGame
                 else
                 {
                     int buyCount = price / _perCostCount * _perCount;
-                    ItemUtil.AddItemUseCost(_itemId, buyCount, _costId, price);
-                    // GuideController.HideGuide();
+                    // ItemUtil.AddItemUseCost(_itemId, buyCount, _costId, price);
+                    bool result = false;
+                    // result
+                    switch (_buyType)
+                    {
+                        case ConstBuyType.TYPE_NORMAL:
+                            break;
+                        case ConstBuyType.TYPE_ITEM:
+                            result = await ItemExchangeSProxy.ItemExchange(_itemId, count);
+                            break;
+                        case ConstBuyType.TYPE_SHOP:
+                            result = await ShopSProxy.ShopBuy(_shopType, _itemId, count);
+                            break;
+                    }
                     if (_onSuccess != null)
                     {
                         _onSuccess();
                     }
-                    if (_showTips)
+                    if (result && _showTips)
                     {
                         PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS);
                     }
@@ -287,14 +302,6 @@ namespace GFGGame
             Reset();
 
         }
-        protected override void UpdateToCheckGuide(object param)
-        {
-            if (!ViewManager.CheckIsTopView(this.viewCom)) return;
-
-            GuideController.TryGuide(_ui.m_btnSure, ConstGuideId.BUY_CLOTHING, 3, "找到需要的物品了,点击购买吧");
-        }
-
-
         /// <summary>
         /// 是否显示购买提示
         /// </summary>
@@ -306,5 +313,12 @@ namespace GFGGame
                 _ui.m_txtBuyTips.visible = value;
             }
         }
+
+        protected override void UpdateToCheckGuide(object param)
+        {
+            if (!ViewManager.CheckIsTopView(this.viewCom)) return;
+
+            GuideController.TryGuide(_ui.m_btnSure, ConstGuideId.BUY_CLOTHING, 3, "找到需要的物品了,点击购买吧");
+        }
     }
 }