hxp
2024-09-18 458f8ad37f944f5a4334dc9e522e6640e4aa2def
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 PlayerFBHelpBattle
#
# @todo:¸±±¾Öúսϵͳ
# @author hxp
# @date 2018-11-24
# @version 1.0
#
# ÏêϸÃèÊö: ¸±±¾Öúսϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2018-11-24 22:30"""
#-------------------------------------------------------------------------------
 
import PlayerFriend
import IpyGameDataPY
import PlayerViewCache
import IPY_GameServer
import PlayerAssist
import ShareDefine
import PyGameData
import GameWorld
import ChConfig
 
import random
import time
 
MaxRobotID = 100 # ×î´ó»úÆ÷ÈËNPC¶¨ÒåID
 
Def_RecType_CheckInPlayer = ShareDefine.Def_UniversalGameRecType_FBHelpBattleCheckInPlayer
 
## ÖúÕ½Íæ¼Ò¼òÒªÐÅÏ¢
class HelpBattlePlayer():
    
    def __init__(self, playerID):
        self.playerID = playerID
        self.job = 0
        self.playerName = ""
        self.playerLV = 0
        self.realmLV = 0
        self.fightPower = 0
        self.familyID = 0
        self.vipLV = 0
        self.checkInCount = 0 # ÀۼƵǼǴÎÊý
        self.checkInTime = 0
        self.todayHelpCountDict = {} # ½ñÌìÒÑÖúÕ½´ÎÊý {(mapID, lineID):count, ...}, Í¨ÓôÎÊýʱlineIDĬÈÏΪ0
        self.getThanksGiftCountDict = {} # Ð­Öú·½½ñÈÕ½ÓÊոøÐлÀñºÐ´ÎÊý {itemID:count, ...}
        return
 
