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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerAssist
#
# @todo:ЭÖúϵͳ
# @author hxp
# @date 2019-12-06
# @version 1.0
#
# ÏêϸÃèÊö: Ð­Öúϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2019-12-06 21:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import PlayerControl
import NPCHurtManager
import ChPyNetSendPack
import NetPackCommon
import IPY_GameWorld
import ItemControler
import ItemCommon
import ChConfig
import ShareDefine
import PyGameData
import FBCommon
 
def DoPlayerOnDay(curPlayer):
    ## ¹ýÌì´¦Àí
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in xrange(ipyDataMgr.GetAssistThanksGiftCount()):
        ipyData = ipyDataMgr.GetAssistThanksGiftByIndex(index)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GetThanksGiftCount % ipyData.GetGiftID(), 0)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoney, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoneySocial, 0)
    Sync_TodayAssistMoneyInfo(curPlayer)
    return
 
def OnPlayerLogin(curPlayer):
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney):
        Sync_TodayAssistMoneyInfo(curPlayer)
    return
 
def OnPlayerLeaveMap(curPlayer):
    ## Íæ¼ÒÀ뿪µØͼ´¦Àí
    
    NPCHurtManager.OnPlayerLeaveMap(curPlayer)
    
    mapID = curPlayer.GetMapID()
    if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) == IPY_GameWorld.fbtTeam:
        mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
        if str(mapID) in mapAssistGiftDict and PlayerControl.GetAssistTagPlayerID(curPlayer):
            lineID = PlayerControl.GetFBFuncLineID(curPlayer)
            OnCancelAssistTeamFB(curPlayer.GetPlayerID(), mapID, lineID, "LeaveMap")
            
    return
 
#// B0 10 ÇëÇóЭÖúBoss #tagCMRequestAssistBoss
#
#struct    tagCMRequestAssistBoss
#
#{
#    tagHead        Head;
#    DWORD        ObjID;
#    DWORD        NPCID;
#};
def OnRequestAssistBoss(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    objID = clientData.ObjID
    npcID = clientData.NPCID
    
    if not GameWorld.IsCrossServer():
        if not curPlayer.GetFamilyID():
            GameWorld.DebugLog("±¾·þbossûÓÐÏÉÃ˲»ÄÜÇëÇóЭÖú!", playerID)
            return
        
    curNPC = GameWorld.FindNPCByNPCID(npcID)
    if not curNPC:
        GameWorld.DebugLog("ЭÖúNPC²»´æÔÚÎÞ·¨Ð­Öú!npcID=%s" % npcID, playerID)
        return
    if curNPC.GetID() != objID:
        GameWorld.DebugLog("ЭÖúNPCʵÀýID²»Ò»ÖÂÎÞ·¨Ð­Öú!npcID=%s,curNPC.GetID()=%s,sendObjID=%s" % (npcID, curNPC.GetID(), objID), playerID)
        return
    
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog('BOSSInfo', npcID)
    if not ipyData or not ipyData.GetCanAssist():
        GameWorld.DebugLog("¸ÃNPC²»ÄÜЭÖú!npcID=%s" % npcID, playerID)
        return
    
    hurtList = NPCHurtManager.GetPlayerHurtList(curNPC)
    if not hurtList.IsNoAssistPlayer(playerID):
        GameWorld.DebugLog("²»ÊǸÃbossµÄ·ÇÖúÕ½ÉËѪÍæ¼Ò£¬ÎÞ·¨·¢ÆðЭÖú!npcID=%s" % npcID, playerID)
        return
    
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_RequestAssist, tick):
        GameWorld.DebugLog("ÇëÇóЭÖúCDÖÐ!npcID=%s" % npcID, playerID)
        return
    
    npcLV = curNPC.GetLV()
    mapID = curPlayer.GetMapID()
    lineID = NPCHurtManager.GetBossLineID(npcID)
    serverGroupID = PlayerControl.GetPlayerServerGroupID(curPlayer)
    queryData = [mapID, lineID, npcID, objID, npcLV, serverGroupID]
    QueryGameServer_PlayerAssist(playerID, "RequestAssistBoss", queryData)
    return
 
 
