hxp
2024-11-11 9f30bc4785beb84ff4ab1504a2279b4a82f9ebd1
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
267
268
269
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActLunhuidian
#
# @todo:Âֻصî
# @author hxp
# @date 2024-11-11
# @version 1.0
#
# ÏêϸÃèÊö: Âֻصî
#
#-------------------------------------------------------------------------------
#"""Version = 2024-11-11 18:00"""
#-------------------------------------------------------------------------------
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import ChPyNetSendPack
import NetPackCommon
import ItemControler
import GameWorld
import ChConfig
 
# ÂÖ»ØÉ趨ÅäÖÃË÷Òý
RoundSetIndex = (
RoundSetIndex_AwardType, # 0 ½±ÀøÀàÐÍ
RoundSetIndex_AwardTypeValue, # 1 ½±ÀøÀàÐͶÔÓ¦Öµ
RoundSetIndex_RoundMax, # 2 ×î´óÂֻشÎÊý
) = range(3)
 
# Âֻؽ±ÀøÀàÐÍ
AwardType_PayMoney = 1
AwardType_Treasure = 2
 
def OnPlayerLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Lunhuidian, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        isReset = __CheckPlayerActLunhuidianAction(curPlayer, actNum)
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if not isReset and actInfo.get(ShareDefine.ActKey_State):
            Sync_ActLunhuidianActionInfo(curPlayer, actNum)
            cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
            ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
            if ipyData:
                roundSetDict = ipyData.GetRoundSetInfo()
                for roundType in roundSetDict.keys():
                    Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
    return
 
def RefreshActLunhuidianActionInfo(actNum):
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerActLunhuidianAction(curPlayer, actNum)
    return
 
def __CheckPlayerActLunhuidianAction(curPlayer, actNum):
    ## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianID % actNum) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("Âֻصî»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,cfgID=%s,actID=%s" % (actNum, cfgID, actID), playerID)
        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_ActLunhuidianID % actNum, actID)
    
    if state:
        Sync_ActLunhuidianActionInfo(curPlayer, actNum)
        ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
        if ipyData:
            roundSetDict = ipyData.GetRoundSetInfo()
            for roundType in roundSetDict.keys():
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), 0)
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType), 1) # ´ÓµÚ1ÂÖ¿ªÊ¼
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), 0)
                Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
    return True
 
def GetRoundSetValue(roundSet, setIndex): return roundSet[setIndex] if len(roundSet) > setIndex else 0
 
def AddLunhuidianValue(curPlayer, awardType, awardTypeValue, addValue):
    ## Ôö¼ÓÂÖ»Øµî½ø¶ÈÖµ
    playerID = curPlayer.GetPlayerID()
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Lunhuidian, {}).values():
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
        if not ipyData:
            continue
        roundSetDict = ipyData.GetRoundSetInfo()
        for roundType, roundSet in roundSetDict.items():
            if awardType != GetRoundSetValue(roundSet, RoundSetIndex_AwardType):
                continue
            if awardTypeValue != GetRoundSetValue(roundSet, RoundSetIndex_AwardTypeValue):
                continue
            
            curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
            updValue = min(curValue + addValue, ChConfig.Def_UpperLimit_DWord)
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), updValue)
            GameWorld.DebugLog("¸üÐÂÂֻصîÀÛ¼ÆÖµ: actNum=%s,cfgID=%s,roundType=%s,awardType=%s,awardTypeValue=%s,addValue=%s,curValue=%s,updValue=%s" 
                               % (actNum, cfgID, roundType, awardType, awardTypeValue, addValue, curValue, updValue), playerID)
            Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
            
    return
 
