#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#---------------------------------------------------------------------  
 | 
#  
 | 
#---------------------------------------------------------------------  
 | 
##@package FunctionNPCCommon  
 | 
# @todo: ¹¦ÄÜNPC¹ÜÀíÆ÷  
 | 
#  
 | 
# @author: panwei  
 | 
# @date 2010-4-26  
 | 
# @version 4.4  
 | 
#  
 | 
# @note:   
 | 
#---------------------------------------------------------------------  
 | 
# @change: "2013-04-18 17:00" wdb ÎïÆ·ÑÕɫʹÓÃÐÞ¸Ä  
 | 
# @change: "2013-04-26 16:00" wdb npcÉ̵êÐÞ¸Ä  
 | 
# @change: "2013-05-03 17:00" wdb npcÉ̵êÅä±í·½Ê½ÐÞ¸Ä  
 | 
# @change: "2013-05-20 15:00" wdb ×°±¸¸½¼ÓÊôÐÔ½Ó¿ÚÐÞ¸Ä  
 | 
# @change: "2013-05-30 10:30" wdb ×°±¸±¦Ê¯ÏâǶµ÷Õû  
 | 
# @change: "2013-07-19 20:00" Alee Ìí¼Ó»Ø¹º  
 | 
# @change: "2013-07-22 17:00" Alee ÎïÆ·¿É°´ÊýÁ¿¹ºÂò  
 | 
# @change: "2013-10-12 21:10" Alee ÏµÍ³Ìáʾ  
 | 
# @change: "2013-10-22 11:10" Alee ÎïÆ·¼¼ÄÜÔöǿЧ¹û,ͳһº¯ÊýEquipAddAdditionEx  
 | 
# @change: "2013-11-08 22:30" Alee É̳ÇÌí¼Ó´ò¿×  
 | 
# @change: "2013-11-19 11:00" hxp Ð޸ijöÊÛÎïÆ·ÅжϽðÇ®ÉÏÏÞÂß¼  
 | 
# @change: "2014-01-16 13:54" xmnathan Õ½ÃËÉ̳ǹºÂò  
 | 
# @change: "2014-01-28 00:55" Alee ¶ñħÉ̵êĬÈÏ׿ԽºÍÌ××°  
 | 
# @change: "2014-02-12 14:00" Alee È¡ÏûºìÃû¹ºÂò³Í·£  
 | 
# @change: "2014-04-07 11:30" Alee ·â°üDWORDµ¼Ö½ӿÚint±¨´í£¬·À·¶·¶Î§¹ý´ó  
 | 
# @change: "2014-05-05 15:00" xmnathan Ì滻ϵͳÌáʾ  
 | 
# @change: "2014-05-21 17:25" xcc Ôö¼Óħ·½Ñ°±¦»ý·Ö¶Ò»»ÎïÆ·¹¦ÄÜ  
 | 
# @change: "2014-06-05 15:30" hxp É̵êNPCÎïÆ·¹ºÂòÔö¼ÓÿÈտɹºÂò´ÎÊýÉÏÏÞÖ§³Ö  
 | 
# @change: "2014-08-04 16:00" Alee Ì××°ÎïÆ·É̵êÐÞ¸Ä  
 | 
# @change: "2014-08-07 20:40" Alee ±¦²Ø»ý·Ö¶Ò»»×¿Ô½ÊôÐÔ×°±¸¹Ì¶¨2ÌõÊôÐÔ  
 | 
# @change: "2014-10-20 16:20" Alee ¶Ò»»Ì××°3׿Խ  
 | 
# @change: "2014-11-05 15:00" Alee É̵깺Âò°ó¶¨ÐÞ¸Ä  
 | 
# @change: "2014-12-11 16:30" hxp É̵ê¶Ò»»×°±¸Ôö¼ÓÖ§³ÖÅäÖÃ×°±¸¶ÔӦ׿ԽÌõÊý  
 | 
# @change: "2015-01-14 00:30" hxp Ôö¼ÓÎïÆ·±ä¸üʼþ»ã±¨  
 | 
# @change: "2015-01-14 16:40" ljd Ôö¼ÓÎïÆ·¶Ò»»ÉÌµê  
 | 
# @change: "2015-01-27 10:50" ljd Ôö¼Ó×°±¸ÎïÆ·À´Ô´±ê¼Ç  
 | 
# @change: "2015-04-03 18:00" hxp ·À·¶»ØÊÕÕ¾Òì³£Çé¿öÎïÆ·Ïûʧ¶øÃ»ÓÐÖØÖñê¼Çλµ¼ÖÂÊýÖµÔ½½ç  
 | 
# @change: "2015-04-16 19:10" ljd É̵긶Ǯʱ´«ÈëÖ§¸¶ÀàÐÍ  
 | 
# @change: "2015-04-27 22:00" hxp Ôö¼ÓBuyItemÁ÷Ïò  
 | 
# @change: "2016-07-20 14:30" hxp »õ±ÒÖ§¸¶Á÷ÏòÕûºÏ  
 | 
# @change: "2016-08-04 18:00" hxp ³öÊۻعº¼Û¸ñÐÞ¸Ä  
 | 
#---------------------------------------------------------------------  
 | 
#"""Version = 2016-08-04 18:00"""  
 | 
#---------------------------------------------------------------------  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
import GameWorld  
 | 
import EventShell  
 | 
import IPY_GameWorld  
 | 
import ItemControler  
 | 
import ChConfig  
 | 
import PlayerControl  
 | 
import ItemCommon  
 | 
import ShareDefine  
 | 
import PlayerFlashSale  
 | 
#import EventSrc  
 | 
import ChItem  
 | 
import IpyGameDataPY  
 | 
import PlayerRune  
 | 
import GameFuncComm  
 | 
import PlayerFairyCeremony  
 | 
import PlayerNewFairyCeremony  
 | 
import PlayerSpringSale  
 | 
import PyGameData  
 | 
  
 | 
import random  
 | 
import math  
 | 
import time  
 | 
  
 | 
# É̵êÀàÐͶ¨Òå  
 | 
ShopType_FairyCeremony = 19 # ÏɽçÊ¢µäÑÌ»¨  
 | 
  
 | 
g_mysticalShopDict = {} #ÉñÃØÉ̵ê{µÈ¼¶·¶Î§:[µÈ¼¶¶Î,{½ðÇ®ÀàÐÍ:¿â}]}  
 | 
#---------------------------------------------------------------------  
 | 
##¿ªÊ¼½»Ò×  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÕæ, Âß¼ÔËÐгɹ¦  
 | 
# @remarks ¿ªÊ¼½»Ò×  
 | 
def StartTrade(curPlayer, tick):  
 | 
  
 | 
    curActionObj = curPlayer.GetActionObj()  
 | 
    if curActionObj == None:  
 | 
        return  
 | 
      
 | 
    if curActionObj.GetGameObjType() != IPY_GameWorld.gotNPC:  
 | 
        return  
 | 
              
 | 
    curActionNPC = GameWorld.GetNPCManager().GetNPCByIndex(curActionObj.GetIndex())  
 | 
    curActionNPCID = curActionNPC.GetNPCID()  
 | 
      
 | 
    # ÉèÖõ±Ç°É̵êµÄnpcid  
 | 
    curPlayer.SetDict(ChConfig.Def_PlayerKey_TradeTagNPC, curActionNPCID)  
 | 
      
 | 
    #É趨Ϊ½ûÖ¹ÕûÀí±³°ü  
 | 
    curPlayer.SetForbiddenResetItem(1)  
 | 
    curPlayer.BeginSpecialEvent(ShareDefine.TYPE_Event_Shop)  
 | 
    return True  
 | 
  
 | 
#------------------------------------------------------------------------------   
 | 
## »ñȡԶ³ÌÉ̵êµÄnpc  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return Ô¶³ÌÉ̵êµÄnpc  
 | 
def GetDirectNpcID():  
 | 
    return 0  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
##½áÊøÊ¼þ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÕæ, Âß¼ÔËÐгɹ¦  
 | 
# @remarks ½áÊøÊ¼þ  
 | 
def ExitEvent(curPlayer, tick):  
 | 
          
 | 
    EventShell.DoExitEvent(curPlayer)  
 | 
    return True  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
##ÇëÇóÉ̵êÎïÆ·ÁÐ±í  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÕæ, Âß¼ÔËÐгɹ¦  
 | 