#// B0 11 ÇëÇóЭÖú×é¶Ó¸±±¾ #tagCMRequestAssistTeamFB
#
#struct    tagCMRequestAssistTeamFB
#
#{
#    tagHead        Head;
#    WORD        MapID;
#    WORD        LineID;
#};
def OnRequestAssistTeamFB(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    mapID = clientData.MapID
    lineID = clientData.LineID
    
    if GameWorld.IsCrossServer():
        return
    
    if not curPlayer.GetFamilyID():
        GameWorld.DebugLog("ûÓÐÏÉÃ˲»ÄÜÇëÇóЭÖú!", playerID)
        return
    
    if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) != IPY_GameWorld.fbtTeam:
        GameWorld.DebugLog("·Ç×é¶Ó¸±±¾²»ÄÜÇëÇóЭÖú!mapID=%s" % mapID, playerID)
        return
    
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_RequestAssist, tick):
        GameWorld.DebugLog("ÇëÇóЭÖúCDÖÐ!mapID=%s,lineID=%s" % (mapID, lineID), playerID)
        return
    
    mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
    if str(mapID) not in mapAssistGiftDict:
        return
    
    teamID = curPlayer.GetTeamID()
    if teamID:
        if curPlayer.GetTeamLV() != IPY_GameWorld.tmlLeader:
            GameWorld.DebugLog("·Ç¶Ó³¤£¬ÎÞ·¨·¢²¼¸±±¾Ð­Öú!")
            return
        
    fbIpyData = FBCommon.GetFBIpyData(mapID)
    fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, lineID)
    if PlayerControl.CheckMoveToFB(curPlayer, mapID, lineID, fbIpyData, fbLineIpyData, tick) != ShareDefine.EntFBAskRet_OK:
        return
    
    queryData = [mapID, lineID]
    QueryGameServer_PlayerAssist(playerID, "RequestAssistTeamFB", queryData)
    return
 
def OnStartAssistTeamFB(playerID, mapID, lineID, tagPlayerID):
    ## ¿ªÊ¼Ð­Öú×é¶Ó¸±±¾£¬Ð­ÖúÍæ¼Ò½øÈ븱±¾µ÷ÓÃ
    queryData = [mapID, lineID, tagPlayerID]
    QueryGameServer_PlayerAssist(playerID, "OnStartAssistTeamFB", queryData)
    return
 
def OnCancelAssistTeamFB(playerID, mapID, lineID, reason):
    ## È¡Ïû¸±±¾Ð­Öú
    queryData = [mapID, lineID, reason]
    QueryGameServer_PlayerAssist(playerID, "OnCancelAssistTeamFB", queryData)
    return
 
def QueryGameServer_PlayerAssist(playerID, queryType, queryData):
    msgInfo = str([queryType, queryData])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "PlayerAssist", msgInfo, len(msgInfo))
    GameWorld.DebugLog("ЭÖúÐÅÏ¢·¢ËÍ GameServer: playerID=%s,queryType=%s,queryData=%s" % (playerID, queryType, queryData))
    return
 
