1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/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 not GameWorld.IsNormalPlayer(curPlayer):
            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()
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(springSaleIpyData)
    packInfo = ChPyNetSendPack.tagMCSpringSaleInfo()
    packInfo.ActNum = actNum
    packInfo.StartDate = startDateStr
    packInfo.EndtDate = endDateStr
    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