def QueryNPCShopItem(playerIndex, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  
 | 
      
 | 
    #ʱ¼ä¼ä¸ôδµ½  
 | 
    if tick - curPlayer.GetTickByType(ChConfig.TYPE_Player_Tick_QueryFuncData) \  
 | 
       < ChConfig.TYPE_Player_Tick_Time[ChConfig.TYPE_Player_Tick_QueryFuncData]:  
 | 
        return  
 | 
      
 | 
    curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_QueryFuncData, tick)   
 | 
      
 | 
    #Ö±½Ó²éѯ£¬´æÔÚ¸ÃNPCID¾Í·¢°ü  
 | 
    tradeTagNPC = clientData.NPCShopID  
 | 
    GameWorld.GetGameData().FilterShopItemByShopType(tradeTagNPC)  
 | 
    shopItemCount = GameWorld.GetGameData().GetFilterShopItemCount()  
 | 
    if shopItemCount <= 0:  
 | 
        return  
 | 
      
 | 
#    # É̵ênpcidÓ뵱ǰ¶Ô»°npc¶ÔÓ¦,0ΪԶ³ÌÉÌµê  
 | 
#    tradeTagNPC = clientData.NPCShopID  
 | 
#    if tradeTagNPC != 0 and not CheckTradeTagNPC(curPlayer, tradeTagNPC):  
 | 
#        return  
 | 
      
 | 
    # ·¢ËÍÉÌÆ·½ñÈÕÒѹºÂò´ÎÊý  
 | 
    #SyncShopItemTodayBuyCount(curPlayer)  
 | 
      
 | 
    # ·¢ËÍÉ̵êÎïÆ·ÁÐ±í  
 | 
    curPlayer.BeginShopEx(tradeTagNPC)      
 | 
    return  
 | 
  
 | 
##ͬ²½É̵êNPCÎïÆ·½ñÈÕ¹ºÂò´ÎÊý  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param npcID  
 | 
# @param itemIndex -1ʱͬ²½¸ÃNPCËùÓÐÎïÆ·  
 | 
# @return   
 | 
def SyncShopItemTodayBuyCount(curPlayer, itemIndexList=[], isReset=False):  
 | 
    dayBuyCntInfo = ChPyNetSendPack.tagMCShopItemDayBuyCntInfo()  
 | 
    dayBuyCntInfo.DayBuyCntList = []  
 | 
    if itemIndexList:  
 | 
        for itemIndex in itemIndexList:  
 | 
            __AppendShopItemDayBuyCntInfo(curPlayer, itemIndex, dayBuyCntInfo.DayBuyCntList, isReset)  
 | 
    else:  
 | 
        ipyDataMgr = IpyGameDataPY.IPY_Data()  
 | 
        for i in xrange(ipyDataMgr.GetStoreCount()):  
 | 
            shopItem = ipyDataMgr.GetStoreByIndex(i)  
 | 
            if not shopItem.GetLimitCnt():  
 | 
                continue  
 | 
            dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID()  
 | 
            curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
            if curDayBuyCnt <= 0:  
 | 
                continue  
 | 
            __AppendShopItemDayBuyCntInfo(curPlayer, shopItem.GetID(), dayBuyCntInfo.DayBuyCntList, isReset)  
 | 
              
 | 
    dayBuyCntInfo.Count = len(dayBuyCntInfo.DayBuyCntList)  
 | 
    NetPackCommon.SendFakePack(curPlayer, dayBuyCntInfo)  
 | 
    return  
 | 
  
 | 
##Ôö¼ÓÉ̵êÎïÆ·½ñÈÕ¹ºÂò´ÎÊýÐÅÏ¢  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param npcID  
 | 
# @param itemIndex  
 | 
# @return   
 | 
def __AppendShopItemDayBuyCntInfo(curPlayer, itemIndex, dayBuyCntList, isReset):  
 | 
    itemDayBuyCnt = ChPyNetSendPack.tagMCShopItemDayBuyCnt()  
 | 
    itemDayBuyCnt.ItemIndex = itemIndex  
 | 
    dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex  
 | 
    curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
    itemDayBuyCnt.BuyCnt = curDayBuyCnt  
 | 
    itemDayBuyCnt.IsReset = int(isReset)  
 | 
    dayBuyCntList.append(itemDayBuyCnt)  
 | 
    return  
 | 
  
 | 
## µÇ¼  
 | 
def ShopItemOnLogin(curPlayer):      
 | 
    SyncMysticalLimitShopInfo(curPlayer)  
 | 
    SyncShopItemTodayBuyCount(curPlayer)  
 | 
    if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MysticalShopGoods % 0):  
 | 
        __DoMysticalShopRefresh(curPlayer, True, GameWorld.GetGameWorld().GetTick())  
 | 
    SyncMysticalShopInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
##É̵êÎïÆ·OnDay  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return   
 | 
def ShopItemOnDay(curPlayer, onEventType):  
 | 
    if onEventType == ShareDefine.Def_OnEventType:  
 | 
        OSSaleOpenMail(curPlayer)  
 | 
        refreshType = [3]  
 | 
        #ÉñÃØÉ̵êˢдÎÊýÖØÖà  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MysticalShopRefreshCnt, 0)  
 | 
        SyncMysticalShopInfo(curPlayer)  
 | 
          
 | 
    elif onEventType == ShareDefine.Def_OnEventTypeEx:  
 | 
        refreshType = [4]  
 | 
        openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)  
 | 
        isMixServer = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_IsMixServer)  
 | 
        if isMixServer:  
 | 
            mixServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_MixServerDay)  
 | 
            if mixServerDay % 3 == 0:  
 | 
                refreshType.append(7)  
 | 
        elif openServerDay % 3 == 0:  
 | 
            refreshType.append(7)  
 | 
    else:  
 | 
        return  
 | 
    ResetShopItemBuyCount(curPlayer, refreshType)  
 | 
    return  
 | 
  
 | 
##É̵êÎïÆ·OnWeek  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return   
 | 
def ShopItemOnWeek(curPlayer, onEventType):  
 | 
    if onEventType == ShareDefine.Def_OnEventType:  
 | 
        refreshType = [1]  
 | 
    elif onEventType == ShareDefine.Def_OnEventTypeEx:  
 | 
        refreshType = [2]  
 | 
    else:  
 | 
        return  
 | 
    ResetShopItemBuyCount(curPlayer, refreshType)  
 | 
    return  
 | 
  
 | 
##É̵êÎïÆ·OnMonth  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return   
 | 
def ShopItemOnMonth(curPlayer, onEventType):  
 | 
    if onEventType == ShareDefine.Def_OnEventType:  
 | 
        refreshType = 5  
 | 
    elif onEventType == ShareDefine.Def_OnEventTypeEx:  
 | 
        refreshType = 6  
 | 
    else:  
 | 
        return  
 | 
    ResetShopItemBuyCount(curPlayer, [refreshType])  
 | 
    return  
 | 
  
 | 
def ShopItemOnCrossPKSeasonChange(curPlayer):  
 | 
    ## °´¿ç·þPKÈü¼¾ÖØÖÃ  
 | 
    refreshType = 8  
 | 
    ResetShopItemBuyCount(curPlayer, [refreshType])  
 | 
    return  
 | 
  
 | 
def ResetShopItemBuyCount(curPlayer, resetTypeList):  
 | 
    #@param resetTypeList: ÐèÒªÖØÖõÄÀàÐÍÁÐ±í  
 | 
    #ÖØÖÃÉ̵êÎïÆ·¹ºÂò´ÎÊý  1£ºÖÜÒ»0µãˢР   2£ºÖÜÒ»5µãˢР   3£ºÃ¿ÈÕ0µãˢР   4£ºÃ¿ÈÕ5µãˢР   5ÿÔÂ0µã    6ÿÔÂ5µã   7ÿ3Ìì5µã  8ÿÈü¼¾  
 | 
    if not resetTypeList:  
 | 
        # Ôݶ¨±ØÐëÖ¸¶¨ÀàÐÍÁÐ±í£¬·ÀÖ¹ÖÕÉíÏÞ¹ºµÄÎó±»ÖØÖà  
 | 
        return  
 | 
      
 | 
    syncIndexList = []  
 | 
    ipyDataMgr = IpyGameDataPY.IPY_Data()  
 | 
    for i in xrange(ipyDataMgr.GetStoreCount()):  
 | 
        shopItem = ipyDataMgr.GetStoreByIndex(i)  
 | 
        if not shopItem.GetLimitCnt():  
 | 
            continue  
 | 
        if shopItem.GetRefreshType() not in resetTypeList:  
 | 
            continue  
 | 
        dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID()  
 | 
        curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
        if curDayBuyCnt <= 0:  
 | 
            continue  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, 0)  
 | 
        syncIndexList.append(shopItem.GetID())  
 | 
    if syncIndexList:  
 | 
        SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True)  
 | 
    return  
 | 
  
 | 
