#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#-------------------------------------------------------------------------------  
 | 
#  
 | 
##@package Player.PlayerSpringSale  
 | 
#  
 | 
# @todo:ÏÞÊ±ÌØ»Ý»î¶¯  
 | 
# @author hxp  
 | 
# @date 2018-7-17  
 | 
# @version 1.0  
 | 
#  
 | 
# ÏêϸÃèÊö: ÏÞÊ±ÌØ»Ý»î¶¯  
 | 
#  
 | 
#-------------------------------------------------------------------------------  
 | 
#"""Version = 2018-7-17 12:00"""  
 | 
#-------------------------------------------------------------------------------  
 | 
  
 | 
import PyGameData  
 | 
import ShareDefine  
 | 
import PlayerControl  
 | 
import IpyGameDataPY  
 | 
import FunctionNPCCommon  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
import GameWorld  
 | 
import ChConfig  
 | 
  
 | 
def GetShopTypeList(cfgID, dayIndex, woldLV):  
 | 
    if cfgID == None or dayIndex == None:  
 | 
        return []  
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("ActSpringSale", cfgID)  
 | 
    if not ipyData:  
 | 
        return []  
 | 
    shopTypeList = GameWorld.GetDictValueByRangeKey(ipyData.GetShopTypeList(), woldLV, [])  
 | 
    todayShopType = shopTypeList[-1] if dayIndex >= len(shopTypeList) else shopTypeList[dayIndex]  
 | 
    return todayShopType  
 | 
  
 | 
def OnPlayerLogin(curPlayer):  
 | 
      
 | 
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {}).values():  
 | 
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  
 | 
        __CheckPlayerSpringSaleAction(curPlayer, actNum)  
 | 
          
 | 
    return  
 | 
  
 | 
def RefreshSpringSaleActionInfo(actNum):  
 | 
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  
 | 
    playerManager = GameWorld.GetPlayerManager()  
 | 
    for index in xrange(playerManager.GetPlayerCount()):  
 | 
        curPlayer = playerManager.GetPlayerByIndex(index)  
 | 
        if curPlayer.GetID() == 0:  
 | 
            continue  
 | 
        __CheckPlayerSpringSaleAction(curPlayer, actNum)  
 | 
    return  
 | 
  
 | 
def __CheckPlayerSpringSaleAction(curPlayer, actNum):  
 | 
    ## ¼ì²éÍæ¼ÒÏÞÊ±ÌØ»Ý»î¶¯Êý¾ÝÐÅÏ¢  
 | 
      
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
      
 | 
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SpringSale, actNum)  
 | 
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)  
 | 
    state = actInfo.get(ShareDefine.ActKey_State, 0)  
 | 
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  
 | 
    woldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)  
 | 
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SpringSaleID % actNum) # Íæ¼ÒÉíÉϵĻID  
 | 
    isReset = False  
 | 
    if actID != playerActID:  
 | 
        isReset = True  
 | 
        shopTypeList = GetShopTypeList(cfgID, actInfo.get(ShareDefine.ActKey_DayIndex, 0), woldLV)  
 | 
        FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, shopTypeList)  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SpringSaleID % actNum, actID)  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SpringSaleMailState % actNum, 0)  
 | 
        #Sync_SpringSaleActionInfo(curPlayer)  
 | 
        GameWorld.DebugLog("ÏÞÊ±ÌØ»ÝÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,shopTypeList=%s" % (actNum, actID, playerActID, state, shopTypeList), playerID)  
 | 
    else:  
 | 
        GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)  
 | 
          
 | 
    playerMailState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SpringSaleMailState % actNum) # Íæ¼ÒÉíÉϵĻÌáÐÑÓʼþ״̬  
 | 
    if actID and state and state != playerMailState:  
 | 
        springSaleIpyData = IpyGameDataPY.GetIpyGameData("ActSpringSale", cfgID)  
 | 
        if springSaleIpyData and springSaleIpyData.GetMailKey() and curPlayer.GetLV() >= springSaleIpyData.GetLVLimit():  
 | 
            PlayerControl.SendMailByKey(springSaleIpyData.GetMailKey(), [playerID], springSaleIpyData.GetMailItemPrize())  
 | 
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SpringSaleMailState % actNum, state)  
 | 
            GameWorld.DebugLog("    ·¢ËÍÐÂÏÞÊ±ÌØ»ÝÓʼþÌáÐÑ! state=%s,playerMailState=%s" % (state, playerMailState), playerID)  
 | 
              
 | 
    if cfgID:  
 | 
        Sync_SpringSaleActionInfo(curPlayer, actNum)  
 | 
    return isReset  
 | 
  
 | 
def IsSpringSaleShopType(shopType):  
 | 
    ## ÅжÏÊÇ·ñ»î¶¯ÖеÄÉÌµê  
 | 
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {}).values():  
 | 
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  
 | 
          
 | 
        state = actInfo.get(ShareDefine.ActKey_State, 0)  
 | 
        if not state:  
 | 
            continue  
 | 
        shopTypeList = GetShopTypeList(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0), actInfo.get(ShareDefine.ActKey_WorldLV, 0))  
 | 
        if not shopTypeList:  
 | 
            continue  
 | 
        actShopType = shopTypeList[-1] if state > len(shopTypeList) else shopTypeList[state - 1]  
 | 
        if shopType == actShopType:  
 | 
            GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý»î¶¯ÖеÄÉ̵êÀàÐÍ: actNum=%s,shopType=%s" % (actNum, shopType))  
 | 
            return True  
 | 
          
 | 
    GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý·Ç»î¶¯Öлò·Ç»î¶¯ÖеÄÉ̵êÀàÐÍ£¡shopType=%s" % (shopType))  
 | 
    return False  
 | 
  
 | 