def OnServerStart():
    GameWorld.Log("¿ª·þ¼ÓÔØÖúÕ½Ïà¹ØÐÅÏ¢...")
    universalRecMgr = GameWorld.GetUniversalRecMgr()
    checkInPlayerRecList = universalRecMgr.GetTypeList(Def_RecType_CheckInPlayer)
    for index in xrange(checkInPlayerRecList.Count()):
        recData = checkInPlayerRecList.At(index)
        playerID = recData.GetValue1()
        helpBattlePlayer = HelpBattlePlayer(playerID)
        helpBattlePlayer.checkInTime = recData.GetTime()
        helpBattlePlayer.fightPower = recData.GetValue2()
        helpBattlePlayer.familyID = recData.GetValue3()
        helpBattlePlayer.checkInCount = recData.GetValue4()
        value5 = recData.GetValue5()
        helpBattlePlayer.playerLV = value5 / 100000
        helpBattlePlayer.vipLV = int(str(value5)[-5:-3])
        helpBattlePlayer.realmLV = int(str(value5)[-3:-1])
        helpBattlePlayer.job = value5 % 10
        helpBattlePlayer.playerName = recData.GetStrValue1()
        strValue3 = recData.GetStrValue3()
        strValue3List = strValue3.split("|")
        helpCountDictStr = strValue3List[0] if len(strValue3List) > 0 else "{}"
        getThanksGiftCountDictStr = strValue3List[1] if len(strValue3List) > 1 else "{}"
        
        if helpCountDictStr.startswith("{") and helpCountDictStr.endswith("}"):
            helpBattlePlayer.todayHelpCountDict = eval(helpCountDictStr)
        else:
            GameWorld.ErrLog("LoadCheckInPlayerError: helpCountDictStr=%s" % helpCountDictStr, playerID)
            
        if getThanksGiftCountDictStr.startswith("{") and getThanksGiftCountDictStr.endswith("}"):
            helpBattlePlayer.getThanksGiftCountDict = eval(getThanksGiftCountDictStr)
        else:
            GameWorld.ErrLog("LoadCheckInPlayerError: getThanksGiftCountDictStr=%s" % getThanksGiftCountDictStr, playerID)
        PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] = helpBattlePlayer
    GameWorld.Log("¼ÓÔØÖúÕ½µÇ¼ÇÍæ¼Ò¼Ç¼: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict))
    return
 
def OnServerClose():
    GameWorld.Log("¹Ø·þ±£´æÖúÕ½Ïà¹ØÐÅÏ¢...")
    universalRecMgr = GameWorld.GetUniversalRecMgr()
    universalRecMgr.Delete(Def_RecType_CheckInPlayer)
    
    GameWorld.Log("±£´æÖúÕ½µÇ¼ÇÍæ¼Ò¼Ç¼: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict))
    checkInPlayerRecList = universalRecMgr.GetTypeList(Def_RecType_CheckInPlayer)
    for playerID, checkInPlayer in PyGameData.g_fbHelpBattleCheckInPlayerDict.items():
        recData = checkInPlayerRecList.AddRec()
        recData.SetTime(checkInPlayer.checkInTime)
        recData.SetValue1(playerID)
        recData.SetValue2(min(max(checkInPlayer.fightPower, 0), ChConfig.Def_UpperLimit_DWord))
        recData.SetValue3(checkInPlayer.familyID)
        recData.SetValue4(checkInPlayer.checkInCount)
        recData.SetValue5(int("%d%02d%02d%d" % (checkInPlayer.playerLV, checkInPlayer.vipLV, checkInPlayer.realmLV, checkInPlayer.job)))
        recData.SetStrValue1(checkInPlayer.playerName)
        strValue3 = "%s|%s" % (str(checkInPlayer.todayHelpCountDict).replace(" ", ""),
                               str(checkInPlayer.getThanksGiftCountDict).replace(" ", ""))
        recData.SetStrValue3(strValue3)
        
    return
 
def HelpBattleOnDay():
    curTime = int(time.time())
    checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê±
    # ÕâÀïÑÓ³¤30·ÖÖÓÇå³ý£¬·ÀÖ¹ÒѾ­±»ÕÙ»½»¹Ã»½áËãµÄµ¼ÖÂÕÒ²»µ½µÇ¼ÇÐÅÏ¢
    checkInValidSeconds = checkInValidHours * 3600 + 30 * 60
    
    # Ç峬ʱµÇ¼Ç£¬ÖØÖÃÐÅÏ¢
    for playerID, checkInPlayer in PyGameData.g_fbHelpBattleCheckInPlayerDict.items():
        checkInTime = checkInPlayer.checkInTime
        if curTime - checkInTime > checkInValidSeconds:
            PyGameData.g_fbHelpBattleCheckInPlayerDict.pop(playerID)
            GameWorld.Log("Çå³ý³¬Ê±ÖúÕ½µÇ¼ÇÍæ¼Ò: curTime=%s,checkInTime=%s" % (curTime, checkInTime), playerID)
            continue
        checkInPlayer.todayHelpCountDict = {}
        checkInPlayer.getThanksGiftCountDict = {}
    return
 
## ÊÇ·ñÔÚÖúÕ½µÇ¼ÇÁбíÀï
def IsInHelpBattleCheckInList(playerID): return playerID in PyGameData.g_fbHelpBattleCheckInPlayerDict
 
def MapServer_FBHelpBattle(curPlayer, msgList):
    ## µØÍ¼Íæ¼ÒÇëÇóÖúÕ½Ïà¹Ø²Ù×÷
    GameWorld.DebugLog("MapServer_FBHelpBattle %s" % str(msgList), curPlayer.GetPlayerID())
    if not msgList:
        return ""
    
    cmd = msgList[0]
    result = []
    
    # µÇ¼Ç
    if cmd == "CheckIn":
        result = __DoPlayerFBHelpBattleCheckIn(curPlayer, msgList)
        
    # Ë¢ÐÂÖúÕ½ÁÐ±í    
    elif cmd == "Refresh":
        result = __DoFBHelpBattleRefresh(curPlayer, msgList)
        
    # ÕÙ»½
    elif cmd == "Call":
        result = __DoFBHelpBattleCall(curPlayer.GetPlayerID(), curPlayer.GetName(), msgList)
    
    # É¨µ´ÕÙ»½
    elif cmd == "SweepCall":
        result = __DoFBHelpBattleSweepCall(curPlayer, msgList)
    
    # Ð­ÖúÍê³É
    elif cmd == "AssistFinish":
        __DoAssistFinish(curPlayer, msgList)
        return
    
    if result == None:
        return
    
    return msgList + result
 
def __DoPlayerFBHelpBattleCheckIn(curPlayer, msgList):
    ## Íæ¼ÒµÇ¼Ç
    checkInCount, fightPower = msgList[1:]
    fightPower = min(fightPower, ChConfig.Def_UpperLimit_DWord) # µÇ¼ÇÖúÕ½Õ½Á¦×î¸ßÔÝÖ§³Ö20E
    curTime = int(time.time())
    playerID = curPlayer.GetPlayerID()
    curCache = PlayerViewCache.FindViewCache(playerID)
    haveViewCache = 1 if curCache else 0
    
    helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict.get(playerID)
    if not helpBattlePlayer:
        helpBattlePlayer = HelpBattlePlayer(playerID)
        PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] = helpBattlePlayer
    helpBattlePlayer.playerName = curPlayer.GetName()
    helpBattlePlayer.playerLV = curPlayer.GetLV()
    helpBattlePlayer.job = curPlayer.GetJob()
    helpBattlePlayer.realmLV = curPlayer.GetOfficialRank()
    helpBattlePlayer.fightPower = fightPower
    helpBattlePlayer.familyID = curPlayer.GetFamilyID()
    helpBattlePlayer.vipLV = curPlayer.GetVIPLv()
    helpBattlePlayer.checkInCount = checkInCount + 1
    helpBattlePlayer.checkInTime = curTime
    
    isOK = 1 # Ä¬Èϳɹ¦
    GameWorld.Log("Íæ¼ÒÖúÕ½µÇ¼Ç: playerLV=%s,fightPower=%s,familyID=%s,vipLV=%s,checkInCount=%s,haveViewCache=%s" 
                  % (curPlayer.GetLV(), fightPower, curPlayer.GetFamilyID(), curPlayer.GetVIPLv(), checkInCount + 1, haveViewCache), playerID)
    return [isOK, haveViewCache]
 
def UpdateCheckInPlayerInfo(playerID, fightPower, familyID, playerName):
    ## ¸üеǼǵÄÖúÕ½Íæ¼ÒµÈ¼¶Õ½Á¦
    if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict:
        return
    fightPower = min(fightPower, ChConfig.Def_UpperLimit_DWord) # µÇ¼ÇÖúÕ½Õ½Á¦×î¸ßÔÝÖ§³Ö20E
    helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID]
    helpBattlePlayer.fightPower = fightPower
    helpBattlePlayer.familyID = familyID
    helpBattlePlayer.playerName = playerName
    GameWorld.DebugLog("¸üÐÂÖúÕ½Íæ¼ÒµÈ¼¶Õ½Á¦: fightPower=%s,familyID=%s" % (fightPower, familyID), playerID)
    return
 