def ResetShopItemBuyCountByShopType(curPlayer, shopTypeList):  
 | 
    ##¸ù¾ÝÉ̵êÀàÐÍÖØÖÃÉ̵êÏÞ¹ºÎïÆ·´ÎÊý  
 | 
    syncIndexList = []  
 | 
    ipyDataMgr = IpyGameDataPY.IPY_Data()  
 | 
    for i in xrange(ipyDataMgr.GetStoreCount()):  
 | 
        shopItem = ipyDataMgr.GetStoreByIndex(i)  
 | 
        if not shopItem.GetLimitCnt():  
 | 
            continue  
 | 
        if shopItem.GetShopType() not in shopTypeList:  
 | 
            continue  
 | 
        dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID()  
 | 
        curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
        if curDayBuyCnt <= 0:  
 | 
            continue  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, 0)  
 | 
        syncIndexList.append(shopItem.GetID())  
 | 
    if syncIndexList:  
 | 
        SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True)  
 | 
    return  
 | 
  
 | 
def MysticalLimitShopOpen(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:  
 | 
        SyncMysticalLimitShopInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def SyncMysticalLimitShopInfo(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  
 | 
  
 | 
def CheckMysticalShopRefresh(curPlayer, tick):  
 | 
    ##ÉñÃØÉ̵êˢР 
 | 
    createRoleTime = curPlayer.GetCreateRoleTime()  
 | 
    diffTime = GameWorld.GetCurrentTime() - GameWorld.GetDateTimeByStr(createRoleTime, ChConfig.TYPE_Time_Format)  
 | 
    pastSeconds = diffTime.days*24*60*60 + diffTime.seconds  
 | 
    refreshTime = IpyGameDataPY.GetFuncCfg('MysteryShopRefresh', 4)  
 | 
    if refreshTime and pastSeconds % refreshTime == 0:  
 | 
        __DoMysticalShopRefresh(curPlayer, True, tick)  
 | 
    return  
 | 
  
 | 
#// A2 32 ÉñÃØÉ̵êˢР#tagCMRefreshMysticalShop  
 | 
#struct    tagCMRefreshMysticalShop  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#};  
 | 
def OnMysticalShopRefresh(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    __DoMysticalShopRefresh(curPlayer, False, tick)  
 | 
    return  
 | 
  
 | 
def __DoMysticalShopRefresh(curPlayer, isFree, tick):  
 | 
    global g_mysticalShopDict #{µÈ¼¶·¶Î§:[µÈ¼¶¶Î,{½ðÇ®ÀàÐÍ:¿â}]}  
 | 
    refreshTime = IpyGameDataPY.GetFuncCfg('MysteryShopRefresh', 4)  
 | 
    if not refreshTime:  
 | 
        return  
 | 
  
 | 
    lastTime = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_MysticalShopLastTime)  
 | 
    if lastTime and tick - lastTime < 1000:  
 | 
        #GameWorld.DebugLog('ÉñÃØÉ̵êˢУ¬¹ýÓÚÆµ·±£¡')  
 | 
        return  
 | 
    curPlayer.SetDict(ChConfig.Def_PlayerKey_MysticalShopLastTime, tick)  
 | 
    if not g_mysticalShopDict:  
 | 
        ipyMgr= IpyGameDataPY.IPY_Data()  
 | 
        for i in xrange(ipyMgr.GetMysteryShopCount()):  
 | 
            ipyData = ipyMgr.GetMysteryShopByIndex(i)  
 | 
            lvRange = ipyData.GetLVRange()  
 | 
            goodsID = ipyData.GetGoodsID()  
 | 
            goodsIpyData = IpyGameDataPY.GetIpyGameData('Store', goodsID)  
 | 
            if not goodsIpyData:  
 | 
                continue  
 | 
            moneyType = goodsIpyData.GetMoneyType()  
 | 
            weight = goodsIpyData.GetLimitValue()  
 | 
            lvkey = tuple(lvRange)  
 | 
            if lvkey not in g_mysticalShopDict:  
 | 
                g_mysticalShopDict[lvkey] = [lvkey[0], {}]  
 | 
                weightDict = {}  
 | 
            if moneyType not in g_mysticalShopDict[lvkey][1]:  
 | 
                g_mysticalShopDict[lvkey][1][moneyType] = []  
 | 
            weightDict[moneyType] = weightDict.get(moneyType, 0) + weight  
 | 
            g_mysticalShopDict[lvkey][1][moneyType].append([weightDict[moneyType], goodsID])  
 | 
    if not g_mysticalShopDict:  
 | 
        return   
 | 
    playerLV = curPlayer.GetLV()  
 | 
    curLVDan, shopDict = GameWorld.GetDictValueByRangeKey(g_mysticalShopDict, playerLV)  
 | 
    if not shopDict:  
 | 
        return  
 | 
    maxCnt = IpyGameDataPY.GetFuncCfg('MysteryShopGoods', 1)  
 | 
    goldGoodsCnt =GameWorld.GetResultByRandomList(IpyGameDataPY.GetFuncEvalCfg('MysteryShopGoods', 2))  
 | 
    if not goldGoodsCnt:  
 | 
        return  
 | 
    specialGoodsID = 0 #±Ø³öµÄÉÌÆ·ID  
 | 
    if not isFree:  
 | 
        #ÓÅÏȵÀ¾ß£¬ÔÙÏÉÓñ  
 | 
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  
 | 
        costItemID = IpyGameDataPY.GetFuncCfg('MysteryShopRefresh', 1)  
 | 
        costItemCntDict = IpyGameDataPY.GetFuncEvalCfg('MysteryShopRefresh', 2)  
 | 
        curRefreshCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MysticalShopRefreshCnt)  
 | 
        cntList = [int(cnt) for cnt in costItemCntDict.keys()]  
 | 
        cntList.sort()  
 | 
        costItemCnt = costItemCntDict[str(cntList[-1])]  
 | 
        for cnt in cntList:  
 | 
            if curRefreshCnt < cnt:  
 | 
                costItemCnt = costItemCntDict[str(cnt)]  
 | 
                break  
 | 
        enough, indexList, hasBind, lackCnt = ItemCommon.GetItem_FromPack_ByID_ExEx(costItemID, itemPack, costItemCnt)  
 | 
        costGold = 0  
 | 
        if not enough:  
 | 
            costGold = lackCnt * IpyGameDataPY.GetFuncCfg('MysteryShopRefresh', 3)  
 | 
            if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGold, ChConfig.Def_Cost_MysteryShopRefresh):  
 | 
                return  
 | 
        ItemCommon.ReduceItem(curPlayer, itemPack, indexList, costItemCnt, False, "MysteryShopRefresh")  
 | 
        curLVRefreshData = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MysticalShopLVRefreshCnt)  
 | 
        curLVRefreshCnt, lvDan = curLVRefreshData / 10000, curLVRefreshData % 10000   
 | 
        updLVRefreshCnt = 1 if curLVDan != lvDan else curLVRefreshCnt + 1 #µÈ¼¶¶Î±ä¸ü£¬ÖØÖøõȼ¶¶ÎµÄˢдÎÊý  
 | 
        updLVRefreshData = min(updLVRefreshCnt * 10000+curLVDan, ChConfig.Def_UpperLimit_DWord)  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MysticalShopLVRefreshCnt, updLVRefreshData)  
 | 
        specialRefreshCfg = IpyGameDataPY.GetFuncEvalCfg('MysteryShopRefresh', 5)  
 | 
        if curLVDan in specialRefreshCfg and updLVRefreshCnt == specialRefreshCfg[curLVDan][0]:  
 | 
            specialGoodsID = specialRefreshCfg[curLVDan][1]  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MysticalShopRefreshCnt, curRefreshCnt+1)  
 | 
          
 | 
    goldGoodsCnt = min(goldGoodsCnt, maxCnt)  
 | 
    sliverGoodsCnt = maxCnt - goldGoodsCnt  
 | 
    goodsResultList = []  
 | 
    if goldGoodsCnt:  
 | 
        goodsResultList += GameWorld.GetResultByRandomListEx(shopDict.get(IPY_GameWorld.TYPE_Price_Gold_Money, []), goldGoodsCnt, [])  
 | 
    if sliverGoodsCnt:  
 | 
        goodsResultList += GameWorld.GetResultByRandomListEx(shopDict.get(IPY_GameWorld.TYPE_Price_Silver_Money, []), sliverGoodsCnt, [])  
 | 
    if specialGoodsID and specialGoodsID not in goodsResultList:  
 | 
        goodsResultList[0] = specialGoodsID  
 | 
        GameWorld.DebugLog('ÉñÃØÉ̵êË¢ÐÂÌØÊâ¹æÔò£¬µÈ¼¶¶Î£º%s,updLVRefreshCnt=%s,specialGoodsID=%s'%(curLVDan, updLVRefreshCnt, specialGoodsID))  
 | 
      
 | 
    GameWorld.DebugLog('ÉñÃØÉ̵êË¢ÐÂisFree=%s,goldGoodsCnt=%s,sliverGoodsCnt=%s,goodsResultList=%s'%(isFree, goldGoodsCnt, sliverGoodsCnt, goodsResultList))  
 | 
    syncIndexList = []  
 | 
    for i in xrange(maxCnt):  
 | 
        goodsID = goodsResultList[i] if i < len(goodsResultList) else 0  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MysticalShopGoods % i, goodsID)  
 | 
          
 | 
        dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % goodsID  
 | 
        curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
        if curDayBuyCnt:  
 | 
            PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, 0)  
 | 
            syncIndexList.append(goodsID)  
 | 
    if syncIndexList:  
 | 
        SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True)  
 | 
    #֪ͨ  
 | 
    SyncMysticalShopInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def SyncMysticalShopInfo(curPlayer):  
 | 
    ##ÉñÃØÉ̵ê֪ͨ  
 | 
    packData = ChPyNetSendPack.tagMCMysticalShopInfo()  
 | 
    packData.RefreshCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MysticalShopRefreshCnt)  
 | 
    packData.GoodsList = []  
 | 
    maxCnt = IpyGameDataPY.GetFuncCfg('MysteryShopGoods', 1)  
 | 
    for i in xrange(maxCnt):  
 | 
        goodsID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MysticalShopGoods % i)  
 | 
        goodsInfo = ChPyNetSendPack.tagMCMysticalShopGoods()  
 | 
        goodsInfo.GoodsID = goodsID  
 | 
        packData.GoodsList.append(goodsInfo)  
 | 
    packData.Count = len(packData.GoodsList)  
 | 
    NetPackCommon.SendFakePack(curPlayer, packData)  
 | 
    return  
 | 
  
 | 