def QueryResult_PlayerAssist(curPlayer, resultList):
    ## Ð­ÖúÐÅÏ¢GameServer·µ»Ø´¦Àí
    if len(resultList) != 3:
        return
    queryType, queryData, result = resultList
    
    # Ê¹ÓÃЭÖú¸ÐлÀñºÐ¸ø½±Àø
    if queryType == "UseAssistThanksGift":
        itemID = queryData[0]
        giftItem = ItemCommon.FindItemInPackByItemID(curPlayer, itemID, IPY_GameWorld.rptItem)
        if not giftItem:
            return
        ItemCommon.DelItem(curPlayer, giftItem, 1)
        
        ipyData = IpyGameDataPY.GetIpyGameData("AssistThanksGift", itemID)
        if ipyData:
            awardItemID, awardItemCount = ipyData.GetRequestPlayerAward()
            ItemControler.GivePlayerItemOrMail(curPlayer, [[awardItemID, awardItemCount, 0]])
            
    # ½ÓÊÕЭÖú¸ÐлÀñºÐ½±Àø¸ø½±Àø
    elif queryType == "GetAssistThanksGift":
        itemID, isExtraAward, isCurDailyDate, updateTodayGiftCount = queryData
        if isCurDailyDate:
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GetThanksGiftCount % itemID, updateTodayGiftCount)
            
        if isExtraAward:
            ipyData = IpyGameDataPY.GetIpyGameData("AssistThanksGift", itemID)
            if ipyData:
                awardItemID, awardItemCount = ipyData.GetAssistPlayerAward()
                ItemControler.GivePlayerItemOrMail(curPlayer, [[awardItemID, awardItemCount, 0]])
                
    # ¿ç·þ·¢²¼Ð­ÖúÍæ¼Ò½±Àø
    elif queryType == "CrossNoAssistPlayerAward":
        assistAwardItemID = queryData[0]
        ItemControler.GivePlayerItemOrMail(curPlayer, [[assistAwardItemID, 1, 0]])
        
    # ¿ç·þЭÖúÍæ¼Ò½±Àø
    elif queryType == "CrossAssistPlayerAward":
        assistMoney, isFriend = queryData
        assistMoneyType = ShareDefine.TYPE_Price_FamilyActivity
        AddTodayAssistMoney(curPlayer, assistMoneyType, assistMoney, isFriend)
          
    return
 
def GameServer_AssistBossMsg(assistData):
    ## GameServerÍÆË͵½Ö¸¶¨bossµØͼµÄÐÅÏ¢
    
    GameWorld.DebugLog("GameServerͬ²½BossЭÖúÐÅÏ¢: %s" % assistData)
    
    msgType = assistData[0]
    
    # ¿ªÊ¼Ð­Öú
    if msgType == "Start":
        assistGUID, assistPlayerID, assistPlayerName, isFriend, tagPlayerID, tagPlayerName, tagTeamID, lineID, objID, npcID, serverGroupID = assistData[1:]
        npchurtList = NPCHurtManager.GetPlayerHurtListEx(lineID, objID, npcID)
        if not npchurtList:
            return
        
        npchurtList.AddAssistPlayer(assistPlayerID, assistPlayerName, isFriend, tagPlayerID, tagPlayerName, tagTeamID)
        QueryGameServer_PlayerAssist(0, "AddAssistBossPlayerOK", [assistGUID, assistPlayerID, tagPlayerID, serverGroupID])
        
    # È¡ÏûЭÖú
    elif msgType == "Cancel":
        assistPlayerID, lineID, objID, npcID = assistData[1:]
        npchurtList = NPCHurtManager.GetPlayerHurtListEx(lineID, objID, npcID)
        if not npchurtList:
            return
        npchurtList.DelHurtPlayer(assistPlayerID, "Cancel", isMapServerDel=False)
        
    return
 
