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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GameWorldLogic.FBProcess.GameLogic_Dingjunge
#
# @todo:¶¨¾ü¸ó
# @author hxp
# @date 2026-01-06
# @version 1.0
#
# ÏêϸÃèÊö: ¶¨¾ü¸ó
#
#-------------------------------------------------------------------------------
#"""Version = 2026-01-06 13:30"""
#-------------------------------------------------------------------------------
 
import FBCommon
import GameWorld
import ShareDefine
import PlayerControl
import PlayerBillboard
import ChPyNetSendPack
import ItemControler
import IpyGameDataPY
import NetPackCommon
import ChConfig
 
# ×Ô¶¯Ñ¡ÔñÅÅÐòÓÅÏȼ¶Ë÷Òý
(
Priority_InSet, # 0
Priority_EffQuality, # 1
Priority_SetPriority, # 2
Priority_EIndex, # 3
Priority_EffInfo, # 4
Priority_EffID, # 5
Priority_AttrID, # 6
) = range(7)
 
def OnFBPlayerOnLogin(curPlayer):
    SyncDingjungeInfo(curPlayer)
    return
 
def OnFBPlayerOnDay(curPlayer):
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGLineID, 0)
    for eIndex in range(len(IpyGameDataPY.GetFuncEvalCfg("DingjungeEff", 1))):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % eIndex, 0)
    for sIndex in range(IpyGameDataPY.GetFuncCfg("DingjungeEff", 3)):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGSelectEffect % sIndex, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGUnSelectCnt, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffAuto, 0) # Ã¿ÈÕÖØÖÃ×Ô¶¯¿ª¹Ø
    SyncDingjungeInfo(curPlayer)
    return
 
def GetNextIpyData(curPlayer):
    ## »ñÈ¡ÏÂÒ»¹ØipyData
    todayLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
    layerNum, levelNum = todayLineID / 100, todayLineID % 100
    if not layerNum:
        ipyData = IpyGameDataPY.GetIpyGameData("FBDJGLevel", 1, 1)
    elif not levelNum:
        ipyData = IpyGameDataPY.GetIpyGameData("FBDJGLevel", layerNum, 1)
    else:
        nextLayerNum = layerNum
        nextLevelNum = levelNum + 1 # ÏÂÒ»¹Ø
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog("FBDJGLevel", nextLayerNum, nextLevelNum)
        if not ipyData:# Ã»ÓÐÏÂÒ»¹ØÈ¡ÏÂÒ»²ã
            nextLayerNum = layerNum + 1
            nextLevelNum = 1
            ipyData = IpyGameDataPY.GetIpyGameDataNotLog("FBDJGLevel", nextLayerNum, nextLevelNum)
    if ipyData:
        return ipyData
    GameWorld.DebugLog("ÒÑͨ¹Ø»òÕÒ²»µ½ÏÂÒ»¹ØÊý¾Ý! layerNum=%s,levelNum=%s" % (layerNum, levelNum))
    return
 
def GetPassLayerMax(curPlayer):
    ## »ñÈ¡ÒÑͨ¹ØµÄ×î´ó²ã¼¶
    mapID = ChConfig.Def_FBMapID_Dingjunge
    highestLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBPassLineID % mapID)
    hLayerNum, hLevelNum = highestLineID / 100, highestLineID % 100
    passLayerMax = max(0, hLayerNum - 1) # Ä¬ÈÏͨ¹ØµÄÊÇÉÏÒ»²ã
    # Èç¹û¹ý¹Ø¼Ç¼ÔÚ±¾²ã£¬ÇÒûÓÐÏÂÒ»¹ØÁË£¬Ò²Ëãͨ¹ØÁ˱¾²ã
    if hLayerNum and hLevelNum and not IpyGameDataPY.GetIpyGameDataNotLog("FBDJGLevel", hLayerNum, hLevelNum + 1):
        passLayerMax = hLayerNum
    return passLayerMax
 
