From fea76cc7386e6c35cfe0f4910f066d04d24061f0 Mon Sep 17 00:00:00 2001
From: xdh <xiefantasy@qq.com>
Date: 星期六, 13 十月 2018 14:26:42 +0800
Subject: [PATCH] 4075 【后端】限时抢购开发

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py
index b3684b9..6774b4b 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py
@@ -57,7 +57,7 @@
 import PlayerControl
 import ItemCommon
 import ShareDefine
-import DataRecordPack
+import PlayerFlashSale
 #import EventSrc
 import ChItem
 import IpyGameDataPY
@@ -340,8 +340,8 @@
     if not ipyData:
         return
     shopType = ipyData.GetShopType()
-    
-    if ipyData.GetOperationActionShop():
+    operationActionShopType = ipyData.GetOperationActionShop()
+    if operationActionShopType == 1:
         actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {})
         state = actInfo.get(ShareDefine.ActKey_State, 0)
         if not state:
@@ -353,6 +353,20 @@
         actShopType = shopTypeList[-1] if state > len(shopTypeList) else shopTypeList[state - 1]
         if shopType != actShopType:
             GameWorld.DebugLog("限时特惠非活动中的商店类型!state=%s,shopType=%s,actShopType=%s,shopTypeList=%s" 
+                               % (state, shopType, actShopType, shopTypeList), curPlayer.GetPlayerID())
+            return
+    elif operationActionShopType == 2:
+        actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FlashSale, {})
+        state = actInfo.get(ShareDefine.ActKey_State, 0)
+        if not state:
+            GameWorld.DebugLog("限时抢购非活动中!state=%s" % (state), curPlayer.GetPlayerID())
+            return
+        shopTypeList = PlayerFlashSale.GetShopTypeList(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0), state)
+        if not shopTypeList:
+            return
+        actShopType = shopTypeList[0]
+        if shopType != actShopType:
+            GameWorld.DebugLog("限时抢购非活动中的商店类型!state=%s,shopType=%s,actShopType=%s,shopTypeList=%s" 
                                % (state, shopType, actShopType, shopTypeList), curPlayer.GetPlayerID())
             return
         
@@ -381,7 +395,7 @@
         if limitBuyCnt == -1:
             GameWorld.DebugLog("    vip%s才能购买"%viplv)
             return
-        
+    
     curDayBuyCnt = 0
     dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex
     if limitBuyCnt > 0:
@@ -394,7 +408,10 @@
             GameWorld.DebugLog("BuyShopItem 修正购买次数!shopType=%s,itemIndex=%s,clientBuyCount=%s,canBuyCnt=%s" 
                                % (shopType, itemIndex, clientBuyCount, canBuyCnt))
             clientBuyCount = canBuyCnt
-            
+    serverLimitCnt = ipyData.GetServerLimitCnt()
+    if serverLimitCnt > 0:
+        clientBuyCount = min(serverLimitCnt, clientBuyCount)
+        
     itemID, itemCount, isBind = ipyData.GetItemID(), ipyData.GetItemCnt(), ipyData.GetIsBind()
     itemListEx = ipyData.GetItemListEx()
     priceType, itemPrice = ipyData.GetMoneyType(), ipyData.GetMoneyNum()
@@ -447,18 +464,43 @@
         GameWorld.Log("Store shop item buy limit! shopType=%s,itemIndex=%s,limitValue=%s" 
                       % (shopType, itemIndex, ipyData.GetLimitValue()), curPlayer.GetPlayerID())
         return
+    if not PlayerControl.HaveMoney(curPlayer, priceType, itemPrice):
+        curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoMoney)
+        return
     
+    if serverLimitCnt > 0: #全服限购判断放到最后面,GameServer直接加次数
+        if curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_StoreQueryState) == 1:
+            #已经在查询中, 不重复查询
+            GameWorld.DebugLog("全服购买次数已经在查询中, 不重复查询 itemIndex=%s" % itemIndex)
+            return
+        cmdStr = '%s' % ([itemIndex, serverLimitCnt, clientBuyCount, totalItemList, mainItemID, limitBuyCnt])
+        GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0,
+                                        "GetStoreServerBuyCnt", cmdStr, len(cmdStr))
+        #设置状态查询中
+        curPlayer.SetDict(ChConfig.Def_PlayerKey_StoreQueryState, 1)
+        return
     #-------------------------开始购买物品-----------------------------
+    DoBuyStoreItem(curPlayer, itemIndex, clientBuyCount, totalItemList, mainItemID, limitBuyCnt, ipyData)
+    
+    return
+
+def DoBuyStoreItem(curPlayer, itemIndex, clientBuyCount, totalItemList, mainItemID, limitBuyCnt, ipyData=None):
+    if not ipyData:
+        ipyData = IpyGameDataPY.GetIpyGameData("Store", itemIndex)
+    priceType, itemPrice = ipyData.GetMoneyType(), ipyData.GetMoneyNum()
+    shopType = ipyData.GetShopType()
+    
     beforeMoney = PlayerControl.GetMoney(curPlayer, priceType)
     infoDict = {"TotalItemList":totalItemList, "ClientBuyCount":clientBuyCount, "ShopType":shopType,
                 "ShopItemIndex":itemIndex, ChConfig.Def_Cost_Reason_SonKey:mainItemID}
-    if not PlayerControl.PayMoney(curPlayer, priceType, itemPrice, ChConfig.Def_Cost_BuyStoreItem, infoDict, clientBuyCount):
-        curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoMoney)
-        return
+    PlayerControl.PayMoney(curPlayer, priceType, itemPrice, ChConfig.Def_Cost_BuyStoreItem, infoDict, clientBuyCount)
+        
     afterMoney = PlayerControl.GetMoney(curPlayer, priceType)
     
     # 今日购买次数+1
     if limitBuyCnt > 0:
+        dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex
+        curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)
         PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, curDayBuyCnt + clientBuyCount)
         SyncShopItemTodayBuyCount(curPlayer, [itemIndex])
         

--
Gitblit v1.8.0