hxp
2026-02-26 5d79b486b2974522c2d1978dc90c3081827224e0
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActHeroAppear
#
# @todo:Î佫µÇ³¡
# @author hxp
# @date 2026-02-26
# @version 1.0
#
# ÏêϸÃèÊö: Î佫µÇ³¡
#
#-------------------------------------------------------------------------------
#"""Version = 2026-02-26 16:00"""
#-------------------------------------------------------------------------------
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import PlayerActSign
import ChPyNetSendPack
import FunctionNPCCommon
import PlayerBillboard
import PlayerTreasure
import NetPackCommon
import ItemControler
import PlayerHero
import PlayerCoin
import GameWorld
import DBDataMgr
import ChConfig
 
def OnActIDChange(actNum, ipyData, state, dbActCfgID):
    ## »î¶¯ID±ä¸ü
    
    if dbActCfgID:
        __onActEnd(actNum, dbActCfgID)
        
    if state:
        __onActStart(actNum, ipyData)
        
    return
 
def OnActInStateRefresh(actNum, ipyData):
    ## »î¶¯ÖÐˢУ¬Ã¿´Î¶¼ÐèҪˢеÄÂß¼­£¬°üº¬ÖضÁÅäÖõÈ
    if not ipyData:
        return
    templateID = ipyData.GetBillTempID()
    
    # Ë¢ÐÂÅÅÃû¹æÔò
    PlayerBillboard.SetOrderRuleListByActTempID(ShareDefine.Def_BT_ActHeroAppear, templateID, groupValue1=actNum)
    return
 
def __onActStart(actNum, ipyData):
    ## »î¶¯¿ªÆô
    billboardMgr = DBDataMgr.GetBillboardMgr()
    billboardObj = billboardMgr.GetBillboard(ShareDefine.Def_BT_ActHeroAppear, groupValue1=actNum)
    billboardObj.ClearData() # ÐÂ»î¶¯ÖØÖðñµ¥Êý¾Ý
    return
 
def __onActEnd(actNum, dbActCfgID):
    ## »î¶¯½áÊø£¬Ê¹ÓàdbActCfgID ´¦Àí½áË㣬֧³Ö½áÊøÇ°Î¬»¤£¬½áÊøºóÆô¶¯µÄÇé¿ö
    ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", dbActCfgID)
    if not ipyData:
        return
    templateID = ipyData.GetBillTempID()
    mailKey = ipyData.GetBillAwardMail()
    
    funcName = "ActHeroAppear_%s_%s" % (dbActCfgID, actNum)
    PlayerBillboard.DoGiveBillboardAwardByActTempID(ShareDefine.Def_BT_ActHeroAppear, funcName, templateID, mailKey, groupValue1=actNum, isClearData=True)
    return
 
## -------------------------------------------------------------------------------------------------
 
def OnPlayerLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HeroAppear, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        isReset = __CheckPlayerActHeroAppearAction(curPlayer, actNum)
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if not isReset and actInfo.get(ShareDefine.ActKey_State):
            Sync_ActHeroAppearActionInfo(curPlayer, actNum)
            Sync_ActHeroAppearPlayerInfo(curPlayer, actNum)
            PlayerActSign.Sync_ActSignPlayerInfo(curPlayer, ShareDefine.OperationActionName_HeroAppear, actNum)
    return
 
def RefreshActHeroAppearActionInfo(actNum):
    ## Ë¢Ð»
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerActHeroAppearAction(curPlayer, actNum)
    return
 