def GetQuickStartLayer(curPlayer):
    ## »ñÈ¡¿ìËÙÌôÕ½µÄÆðʼ²ã¼¶
    # @return: >1-¿É¿ìËÙÌôÕ½µÄÆðʼ²ã¼¶
    passLayerMax = GetPassLayerMax(curPlayer)
    backLayers = IpyGameDataPY.GetFuncCfg("Dingjunge", 1)
    quickStartLayer = passLayerMax + 1 - backLayers # ÐèÒª+1²ã
    if quickStartLayer > 1:
        return quickStartLayer
    return 0
 
def OnTurnFightRequest(curPlayer, mapID, funcLineID, tagType, tagID, valueList):
    ## »ØºÏÕ½¶·ÇëÇó 
    highestLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBPassLineID % mapID)
    quickStartLayer = GetQuickStartLayer(curPlayer)
    if quickStartLayer:
        todayLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
        if not todayLineID:
            GameWorld.DebugLog("½ñÈÕ»¹Î´¿ìËÙÕ½¶·ÎÞ·¨ÊÖ¶¯ÌôÕ½! highestLineID=%s,quickStartLayer=%s" % (highestLineID, quickStartLayer))
            return
    nextIpyData = GetNextIpyData(curPlayer)
    if not nextIpyData:
        return
    layerNum = nextIpyData.GetLayerNum()
    levelNum = nextIpyData.GetLevelNum()
    funcLineID = layerNum * 100 + levelNum
    return True, funcLineID
 
def GetFBNPCLineupInfo(curPlayer, mapID, funcLineID):
    ## »ñÈ¡NPCÕóÈÝÏà¹Ø
    # @return: npcLineupIDList, strongerLV, difficulty
    
    layerNum, levelNum = funcLineID / 100, funcLineID % 100
    ipyData = IpyGameDataPY.GetIpyGameData("FBDJGLevel", layerNum, levelNum)
    if not ipyData:
        return
    
    npcLineupIDList = ipyData.GetLineupIDList()
    strongerLV = ipyData.GetNPCLV()
    difficulty = ipyData.GetDifficulty()
    
    return npcLineupIDList, strongerLV, difficulty
 
def OnTurnFightAward(curPlayer, guid, mapID, funcLineID, winFaction, statMsg, dateStr, reqData, awardDict):
    ## »ØºÏÕ½¶·½áËã½±Àø
    if not curPlayer:
        return
    
    isWin = winFaction == ChConfig.Def_FactionA
    
    if not isWin:
        return
    
    todayLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
    GameWorld.DebugLog("¶¨¾ü¸ó½áËã: funcLineID=%s,todayLineID=%s" % (funcLineID, todayLineID))
    if todayLineID >= funcLineID:
        GameWorld.DebugLog("½ñÈÕÒѹý¹ØµÄ²»Öظ´½áËã½±Àø! todayLineID=%s >= %s" % (todayLineID, funcLineID))
        return
    
    layerNum, levelNum = funcLineID / 100, funcLineID % 100
    ipyData = IpyGameDataPY.GetIpyGameData("FBDJGLevel", layerNum, levelNum)
    if not ipyData:
        return
    
    awardItemList = []
    highestLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBPassLineID % mapID)
    # Ê×ͨ
    if funcLineID > highestLineID:
        firstPassAwardList = ipyData.GetPassAwardList()
        awardItemList += firstPassAwardList
        GameWorld.DebugLog("Ê״ιý¹Ø: highestLineID=%s,firstPassAwardList=%s" % (highestLineID, firstPassAwardList))
        FBCommon.SetFBPass(curPlayer, mapID, funcLineID)
        PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_Dingjunge, funcLineID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGLineID, funcLineID)
    
    awardItemList += ipyData.GetAwardList() # ÌôÕ½½±Àø
    GameWorld.DebugLog("×îÖÕ½±Àø: mapID=%s,layerNum=%s,levelNum=%s,awardItemList=%s" % (mapID, layerNum, levelNum, awardItemList))
    awardDict.update({FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(awardItemList)})
    
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["Dingjunge", False, {}], isNotifyAward=False)
    
    if not IpyGameDataPY.GetIpyGameDataNotLog("FBDJGLevel", layerNum, levelNum + 1):
        GameWorld.DebugLog("±¾²ãûÓÐÏÂÒ»¹ØÁË£¬Í¨¹Ø±¾²ã!: layerNum=%s,levelNum=%s" % (layerNum, levelNum))
        GivePassLayerEff(curPlayer, 1)
        
    SyncDingjungeInfo(curPlayer)
    return
 
