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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActBuyCountGift
#
# @todo:¹ºÂò´ÎÊýÀñ°ü»î¶¯
# @author hxp
# @date 2024-06-05
# @version 1.0
#
# ÏêϸÃèÊö: ¹ºÂò´ÎÊýÀñ°ü»î¶¯
#
#-------------------------------------------------------------------------------
#"""Version = 2024-06-05 12:00"""
#-------------------------------------------------------------------------------
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import ChPyNetSendPack
import FunctionNPCCommon
import DataRecordPack
import NetPackCommon
import ItemControler
import IPY_GameWorld
import PlayerCoin
import GameWorld
import ChConfig
 
def OnDay(curPlayer, onEventType):
    OnCheckRelateFuncAct(curPlayer)
    if onEventType != ShareDefine.Def_OnEventType:
        return
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
            continue
        ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
        if not ipyData:
            continue
        CTGCountDayResetList = ipyData.GetCTGCountDayResetList()
        if not CTGCountDayResetList:
            continue
        
        awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
        for buyCount in CTGCountDayResetList:
            awardRecord = GameWorld.SetBitValue(awardRecord, buyCount, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, awardRecord)
        Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
        
    return
 
def OnPlayerLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        isReset = __CheckPlayerBuyCountGiftAction(curPlayer, actNum)
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if not isReset and actInfo.get(ShareDefine.ActKey_State) and curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
            Sync_BuyCountGiftActionInfo(curPlayer, actNum)
            Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
            
    return
 
def OnCheckRelateFuncAct(curPlayer, openFuncIDList=None):
    ## ¼ì²é¹ØÁª¹¦ÄÜID¿ªÆôµÄ»î¶¯
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
        if not ipyData:
            continue
        if not hasattr(ipyData, "GetRelateFuncID"):
            continue
        relateFuncID = ipyData.GetRelateFuncID()
        if not relateFuncID:
            continue
        if openFuncIDList and relateFuncID not in openFuncIDList:
            continue
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        __CheckPlayerBuyCountGiftAction(curPlayer, actNum)
        
    return
 
def RefreshBuyCountGiftActionInfo(actNum):
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerBuyCountGiftAction(curPlayer, actNum)
        
    return
 
def __CheckPlayerBuyCountGiftAction(curPlayer, actNum):
    ## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum) # Íæ¼ÒÉíÉϵĻID
    
    funcActInfo = GameWorld.GetActRelateFuncInfo(curPlayer, "ActBuyCountGift", actInfo, playerActID)
    if funcActInfo:
        isInAct, actID = funcActInfo
        if not isInAct:
            return
        
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,cfgID=%s,actID=%s" % (actNum, cfgID, actID), curPlayer.GetPlayerID())
        return
    GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÖØÖÃ! actNum=%s,cfgID=%s,actID=%s,playerActID=%s,state=%s" % (actNum, cfgID, actID, playerActID, state), playerID)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftID % actNum, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, 0)
    
    if state:
        # ÖØÖóäÖµID³äÖµ¼Ç¼
        __ResetCTGIDCount(curPlayer, actInfo)
        
        Sync_BuyCountGiftActionInfo(curPlayer, actNum)
        Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
        
    return True
 
def __ResetCTGIDCount(curPlayer, actInfo):
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
    if not ipyData:
        return
    resetCTGIDList = ipyData.GetCTGIDList()
    PlayerCoin.DoResetCTGCountByIDList(curPlayer, "ActBuyCountGift", resetCTGIDList)
    
    shopType = ipyData.GetActShopType()
    if shopType:
        FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, [shopType])
    return
 