## »Ø¹ºÎïÆ·  
 | 
#  @param None  
 | 
#  @return None  
 | 
def BuyItemBack(curPlayer, clientPack, tick):  
 | 
    index = clientPack.Index  
 | 
  
 | 
    backPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptRecycle)  
 | 
    if index >= backPack.GetCount():  
 | 
        #¼Ù°üÍ˳ö  
 | 
        return  
 | 
      
 | 
    curItem = backPack.GetAt(index)  
 | 
    if not curItem or curItem.IsEmpty():  
 | 
        #ûÓÐÎïÆ·Í˳ö  
 | 
        return  
 | 
      
 | 
    realPutCount = curItem.GetCount()  
 | 
    itemControl = ItemControler.PlayerItemControler(curPlayer)  
 | 
    if not itemControl.CanPutInItem(IPY_GameWorld.rptItem,   
 | 
                                    curItem.GetItemTypeID(),   
 | 
                                    realPutCount,   
 | 
                                    curItem.GetIsBind()):  
 | 
        #ÎïÆ·²»ÄÜ·ÅÈëÍ˳ö  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [IPY_GameWorld.rptItem])  
 | 
        return   
 | 
      
 | 
    itemPrice, priceType = __GetItemSellPrice(curPlayer, curItem)  
 | 
    itemPrice = int(itemPrice) * realPutCount  
 | 
    if not priceType or not itemPrice:  
 | 
        return  
 | 
           
 | 
    #¸¶Ç®  
 | 
    infoDict = {ChConfig.Def_Cost_Reason_SonKey:curItem.GetItemTypeID()}  
 | 
    if not PlayerControl.PayMoney(curPlayer, priceType, itemPrice, ChConfig.Def_Cost_BuyItemBack, infoDict):  
 | 
        return  
 | 
      
 | 
    itemControl.PutInItem(IPY_GameWorld.rptItem, curItem, event=["BuyItemBack", False, {}])  
 | 
      
 | 
    itemIndexs = str(curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_DelPackIndex))  
 | 
    itemIndexs = itemIndexs.replace(str(index + 1), '')  
 | 
    if itemIndexs == '':  
 | 
        #ûÓÐÎïÆ·±£Áô 0  
 | 
        itemIndexs = '0'  
 | 
      
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_DelPackIndex, int(itemIndexs))  
 | 
    return  
 | 
  
 | 
def PayAutoBuyItem(curPlayer, lackItemDict, priceType, costType=ChConfig.Def_Cost_Unknown, infoDict={}, isCheck=False, shopItemIndexDict=None):  
 | 
    ''' Ö§¸¶×Ô¶¯¹ºÂòÎïÆ·ÏûºÄ£¬´ÓÉ̳ÇÖйºÂò£¬Ö±½Ó¿ÛÇ®£¬²»²úÉúÎïÆ·  
 | 
            Ò»°ãÓÃÓÚ»ù´¡É̵ê×Ô¶¯¹ºÂòÎïÆ·£¬²»¿¼ÂǸ´ÔÓµÄÏÞ¹ºÂß¼  
 | 
    @param isCheck: ÊÇ·ñÖ»ÊǼì²é£¬²»Ö´ÐÐʵ¼ÊÏûºÄÂß¼  
 | 
    @param shopItemIndexDict: Ö¸¶¨¹ºÂòµÄÉÌÆ·¶ÔÓ¦É̳DZíÉÌÆ·IDË÷Òý×ֵ䣬Èç¹ûûÓÐÖ¸¶¨ÉÌÆ·Ë÷Òý£¬Ôò°´ÏûºÄµÄ¼Û¸ñÀàÐÍ×Ô¶¯ËÑË÷ÉÌ³Ç±í  
 | 
    '''  
 | 
      
 | 
    addLimitCountInfo = {}  
 | 
    totalMoney = 0  
 | 
    # ¼ÆËã×Ô¶¯¹ºÂòÏûºÄ  
 | 
    for itemID, lackCnt in lackItemDict.items():  
 | 
        if lackCnt <= 0:  
 | 
            continue  
 | 
          
 | 
        curItem = GameWorld.GetGameData().GetItemByTypeID(itemID)  
 | 
        if not curItem:  
 | 
            return  
 | 
          
 | 
        if shopItemIndexDict and itemID in shopItemIndexDict:  
 | 
            itemIndex = shopItemIndexDict[itemID]  
 | 
            ipyData = IpyGameDataPY.GetIpyGameData("Store", itemIndex)  
 | 
        else:  
 | 
            ipyData = ItemCommon.GetShopItemPriceIpyData(itemID, priceType)  
 | 
        if not ipyData:  
 | 
            return  
 | 
          
 | 
        itemIndex = ipyData.GetID()  
 | 
        shopType = ipyData.GetShopType()  
 | 
        priceType = ipyData.GetMoneyType()  
 | 
        itemMoney = ipyData.GetMoneyNum()  
 | 
        limitCntList = ipyData.GetLimitCnt()  
 | 
        if limitCntList:  
 | 
            limitBuyCnt = limitCntList[0]  
 | 
            curDayBuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex)  
 | 
            canBuyCnt = max(0, limitBuyCnt - curDayBuyCnt)  
 | 
            if canBuyCnt < lackCnt:  
 | 
                GameWorld.Log("×Ô¶¯¹ºÂò´ÎÊý²»×㣡shopType=%s,itemIndex=%s,itemID=%s,limitBuyCnt=%s,curDayBuyCnt=%s,canBuyCnt=%s < %s"   
 | 
                              % (shopType, itemIndex, itemID, limitBuyCnt, curDayBuyCnt, canBuyCnt, lackCnt), curPlayer.GetPlayerID())  
 | 
                return  
 | 
            addLimitCountInfo[itemIndex] = lackCnt  
 | 
              
 | 
        totalMoney += (lackCnt * itemMoney)  
 | 
          
 | 
    if totalMoney <= 0:  
 | 
        return  
 | 
      
 | 
    if isCheck:  
 | 
        return PlayerControl.HaveMoney(curPlayer, priceType, totalMoney)  
 | 
      
 | 
    GameWorld.DebugLog("¿Û³ý×Ô¶¯¹ºÂòÏûºÄ: lackItemDict=%s,priceType=%s,totalMoney=%s,costType=%s,addLimitCountInfo=%s"   
 | 
                       % (lackItemDict, priceType, totalMoney, costType, addLimitCountInfo), curPlayer.GetPlayerID())  
 | 
      
 | 
    if not PlayerControl.PayMoney(curPlayer, priceType, totalMoney, costType, infoDict):  
 | 
        return  
 | 
      
 | 
    if addLimitCountInfo:  
 | 
        syncIndexList = []  
 | 
        for itemIndex, lackCnt in addLimitCountInfo.items():  
 | 
            curDayBuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex)  
 | 
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex, curDayBuyCnt + lackCnt)  
 | 
            syncIndexList.append(itemIndex)  
 | 
        SyncShopItemTodayBuyCount(curPlayer, syncIndexList)  
 | 
          
 | 
    return True  
 | 
  
 | 