def OnPlayerFBQuickPass(curPlayer, mapID, lineID):
    '''¸±±¾¿ìËÙ¹ý¹ØÑéÖ¤
    @param mapID: Êý¾ÝµØÍ¼ID
    @param lineID: Ä¿±ê¹Ø¿¨Ïß·ID£¬¿ÉÒ»´ÎÐÔÌø¶à¹Ø£¬¸ù¾Ý¹¦ÄÜÓÉǰ¶Ë·¢°ü¾ö¶¨»òºó¶ËÖ±½Ó¾ö¶¨
    @return: (lineID, quickCnt, quickFightPower, quickData) »ò  None
    @note: lineID Óɺó¶Ë¾ö¶¨µÄ¿ìËÙ¹ý¹Øµ½ÄÄ£¬Èç¹ûǰ¶Ë¾ö¶¨µÄÔòÖ±½Ó·µ»Ø lineID
    @note: quickCnt ±¾´Î×ܹ²Ìø¹ý¼¸¹Ø 
    @note: quickFightPower Ä¿±êÕóÈÝÕ½Á¦£¬ÓÃÓÚÑéÖ¤Õ½Á¦ÊÇ·ñÂú×ã¿ìËÙ¹ý¹Ø
    @note: quickData À©Õ¹Êý¾Ý£¬¹¦ÄÜ×Ô¶¨Ò壬´«¸ø OnPlayerFBQuickPassResult
    '''
    
    todayLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
    if todayLineID:
        GameWorld.DebugLog("½ñÈÕÒѾ­ÔÚÊÖ¶¯Õ½¶·ÁË£¬ÎÞ·¨¿ìËÙÌôÕ½! todayLineID=%s" % (todayLineID))
        return
    
    highestLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBPassLineID % mapID)
    quickStartLayer = GetQuickStartLayer(curPlayer)
    if not quickStartLayer:
        GameWorld.DebugLog("»¹Î´´ïµ½¿É¿ìËÙÌôÕ½µÄ²ã¼¶! highestLineID=%s" % (highestLineID))
        return
    quickData = [highestLineID, quickStartLayer]
    quickCnt = 0
    quickFightPower = 0
    return lineID, quickCnt, quickFightPower, quickData
 
def OnPlayerFBQuickPassResult(curPlayer, mapID, lineID, quickData):
    ## ¸±±¾¿ìËÙ¹ý¹Ø½á¹û
    
    highestLineID, quickStartLayer = quickData
    playerID = curPlayer.GetPlayerID()
    passLayerMax = GetPassLayerMax(curPlayer) # ÀúÊ·×î´ó¹ý¹Ø²ã¼¶
    todayLineID = quickStartLayer * 100 + 0 # ÏÈÉèÖÃÒѹýµ½Æðʼ²ãµÚ0¹Ø£¬Ç°¶ËÈç¹ûÓÐÎÊÌâÔÙÉèÖÃΪÉÏÒ»²ã×îºóÒ»¹Ø
    GameWorld.DebugLog("¶¨¾ü¸ó¿ìËÙÕ½¶·: highestLineID=%s,passLayerMax=%s,quickStartLayer=%s,todayLineID=%s" 
                       % (highestLineID, passLayerMax, quickStartLayer, todayLineID), playerID)
    
    # ¿ìËÙ¹ý¹Ø½±Àø°´ÀúÊ·×î´ó¹ý¹Ø²ã¼¶ÁìÈ¡
    awardItemDict = {}
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetFBDJGQuickCount()):
        quickIpyData = ipyDataMgr.GetFBDJGQuickByIndex(index)
        needLayer = quickIpyData.GetNeedLayer()
        if needLayer > passLayerMax:
            break
        quickItemList = quickIpyData.GetQuickAwardList()
        for itemInfo in quickItemList:
            itemID, itemCount = itemInfo[:2]
            awardItemDict[itemID] = awardItemDict.get(itemID, 0) + itemCount
    awardItemList = [[itemID, itemCount] for itemID, itemCount in awardItemDict.items()]
    
    # ÉèÖÃÆðʼ²ã¹Ø¿¨
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGLineID, todayLineID)
    
    addEffCnt = quickStartLayer - 1 # -1ÊÇ´ú±í¼Ó³ÉЧ¹û½áËãµ½ÆðʼµÄÉÏÒ»²ã£¬Ã¿¹ý1²ã+1´Î
    GivePassLayerEff(curPlayer, addEffCnt)
    SyncDingjungeInfo(curPlayer)
    
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["Dingjunge", False, {}])
    return
 