def UpdateCheckInPlayerInfoByRefresh(curPlayer, refreshType, value):
    ## ¸üеǼǵÄÖúÕ½Íæ¼ÒÏÉÃËID
    playerID = curPlayer.GetPlayerID()
    if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict:
        return
    helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID]
    if refreshType == IPY_GameServer.CDBPlayerRefresh_LV:
        helpBattlePlayer.playerLV = value
    elif refreshType == IPY_GameServer.CDBPlayerRefresh_VIPLv:
        helpBattlePlayer.vipLV = value
    else:
        return
    GameWorld.DebugLog("¸üÐÂÖúÕ½Íæ¼ÒÐÅÏ¢: refreshType=%s,value=%s" % (refreshType, value), playerID)
    return
 
def __DoFBHelpBattleRefresh(curPlayer, msgList):
    ## ÖúÕ½ÁбíË¢ÐÂ
    mapID, funcLineID, isClientRefresh, costMoneyList, calledPlayerIDDict = msgList[1:]
    
    helpBattlePlayerDict = {} # Í¬²½¸øµØÍ¼·þÎñÆ÷µÄ´ýÑ¡ÖúÕ½Íæ¼ÒÁбíÐÅÏ¢
    
    ipyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID)
    if not ipyData:
        return [helpBattlePlayerDict]
    
    fightPowerMin = ipyData.GetFightPowerMin()
    fightPowerMax = ipyData.GetFightPowerMax()
    limitLV = ipyData.GetLVLimit()
    dayFreeHelpCountInfo = ipyData.GetDayFreeHelpCount() # Ã¿ÈÕÃâ·ÑÖúÕ½´ÎÊý£¬[ÿÈÕÃâ·ÑÖúÕ½´ÎÊý, ÊÇ·ñËùÓвãͨÓÃ]
    dayFreeHelpCount = 0 # 0ΪÎÞÏÞÖÆ´ÎÊý
    helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0
    if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2:
        dayFreeHelpCount, isAllLineCount = dayFreeHelpCountInfo
        if isAllLineCount:
            helpCountLineID = 0
    helpCountKey = (mapID, helpCountLineID)
    
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("Ë¢ÐÂÖúÕ½Áбí: mapID=%s,funcLineID=%s,helpCountLineID=%s,isClientRefresh=%s,costMoneyList=%s,calledPlayerIDDict=%s" 
                  % (mapID, funcLineID, helpCountLineID, isClientRefresh, costMoneyList, calledPlayerIDDict), playerID)
    
    onlyFree = False
    goldCallCount = 0
    nowFreeRelationCount, nowRelationCount, nowRobotCount = 0, 0, 0
    atleastFreeRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 1) # ÖÁÉÙÃâ·ÑÉç½»ÈËÊý£¬ÎÞÉç½»ÔòºöÂÔ
    atleastRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 2) # ÖÁÉÙÉç½»ÈËÊý£¬ÎÞÉç½»ÔòºöÂÔ£¨ÈËÊý°üº¬Ãâ·ÑÉç½»ÈËÊý£©
    atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # ÖúÕ½Áбí»úÆ÷ÈËÖÁ¶àÊýÁ¿
    allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # ÖúÕ½ÁбíÊÇ·ñ³öÏÖ·ÇÉç½»¹ØÏµÍæ¼Ò
    GameWorld.DebugLog("    atleastFreeRelationCount=%s,atleastRelationCount=%s" % (atleastFreeRelationCount, atleastRelationCount))
    
    #ÒѾ­ÕÙ»½µÄ±£Áô
    for calledPlayerID, callInfo in calledPlayerIDDict.items():
        needGoldCall, job, relation = callInfo
        # Íæ¼Ò¾µÏñ
        if calledPlayerID in PyGameData.g_fbHelpBattleCheckInPlayerDict:
            helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[calledPlayerID]
            helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, job, relation)
            if needGoldCall:
                goldCallCount += 1
            if relation:
                nowRelationCount += 1
                if not needGoldCall:
                    nowFreeRelationCount += 1
        # »úÆ÷ÈËNPC
        elif 1 <= calledPlayerID <= MaxRobotID:
            nowRobotCount += 1
            helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, job)
        else:
            GameWorld.ErrLog("ÒÑÕÙ»½µÄÖúÕ½Íæ¼ÒÕÒ²»µ½¾µÏñ»º´æ£¡ÀíÂÛÉϲ»´æÔÚ¸ÃÇé¿ö£¬¾µÏñ»º´æÊÍ·Å»á±ÈµÇ¼ÇÓÐЧʱ³¤¶à°ëСʱ£¡")
            continue
            
    if helpBattlePlayerDict:
        GameWorld.Log("ÒÑÕÙ»½µÄÖúÕ½: %s" % str(helpBattlePlayerDict), playerID)
        
    curTime = int(time.time())
    maxHelpPlayerSelectCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 1) # ×î´ó¿ÉÒÔÑ¡ÔñÖúÕ½µÄÍæ¼Ò¸öÊý
    maxGoldHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 3) # ×î´ó¸¶·ÑÕÙ»½ÈËÊý
    checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê±
    checkInValidSeconds = checkInValidHours * 3600
    
    checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys()
    random.shuffle(checkInPlayerIDList)
    GameWorld.Log("    µÇ¼ÇÖúÕ½ÈËÊý=%s" % (len(checkInPlayerIDList)), playerID)
    
    if not allowNoRelation:
        atleastRelationCount = maxHelpPlayerSelectCount
        GameWorld.DebugLog("²»ÔÊÐí³öÏÖ·ÇÉç½»ÈËÊý£¬Ä¬ÈÏÉèÖÃÖÁÉÙÉç½»ÈËÊýΪ×î´ó¿ÉÑ¡ÔñÈËÊý! %s" % atleastRelationCount)
        
    # 1. ÖÁÉÙÉç½»¹ØÏµÈËÊý»¹²»×ãµÄ£¬ÏÈ´¦ÀíÖÁÉÙÉç½»¹ØÏµÈËÊý
    if nowRelationCount < atleastRelationCount:
        relationIDList = []
        friendIDList = PlayerFriend.GetFriendStruct(playerID).GetSocialIDList()
        relationIDList += friendIDList
        #GameWorld.DebugLog("    ºÃÓÑIDÁбí, friendIDList=%s" % friendIDList, playerID)
        curFamily = curPlayer.GetFamily()
        familyMemList = []
        if curFamily:
            for index in xrange(curFamily.GetCount()):
                member = curFamily.GetAt(index)
                memberID = member.GetPlayerID()
                familyMemList.append(memberID)
                if memberID != playerID and memberID not in relationIDList:
                    relationIDList.append(memberID)
        #GameWorld.DebugLog("    ÃËÓÑIDÁбí, familyMemList=%s" % familyMemList, playerID)
        
        random.shuffle(relationIDList)
        #GameWorld.DebugLog("    ÓÐÉç½»µÄIDÁбí, relationIDList=%s" % relationIDList, playerID)
        tempRelationHelpPlayerList = []
        for relationID in relationIDList:
            if nowRelationCount >= atleastRelationCount:
                break
            if relationID not in checkInPlayerIDList:
                continue
            helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[relationID]
            canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, relationID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax,
                                                       checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount)
            if not canHelp:
                continue
            
            # Ãâ·ÑÉç½»ÈËÊý²»×ãÇÒÃâ·Ñ   or  Ãâ·ÑÉç½»ÈËÊý¹»ÁËÇÒ×ÜÉç½»ÈËÊý»¹²»¹»  ; ¶¼Ö±½Ó¼ÓÈëÖúÕ½Áбí
            if (nowFreeRelationCount < atleastFreeRelationCount and not needGoldCall) \
                or (nowFreeRelationCount >= atleastFreeRelationCount and nowRelationCount < atleastRelationCount):
                goldCallCount, nowRelationCount, nowFreeRelationCount = \
                    __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount)
            else:
                lackRelationCount = atleastRelationCount - nowRelationCount
                if len(tempRelationHelpPlayerList) < lackRelationCount:
                    tempRelationHelpPlayerList.append([helpBattlePlayer, needGoldCall])
                    
        lackRelationCount = atleastRelationCount - nowRelationCount
        if lackRelationCount > 0:
            for helpBattlePlayer, needGoldCall in tempRelationHelpPlayerList[:lackRelationCount]:
                goldCallCount, nowRelationCount, nowFreeRelationCount = \
                    __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount)
    
    # 2. ³£¹æÌí¼ÓÖúÕ½ÈËÊý        
    if allowNoRelation:
        for checkInPlayerID in checkInPlayerIDList:
            if len(helpBattlePlayerDict) >= maxHelpPlayerSelectCount:
                GameWorld.DebugLog("    ³¬¹ý×î´ó¸öÊýÁ˲»´¦Àí, checkInPlayerID=%s" % checkInPlayerID)
                break
            helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID]
            canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax,
                                                       checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount)
            if not canHelp:
                continue
            
            goldCallCount, nowRelationCount, nowFreeRelationCount = \
                __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount)
        
    # 3. ²»×ãµÄ»úÆ÷ÈËNPC²¹×ã
    openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # ¿ª·ÅµÄÖ°Òµ
    lackCount = maxHelpPlayerSelectCount - len(helpBattlePlayerDict)
    robotID = 0 # »úÆ÷ÈËNPC¶¨ÒåID´Ó1¿ªÊ¼
    while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount:
        robotID += 1
        if robotID in helpBattlePlayerDict:
            continue
        lackCount -= 1
        nowRobotCount += 1
        randJob = random.choice(openJobList)
        helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob)
    
    GameWorld.Log("    helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID)
    return [helpBattlePlayerDict]
 
def __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax,
                       checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree=False, goldCallCount=0, maxGoldHelpPlayerCount=0):            
    ## ³£¹æ¼ì²éÊÇ·ñÂú×ãÖúÕ½Ìõ¼þ
    if checkInPlayerID == playerID:
        GameWorld.DebugLog("    ×Ô¼º²»´¦Àí, checkInPlayerID=%s" % checkInPlayerID)
        return False, False
    if checkInPlayerID in helpBattlePlayerDict:
        GameWorld.DebugLog("    ÒѾ­ÔÚÖúÕ½ÀïµÄ²»´¦Àí, checkInPlayerID=%s" % checkInPlayerID)
        return False, False
    checkInPlayerLV = helpBattlePlayer.playerLV
    checkInPlayerFightPower = helpBattlePlayer.fightPower
    checkInTime = helpBattlePlayer.checkInTime
    if checkInPlayerLV < limitLV:
        GameWorld.DebugLog("    µÈ¼¶²»×ã, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV))
        return False, False
    if fightPowerMin and checkInPlayerFightPower < fightPowerMin:
        GameWorld.DebugLog("    Õ½Á¦²»×ã, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin))
        return False, False
    if fightPowerMax and checkInPlayerFightPower > fightPowerMax:
        GameWorld.DebugLog("    Õ½Á¦³¬³ö, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax))
        return False, False
    passTime = curTime - checkInTime
    if passTime > checkInValidSeconds:
        GameWorld.DebugLog("    µÇ¼Ç³¬Ê±, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds))
        return False, False
    todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0)
    needGoldCall = dayFreeHelpCount and todayHelpCount >= dayFreeHelpCount
    if needGoldCall:
        if onlyFree:
            GameWorld.DebugLog("    ²»ÊÇÃâ·Ñ, checkInPlayerID=%s,todayHelpCount=%s > dayFreeHelpCount=%s" % (checkInPlayerID, todayHelpCount, dayFreeHelpCount))
            return False, needGoldCall
        if goldCallCount >= maxGoldHelpPlayerCount:
            GameWorld.DebugLog("    ³¬¹ý×î´ó¸¶·ÑÕÙ»½ÈËÊý, checkInPlayerID=%s,goldCallCount=%s > maxGoldHelpPlayerCount=%s" % (checkInPlayerID, goldCallCount, maxGoldHelpPlayerCount))
            return False, needGoldCall
    return True, needGoldCall
 
def __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount):
    ## Ìí¼ÓÖúÕ½Íæ¼Òµ½ÖúÕ½Áбí
    if needGoldCall:
        goldCallCount += 1
    relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer)
    if relation:
        nowRelationCount += 1
        if not needGoldCall:
            nowFreeRelationCount += 1
    helpPlayerID = helpBattlePlayer.playerID
    helpBattlePlayerDict[helpPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation)
    GameWorld.DebugLog("    ÖúÕ½ÁбíÌí¼ÓÍæ¼Ò: helpPlayerID=%s,needGoldCall=%s,relation=%s,goldCallCount=%s,nowRelationCount=%s,nowFreeRelationCount=%s" 
                       % (helpPlayerID, needGoldCall, relation, goldCallCount, nowRelationCount, nowFreeRelationCount))
    return goldCallCount, nowRelationCount, nowFreeRelationCount
 
def __GetHelpBattleRelation(curPlayer, helpBattlePlayer):
    ## »ñÈ¡ÖúÕ½Éç½»¹ØÏµ 0-ÎÞ£¬1-ºÃÓÑ£¬2-ÃËÓÑ
    if not helpBattlePlayer:
        return 0
    playerID = curPlayer.GetPlayerID()
    tagPlayerID = helpBattlePlayer.playerID
    tagFamilyID = helpBattlePlayer.familyID
    relationList = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 3, []) # Éç½»¹ØÏµÓÅÏȼ¶
    for checkRelation in relationList:
        if checkRelation == 1:
            if PlayerFriend.IsFriend(playerID, tagPlayerID):
                return checkRelation
        if checkRelation == 2:
            if tagFamilyID and curPlayer.GetFamilyID() == tagFamilyID:
                return checkRelation
    return 0
 