def OnPlayerEnterAssistFB(curPlayer, mapID, lineID=0):
    ## Íæ¼Ò½øÈëЭÖú¸±±¾
    
    if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) != IPY_GameWorld.fbtTeam:
        return
    
    mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
    if str(mapID) not in mapAssistGiftDict:
        return
    
    playerID = curPlayer.GetPlayerID()
    gameFB = GameWorld.GetGameFB()
    noAssistPlayerID = gameFB.GetGameFBDictByKey("FBNoAssistPlayerID")
    if noAssistPlayerID:
        if playerID != noAssistPlayerID:
            OnStartAssistTeamFB(playerID, mapID, lineID, noAssistPlayerID)
        return
    
    if curPlayer.GetTeamID():
        if curPlayer.GetTeamLV() != IPY_GameWorld.tmlLeader:
            # ·Ç¶Ó³¤ÏȽøÈëµÄ£¬Ôݲ»´¦Àí£¬µÈ´ý¶Ó³¤½øÈëºóͳһ´¦Àí
            return
        
    noAssistPlayerID = playerID # ¶Ó³¤»òÎÞ¶ÓÎé½øÈëÔòΪ·ÇЭÖúÍæ¼Ò
    gameFB.SetGameFBDict("FBNoAssistPlayerID", noAssistPlayerID)
    GameWorld.DebugLog("ÉèÖø±±¾·ÇЭÖúÍæ¼Ò: noAssistPlayerID=%s" % noAssistPlayerID)
    
    copyPlayerManager = GameWorld.GetMapCopyPlayerManager()
    for index in xrange(copyPlayerManager.GetPlayerCount()):
        player = copyPlayerManager.GetPlayerByIndex(index)
        if not player:
            continue
        fbPlayerID = player.GetPlayerID()
        if fbPlayerID == noAssistPlayerID:
            continue
        if PlayerControl.GetAssistTagPlayerID(player) != noAssistPlayerID:
            OnStartAssistTeamFB(fbPlayerID, mapID, lineID, noAssistPlayerID)
            
    return
 
def OnFBAssistOver(isPass, mapID, lineID=0):
    ''' ¸±±¾Ð­Öú½áÊø
    @return: noAssistPlayerID, assistMoneyType, assistPlayerMoneyDict
        µ± noAssistPlayerID Îª0ʱ´ú±íûÓгɹ¦½áËãЭÖú£¬¸±±¾¶îÍâµÄЭÖú½±ÀøÒ²²»ÄܽáË㣬·ÀÖ¹±»Ë¢Ð­Öú½±Àø
    '''
    assistPlayerMoneyDict = {}
    assistMoneyType = ShareDefine.TYPE_Price_FamilyActivity
    defaultReturn = (0, assistMoneyType, assistPlayerMoneyDict)
    gameFB = GameWorld.GetGameFB()
    noAssistPlayerID = gameFB.GetGameFBDictByKey("FBNoAssistPlayerID")
    GameWorld.DebugLog("¸±±¾Ð­Öú½áËã: isPass=%s,mapID=%s,lineID=%s,noAssistPlayerID=%s" % (isPass, mapID, lineID, noAssistPlayerID))
    
    if not isPass or not noAssistPlayerID:
        return defaultReturn
    
    copyPlayerManager = GameWorld.GetMapCopyPlayerManager()
    noAssistPlayer = copyPlayerManager.FindPlayerByID(noAssistPlayerID)
    if not noAssistPlayer:
        GameWorld.DebugLog("    ·ÇЭÖúÍæ¼Ò²»ÔÚ£¬²»½áËãЭÖú½±Àø!")
        return defaultReturn
    
    mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
    if str(mapID) not in mapAssistGiftDict:
        return  defaultReturn
    liheItemID, assistMoney = mapAssistGiftDict[str(mapID)]
    
    friendList, memFamilyIDDict = [], {}
    teamID = GameWorld.GetGameWorld().GetPropertyID()
    if teamID in PyGameData.g_teamFBMemRelationDict:
        friendList, memFamilyIDDict = PyGameData.g_teamFBMemRelationDict[teamID][:2]
    noAssistPlayerFamilyID = memFamilyIDDict.get(noAssistPlayerID, 0)
    
    assistAwardItemID = liheItemID
    assistPlayerDict = {}
    for index in xrange(copyPlayerManager.GetPlayerCount()):
        curPlayer = copyPlayerManager.GetPlayerByIndex(index)
        if not curPlayer:
            continue
        
        playerID = curPlayer.GetPlayerID()
        if playerID == noAssistPlayerID:
            continue
        
        assistPlayer = curPlayer
        assistPlayerID = playerID
        isFriend = [noAssistPlayerID, playerID] in friendList or [playerID, noAssistPlayerID] in friendList
        assistFamilyID = assistPlayer.GetFamilyID()
        
        addAssistMoney = AddTodayAssistMoney(curPlayer, assistMoneyType, assistMoney, isFriend)
        assistPlayerMoneyDict[assistPlayerID] = addAssistMoney
        GameWorld.DebugLog("ЭÖú·½¸ø»îÔ¾Áî½±Àø: assistPlayerID=%s,assistMoney=%s,isFriend=%s,addAssistMoney=%s" 
                           % (assistPlayerID, assistMoney, isFriend, addAssistMoney), mapID, lineID)
        
        todayGiftCount = assistPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GetThanksGiftCount % liheItemID)
        assistPlayerDict[assistPlayerID] = {"PlayerName":assistPlayer.GetPlayerName(), "Job":assistPlayer.GetJob(), 
                                            "LV":assistPlayer.GetLV(), "RealmLV":assistPlayer.GetOfficialRank(),
                                            "TodayGiftCount":todayGiftCount, "Face":assistPlayer.GetFace(), "FacePic":assistPlayer.GetFacePic()}
        
        # Ôݶ¨Ö§³Öͬ¶ÓÎ鲻ͬÏÉÃ˼äЭÖú
        if assistFamilyID and assistFamilyID == noAssistPlayerFamilyID:
            notifyParam = [assistPlayer.GetPlayerName(), noAssistPlayer.GetPlayerName(), mapID]
            PlayerControl.FamilyNotify(assistFamilyID, "AssistFBFinish", notifyParam)
                
    if assistPlayerDict:
        GameWorld.DebugLog("·¢²¼·½¸ø¸ÐлÀñºÐ½±Àø: noAssistPlayerID=%s,assistAwardItemID=%s" % (noAssistPlayerID, assistAwardItemID), mapID, lineID)
        ItemControler.GivePlayerItemOrMail(noAssistPlayer, [[assistAwardItemID, 1, 0]])
        
    queryData = [mapID, lineID, noAssistPlayerID, assistAwardItemID, assistPlayerDict]
    QueryGameServer_PlayerAssist(0, "OnFBAssistOver", queryData)
    return noAssistPlayerID, assistMoneyType, assistPlayerMoneyDict
 