def GivePassLayerEff(curPlayer, addEffCnt=1):
    unSelectCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGUnSelectCnt) + addEffCnt
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGUnSelectCnt, unSelectCnt)
    GameWorld.DebugLog("Ôö¼ÓЧ¹û¼Ó³É´ÎÊý: addEffCnt=%s,unSelectCnt=%s" % (addEffCnt, unSelectCnt))
    if not __doAutoSelectAll(curPlayer):
        __randSelectEff(curPlayer)
    return
 
#// B1 01 ¶¨¾ü¸óЧ¹ûÔ¤Éè #tagCSDingjungeEffSet
#
#struct    tagCSDingjungeEffSet
#{
#    tagHead         Head;
#    BYTE        SelectAuto;    //ÊÇ·ñÆôÓÃ×Ô¶¯Ñ¡Ôñ
#    BYTE        SelectSetCnt;
#    WORD        SelectSetAttrIDList[SelectSetCnt];    //Ô¤ÉèÓÅÏÈÑ¡ÔñÊôÐÔIDÁбí [ÓÅÏȼ¶1ÊôÐÔID, ...]
#};
def OnDingjungeEffSet(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    selectAuto = 1 if clientData.SelectAuto else 0
    selectSetAttrIDList = clientData.SelectSetAttrIDList
    
    canSetAttrIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetFBDJGEffectCount()):
        ipyData = ipyDataMgr.GetFBDJGEffectByIndex(index)
        attrID = ipyData.GetAttrID()
        if attrID not in canSetAttrIDList:
            canSetAttrIDList.append(attrID)
    canSetAttrIDList.sort()
    
    GameWorld.DebugLog("Ч¹ûÔ¤Éè: selectAuto=%s,selectSetAttrIDList=%s,canSetAttrIDList=%s" % (selectAuto, selectSetAttrIDList, canSetAttrIDList))
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffAuto, selectAuto)
    for ssIndex in range(IpyGameDataPY.GetFuncCfg("DingjungeEff", 4)):
        attrID = selectSetAttrIDList[ssIndex] if len(selectSetAttrIDList) > ssIndex else 0
        if attrID not in canSetAttrIDList:
            attrID = 0
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffSet % ssIndex, attrID)
    SyncDingjungeInfo(curPlayer)
    return
 