##¹ºÂòÎïÆ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÕæ, Âß¼ÔËÐгɹ¦  
 | 
def BuyItem(curPlayer, tick):  
 | 
      
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
      
 | 
    buyItemList = IPY_GameWorld.IPY_CBuyItemList()      
 | 
    itemIndex = buyItemList.GetBuyItemIndex()  
 | 
    if itemIndex < 0:  
 | 
        return  
 | 
      
 | 
    clientBuyCount = buyItemList.GetBuyCount()  
 | 
    if not clientBuyCount:  
 | 
        return  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("Store", itemIndex)  
 | 
    if not ipyData:  
 | 
        return  
 | 
    shopType = ipyData.GetShopType()  
 | 
    operationActionShopType = ipyData.GetOperationActionShop()  
 | 
    if operationActionShopType == 1:  
 | 
        if not PlayerSpringSale.IsSpringSaleShopType(shopType):  
 | 
            return  
 | 
    elif operationActionShopType == 2:  
 | 
        if not PlayerFlashSale.IsFlashSaleShopType(shopType):  
 | 
            return  
 | 
          
 | 
    # ÎïÆ·ÐÅÏ¢  
 | 
    limitLV = ipyData.GetLimitLV()  
 | 
    if limitLV and curPlayer.GetLV() < limitLV:  
 | 
        return  
 | 
    LimitVIPLVList = ipyData.GetLimitVIPLV()  
 | 
    LimitCntList = ipyData.GetLimitCnt()  
 | 
    limitBuyCnt = 0  
 | 
    if LimitVIPLVList or LimitCntList:  
 | 
        if not LimitVIPLVList:  
 | 
            LimitVIPLVList = [0]  
 | 
        if not LimitCntList:  
 | 
            LimitCntList = [0]  
 | 
  
 | 
        if len(LimitVIPLVList) != len(LimitCntList):  
 | 
            GameWorld.Log("    ¹ºÂòÎïÆ·LimitVIPLV  LimitCnt ³¤¶È²»Í¬")  
 | 
            return  
 | 
        curVIPlv = curPlayer.GetVIPLv()  
 | 
        limitBuyCnt = -1  
 | 
        for i, viplv in enumerate(LimitVIPLVList):  
 | 
            if curVIPlv < viplv:  
 | 
                break  
 | 
            limitBuyCnt = LimitCntList[i]  
 | 
        if limitBuyCnt == -1:  
 | 
            GameWorld.DebugLog("    vip%s²ÅÄܹºÂò"%viplv)  
 | 
            return  
 | 
      
 | 
    curDayBuyCnt = 0  
 | 
    dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex  
 | 
    if limitBuyCnt > 0:  
 | 
        curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey)  
 | 
        canBuyCnt = max(0, limitBuyCnt - curDayBuyCnt)  
 | 
        if canBuyCnt <= 0:  
 | 
            GameWorld.DebugLog("BuyShopItem ½ñÈÕ¹ºÂò´ÎÊýÒÑÂú£¡shopType=%s,itemIndex=%s" % (shopType, itemIndex))  
 | 
            return  
 | 
        if clientBuyCount > canBuyCnt:  
 | 
            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()  
 | 
      
 | 
    itemPrice *= clientBuyCount  
 | 
    job = curPlayer.GetJob()  
 | 
    jobItemList = ipyData.GetJobItem()  
 | 
    totalItemList = []  
 | 
    if itemID:  
 | 
        jobItemID = GetShopJobItem(job, itemID, jobItemList)  
 | 
        totalItemList.append([jobItemID, itemCount * clientBuyCount, isBind])  
 | 
    for itemIDEx, itemCountEx, isBindEx in itemListEx:  
 | 
        jobItemID = GetShopJobItem(job, itemIDEx, jobItemList)  
 | 
        totalItemList.append([jobItemID, itemCountEx * clientBuyCount, isBindEx])  
 | 
    #ÔÊÐí¼ÛÇ®ÅäÖÃ0£¬ÓÃÀ´Ãâ·Ñ¹ºÂò  
 | 
    if not totalItemList:  
 | 
        GameWorld.ErrLog("Store shop item error! shopType=%s,totalItemList=%s,itemPrice=%s" % (shopType, totalItemList, itemPrice))  
 | 
        return  
 | 
      
 | 
    mainItemID = 0  
 | 
    needPackSpaceDict = {}  
 | 
    for i, itemInfo in enumerate(totalItemList):  
 | 
        itemID = itemInfo[0]  
 | 
        itemCnt = itemInfo[1]  
 | 
        curItem = GameWorld.GetGameData().GetItemByTypeID(itemID)  
 | 
        if not curItem:  
 | 
            GameWorld.ErrLog("Store shop item error! shopType=%s,itemID=%s" % (shopType, itemID))  
 | 
            return  
 | 
        packType = ChConfig.GetItemPackType(curItem)  
 | 
        needSpace = ItemControler.GetItemNeedPackCount(packType, curItem, itemCnt)  
 | 
        needPackSpaceDict[packType] = needPackSpaceDict.get(packType, 0) + needSpace  
 | 
          
 | 
        if i == 0:  
 | 
            mainItemID = itemID  
 | 
      
 | 
    if not mainItemID:  
 | 
        return  
 | 
      
 | 
    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):  
 | 
            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(), clientBuyCount):  
 | 
        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):  
 | 
        GameWorld.ErrLog("¹ºÂòÉ̳ÇÎïÆ·Êµ¼Ê¿Û³ý»õ±Òʱʧ°Ü: itemIndex=%s,clientBuyCount=%s,priceType=%s,itemPrice=%s"   
 | 
                         % (itemIndex, clientBuyCount, priceType, itemPrice))  
 | 
        return  
 | 
          
 | 
    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])  
 | 
          
 | 
    dataDict = {"ShopType":shopType, "ShopItemIndex":itemIndex, "ClientBuyCount":clientBuyCount,   
 | 
                "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, False, curPlayer=curPlayer)  
 | 
        if not curItemObj:  
 | 
            continue  
 | 
        userData = curItemObj.GetUserData()  
 | 
        if not sendMailKey:  
 | 
            packType = ChConfig.GetItemPackType(curItemObj)  
 | 
            if not itemControl.PutInItem(packType, curItemObj, event=[ChConfig.ItemGive_BuyItem, isForceEvent, dataDict]):  
 | 
                curItemObj.Clear()  
 | 
                continue  
 | 
        else:  
 | 
            curItemObj.Clear()  
 | 
        EventShell.EventRespons_BuyItem(curPlayer, itemID, itemCount)  
 | 
          
 | 
        if ipyData.GetNotifyMark() and itemID == mainItemID:  
 | 
            PlayerControl.WorldNotify(0, ipyData.GetNotifyMark(), [curPlayer.GetName(), mainItemID, userData])  
 | 
              
 | 
        # ¹ºÂòÓÀ¾ÃÊØ»¤Ê±É¾³ýÏÞÊ±ÊØ»¤  
 | 
        if itemID == 4101:  
 | 
            delGuardItem = ItemCommon.FindItemInPackByItemID(curPlayer, 4105, IPY_GameWorld.rptItem)  
 | 
            if delGuardItem:  
 | 
                ItemCommon.DelItem(curPlayer, delGuardItem, 1)  
 | 
                  
 | 
    if sendMailKey:  
 | 
        PlayerControl.SendMailByKey(sendMailKey, [curPlayer.GetID()], totalItemList, detail=dataDict)  
 | 
    #´¥·¢ÈÎÎñ¹ºÂòÎïÆ·  
 | 
    EventShell.EventRespons_ShopBuy(curPlayer, shopType)  
 | 
    #curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrShopOK)  
 | 
    SyncShoppingResult(curPlayer, itemIndex, clientBuyCount)  
 | 
      
 | 
    if shopType == ShopType_FairyCeremony:  
 | 
        PlayerFairyCeremony.OnBuyFireworks(curPlayer, itemIndex, clientBuyCount)  
 | 
#    if itemIndex in IpyGameDataPY.GetFuncEvalCfg('NewCeremonyFireParty', 1, {}).values():  
 | 
#        PlayerNewFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Fireworks, clientBuyCount)  
 | 
    return  
 | 
  
 | 
def GetShopJobItem(job, itemID, jobItemList):  
 | 
    ## »ñÈ¡É̳ÇÎïÆ·¶ÔÓ¦µÄÖ°ÒµÎïÆ·£¬ Ö°Òµ´Ó1¿ªÊ¼  
 | 
    for jobItemIDList in jobItemList:  
 | 
        if type(jobItemIDList) not in [list, tuple]:  
 | 
            GameWorld.ErrLog("É̳ÇÖ°ÒµÎïÆ·×é¸ñʽ´íÎó!shopItemID=%s,jobItemList=%s" % (itemID, jobItemList))  
 | 
            return itemID  
 | 
        if itemID in jobItemIDList:  
 | 
            if job <= 0 or job > len(jobItemIDList):  
 | 
                GameWorld.ErrLog("É̳ÇÖ°ÒµÎïÆ·ÅäÖôíÎó,ûÓиÃÖ°Òµ¶ÔÓ¦ÎïÆ·ID!shopItemID=%s,job=%s" % (itemID, job))  
 | 
                return itemID  
 | 
            return jobItemIDList[job - 1]  
 | 
    return itemID  
 | 
  
 | 
def SyncShoppingResult(curPlayer, itemIndex, itemCnt):  
 | 
    #֪ͨ¹ºÂò½á¹û  
 | 
    resultInfo = ChPyNetSendPack.tagMCShoppingResult()  
 | 
    resultInfo.ItemIndex = itemIndex  
 | 
    resultInfo.ItemCnt = itemCnt  
 | 
    NetPackCommon.SendFakePack(curPlayer, resultInfo)  
 | 
    return  
 | 
  
 | 
## É̵깺ÂòÎïÆ·ÏÞÖÆÌõ¼þÀ©Õ¹  
 | 
#  @param curPlayer Íæ¼ÒʵÀý  
 | 
#  @return   
 | 
def CheckBuyItemLimitEx(curPlayer, shopNPCID, itemIndex, curItemID, limitValue, clientBuyCount):  
 | 
    if shopNPCID == 7: #·ûÓ¡ÉÌµê  
 | 
        return not PlayerRune.GetIsOpenByRuneID(curPlayer, curItemID)  
 | 
    if shopNPCID in [8, 9, 10]: #ÏÉÃËÉÌµê  
 | 
        if curPlayer.GetFamilyID() == 0:  
 | 
            #ÎÞ¼Ò×å  
 | 
            return True  
 | 
        curFamilyLV = curPlayer.GetFamilyLV()  
 | 
        if curFamilyLV <= 0:  
 | 
            curFamilyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyLV)  
 | 
        return curFamilyLV < limitValue  
 | 
    if shopNPCID in [15]: # ¿ª·þÌØ»ÝÉÌµê  
 | 
        #playerCreateRoleDays = GameWorld.GetCreateRoleDays(curPlayer)  
 | 
        openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)+1  
 | 
        return openServerDay != limitValue  
 | 
      
 | 
    #ÏɽçÊ¢µä - ÑÌ»¨¿ñ»¶  
 | 
    if shopNPCID == ShopType_FairyCeremony:  
 | 
        return not PlayerFairyCeremony.IsCanBuyFireworks(curPlayer, itemIndex, clientBuyCount)  
 | 
      
 | 
    #ÁíÒ»¸öÏɽçÊ¢µä¿ÉÓÃÆäËûÉ̵êNPCID£¬ÕâÀïÏÈ×¢ÊÍ£¬Ö®ºóÔÙ¸Ä  
 | 