def AddTodayAssistMoney(curPlayer, moneyType, addMoney, isSocialEx):
    ''' Ôö¼Ó½ñÈÕЭÖú»õ±Ò½±Àø    
    @param moneyType: »õ±ÒÀàÐÍ
    @param addMoney: ³£¹æÔö¼Ó£¬ÓÐÿÈÕÉÏÏÞ
    @param isSocialEx: ÊÇ·ñÉç½»¼Ó³É£¬²»¼ÆÈë³£¹æÉÏÏÞ
    '''
    
    todayAssistMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney)
    socialMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoneySocial)
    todayAssistMoneyMax = IpyGameDataPY.GetFuncCfg("AssistAward", 4)
    if todayAssistMoney >= todayAssistMoneyMax:
        return 0
    
    addValue = min(addMoney, todayAssistMoneyMax - todayAssistMoney)
    socialEx = 0
    if isSocialEx:
        friendAddAssistMoneyPer = IpyGameDataPY.GetFuncCfg("AssistAward", 3)
        socialEx = int(addValue * friendAddAssistMoneyPer / 100.0)
        
    realAdd = addValue + socialEx
    
    if not GameWorld.IsCrossServer():
        PlayerControl.GiveMoney(curPlayer, moneyType, realAdd)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoney, todayAssistMoney + addValue)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoneySocial, socialMoney + socialEx)
    
    Sync_TodayAssistMoneyInfo(curPlayer)
    return realAdd
 
def Sync_TodayAssistMoneyInfo(curPlayer):
    ## Í¨Öª½ñÈÕÒÑ»ñµÃЭÖú»õ±ÒÐÅÏ¢
    infoPack = ChPyNetSendPack.tagMCTodayAssistMoneyInfo()
    infoPack.TodayAssistMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney)
    infoPack.SocialMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoneySocial)
    NetPackCommon.SendFakePack(curPlayer, infoPack)
    return