#// B1 02 ¶¨¾ü¸óЧ¹ûÑ¡Ôñ #tagCSDingjungeEffSelect
#
#struct    tagCSDingjungeEffSelect
#{
#    tagHead         Head;
#    BYTE        SelectType;    //0-ÊÖ¶¯Ñ¡Ôñ£¬1-·ÅÆú±¾´ÎÑ¡Ôñ£¬2-Ò»¼üÑ¡Ôñ£¨½ö¿ªÆôÁË×Ô¶¯Ñ¡ÔñʱÓÐЧ£©
#    BYTE        SelectIndex;    //ÊÖ¶¯Ñ¡ÔñË÷Òý 0~n
#    BYTE        ReplaceHole;    //ÊÖ¶¯Ñ¡ÔñÌæ»»²Ûλ 1~n£¬²Ûλ=²ÛË÷Òý+1£¬Éý¼¶Ê±¿ÉÖ±½Ó·¢0
#};
def OnDingjungeEffSelect(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    selectType = clientData.SelectType
    selectIndex = clientData.SelectIndex
    replaceHole = clientData.ReplaceHole
    
    if selectType == 2:
        __doAutoSelectAll(curPlayer)
    elif selectType == 1:
        __randSelectEff(curPlayer, isReset=True)
    else:
        if __doSelectEff(curPlayer, selectIndex, replaceHole):
            __randSelectEff(curPlayer, isReset=True)
            
    SyncDingjungeInfo(curPlayer)
    return
 
def __doAutoSelectAll(curPlayer):
    if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffAuto):
        GameWorld.DebugLog("먦Æô×Ô¶¯Ñ¡Ôñ!")
        return
    unSelectCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGUnSelectCnt)
    
    selectSetAttrIDList = [] # Ð§¹ûÑ¡ÔñÔ¤Éè
    for ssIndex in range(IpyGameDataPY.GetFuncCfg("DingjungeEff", 4)):
        attrID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffSet % ssIndex)
        if attrID:
            selectSetAttrIDList.append(attrID)
            
    effHoleCnt = __getUnlockEffHoleCnt(curPlayer)
        
    GameWorld.DebugLog("Ö´ÐÐÒ»¼üÑ¡Ôñ¼Ó³ÉЧ¹û: unSelectCnt=%s,effHoleCnt=%s,selectSetAttrIDList=%s" % (unSelectCnt, effHoleCnt, selectSetAttrIDList))
    
    randEffCnt = IpyGameDataPY.GetFuncCfg("DingjungeEff", 3)
    for _ in range(unSelectCnt):
        effIDList = __randSelectEff(curPlayer, randEffCnt)
        if not effIDList:
            break
        if not __doAutoSelectEff(curPlayer, effIDList, selectSetAttrIDList, effHoleCnt):
            # ²»ÐèÒª×Ô¶¯Ñ¡Ôñ£¬Ö±½ÓÍ˳ö£¬Íæ¼ÒÊÖ¶¯Ñ¡Ôñ
            break
        # ×Ô¶¯Ñ¡ÔñºóÖØÖÃ
        for sIndex in range(randEffCnt):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGSelectEffect % sIndex, 0)
    return True
 
def __getUnlockEffHoleCnt(curPlayer):
    ## »ñÈ¡ÒѽâËøµÄЧ¹û²ÛÊý
    todayLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
    effHoleNeedLVIDList = IpyGameDataPY.GetFuncEvalCfg("DingjungeEff", 1)
    effHoleCnt = 0 # ÒѽâËøµÄЧ¹û²ÛÊý
    for needLVID in effHoleNeedLVIDList:
        if todayLineID >= needLVID:
            effHoleCnt += 1
    return effHoleCnt
 
def __randSelectEff(curPlayer, randEffCnt=0, isReset=False):
    ## Ëæ»úÉú³É´ýÑ¡Ôñ¼Ó³ÉЧ¹û
    unSelectCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGUnSelectCnt)
    if unSelectCnt <= 0:
        GameWorld.DebugLog("ûÓÐδ´¦ÀíµÄ¼Ó³ÉЧ¹û´ÎÊýÁË")
        return
    if not randEffCnt:
        randEffCnt = IpyGameDataPY.GetFuncCfg("DingjungeEff", 3)
    effIDList = []
    if isReset:
        # ÖØÖÃ
        for sIndex in range(randEffCnt):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGSelectEffect % sIndex, 0)
    else:
        for sIndex in range(randEffCnt):
            effID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGSelectEffect % sIndex)
            if not effID:
                break
            effIDList.append(effID)
    if effIDList:
        GameWorld.DebugLog("ÒÑ´æÔÚδѡÔñµÄ¼Ó³ÉЧ¹ûµÈÑ¡ÔñºóÔÙÉú³É: effIDList=%s,unSelectCnt=%s" % (effIDList, unSelectCnt))
        return effIDList
    
    fullLVEffIDList = [] # ÒÑÂú¼¶µÄЧ¹ûIDÁбí
    effMaxLV = IpyGameDataPY.GetFuncCfg("DingjungeEff", 2)
    for eIndex in range(len(IpyGameDataPY.GetFuncEvalCfg("DingjungeEff", 1))):
        effInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffect % eIndex)
        if not effInfo:
            break
        effID, effLV = effInfo / 100, effInfo % 100
        if effLV >= effMaxLV:
            fullLVEffIDList.append(effID)
            
    randWeightList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetFBDJGEffectCount()):
        ipyData = ipyDataMgr.GetFBDJGEffectByIndex(index)
        effID = ipyData.GetEffID()
        if effID in fullLVEffIDList:
            # ÅųýÂú¼¶µÄ
            continue
        randWeight = ipyData.GetRandWeight()
        if randWeight:
            randWeightList.append([randWeight, effID])
        
    # Ëæ»úЧ¹û£¬²»Öظ´
    randCnt = 200
    while len(effIDList) < randEffCnt and randCnt > 0:
        randCnt -= 1
        randEffID = GameWorld.GetResultByWeightList(randWeightList)
        if randEffID not in effIDList:
            effIDList.append(randEffID)
            
    unSelectCnt -= 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGUnSelectCnt, unSelectCnt)
    for sIndex in range(randEffCnt):
        effID = effIDList[sIndex] if len(effIDList) > sIndex else 0
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGSelectEffect % sIndex, effID)
    #GameWorld.DebugLog("Ëæ»úÉú³É¼Ó³ÉЧ¹û: effIDList=%s,unSelectCnt=%s,fullLVEffIDList=%s" % (effIDList, unSelectCnt, fullLVEffIDList))
    return effIDList
 