def __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, job, relation=0):
    ## »ñȡͬ²½¸øµØÍ¼µÄÖúÕ½Íæ¼Ò¼òÒªÐÅÏ¢
    helpPlayerDict = {"Job":job}
    if not helpBattlePlayer:
        return helpPlayerDict
    if needGoldCall:
        helpPlayerDict["NeedGoldCall"] = 1
    helpPlayerDict["Name"] = helpBattlePlayer.playerName
    helpPlayerDict["LV"] = helpBattlePlayer.playerLV
    #helpPlayerDict["Job"] = helpBattlePlayer.job
    helpPlayerDict["RealmLV"] = helpBattlePlayer.realmLV
    helpPlayerDict["FightPower"] = helpBattlePlayer.fightPower
    helpPlayerDict["Relation"] = relation
    return helpPlayerDict
 
def __DoFBHelpBattleSweepCall(curPlayer, msgList):
    ''' É¨µ´ÖúÕ½ÁбíË¢ÐÂÇÒÖ±½ÓÕÙ»½
            Ëæ»úÑ¡ÔñÃâ·ÑµÄÍæ¼Ò
    '''
    mapID, funcLineID = msgList[1:]
    
    helpBattlePlayerDict = {} # Í¬²½¸øµØÍ¼·þÎñÆ÷µÄ´ýÑ¡ÖúÕ½Íæ¼ÒÁбíÐÅÏ¢
    
    fbFuncIpyData = IpyGameDataPY.GetIpyGameData("FBFunc", mapID)
    fbHelpIpyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID)
    if not fbFuncIpyData or not fbHelpIpyData:
        return [helpBattlePlayerDict]
    
    fightPowerMin = fbHelpIpyData.GetFightPowerMin()
    fightPowerMax = 0#fbHelpIpyData.GetFightPowerMax() # É¨µ´Ôݲ»ÏÞÖÆ×î¸ßÕ½Á¦
    limitLV = fbHelpIpyData.GetLVLimit()
    dayFreeHelpCountInfo = fbHelpIpyData.GetDayFreeHelpCount() # Ã¿ÈÕÃâ·ÑÖúÕ½´ÎÊý£¬[ÿÈÕÃâ·ÑÖúÕ½´ÎÊý, ÊÇ·ñËùÓвãͨÓÃ]
    dayFreeHelpCount = 0 # 0ΪÎÞÏÞÖÆ´ÎÊý
    helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0
    if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2:
        dayFreeHelpCount, isAllLineCount = dayFreeHelpCountInfo
        if isAllLineCount:
            helpCountLineID = 0
    helpCountKey = (mapID, helpCountLineID)
    
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("ɨµ´Ë¢ÐÂÖúÕ½Áбí: mapID=%s,funcLineID=%s,helpCountLineID=%s" % (mapID, funcLineID, helpCountLineID), playerID)
    
    curTime = int(time.time())
    maxHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 2) # ×î´óÖúÕ½ÈËÊý
    checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê±
    checkInValidSeconds = checkInValidHours * 3600
    
    atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # ÖúÕ½Áбí»úÆ÷ÈËÖÁ¶àÊýÁ¿
    allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # ÖúÕ½ÁбíÊÇ·ñ³öÏÖ·ÇÉç½»¹ØÏµÍæ¼Ò
    
    onlyFree = True
    checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys()
    random.shuffle(checkInPlayerIDList) # Ë¢Ð´¿Ëæ»ú
    GameWorld.Log("    µÇ¼ÇÖúÕ½ÈËÊý=%s" % (len(checkInPlayerIDList)), playerID)
    for checkInPlayerID in checkInPlayerIDList:
        if len(helpBattlePlayerDict) >= maxHelpPlayerCount:
            GameWorld.DebugLog("    ³¬¹ý×î´ó¸öÊýÁ˲»´¦Àí, checkInPlayerID=%s" % checkInPlayerID)
            break
        helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID]
        canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax,
                                                   checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree)
        if not canHelp:
            continue
        relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer)
        if not allowNoRelation and not relation:
            continue
        helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1
        helpBattlePlayerDict[checkInPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation)
        
    nowRobotCount = 0
    # ²»×ãµÄ»úÆ÷ÈËNPC²¹×ã
    openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # ¿ª·ÅµÄÖ°Òµ
    lackCount = maxHelpPlayerCount - len(helpBattlePlayerDict)
    robotID = 0 # »úÆ÷ÈËNPC¶¨ÒåID´Ó1¿ªÊ¼
    while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount:
        robotID += 1
        if robotID in helpBattlePlayerDict:
            continue
        lackCount -= 1
        nowRobotCount += 1
        randJob = random.choice(openJobList)
        helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob)
    
    GameWorld.Log("    helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID)
    return [helpBattlePlayerDict]
 
def __DoFBHelpBattleCall(callPlayerID, callPlayerName, msgList):
    ''' ÖúÕ½ÕÙ»½£¬²»¹Ü×îÖÕ¹ý¹ØÓë·ñ£¬±»ÕÙ»½·½¶¼Ö±½ÓËãÖúÕ½³É¹¦£¬ÕâÀï´¦Àí±»ÕÙ»½µÄ£¬Ö÷¶¯·½ÔÚµØÍ¼Ö±½Ó´¦Àí
    '''
    # calledPlayerDict = {} # {±»ÕÙ»½µÄÍæ¼ÒID:¹ØÏµ, ...}
    mapID, funcLineID, calledPlayerDict = msgList[1:]
    fbFuncIpyData = IpyGameDataPY.GetIpyGameData("FBFunc", mapID)
    fbHelpIpyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID)
    if not fbFuncIpyData or not fbHelpIpyData or not calledPlayerDict:
        return
    
    helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0
    dayFreeHelpCountInfo = fbHelpIpyData.GetDayFreeHelpCount()
    if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2:
        isAllLineCount = dayFreeHelpCountInfo[1]
        if isAllLineCount:
            helpCountLineID = 0
    helpCountKey = (mapID, helpCountLineID)
    
    GameWorld.DebugLog("ÕÙ»½ÖúÕ½: mapID=%s, funcLineID=%s, helpCountKey=%s, calledPlayerDict=%s" % (mapID, funcLineID, helpCountKey, calledPlayerDict), callPlayerID)
    for calledPlayerID in calledPlayerDict.keys():
        if calledPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict:
            continue
        helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[calledPlayerID]
        helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1
    return
 