#    if itemIndex in IpyGameDataPY.GetFuncEvalCfg('NewCeremonyFireParty', 1, {}).values():  
 | 
#        return not PlayerNewFairyCeremony.IsCanBuyFireworks(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(),  
 | 
#                     shopItem.GetLimitPlusType3():shopItem.GetLimitPlusValue3(),  
 | 
#                     }  
 | 
#      
 | 
#    for limitType, limitValue in limitPlusDict.items():  
 | 
#        if limitType <= 0:  
 | 
#            continue  
 | 
#          
 | 
#        # ÓÅÏÈÅжÏNPC¶ÀÓÐµÄ  
 | 
#        callFunc = GameWorld.GetExecFunc(EventSrc, "FunctionNPCShopBuyCheck.CheckByNPC_%s_%s"   
 | 
#                                         % (shopNPCID, limitType))  
 | 
#          
 | 
#        if callFunc:  
 | 
#            return callFunc(curPlayer, shopItem.GetItemID(), limitValue)  
 | 
#          
 | 
#        # ¹«¹²ÏÞÖÆÌõ¼þÅÐ¶Ï  
 | 
#        callFunc = GameWorld.GetExecFunc(EventSrc, "FunctionNPCShopBuyCheck.CheckPublic_%s" % limitType)  
 | 
#          
 | 
#        if callFunc:  
 | 
#            return callFunc(curPlayer, shopItem.GetItemID(), limitValue)  
 | 
      
 | 
    # Ä¬Èϲ»ÏÞÖÆ  
 | 
    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  
 | 
  
 | 
  
 | 
## É̵ênpcid  
 | 
#  @param curPlayer Íæ¼ÒʵÀý  
 | 
#  @return   
 | 
def GetCurTradeTagNPC(curPlayer):  
 | 
    curActionNPCID = -1  
 | 
  
 | 
    # µ±Ç°É̵êµÄnpcid  
 | 
    tradeTagNPC = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_TradeTagNPC)  
 | 
    # Ô¶³ÌÉÌµê  
 | 
    if not tradeTagNPC:  
 | 
        return GetDirectNpcID()  
 | 
  
 | 
    # É̵ênpcidÓ뵱ǰ¶Ô»°npc¶ÔÓ¦  
 | 
    elif CheckTradeTagNPC(curPlayer, tradeTagNPC):  
 | 
        return tradeTagNPC  
 | 
      
 | 
    else:  
 | 
        GameWorld.ErrLog("GetCurStoreItemList:trade tag NPC not match:%s"%tradeTagNPC,  
 | 
                          curPlayer.GetPlayerID())  
 | 
             
 | 
    return curActionNPCID  
 | 
  
 | 
## ÅжϼǼµÄÉ̵ênpcidÊÇ·ñÕýÈ·  
 | 
#  @param curPlayer Íæ¼ÒʵÀý  
 | 
#  @param tradeTagNPC   
 | 
#  @return   
 | 
def CheckTradeTagNPC(curPlayer, tradeTagNPC):  
 | 
      
 | 
    curActionObj = curPlayer.GetActionObj()  
 | 
    if not curActionObj:  
 | 
        return False  
 | 
      
 | 
    if curActionObj.GetGameObjType() != IPY_GameWorld.gotNPC:  
 | 
        return False  
 | 
      
 | 
    curActionNPC = GameWorld.GetNPCManager().GetNPCByIndex(curActionObj.GetIndex())  
 | 
    if curActionNPC.GetNPCID() != tradeTagNPC:  
 | 
        return False  
 | 
  
 | 
    return True  
 | 
  
 | 
#--------------------³öÊÛÎïÆ·  
 | 
##³öÊÛÎïÆ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÕæ, Âß¼ÔËÐгɹ¦  
 | 
# @remarks ³öÊÛÎïÆ·  
 | 
def SellItem(curPlayer, tick):  
 | 
    #1¼ì²éʼþ·¢ÉúµÄ˳Ðò  
 | 
    sendData = IPY_GameWorld.IPY_CPlayerSellItem()  
 | 
    packType = sendData.GetPackType()  
 | 
    itemIndex = sendData.GetItemIndex()  
 | 
    shopType = ChConfig.Def_ShopType_NpcShop  
 | 
      
 | 
    return SellPackItem(curPlayer, packType, [itemIndex], shopType)  
 | 
  
 | 
#// A3 11 ÅúÁ¿³öÊÛÎïÆ· #tagCMSellItem  
 | 
#  
 | 
#struct    tagCMSellItem  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        PackType;        //±³°üÀàÐÍ  
 | 
#    BYTE        Count;            //Ë÷ÒýÊýÁ¿  
 | 
#    BYTE        ItemIndex[Count];        //ÎïÆ·Ë÷Òý  
 | 
#};  
 | 
def OnSellManyItem(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    packType = clientData.PackType  
 | 
    ItemIndexList = clientData.ItemIndex  
 | 
    if not ItemIndexList:  
 | 
        return  
 | 
    shopType = ChConfig.Def_ShopType_NpcShop  
 | 
    isOk = SellPackItem(curPlayer, packType, ItemIndexList, shopType)  
 | 
    if isOk:  
 | 
        curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitKeySell, 1)  
 | 
          
 | 
    return   
 | 
#---------------------------------------------------------------------  
 | 