def __CheckPlayerActHeroAppearAction(curPlayer, actNum):
    ## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HeroAppear, 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_ActHeroAppearID % actNum) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("Î佫µÇ³¡»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,cfgID=%s,actID=%s" % (actNum, cfgID, actID), playerID)
        return
    lastCfgID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearCfgID % actNum)
    GameWorld.DebugLog("Î佫µÇ³¡»î¶¯ÖØÖÃ! actNum=%s,cfgID=%s,actID=%s,playerActID=%s,state=%s,lastCfgID=%s" 
                       % (actNum, cfgID, actID, playerActID, state, lastCfgID), playerID)
    if lastCfgID:
        __resetActByCfgID(curPlayer, lastCfgID)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearCfgID % actNum, cfgID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearID % actNum, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearStarIndex % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearStarAward % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearCallIndex % actNum, 0)
    
    if state:
        Sync_ActHeroAppearActionInfo(curPlayer, actNum)
        Sync_ActHeroAppearPlayerInfo(curPlayer, actNum)
        __resetActByCfgID(curPlayer, cfgID)
        
    return True
 
def __resetActByCfgID(curPlayer, cfgID):
    if not cfgID:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
    if not ipyData:
        return
    actNum = ipyData.GetActNum()
    # Ç©µ½
    PlayerActSign.ResetActSign(curPlayer, ShareDefine.OperationActionName_HeroAppear, actNum)
    # Ñ°±¦
    PlayerTreasure.ResetTreasureType(curPlayer, [ipyData.GetActTreasureType()])
    # É̵ê
    shopTypeList = [ipyData.GetGiftShopType(), ipyData.GetExShopType()]
    FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, shopTypeList, ipyData.GetExShopRecycleMail())
    # ³äÖµ
    resetCTGIDList = []
    resetCTGIDList += ipyData.GetSkinCTGIDList()
    resetCTGIDList += ipyData.GetGiftCTGIDList()
    PlayerCoin.DoResetCTGCountByIDList(curPlayer, "ActHeroAppear", resetCTGIDList)
    return
 
def GetActNumByTreasureType(curPlayer, treasureType):
    ## ¸ù¾ÝѰ±¦ÀàÐÍ»ñÈ¡»î¶¯ÖеÄÎ佫µÇ³¡actNum
    # @return: 0-·Ç»î¶¯ÖУ»>0-»î¶¯ÖеÄactNum
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HeroAppear, {}).values():
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
        if not ipyData:
            continue
        if treasureType != ipyData.GetActTreasureType():
            continue
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        return actNum
    return 0
 
def IsActCanTreasureHero(curPlayer, treasureType, heroID, gridNum):
    ## ÊÇ·ñ»î¶¯Öпɲú³öµÄÎ佫
    
    actOnlyHeroLibList = IpyGameDataPY.GetFuncEvalCfg("HeroAppear", 1)
    if gridNum not in actOnlyHeroLibList:
        #GameWorld.DebugLog("·ÇµÇ³¡Î佫¸ñ×ӵĿÉÖ±½Ó²ú³ö! heroID=%s,gridNum=%s" % (heroID, gridNum))
        return True
    #GameWorld.DebugLog("ÑéÖ¤¿É·ñ²ú³ö»î¶¯Î佫! heroID=%s,gridNum=%s" % (heroID, gridNum))
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HeroAppear, {}).values():
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
        if not ipyData:
            continue
        if treasureType != ipyData.GetActTreasureType():
            continue
        actHeroIDList = ipyData.GetActHeroIDList()        
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        callHeroIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearCallIndex % actNum)
        if not actHeroIDList or len(actHeroIDList) <= callHeroIndex:
            return False
        callHeroID = actHeroIDList[callHeroIndex]
        if heroID != callHeroID:
            #GameWorld.DebugLog("·ÇÑ¡ÔñµÄµÇ³¡Î佫£¬²»¿É²ú³ö! heroID=%s != %s,callHeroIndex=%s,%s" % (heroID, callHeroID, callHeroIndex, actHeroIDList))
            return False
        return True
    return False
 