def __doAutoSelectEff(curPlayer, selectEffIDList, selectSetAttrIDList, effHoleCnt):
    ## ×Ô¶¯Ñ¡Ôñ¼Ó³É
            
    # ÈôËæ»ú³öÁ˶àÖÖÔ¤ÉèÄڵĵÄÊôÐÔ£¬ÔòÓÅÏÈÑ¡ÔñÆ·Öʸߵģ¬Ö»³öÏÖµ¥ÖÖÔ¤ÉèÄÚÊôÐԵϰ£¬ÔòÔ¤ÉèÓÅÏÈ
    priorityEffList = [] # Æ·ÖÊÓÅÏÈ
    for effID in selectEffIDList:
        effIpyData = IpyGameDataPY.GetIpyGameData("FBDJGEffect", effID)
        if not effIpyData:
            continue
        effQuality = effIpyData.GetEffQuality()
        attrID = effIpyData.GetAttrID()
        inSet = 0 # Ô¤ÉèÓÅÏÈ£¬µ«¶à¸öÔ¤Éèͬʱ³öÏÖʱ£¬ÏÈÆ·ÖÊÓÅÏÈ£¬ÔÙÔ¤ÉèÓÅÏȼ¶
        setPriority = 0 # Ô¤ÉèÅÅÐòÓÅÏȼ¶
        if attrID in selectSetAttrIDList:
            inSet = 1
            setPriority = len(selectSetAttrIDList) - selectSetAttrIDList.index(attrID)
            
        effLV = 1 # ³õʼ1¼¶
        effInfo = effID * 100 + effLV
        eIndex = -1 # ÉúЧË÷Òý£¬ÉèΪ-1£¬±ÈÒÑÉúЧµÄµÍ
        priorityEffList.append([inSet, effQuality, setPriority, eIndex, effInfo, effID, attrID])
        
    priorityEffList.sort(reverse=True)
    if not priorityEffList:
        return
    #GameWorld.DebugLog("    ÅÅÐòÓÅÏȼ¶: [inSet, effQuality, setPriority, eIndex, effInfo, effID, attrID]")
    #GameWorld.DebugLog("    ´ýÑ¡ÔñÅÅÐò: %s" % priorityEffList)
    selectEff = priorityEffList[0] # ×Ô¶¯Ñ¡ÔñµÚÒ»¸ö
    #selectAttrID = selectEff[Priority_AttrID]
    selectEffID = selectEff[Priority_EffID]
    selectEffInfo = selectEff[Priority_EffInfo]
            
    effMaxLV = IpyGameDataPY.GetFuncCfg("DingjungeEff", 2)
    emptyIndex = -1
    effList = [] # ÒÑÉúЧµÄЧ¹û
    for eIndex in range(effHoleCnt):
        effInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffect % eIndex)
        if not effInfo:
            if emptyIndex == -1:
                #GameWorld.DebugLog("    »¹ÓпղÛ: eIndex=%s" % eIndex)
                emptyIndex = eIndex
            continue
        
        effID, effLV = effInfo / 100, effInfo % 100
        
        effIpyData = IpyGameDataPY.GetIpyGameData("FBDJGEffect", effID)
        if not effIpyData:
            continue
        effQuality = effIpyData.GetEffQuality()
        attrID = effIpyData.GetAttrID()
        
        # ÒÑ´æÔÚ£¬Éý¼¶
        if effID == selectEffID and effLV < effMaxLV:
            effLV += 1
            effInfo = effID * 100 + effLV
            #GameWorld.DebugLog("    ÒÑ´æÔÚ¸ÃЧ¹ûÖ±½ÓÉý¼¶: eIndex=%s,effID=%s,effLV=%s,attrID=%s" % (eIndex, effID, effLV, attrID))
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % eIndex, effInfo)
            return True
        
        inSet = 0 # Ô¤ÉèÓÅÏÈ£¬µ«¶à¸öÔ¤Éèͬʱ³öÏÖʱ£¬ÏÈÆ·ÖÊÓÅÏÈ£¬ÔÙÔ¤ÉèÓÅÏȼ¶
        setPriority = 0 # Ô¤ÉèÅÅÐòÓÅÏȼ¶
        if attrID in selectSetAttrIDList:
            inSet = 1
            setPriority = len(selectSetAttrIDList) - selectSetAttrIDList.index(attrID)
            
        effList.append([inSet, effQuality, setPriority, eIndex, effInfo, effID, attrID])
        
    # ¿Õ²Û
    if emptyIndex != -1:
        eIndex = emptyIndex
        effID = selectEffID
        effLV = 1
        effInfo = effID * 100 + effLV
        #GameWorld.DebugLog("    ¿Õ²ÛÖ±½ÓÉèÖÃ: emptyIndex=%s,effID=%s,effLV=%s,attrID=%s,effList=%s" % (eIndex, effID, effLV, selectAttrID, effList))
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % eIndex, effInfo)
        return True
    
    # Ìæ»»Âß¼­
    effList.append(selectEff) # Ñ¡ÔñÏîÔÙÓëÉúЧµÄÒ»ÆðÅÅÐò
    effList.sort(reverse=True)
    
    lastEff = effList[-1]
    lastEIndex = lastEff[Priority_EIndex]
    #lastEffID = lastEff[Priority_EffID]
    #lastAttrID = lastEff[Priority_AttrID]
    if lastEIndex == -1:
        pass
        #GameWorld.DebugLog("    ÓÅÏȼ¶±ÈÒÑÉúЧµÄµÍ£¬Ö±½ÓÉáÆú! lastEIndex=%s,lastEffID=%s,lastAttrID=%s,effList=%s" % (lastEIndex, lastEffID, lastAttrID, effList))
    else:
        replaceIndex = lastEIndex
        effInfo = selectEffInfo
        #GameWorld.DebugLog("    ÓÅÏȼ¶±ÈÒÑÉúЧµÄ¸ß£¬Ö±½ÓÌæ»»! replaceIndex=%s,selectAttrID=%s,effInfo=%s,effList=%s" % (replaceIndex, selectAttrID, effInfo, effList))
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % replaceIndex, effInfo)
            
    return True
 
