ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/FunctionNPCCommon.py
@@ -57,17 +57,19 @@
import PlayerControl
import ItemCommon
import ShareDefine
import DataRecordPack
import EventSrc
import PlayerFlashSale
#import EventSrc
import ChItem
import IpyGameDataPY
import PlayerRune
import PlayerSuccess
import GameFuncComm
import PlayerFairyCeremony
import PlayerSpringSale
import PyGameData
import random
import math
import time
#---------------------------------------------------------------------
##开始交易
# @param curPlayer 玩家实例
@@ -190,7 +192,16 @@
## 登录
def ShopItemOnLogin(curPlayer):
    if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_SuperGift):
        GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_SuperGift, 1)
        isGet = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftFirstRecord)
        if isGet:#首充奖励已领取则代表超值礼包已开启过,
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SuperGiftHasOpen, 1)
    SyncMysticalShopInfo(curPlayer)
    SyncShopItemTodayBuyCount(curPlayer)
    SyncSuperGiftInfo(curPlayer)
    return
##商店物品OnDay
@@ -198,6 +209,8 @@
# @return 
def ShopItemOnDay(curPlayer, onEventType):
    if onEventType == ShareDefine.Def_OnEventType:
        UpdataSuperGiftTime(curPlayer, True)
        OSSaleOpenMail(curPlayer)
        refreshType = [3]
    elif onEventType == ShareDefine.Def_OnEventTypeEx:
        refreshType = [4]
@@ -229,8 +242,14 @@
    __ResetShopItemBuyCount(curPlayer, [refreshType])
    return
def ShopItemOnCrossPKSeasonChange(curPlayer):
    ## 按跨服PK赛季重置
    refreshType = 8
    __ResetShopItemBuyCount(curPlayer, [refreshType])
    return
def __ResetShopItemBuyCount(curPlayer, onEventTypeList):
    #重置商店物品购买次数  1:周一0点刷新    2:周一5点刷新    3:每日0点刷新    4:每日5点刷新    5每月0点    6每月5点
    #重置商店物品购买次数  1:周一0点刷新    2:周一5点刷新    3:每日0点刷新    4:每日5点刷新    5每月0点    6每月5点   7每3天5点  8每赛季
    syncIndexList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetStoreCount()):
@@ -267,6 +286,49 @@
        syncIndexList.append(shopItem.GetID())
    if syncIndexList:
        SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True)
    return
def MysticalShopOpen(curPlayer, befLV, aftLV):
    ##神秘限购开启
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('Store', {'ShopType':16}, True)
    if not ipyDataList:
        return
    curTime = int(time.time())
    syncGoodsList = []
    for ipyData in ipyDataList:
        limitLV = ipyData.GetLimitLV()
        if befLV < limitLV and aftLV >= limitLV:
            goodsID = ipyData.GetID()
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ShopItemStartTime % goodsID, curTime)
            syncGoodsList.append(goodsID)
            GameWorld.DebugLog('神秘限购商品%s 开卖'%goodsID, curPlayer.GetID())
    if syncGoodsList:
        SyncMysticalShopInfo(curPlayer)
    return
def SyncMysticalShopInfo(curPlayer):
    ##神秘限购通知
    packData = ChPyNetSendPack.tagMCMysticalShopTimeInfo()
    packData.ShopTimeList = []
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('Store', {'ShopType':16}, True)
    curTime = int(time.time())
    for ipyData in ipyDataList:
        goodsID = ipyData.GetID()
        startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ShopItemStartTime % goodsID)
        if not startTime:
            continue
        if curTime - startTime >= ipyData.GetLimitValue():
            #超时的重置
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ShopItemStartTime % goodsID, 0)
        else:
            goodsTime = ChPyNetSendPack.tagMCMysticalShopTime()
            goodsTime.GoodsID = goodsID
            goodsTime.StartTime = startTime
            packData.ShopTimeList.append(goodsTime)
    if not packData.ShopTimeList:
        return
    packData.Count = len(packData.ShopTimeList)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
## 回购物品
@@ -321,7 +383,10 @@
# @param tick 时间戳
# @return 返回值真, 逻辑运行成功
def BuyItem(curPlayer, tick):
    if GameWorld.IsCrossServer():
        return
    buyItemList = IPY_GameWorld.IPY_CBuyItemList()    
    itemIndex = buyItemList.GetBuyItemIndex()
    if itemIndex < 0:
@@ -335,19 +400,33 @@
    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:
            GameWorld.DebugLog("限时特惠非活动中!state=%s" % (state), curPlayer.GetPlayerID())
            return
        shopTypeList = actInfo.get(ShareDefine.ActKey_ShopTypeList, [])
        shopTypeList = PlayerSpringSale.GetShopTypeList(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
        if not shopTypeList:
            return
        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
        
@@ -376,7 +455,7 @@
        if limitBuyCnt == -1:
            GameWorld.DebugLog("    vip%s才能购买"%viplv)
            return
    curDayBuyCnt = 0
    dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex
    if limitBuyCnt > 0:
@@ -389,7 +468,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()
@@ -418,8 +500,8 @@
        if not curItem:
            GameWorld.ErrLog("Store shop item error! shopType=%s,itemID=%s" % (shopType, itemID))
            return
        packType = ShareDefine.rptRune if curItem.GetType() == ChConfig.Def_ItemType_Rune else IPY_GameWorld.rptItem
        needSpace = int(math.ceil(float(itemCnt) / curItem.GetPackCount()))
        packType = ChConfig.GetItemPackType(curItem.GetType())
        needSpace = ItemControler.GetItemNeedPackCount(packType, curItem, itemCnt)
        needPackSpaceDict[packType] = needPackSpaceDict.get(packType, 0) + needSpace
        
        if i == 0:
@@ -430,30 +512,62 @@
    
    GameWorld.DebugLog("购买物品: shopType=%s,itemIndex=%s,clientBuyCount=%s,totalItemList=%s,mainItemID=%s,needPackSpaceDict=%s" 
                       % (shopType, itemIndex, clientBuyCount, totalItemList, mainItemID, needPackSpaceDict), curPlayer.GetPlayerID())
    mailKey = ipyData.GetMailKey()
    isLackPack = False #是否背包不足
    for packType, needSpace in needPackSpaceDict.items():
        if needSpace > ItemCommon.GetItemPackSpace(curPlayer, packType, needSpace):
            curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoPlace)
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [packType])
            return
            isLackPack = True
            if mailKey:
                break
            else:
                curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoPlace)
                PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [packType])
                return
    sendMailKey = mailKey if isLackPack and mailKey else '' #背包不足且配置了mailKey的才发邮件
        
    # 购买限制条件扩展
    if CheckBuyItemLimitEx(curPlayer, shopType, itemIndex, mainItemID, ipyData.GetLimitValue()):
        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, sendMailKey])
        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, sendMailKey, ipyData)
    return
def DoBuyStoreItem(curPlayer, itemIndex, clientBuyCount, totalItemList, mainItemID, limitBuyCnt, sendMailKey, ipyData=None):
    if not ipyData:
        ipyData = IpyGameDataPY.GetIpyGameData("Store", itemIndex)
    priceType, itemPrice = ipyData.GetMoneyType(), ipyData.GetMoneyNum()
    itemPrice *= clientBuyCount
    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])
        
@@ -461,23 +575,26 @@
                "ItemPrice":itemPrice, "MoneyType":priceType, 
                "BeforeMoney":beforeMoney, "AfterMoney":afterMoney}
    isForceEvent = priceType not in [IPY_GameWorld.TYPE_Price_Silver_Money]
    itemControl = ItemControler.PlayerItemControler(curPlayer)
    for itemID, itemCount, isBind in totalItemList:
        curItemObj = ItemControler.GetOutPutItemObj(itemID, itemCount, isBind)
        if not curItemObj:
            continue
        userData = curItemObj.GetUserData()
        packType = ShareDefine.rptRune if curItemObj.GetType() == ChConfig.Def_ItemType_Rune else IPY_GameWorld.rptItem
        if not itemControl.PutInItem(packType, curItemObj, event=[ChConfig.ItemGive_BuyItem, isForceEvent, dataDict]):
        if not sendMailKey:
            packType = ChConfig.GetItemPackType(curItemObj.GetType())
            if not itemControl.PutInItem(packType, curItemObj, event=[ChConfig.ItemGive_BuyItem, isForceEvent, dataDict]):
                curItemObj.Clear()
                continue
        else:
            curItemObj.Clear()
            continue
        EventShell.EventRespons_BuyItem(curPlayer, itemID, itemCount)
        
        if ipyData.GetNotifyMark() and itemID == mainItemID:
            PlayerControl.WorldNotify(0, ipyData.GetNotifyMark(), [curPlayer.GetName(), mainItemID, userData])
    if sendMailKey:
        PlayerControl.SendMailByKey(sendMailKey, [curPlayer.GetID()], totalItemList, detail=dataDict)
    #触发任务购买物品
    EventShell.EventRespons_ShopBuy(curPlayer, shopType)
    #curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrShopOK)