def __DoAssistFinish(curPlayer, msgList):
    ## Ð­ÖúÍê³É
    
    liheItemID, mapID, lineID, assistPlayerIDList = msgList[1:]
    
    assistPlayerDict = {}
    for assistPlayerID in assistPlayerIDList:
        if assistPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict:
            continue
        helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[assistPlayerID]
        assistPlayerDict[assistPlayerID] = {"PlayerName":helpBattlePlayer.playerName, "Job":helpBattlePlayer.job,
                                            "LV":helpBattlePlayer.playerLV, "RealmLV":helpBattlePlayer.realmLV,
                                            "TodayGiftCount":helpBattlePlayer.getThanksGiftCountDict.get(liheItemID, 0)}
    
    # ²åÈëÐÂЭÖú¸Ðл
    PlayerAssist.AddNewAssistThanks(curPlayer, liheItemID, mapID, lineID, assistPlayerDict)
    return
 
def UpdateGetThanksGiftCountDict(curPlayer, itemID, updateTodayGiftCount):
    ## ¸üнñÈÕ½ÓÊÕ¸ÐлÀñºÐ´ÎÊý
    
    playerID = curPlayer.GetPlayerID()
    if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict:
        return
    helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID]
    helpBattlePlayer.getThanksGiftCountDict[itemID] = updateTodayGiftCount
    GameWorld.DebugLog("    ¸üоµÏñЭÖú½ñÈÕ½ÓÊÕ¸ÐлÀñºÐ´ÎÊý: itemID=%s,updateTodayGiftCount=%s" % (itemID, updateTodayGiftCount), playerID)
    return