##³öÊÛÖ¸¶¨±³°üÎïÆ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param packType ±³°üÀàÐÍ  
 | 
# @param itemIndex ÎïÆ·Ë÷Òý  
 | 
# @param shopType É̵êÀàÐÍ,1NPCÉ̵꣬2Ô¶³Ì··ÊÛ  
 | 
# @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý  
 | 
# @remarks ³öÊÛÖ¸¶¨±³°üÎïÆ·  
 | 
def SellPackItem(curPlayer, packType, itemIndexList, shopType):  
 | 
    backPack = curPlayer.GetItemManager().GetPack(packType)  
 | 
    if backPack == None:  
 | 
        return False  
 | 
      
 | 
    totalSellPriceDict = {}  
 | 
    hasSellOK = False  
 | 
    notForceRecordEquipTypeList = range(ChConfig.Def_ItemType_retWeapon, ChConfig.Def_ItemType_retNeck)  
 | 
    for itemIndex in itemIndexList:  
 | 
        curItem = backPack.GetAt(itemIndex)  
 | 
          
 | 
        if not __CheckItemSell(curPlayer, curItem):  
 | 
            continue  
 | 
        hasSellOK = True  
 | 
        #µ±Ç°ÎïÆ·ÊýÁ¿  
 | 
        curItemCount = curItem.GetCount()  
 | 
        #itemName = curItem.GetName()  
 | 
        #»ñµÃµ¥¸öÎïÆ·ÏúÊÛ¼Û¸ñ  
 | 
        curItemSellPrice, curItemSellType = __GetItemSellPrice(curPlayer, curItem)  
 | 
        #»ñµÃÕû×éÏúÊÛ¼Û¸ñ  
 | 
        curAllItemSellPrice = int(curItemSellPrice) * curItemCount  
 | 
        totalSellPriceDict[curItemSellType] = totalSellPriceDict.get(curItemSellType, 0) + curAllItemSellPrice  
 | 
        #GameWorld.Log('curItemSellPrice=%s,curAllItemSellPrice=%s,curItemCount=%s'%(curItemSellPrice,curAllItemSellPrice,curItemCount))  
 | 
          
 | 
        #===========================================================================================  
 | 
        # #ÒòÈռǼǼ¹ý´ó, Ìí¼Ó¼Ç¼ɸѡÌõ¼þ  
 | 
        # if ItemControler.ItemNeedRecord(curItem):  
 | 
        #    #Ïêϸ¼Ç¼װ±¸ÐÅÏ¢  
 | 
        #    DataRecordPack.DR_GetMoneyBySellPackItem(curPlayer, curItemSellType, curAllItemSellPrice)  
 | 
        #===========================================================================================  
 | 
          
 | 
        isForceDR = curItem.GetType() not in notForceRecordEquipTypeList and not ItemControler.ItemNotNeedRecord(curItem)  
 | 
        #ÎïÆ·Ïûʧ  
 | 
        ItemCommon.DelItem(curPlayer, curItem, curItemCount, False, ChConfig.ItemDel_SellPackItem, isForceDR=isForceDR)  
 | 
        #PutItemInBuyBackPack(curPlayer, curItem)  
 | 
    if not hasSellOK:  
 | 
        return False  
 | 
    for priceType, priceMoney in totalSellPriceDict.items():  
 | 
        #Íæ¼ÒÇ®Ôö¼Ó  
 | 
        addDataDict = {}  
 | 
        PlayerControl.GiveMoney(curPlayer, priceType, priceMoney, ChConfig.Def_GiveMoney_SellPackItem, addDataDict, False)  
 | 
        PlayerControl.NotifyCode(curPlayer, "GetMoney01", [priceType, priceMoney])  
 | 
    return True  
 | 
  
 | 
  
 | 
## ÊÛÂôÎïÆ·»Ø¹º±³°üµÄ´¦Àí, ·ÅÈë¿Õλ²»µþ¼Ó(±¾ÏîĿûÓлعº£¬ÏÈÆÁ±Î)  
 | 
#  @param None  
 | 
#  @return None  
 | 
def PutItemInBuyBackPack(curPlayer, curItem):  
 | 
    return  
 | 
    itemIndexs = str(curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_DelPackIndex))  
 | 
    backPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptRecycle)  
 | 
    emptyIndex = ItemCommon.GetEmptyIndexInPack(curPlayer, IPY_GameWorld.rptRecycle)  
 | 
    if emptyIndex == -1:  
 | 
        #Çå³ý¾ÉÎïÆ·  
 | 
        emptyIndex = int(itemIndexs[0]) - 1  
 | 
        item = backPack.GetAt(emptyIndex)  
 | 
        item.Clear()  
 | 
        itemIndexs = itemIndexs[1:]  
 | 
    else:  
 | 
        # Çå¿Õ¿Õ¸ñλ·À·¶, ·ÀÖ¹Òì³£Çé¿öÎïÆ·Ïûʧ¶øÃ»ÓÐÖØÖñê¼Çλµ¼ÖÂÊýÖµÔ½½ç  
 | 
        itemIndexs = itemIndexs.replace(str(emptyIndex + 1), '')  
 | 
        item = backPack.GetAt(emptyIndex)  
 | 
          
 | 
    itemIndexs = "%s%s"%(itemIndexs, emptyIndex + 1)  
 | 
      
 | 
    #·ÅÈëÐÂÎïÆ·  
 | 
    item.PutIn(curItem)  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_DelPackIndex, int(itemIndexs))  
 | 
    return  
 | 
  
 | 
  
 | 
##¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ³öÊÛ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param curItem ÎïÆ·ÊµÀý  
 | 
# @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý  
 | 
# @remarks ¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ³öÊÛ  
 | 
def __CheckItemSell(curPlayer, curItem) :  
 | 
    if not ItemCommon.CheckItemCanUse(curItem) or ItemControler.GetIsAuctionItem(curItem):  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_644055")  
 | 
        return  
 | 
      
 | 
    #if ItemControler.IsEventItem(curItem):  
 | 
    #    PlayerControl.NotifyCode(curPlayer, "itemuse_chenxin_31379")  
 | 
    #    return  
 | 
      
 | 
    if curItem.GetCanSell() == 0:  
 | 
        #²»ÄܳöÊÛµÄÎïÆ·,ÎÞ·¨³öÊÛ  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_272921")  
 | 
        return  
 | 
      
 | 
    #»ñµÃµ¥¸öÎïÆ·ÏúÊÛ¼Û¸ñ  
 | 
    itemPrice , priceType = __GetItemSellPrice(curPlayer, curItem)  
 | 
    itemPrice = int(itemPrice) * curItem.GetCount()  
 | 
      
 | 
    if not itemPrice or not priceType:  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_272921")  
 | 
        return  
 | 
      
 | 
    if not PlayerControl.CanGiveMoney(curPlayer, priceType, itemPrice):  
 | 
        # ¶Ô²»Æð£¬ÄúЯ´øµÄ½ðÇ®ÒѾ´ïÉÏÏÞ,²Ù×÷ÎÞЧ  
 | 
        #PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_609765")  
 | 
        return  
 | 
          
 | 
    return True  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
##»ñµÃÎïÆ·µÄ³öÊÛ¼Û¸ñ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param curItem ÎïÆ·ÊµÀý  
 | 
# @return ·µ»ØÖµ, ÎïÆ·µÄ³öÊÛ¼Û¸ñ  
 | 
# @remarks »ñµÃÎïÆ·µÄ³öÊÛ¼Û¸ñ  
 | 
def __GetItemSellPrice(curPlayer, curItem):  
 | 
    #ΪÅäºÏ¿Í»§¶Ë,½øÐÐÒÔÏÂÂß¼(ÏòÉÏÈ¡Õû)  
 | 
    #2012-03-26 jiang Ä;ÃÕâÀï²»½øÐгýChConfig.Def_EndureRepairParameterµÄת»»¸ÃÓй«Ê½×Ô¼º¼ÆËã  
 | 
    #curItemEndure = curItem.GetCurDurg()  
 | 
    #curItemMaxEndure = curItem.GetMaxEndure()  
 | 
      
 | 
    # Ð޸Ĵ˺¯ÊýÇëͬʱÐ޸ĠÍÑ»ú¹Ò³öÊÛ  
 | 
    #µ±Ç°ÎïÆ·¼Û¸ñ Ô¼Û³öÊÛ  
 | 
    priceType = curItem.GetGoldPaperPrice()  
 | 
    if not priceType:  
 | 
        priceType = IPY_GameWorld.TYPE_Price_Silver_Money  
 | 
    curItemPrice = curItem.GetSilverPrice()  
 | 
    return curItemPrice, priceType  
 | 
  
 | 