#// AA 01 Î佫µÇ³¡ÉýÐÇÎ佫ѡÔñ #tagCSActHeroAppearStarHeroSelect
#
#struct    tagCSActHeroAppearStarHeroSelect
#{
#    tagHead        Head;
#    BYTE        ActNum;        // »î¶¯±àºÅ
#    BYTE        StarHeroIndex;    // ÉýÐǼƻ®Ñ¡ÔñµÄÎ佫IDË÷Òý
#};
def OnStarHeroSelect(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    actNum = clientData.ActNum
    starHeroIndex = clientData.StarHeroIndex
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HeroAppear, actNum)
    if not actInfo or not actInfo.get(ShareDefine.ActKey_State):
        GameWorld.DebugLog("¸ÃÎ佫µÇ³¡·Ç»î¶¯ÖÐ: actNum=%s" % actNum, playerID)
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
    if not ipyData:
        return
    actHeroIDList = ipyData.GetActHeroIDList()
    if not actHeroIDList or len(actHeroIDList) <= starHeroIndex:
        GameWorld.DebugLog("Î佫µÇ³¡ÐǼ¶¼Æ»®Î佫ѡÔñË÷Òý·Ç·¨: actNum=%s,cfgID=%s,starHeroIndex=%s,actHeroIDList=%s" 
                           % (actNum, cfgID, starHeroIndex, actHeroIDList), playerID)
        return
    
    starAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarAward % actNum)
    if starAward:
        GameWorld.DebugLog("Î佫µÇ³¡ÐǼ¶¼Æ»®ÒѾ­Áì¹ý½±ÎÞ·¨ÐÞ¸ÄÐǼ¶¼Æ»®Î佫: actNum=%s" % actNum, playerID)
        return
    
    starHeroID = actHeroIDList[starHeroIndex]
    GameWorld.DebugLog("Î佫µÇ³¡ÐǼ¶¼Æ»®Î佫ÐÞ¸Ä: actNum=%s,cfgID=%s,starHeroIndex=%s,starHeroID=%s,actHeroIDList=%s" 
                           % (actNum, cfgID, starHeroIndex, starHeroID, actHeroIDList), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearStarIndex % actNum, starHeroIndex)
    Sync_ActHeroAppearPlayerInfo(curPlayer, actNum)
    return
 
#// AA 02 Î佫µÇ³¡ÕÐļÎ佫ѡÔñ #tagCSActHeroAppearCallHeroSelect
#
#struct    tagCSActHeroAppearCallHeroSelect
#{
#    tagHead        Head;
#    BYTE        ActNum;        // »î¶¯±àºÅ
#    BYTE        CallHeroIndex;    // ÕÐļѡÔñµÄÎ佫IDË÷Òý
#};
def OnCallHeroSelect(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    actNum = clientData.ActNum
    callHeroIndex = clientData.CallHeroIndex
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HeroAppear, actNum)
    if not actInfo or not actInfo.get(ShareDefine.ActKey_State):
        GameWorld.DebugLog("¸ÃÎ佫µÇ³¡·Ç»î¶¯ÖÐ: actNum=%s" % actNum, playerID)
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
    if not ipyData:
        return
    actHeroIDList = ipyData.GetActHeroIDList()
    if not actHeroIDList or len(actHeroIDList) <= callHeroIndex:
        GameWorld.DebugLog("Î佫µÇ³¡ÕÐļÎ佫ѡÔñË÷Òý·Ç·¨: actNum=%s,cfgID=%s,callHeroIndex=%s,actHeroIDList=%s" 
                           % (actNum, cfgID, callHeroIndex, actHeroIDList), playerID)
        return
    
    starHeroID = actHeroIDList[callHeroIndex]
    GameWorld.DebugLog("Î佫µÇ³¡ÕÐļÎ佫ÐÞ¸Ä: actNum=%s,cfgID=%s,callHeroIndex=%s,starHeroID=%s,actHeroIDList=%s" 
                           % (actNum, cfgID, callHeroIndex, starHeroID, actHeroIDList), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearCallIndex % actNum, callHeroIndex)
    Sync_ActHeroAppearPlayerInfo(curPlayer, actNum)
    return
 