def GetLunhuidianAward(curPlayer, dataEx, dataExStr):
    ## ÁìÈ¡½±Àø
    # @param awardInfo: ÒªÁìÈ¡µÄ½±ÀøÐÅÏ¢ roundType|needValue
    actNum = dataEx
    awardSplitList = dataExStr.split("|")
    if len(awardSplitList) != 2:
        GameWorld.DebugLog("·¢ËÍÁìÈ¡¸ñʽ´íÎó: dataExStr=%s" % dataExStr)
        return
    roundType = GameWorld.ToIntDef(awardSplitList[0], 0)
    needValue = GameWorld.ToIntDef(awardSplitList[1], 0)
    
    playerID = curPlayer.GetPlayerID()
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
    if not actInfo or not actInfo.get(ShareDefine.ActKey_State):
        GameWorld.DebugLog("¸ÃÂֻصî·Ç»î¶¯ÖÐ: actNum=%s" % actNum)
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
    if not ipyData:
        return
    roundSetDict = ipyData.GetRoundSetInfo()
    if roundType not in roundSetDict:
        GameWorld.DebugLog("¸ÃÂֻصîÀàÐͲ»ÔÚ±¾´Î»î¶¯ÖÐ: actNum=%s,roundType=%s not in %s" % (actNum, roundType, roundSetDict))
        return
    roundSet = roundSetDict[roundType]
    roundMax = GetRoundSetValue(roundSet, RoundSetIndex_RoundMax)
    
    awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLunhuidianAward", roundType)
    if not awardIpyDataList:
        return
    
    curRound = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType))
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType))
    
    roundValueMax = 0
    unGetIndexList = []
    awardIndex, awardItemList = None, []
    for awardIpyData in awardIpyDataList:
        needV = awardIpyData.GetNeedValue()
        roundValueMax = max(roundValueMax, needV)
        aIndex = awardIpyData.GetAwardIndex()
        if needValue == needV:
            awardIndex = aIndex
            awardItemList = awardIpyData.GetAwardItemList()
        else:
            if not awardState&pow(2, aIndex):
                unGetIndexList.append(aIndex)
                
    if awardIndex == None:
        GameWorld.DebugLog("ÂֻصîûÓиý±Àø! actNum=%s,roundType=%s,needValue=%s" % (actNum, roundType, needValue), playerID)
        return
    
    if awardState&pow(2, awardIndex):
        GameWorld.DebugLog("ÂֻصÀøÒÑÁì½±! actNum=%s,roundType=%s,needValue=%s,awardIndex=%s" 
                           % (actNum, roundType, needValue, awardIndex), playerID)
        return
    
    if curValue < needValue:
        GameWorld.DebugLog("Âֻصǰֵ²»×㣬ÎÞ·¨Áì½±! actNum=%s,roundType=%s,curRound=%s,curValue=%s < %s" 
                           % (actNum, roundType, curRound, curValue, needValue), playerID)
        return
    
    updState = awardState|pow(2, awardIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), updState)
    GameWorld.DebugLog("ÁìÈ¡ÂֻصÀø! actNum=%s,roundType=%s,needValue=%s,awardIndex=%s,awardState=%s,updState=%s,curRound=%s" 
                       % (actNum, roundType, needValue, awardIndex, awardState, updState, curRound), playerID)
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList)
    
    GameWorld.DebugLog("    curRound=%s/%s,unGetIndexList=%s,curValue=%s,roundValueMax=%s" 
                       % (curRound, roundMax, unGetIndexList, curValue, roundValueMax), playerID)
    if not unGetIndexList and curRound < roundMax:
        updRound = curRound + 1
        updValue = max(0, curValue - roundValueMax)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType), updRound)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), updValue)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), 0)
        GameWorld.DebugLog("    ±¾ÂÖ´ÎËùÓн±ÀøÒѾ­ÁìÈ¡Íê±Ï£¬½øÈëÏÂÒ»ÂÖ! updRound=%s,updValue=%s" % (updRound, updValue), playerID)
        
    Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
    return
 
def Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType):
    clientPack = ChPyNetSendPack.tagMCActLunhuidianPlayerInfo()
    clientPack.ActNum = actNum
    clientPack.RoundType = roundType
    clientPack.CurRound = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType))
    clientPack.CurValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
    clientPack.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType))
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_ActLunhuidianActionInfo(curPlayer, actNum, roundType=0):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
    if not actInfo:
        return
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
    if not ipyData:
        return
    
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    clientPack = ChPyNetSendPack.tagMCActLunhuidianInfo()
    clientPack.Clear()
    clientPack.ActNum = actNum
    clientPack.StartDate = startDateStr
    clientPack.EndtDate = endDateStr
    clientPack.ResetType = ipyData.GetResetType()
    clientPack.LimitLV = ipyData.GetLVLimit()
    
    roundSetDict = ipyData.GetRoundSetInfo()
    for roundType, roundSet in roundSetDict.items():
        roundInfo = ChPyNetSendPack.tagMCActLunhuidianRound()
        roundInfo.RoundType = roundType
        roundInfo.AwardType = GetRoundSetValue(roundSet, RoundSetIndex_AwardType)
        roundInfo.AwardTypeValue = GetRoundSetValue(roundSet, RoundSetIndex_AwardTypeValue)
        roundInfo.RoundMax = GetRoundSetValue(roundSet, RoundSetIndex_RoundMax)
        roundInfo.AwardList = []
        
        awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLunhuidianAward", roundType)
        if awardIpyDataList:
            for awardIpyData in awardIpyDataList:
                award = ChPyNetSendPack.tagMCActLunhuidianAward()
                award.AwardIndex = awardIpyData.GetAwardIndex()
                award.NeedValue = awardIpyData.GetNeedValue()
                for itemID, itemCount, isAuctionItem in awardIpyData.GetAwardItemList():
                    item = ChPyNetSendPack.tagMCActLunhuidianItem()
                    item.ItemID = itemID
                    item.ItemCount = itemCount
                    item.IsBind = isAuctionItem
                    award.AwardItemList.append(item)
                award.Count = len(award.AwardItemList)
                
                roundInfo.AwardList.append(award)
        roundInfo.AwardCount = len(roundInfo.AwardList)
        
        clientPack.RoundList.append(roundInfo)
    clientPack.RoundCount = len(clientPack.RoundList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return