def __doSelectEff(curPlayer, selectIndex, replaceHole):
    ## ÊÖ¶¯Ñ¡ÔñЧ¹û
    selectEffID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGSelectEffect % selectIndex)
    GameWorld.DebugLog("ÊÖ¶¯Ñ¡ÔñЧ¹û: selectIndex=%s,selectEffID=%s,replaceHole=%s" % (selectIndex, selectEffID, replaceHole))
    if not selectEffID:
        return
    effHoleCnt = __getUnlockEffHoleCnt(curPlayer)
    effMaxLV = IpyGameDataPY.GetFuncCfg("DingjungeEff", 2)
    emptyIndex = -1
    for eIndex in range(effHoleCnt):
        effInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffect % eIndex)
        if not effInfo:
            if emptyIndex == -1:
                GameWorld.DebugLog("    »¹ÓпղÛ: eIndex=%s" % eIndex)
                emptyIndex = eIndex
            continue
        effID, effLV = effInfo / 100, effInfo % 100
        # ÒÑ´æÔÚ£¬Éý¼¶
        if effID == selectEffID:
            if effLV >= effMaxLV:
                GameWorld.DebugLog("    ÒÑ´æÔÚ¸ÃЧ¹ûÇÒÒÑÂú¼¶: eIndex=%s,effID=%s,effLV=%s" % (eIndex, effID, effLV))
                return
            effLV += 1
            effInfo = effID * 100 + effLV
            GameWorld.DebugLog("    ÒÑ´æÔÚ¸ÃЧ¹ûÖ±½ÓÉý¼¶: eIndex=%s,effID=%s,effLV=%s" % (eIndex, effID, effLV))
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % eIndex, effInfo)
            return True
        
    # ¿Õ²Û
    if emptyIndex != -1:
        eIndex = emptyIndex
        effID = selectEffID
        effLV = 1
        effInfo = effID * 100 + effLV
        GameWorld.DebugLog("    ¿Õ²ÛÖ±½ÓÉèÖÃ: emptyIndex=%s,effID=%s,effLV=%s" % (eIndex, effID, effLV))
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % eIndex, effInfo)
        return True
    
    # Ìæ»»Âß¼­
    if replaceHole < 1 or replaceHole > effHoleCnt:
        GameWorld.DebugLog("    Ìæ»»µÄÄ¿±ê²Ûλ²»¿ÉÓÃ: replaceHole=%s,effHoleCnt=%s" % (replaceHole, effHoleCnt))
        return
    
    effLV = 1
    selectEffInfo = selectEffID * 100 + effLV
    replaceIndex = replaceHole - 1
    effInfo = selectEffInfo
    GameWorld.DebugLog("    ÊÖ¶¯Ñ¡ÔñÌæ»»! replaceIndex=%s,effInfo=%s" % (replaceIndex, effInfo))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DJGEffect % replaceIndex, effInfo)
    return True
 