def GetHeroAppearStarFreeAward(curPlayer, dataEx):
    ## ÁìÈ¡ÉýÐǼƻ®Ãâ·Ñ½±Àø
    actNum = dataEx
    playerID = curPlayer.GetPlayerID()
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HeroAppear, 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("ActHeroAppear", cfgID)
    if not ipyData:
        return
    starGiftTempID = ipyData.GetStarGiftTempID()
    actHeroIDList = ipyData.GetActHeroIDList()
    starHeroIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarIndex % actNum)
    if starHeroIndex >= len(actHeroIDList):
        return
    starHeroID = actHeroIDList[starHeroIndex]
    
    awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActHeroAppearStar", starGiftTempID)
    if not awardIpyDataList:
        return
    
    heroStar = PlayerHero.GetHeroItemStarMax(curPlayer, starHeroID)
    
    awardItemList = []
    updStarAward = starAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarAward % actNum)
    for awardIpyData in awardIpyDataList:
        if heroStar < awardIpyData.GetNeedStar():
            continue
        awardIndex = awardIpyData.GetAwardIndex()
        if starAward&pow(2, awardIndex):
            continue
        awardItemList += awardIpyData.GetFreeAwardItemList()
        updStarAward |= pow(2, awardIndex)
        
    GameWorld.DebugLog("Î佫µÇ³¡ÐǼ¶¼Æ»®Ãâ·Ñ½±ÀøÁìÈ¡! actNum=%s,cfgID=%s,starHeroIndex=%s,starHeroID=%s,heroStar=%s,starAward=%s" 
                       % (actNum, cfgID, starHeroIndex, starHeroID, heroStar, starAward), playerID)
    if not awardItemList:
        GameWorld.DebugLog("ûÓпÉÁìÃâ·Ñ½±Àø!", playerID)
        return
    GameWorld.DebugLog("updStarAward=%s,awardItemList=%s" % (updStarAward, awardItemList), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHeroAppearStarAward % actNum, updStarAward)
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["HeroAppearStar", False, {}])
    Sync_ActHeroAppearPlayerInfo(curPlayer, actNum)
    return
 
def GetCTGActItemList(curPlayer, ctgID):
    ## »î¶¯³äÖµID¶îÍâÎïÆ·Áбí
    # @return: [[itemID,count], ...]
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HeroAppear, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
        if not ipyData:
            continue
        starGiftTempID = ipyData.GetStarGiftTempID()
        actHeroIDList = ipyData.GetActHeroIDList()
        starHeroIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarIndex % actNum)
        if starHeroIndex >= len(actHeroIDList):
            continue
        starHeroID = actHeroIDList[starHeroIndex]
        
        awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActHeroAppearStar", starGiftTempID)
        if not awardIpyDataList:
            continue
        for awardIpyData in awardIpyDataList:
            if ctgID != awardIpyData.GetStarGiftCTGID():
                continue
            heroGiftItemInfo = awardIpyData.GetHeroGiftItemInfo()
            if str(starHeroID) not in heroGiftItemInfo:
                return []
            return heroGiftItemInfo[str(starHeroID)]
    return []
 
def Sync_ActHeroAppearPlayerInfo(curPlayer, actNum):
    clientPack = ChPyNetSendPack.tagSCActHeroAppearPlayerInfo()
    clientPack.ActNum = actNum
    clientPack.StarHeroIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarIndex % actNum)
    clientPack.StarFreeAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearStarAward % actNum)
    clientPack.CallHeroIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHeroAppearCallIndex % actNum)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_ActHeroAppearActionInfo(curPlayer, actNum, roundType=0):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HeroAppear, actNum)
    if not actInfo or not actInfo.get(ShareDefine.ActKey_State):
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActHeroAppear", cfgID)
    if not ipyData:
        return
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    clientPack = ChPyNetSendPack.tagSCActHeroAppearInfo()
    clientPack.ActType = ShareDefine.OperationActTypeDict.get(ShareDefine.OperationActionName_HeroAppear, 0)
    clientPack.ActNum = actNum
    clientPack.StartDate = startDateStr
    clientPack.EndtDate = endDateStr
    clientPack.CfgID = cfgID
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return