##¼ì²éÍæ¼Ò¿É·ñ¿ªÊ¼NPCʼþ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý  
 | 
# @remarks ¼ì²éÍæ¼Ò¿É·ñ¿ªÊ¼NPCʼþ  
 | 
def CheckPlayerCanStateEvent(curPlayer):  
 | 
    if curPlayer.GetPlayerAction() not in ChConfig.Def_Player_DoEvent_State :  
 | 
        #CannotDoing ¶Ô²»Æð£¬Äúµ±Ç°×´Ì¬ÎÞ·¨½øÐд˲Ù×÷£¬²Ù×÷ÎÞЧ  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_740826")  
 | 
        return False  
 | 
      
 | 
    return True  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
##¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ·ÅÈëºÏ³É±³°ü.  
 | 
# @param curItem ÎïÆ·ÊµÀý  
 | 
# @return ²¼¶ûÖµ  
 | 
# @remarks ¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ·ÅÈëºÏ³É±³°ü  
 | 
def __CheckItemCanPutInComposePack(curItem):  
 | 
    return curItem.GetType() in ChConfig.Def_Compose_Can_Put_List  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
##ͨÓñ³°ü·ÅÈë²Ù×÷  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param srcBackpack Æðµã±³°ü  
 | 
# @param desBackPack Ä¿±ê±³°ü  
 | 
# @param srcIndex ÆðµãË÷Òý  
 | 
# @param destIndex Ä¿±êË÷Òý  
 | 
# @param putItemCount ·ÅÈëÊýÁ¿  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÎÞÒâÒå  
 | 
# @remarks Í¨Óñ³°ü·ÅÈë²Ù×÷  
 | 
def BackpackOperate(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex, putItemCount, tick):  
 | 
    #»ñµÃÐèÒª²Ù×÷µÄÎïÆ·µÄÎïÆ·  
 | 
    scrItem = __GetBackPackOperateItem(curPlayer, srcBackpack, desBackPack, srcIndex)  
 | 
      
 | 
    if scrItem == None:  
 | 
        return  
 | 
  
 | 
    itemControl = ItemControler.PlayerItemControler(curPlayer)  
 | 
      
 | 
    if not itemControl.CanPutInItem(desBackPack, scrItem.GetItemTypeID(), putItemCount, scrItem.GetIsBind()):  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [desBackPack])     
 | 
        return  
 | 
      
 | 
    #ÍÏ×§ÎïÆ·  
 | 
    ItemControler.DragItem(curPlayer, srcBackpack, srcIndex, desBackPack, destIndex, putItemCount)  
 | 
    return  
 | 
#---------------------------------------------------------------------  
 | 
##ͨÓñ³°ü²Ù×÷¼ì²é  
 | 
# @param scrItem ·ÅÈëÎïÆ·  
 | 
# @param desBackPack Ä¿±ê±³°ü  
 | 
# @return ²¼¶ûÖµ  
 | 
# @remarks Í¨Óñ³°ü²Ù×÷¼ì²é  
 | 
def __CheckBackPackOperate(scrItem, desBackPack):  
 | 
    #ÌØÊâ¼ì²é  
 | 
    if desBackPack in ChConfig.Def_ComposePack_List:  
 | 
        if not __CheckItemCanPutInComposePack(scrItem):  
 | 
            GameWorld.ErrLog('BackpackOperate ItemErr = %s, ItemType = %s'%(scrItem.GetItemTypeID(), scrItem.GetType()))  
 | 
            return False  
 | 
  
 | 
    return True  
 | 
#---------------------------------------------------------------------  
 | 
##»ñµÃ±³°üµ±Ç°²Ù×÷µÄÎïÆ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param srcBackpack Æðʼ±³°ü  
 | 
# @param desBackPack Ä¿µÄ±³°ü  
 | 
# @param srcIndex ÆðʼÎïÆ·Ë÷Òý  
 | 
# @return ²Ù×÷ÎïÆ·ÊµÀý»òÕßNone  
 | 
# @remarks »ñµÃ±³°üµ±Ç°²Ù×÷µÄÎïÆ·  
 | 
def __GetBackPackOperateItem(curPlayer, srcBackpack, desBackPack, srcIndex):  
 | 
    #²Ù×÷±³°ü¼ì²é  
 | 
    if srcBackpack not in ChConfig.Def_BackpackOperate_List or desBackPack not in ChConfig.Def_BackpackOperate_List:  
 | 
        GameWorld.ErrLog('PackItemExchange packErr, srcBackpack = %s, \  
 | 
            desBackPack = %s'%(srcBackpack, desBackPack), curPlayer.GetID())  
 | 
        return  
 | 
      
 | 
    #»ñµÃ·ÅÈëµÄÎïÆ·  
 | 
    scrItem = curPlayer.GetItemManager().GetPack(srcBackpack).GetAt(srcIndex)  
 | 
      
 | 
    #---ÎïÆ·¼ì²é---  
 | 
    if not ItemCommon.CheckItemCanUse(scrItem):  
 | 
        return  
 | 
      
 | 
    #ÌØÊâ¼ì²é  
 | 
    if not __CheckBackPackOperate(scrItem, desBackPack):  
 | 
        return  
 | 
      
 | 
    return scrItem  
 | 
#---------------------------------------------------------------------  
 | 
##ͨÓñ³°ü½»»»²Ù×÷  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param srcBackpack Æðµã±³°ü  
 | 
# @param destBackPack Ä¿±ê±³°ü  
 | 
# @param srcIndex ÆðµãË÷Òý  
 | 
# @param destIndex Ä¿±êË÷Òý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return ·µ»ØÖµÎÞÒâÒå  
 | 
# @remarks Í¨Óñ³°ü½»»»²Ù×÷  
 | 
def PackItemExchange(curPlayer, srcBackpack, destBackPack, srcIndex, destIndex, tick):  
 | 
    #»ñµÃÐèÒª²Ù×÷µÄÎïÆ·µÄÎïÆ·  
 | 
    scrItem = __GetBackPackOperateItem(curPlayer, srcBackpack, destBackPack, srcIndex)  
 | 
      
 | 
    if scrItem == None:  
 | 
        return  
 | 
      
 | 
    #---Ñé֤Ŀ±ê±³°ü¸ñ×Ó--  
 | 
    destItem = curPlayer.GetItemManager().GetPack(destBackPack).GetAt(destIndex)  
 | 
    #Ä¿±ê¸ñ×ÓÖ»ÑéÖ¤Ëø¶¨, ¿ÉÒÔÔÊÐí¿Õλ  
 | 
    if destItem == None or destItem.GetIsLocked():  
 | 
        return  
 | 
      
 | 
    ItemCommon.DoLogicSwitchItem(curPlayer, scrItem, destItem, destBackPack)  
 | 
    return  
 | 
  
 | 
  
 | 
## »ñµÃ½ðÇ®¸¶·Ñ×Öµä  
 | 
#  @param moneyList ½ðÇ®Áбí [½ðÇ®ÀàÐÍ£¬ ½ðÇ®ÊýÁ¿£¬¡£¡£¡£]  
 | 
#  @param payMoneyDict ½ðÇ®ÀÛ¼Ó×Öµä  
 | 
#  @return ½ðÇ®ÀÛ¼Ó×Öµä  
 | 
#  @remarks »ñµÃ½ðÇ®¸¶·Ñ×Öµä  
 | 
def GetPayMoneyDict(moneyList, payMoneyDict={}):  
 | 
    length = len(moneyList)  
 | 
      
 | 
    for index in range(0, length, 2):  
 | 
        moneyType = moneyList[index]  
 | 
        money = moneyList[index + 1]  
 | 
          
 | 
        payMoney = payMoneyDict.get(moneyType)  
 | 
        if payMoney == None:  
 | 
            payMoneyDict[moneyType] = money  
 | 
        else:  
 | 
            payMoneyDict[moneyType] += money  
 | 
      
 | 
    return payMoneyDict  
 | 
  
 | 
  
 | 
## ¼ì²é½ðÇ®  
 | 
#  @param curPlayer Íæ¼Ò  
 | 
#  @param payMoneyDict ¸¶Ç®×Öµä  
 | 
#  @return BOOLÊÇ·ñ×ã¹»  
 | 
#  @remarks ¼ì²é½ðÇ®  
 | 
def CheckPayMoney(curPlayer, payMoneyDict):  
 | 
      
 | 
    for moneyType, money in payMoneyDict.items():  
 | 
          
 | 
        #ÑéÖ¤ÊÖÐø·Ñ  
 | 
        if not PlayerControl.HaveMoney(curPlayer, moneyType, money):  
 | 
            return False  
 | 
      
 | 
    return True  
 | 
  
 |