def OnGetBuyCountGiftAward(curPlayer, buyCount, actNum):
    playerID = curPlayer.GetPlayerID()
    
    actNum = GameWorld.ToIntDef(actNum, 0)
    if actNum <= 0:
        GameWorld.DebugLog("ûÓÐÖ¸¶¨ÁìÈ¡µÄ»î¶¯±àºÅ! actNum=%s" % actNum, playerID)
        return
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
    
    if not actInfo.get(ShareDefine.ActKey_State):
        GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü·Ç»î¶¯ÖÐÎÞ·¨ÁìÈ¡½±Àø! actNum=%s" % actNum, playerID)
        return
    if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
    if not ipyData:
        return
    CTGIDList = ipyData.GetCTGIDList()
    CTGCountAwardInfo = ipyData.GetCTGCountAwardInfo()
    if buyCount not in CTGCountAwardInfo:
        GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°üûÓиôÎÊýÀñ°ü½±Àø! actNum=%s,cfgID=%s,buyCount=%s" % (actNum, cfgID, buyCount), playerID)
        return
    awardItemList = CTGCountAwardInfo[buyCount]
    
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
    if awardRecord & pow(2, buyCount):
        GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÒѾ­ÁìÈ¡¹ý¸Ã½±Àø! actNum=%s,cfgID=%s,buyCount=%s,awardRecord=%s" 
                      % (actNum, cfgID, buyCount, awardRecord), playerID)
        return
    
    totalBuyCount = 0
    for ctgID in CTGIDList:
        totalBuyCount += curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % ctgID)
        
    if totalBuyCount < buyCount:
        GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÀۼƹºÂò´ÎÊý²»×㣬ÎÞ·¨Ãâ·ÑÁìÈ¡! actNum=%s,cfgID=%s,CTGIDList=%s,totalBuyCount=%s < %s" 
                      % (actNum, cfgID, CTGIDList, totalBuyCount, buyCount), playerID)
        return
    
    # ¼ì²é±³°ü
    if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
        return
    
    awardRecord |= pow(2, buyCount)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, awardRecord)
    Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
    
    for itemID, itemCount, isAuctionItem in awardItemList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["ActBuyCountGift", False, {}])
    ItemControler.NotifyGiveAwardInfo(curPlayer, awardItemList, "ActBuyCountGift")
    
    addDataDict = {"actNum":actNum, "cfgID":cfgID, "buyCount":buyCount, "awardItemList":str(awardItemList)}
    DataRecordPack.DR_FuncGiveItem(curPlayer, "ActBuyCountGift", addDataDict)
    GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÁìÈ¡½±Àø! actNum=%s,cfgID=%s,buyCount=%s,awardItemList=%s" 
                  % (actNum, cfgID, buyCount, awardItemList), playerID)
    return
 
def Sync_BuyCountGiftPlayerInfo(curPlayer, actNum):
    ## Í¨ÖªÍæ¼ÒÊý¾ÝÐÅÏ¢
    clientPack = ChPyNetSendPack.tagMCActBuyCountGiftPlayerInfo()
    clientPack.ActNum = actNum
    clientPack.GiftAwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_BuyCountGiftActionInfo(curPlayer, actNum):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum)
    if not playerActID:
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
    if not ipyData:
        return
    CTGCountAwardInfo = ipyData.GetCTGCountAwardInfo()
    
    if hasattr(ipyData, "GetRelateFuncID") and ipyData.GetRelateFuncID():
        startDateStr, endDateStr = GameWorld.GetActRelateFuncDate(ipyData, playerActID, True)
    else:
        startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    startDateSync = actInfo.get(ShareDefine.ActKey_StartDateSync, startDateStr)
    actInfo = ChPyNetSendPack.tagMCActBuyCountGiftInfo()
    actInfo.ActNum = actNum
    actInfo.StartDate = startDateSync
    actInfo.EndtDate = endDateStr
    actInfo.LimitLV = ipyData.GetLVLimit()
    actInfo.IsDayReset = ipyData.GetIsDayReset()
    actInfo.ResetType = ipyData.GetResetType()
    actInfo.ShopType = ipyData.GetActShopType()
    actInfo.CTGIDList = ipyData.GetCTGIDList()
    actInfo.CTGIDCount = len(actInfo.CTGIDList)
    
    actInfo.BuyCountGiftList = []
    for buyCount, awardItemList in CTGCountAwardInfo.items():
        giftbag = ChPyNetSendPack.tagMCActBuyCountGift()
        giftbag.NeedBuyCount = buyCount
        giftbag.AwardItemList = []
        for itemID, itemCount, isAuctionItem in awardItemList:
            giftItem = ChPyNetSendPack.tagMCActBuyCountGiftItem()
            giftItem.ItemID = itemID
            giftItem.ItemCount = itemCount
            giftItem.IsBind = isAuctionItem
            giftbag.AwardItemList.append(giftItem)
        giftbag.Count = len(giftbag.AwardItemList)
        actInfo.BuyCountGiftList.append(giftbag)
    actInfo.GiftCount = len(actInfo.BuyCountGiftList)
    
    NetPackCommon.SendFakePack(curPlayer, actInfo)
    return