| #!/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 OnPlayerLogin(curPlayer):  | 
|     isReset = __CheckPlayerSpringSaleAction(curPlayer)  | 
|     if not isReset:  | 
|         actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actInfo.get(ShareDefine.ActKey_State):  | 
|             Sync_SpringSaleActionInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshSpringSaleActionInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerSpringSaleAction(curPlayer)  | 
|     return  | 
|   | 
| def __CheckPlayerSpringSaleAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼ÒÏÞÊ±ÌØ»Ý»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {})  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     shopTypeList = actInfo.get(ShareDefine.ActKey_ShopTypeList, [])  | 
|     #if not state or not shopTypeList:  | 
|     #    return  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SpringSaleID) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SpringSaleID, actID)  | 
|     FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, shopTypeList)  | 
|       | 
|     GameWorld.DebugLog("ÏÞÊ±ÌØ»ÝÖØÖÃ! actID=%s,playerActID=%s,state=%s,shopTypeList=%s" % (actID, playerActID, state, shopTypeList), playerID)  | 
|       | 
|     Sync_SpringSaleActionInfo(curPlayer)  | 
|     return True  | 
|   | 
| def Sync_SpringSaleActionInfo(curPlayer):  | 
|     ## Í¨ÖªÏÞÊ±ÌØ»Ý»î¶¯ÐÅÏ¢  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {})  | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  | 
|     shopTypeList = actInfo.get(ShareDefine.ActKey_ShopTypeList, 0)  | 
|       | 
|     if not cfgID or 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  | 
|       | 
|     packInfo = ChPyNetSendPack.tagMCSpringSaleInfo()  | 
|     packInfo.StartDate = springSaleIpyData.GetStartDate()  | 
|     packInfo.EndtDate = springSaleIpyData.GetEndDate()  | 
|     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()  | 
|             for itemID, itemCount, isBind in itemList:  | 
|                 item = ChPyNetSendPack.tagMCSpringSaleItem()  | 
|                 item.ItemID = itemID  | 
|                 item.ItemCount = itemCount  | 
|                 item.IsBind = isBind  | 
|                 item.IsMainItem = int(itemID == itemIpyData.GetMainItemID())  | 
|                 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  | 
|   | 
|   |