def Sync_SpringSaleActionInfo(curPlayer, actNum):  
 | 
    ## Í¨ÖªÏÞÊ±ÌØ»Ý»î¶¯ÐÅÏ¢  
 | 
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SpringSale, actNum)  
 | 
    if not actInfo:  
 | 
        return  
 | 
      
 | 
    #ÐèÒªÌáǰ֪ͨ£¬ËùÒÔÈ¥µô´ËÏÞÖÆ  
 | 
    #if not actInfo.get(ShareDefine.ActKey_State):  
 | 
    #    return  
 | 
      
 | 
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  
 | 
    if not cfgID:  
 | 
        return  
 | 
    shopTypeList = GetShopTypeList(cfgID, actInfo.get(ShareDefine.ActKey_DayIndex, 0), actInfo.get(ShareDefine.ActKey_WorldLV, 0))  
 | 
    if not shopTypeList:  
 | 
        return  
 | 
      
 | 
    springSaleIpyData = IpyGameDataPY.GetIpyGameData("ActSpringSale", cfgID)  
 | 
    if not springSaleIpyData:  
 | 
        return  
 | 
      
 | 
    startTimeList = springSaleIpyData.GetStartTimeList()  
 | 
    endTimeList = springSaleIpyData.GetEndTimeList()  
 | 
    if len(startTimeList) != len(endTimeList):  
 | 
        GameWorld.ErrLog("ÏÞÊ±ÌØ»Ý¿ª¹ØÊ±¼äʱ·ÖÅäÖôíÎó!cfgID=%s" % cfgID)  
 | 
        return  
 | 
    job = curPlayer.GetJob()  
 | 
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1  
 | 
    packInfo = ChPyNetSendPack.tagMCSpringSaleInfo()  
 | 
    packInfo.ActNum = actNum  
 | 
    packInfo.StartDate = GameWorld.GetOperationActionDateStr(springSaleIpyData.GetStartDate(), openServerDay)  
 | 
    packInfo.EndtDate = GameWorld.GetOperationActionDateStr(springSaleIpyData.GetEndDate(), openServerDay)  
 | 
    packInfo.AdvanceMinutes = springSaleIpyData.GetAdvanceMinutes()  
 | 
    packInfo.ActivityTime = []  
 | 
    for i, startTime in enumerate(startTimeList):  
 | 
        timeInfo = ChPyNetSendPack.tagMCSpringSaleTime()  
 | 
        timeInfo.StartTime = startTime  
 | 
        timeInfo.EndtTime = endTimeList[i]  
 | 
        packInfo.ActivityTime.append(timeInfo)  
 | 
    packInfo.ActivityTimeCount = len(packInfo.ActivityTime)  
 | 
    packInfo.IsDayReset = springSaleIpyData.GetIsDayReset()  
 | 
    packInfo.LimitLV = springSaleIpyData.GetLVLimit()  
 | 
    packInfo.ShopInfo = []  
 | 
    for shopType in shopTypeList:  
 | 
          
 | 
        shopItemIpyDataList = IpyGameDataPY.GetIpyGameDataByCondition("Store", {"ShopType":shopType}, True, True)  
 | 
        if not shopItemIpyDataList:  
 | 
            continue  
 | 
          
 | 
        shop = ChPyNetSendPack.tagMCSpringSaleShop()  
 | 
        shop.GiftbagInfo = []  
 | 
          
 | 
        for itemIpyData in shopItemIpyDataList:  
 | 
            giftBag = ChPyNetSendPack.tagMCSpringSaleGiftbag()  
 | 
            giftBag.GiftID = itemIpyData.GetID()  
 | 
            giftBag.BuyCountLimit = 0 if not itemIpyData.GetLimitCnt() else itemIpyData.GetLimitCnt()[0]  
 | 
            giftBag.MoneyType = itemIpyData.GetMoneyType()  
 | 
            giftBag.MoneyNumber = itemIpyData.GetMoneyNum()  
 | 
            giftBag.MoneyOriginal = itemIpyData.GetMoneyOriginal()  
 | 
            giftBag.ItemInfo = []  
 | 
            itemList = [[itemIpyData.GetItemID(), itemIpyData.GetItemCnt(), itemIpyData.GetIsBind()]]  
 | 
            itemList += itemIpyData.GetItemListEx()  
 | 
            jobItemList = itemIpyData.GetJobItem()  
 | 
            for itemID, itemCount, isBind in itemList:  
 | 
                item = ChPyNetSendPack.tagMCSpringSaleItem()  
 | 
                jobItemID = FunctionNPCCommon.GetShopJobItem(job, itemID, jobItemList)  
 | 
                item.ItemID = jobItemID  
 | 
                item.ItemCount = itemCount  
 | 
                item.IsBind = isBind  
 | 
                item.IsMainItem = int(itemID == FunctionNPCCommon.GetShopJobItem(job, itemIpyData.GetMainItemID(), jobItemList))  
 | 
                giftBag.ItemInfo.append(item)  
 | 
            giftBag.GiftItemCount = len(giftBag.ItemInfo)  
 | 
            shop.GiftbagInfo.append(giftBag)  
 | 
              
 | 
        shop.GiftbagCount = len(shop.GiftbagInfo)  
 | 
        packInfo.ShopInfo.append(shop)  
 | 
          
 | 
    packInfo.ShopCount = len(packInfo.ShopInfo)  
 | 
    NetPackCommon.SendFakePack(curPlayer, packInfo)  
 | 
    return  
 | 
  
 | 
  
 |