@@ -521,12 +638,21 @@
        if curFamilyLV <= 0:
            curFamilyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyLV)
        return curFamilyLV < limitValue
    if shopNPCID in [15]: # 限时特惠商店
        playerCreateRoleDays = GameWorld.GetCreateRoleDays(curPlayer)
        return playerCreateRoleDays != limitValue
    if shopNPCID in [15]: # 开服特惠商店
        #playerCreateRoleDays = GameWorld.GetCreateRoleDays(curPlayer)
        openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)+1
        return openServerDay != limitValue
    #烟花狂欢
    if itemIndex in IpyGameDataPY.GetFuncEvalCfg('CeremonyFireParty', 1, {}).values():
        return not PlayerFairyCeremony.IsCanBuyFireworks(curPlayer, itemIndex)
#    if itemIndex in dict(IpyGameDataPY.GetFuncEvalCfg('SuperGiftTimeList')):
#        return not CheckSuperGiftBuy(curPlayer, itemIndex)
    if shopNPCID == 16:#神秘限购
        startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ShopItemStartTime % itemIndex)
        curTime = int(time.time())
        return not startTime or curTime - startTime >= limitValue
#    
#    limitPlusDict = {shopItem.GetLimitPlusType1():shopItem.GetLimitPlusValue1(),
#                     shopItem.GetLimitPlusType2():shopItem.GetLimitPlusValue2(),
@@ -553,6 +679,64 @@
    # 默认不限制
    return False
def OSSaleOpenMail(curPlayer):
    #开服特惠开启邮件
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_OSSail):
        return
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)+1
    if openServerDay not in IpyGameDataPY.GetFuncEvalCfg('OSSaleOpenMail'):
        return
    addItemList = IpyGameDataPY.GetFuncEvalCfg('OSSaleOpenMail', 2)
    PlayerControl.SendMailByKey('SellMail1', [curPlayer.GetID()], addItemList)
    return
#超值礼包购买时间
def UpdataSuperGiftTime(curPlayer, isOnday=False):
    curTime = int(time.time())
    if isOnday:
        startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SuperGiftStartTime)
        if not startTime:
            return
        superGiftTimeList = IpyGameDataPY.GetFuncEvalCfg('SuperGiftTimeList')
        maxDay = max([info[1] for info in superGiftTimeList])
        if curTime - startTime >= maxDay * 86400:
            #活动结束 重置
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SuperGiftStartTime, 0)
    else:
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SuperGiftHasOpen):
            #老号已开启过超值礼包则不再开启
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SuperGiftStartTime, curTime)
        addItemList = IpyGameDataPY.GetFuncEvalCfg('SuperGiftTimeList', 2)
        PlayerControl.SendMailByKey('SellMail2', [curPlayer.GetID()], addItemList)
        SyncSuperGiftInfo(curPlayer)
    return True
def SyncSuperGiftInfo(curPlayer):
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SuperGiftStartTime)
    if not startTime:
        return
    packData = ChPyNetSendPack.tagMCSuperGiftInfo()
    packData.StartTime = startTime
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
def CheckSuperGiftBuy(curPlayer, giftID):
    #超值礼包是否可购买
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SuperGiftStartTime)
    if not startTime:
        return
    superGiftTimeDict = dict(IpyGameDataPY.GetFuncEvalCfg('SuperGiftTimeList'))
    totalDay = superGiftTimeDict.get(giftID, 0)
    if not totalDay:
        return
    curTime = int(time.time())
    if (curTime - startTime)/86400 >= totalDay:
        #已结束
        return
    return True
## 商店npcid
#  @param curPlayer 玩家实例
#  @return