def SyncDingjungeInfo(curPlayer):
    clientPack = ChPyNetSendPack.tagSCDingjungeInfo()
    clientPack.TodayPass = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGLineID)
    effList = [] # ÒÑÉúЧµÄЧ¹û
    for eIndex in range(len(IpyGameDataPY.GetFuncEvalCfg("DingjungeEff", 1))):
        effInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffect % eIndex)
        if not effInfo:
            break
        effID, effLV = effInfo / 100, effInfo % 100
        eff = ChPyNetSendPack.tagSCDingjungeEff()
        eff.EffIndex = eIndex
        eff.EffID = effID
        eff.EffLV = effLV
        effList.append(eff)
    clientPack.EffList = effList
    clientPack.EffCnt = len(clientPack.EffList)
    selectEffList = [] # ´ýÑ¡ÔñµÄЧ¹û
    for sIndex in range(IpyGameDataPY.GetFuncCfg("DingjungeEff", 3)):
        effID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGSelectEffect % sIndex)
        if not effID:
            break
        selectEffList.append(effID)
    clientPack.SelectEffList = selectEffList
    clientPack.SelectEffCnt = len(clientPack.SelectEffList)
    clientPack.UnSelectCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGUnSelectCnt)
    clientPack.SelectAuto = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffAuto)
    selectSetAttrIDList = [] # Ð§¹ûÑ¡ÔñÔ¤Éè
    for ssIndex in range(IpyGameDataPY.GetFuncCfg("DingjungeEff", 4)):
        attrID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DJGEffSet % ssIndex)
        selectSetAttrIDList.append(attrID)
    clientPack.SelectSetAttrIDList = selectSetAttrIDList
    clientPack.SelectSetCnt = len(clientPack.SelectSetAttrIDList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return