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
#!/usr/bin/python
# -*- coding: GBK -*-
#
##@package
#
# @todo: ¸öÍÆÂß¼­
#
# @author: Alee
# @date 2018-5-20 ÏÂÎç02:10:00
# @version 1.0
#
# @note: 
#
#---------------------------------------------------------------------
 
import GameWorld
#import ChConfig
import ReadChConfig
import IpyGameDataPY
import datetime
import PlayerViewCache
import urllib
import ChConfig
import PlayerControl
import PyDataManager
import time
import json
# VIPȨÏÞ
Def_Onoff_VIPCount = 5
(
Def_Onoff_Time, #Ãâ´òÈÅʱ¼ä¿ª¹Ø
Def_Onoff_Boss, #¹Ø×¢BOSS
Def_Onoff_Chat, #˽ÁÄ
Def_Onoff_TJGDead,  #ÍÑ»úËÀÍö
Def_Onoff_TJGTimeLess,  #ÍÑ»úʱ¼ä²»×ã1Сʱ
) = range(Def_Onoff_VIPCount)
 
#·ÇVIPȨÏÞ
Def_GeTui_FMT = -2 # ·âħ̳
Def_GeTui_ZhuXianBoss = -3 # ÖïÏÉBOSS
 
# ÐÂÍæ¼Ò»¹Ã»ÓÐÍÑ»úʱ¼ä ÓÐÀûÓÚÍì»ØÁ÷Ê§Íæ¼Ò
g_NewGuyNoTJGTime = {} # {playerID:[playername,getuiid, tick]}
 
g_FMTGeTuiLimit = {}    # ·âÄ§Ì³ÍÆËÍÏÞÖÆ ¹ýÓÚÆµ·±¿ØÖÆÏ¶Ìʱ¼ä֪ͨ
 
def ClearFMTGeTuiLimit():
    global g_FMTGeTuiLimit
    g_FMTGeTuiLimit = {}
 
 
 
def GetTimeLimit(timeStr):
    # ¼ì²é¸ñʽºóתÊý×Ö
    timeList = timeStr.split("-")
    if len(timeList) != 2:
        return
    
    numList = timeList[0].split(":")
    if len(numList) != 2:
        return 
    
    num1 = GameWorld.ToIntDef(numList[0], 0)
    num2 = GameWorld.ToIntDef(numList[1], 0)
    
    if num1 < 0 or num1 > 24:
        return 
    if num2 < 0 or num2 > 60:
        return 
    
    numList2 = timeList[1].split(":")
    if len(numList2) != 2:
        return 
    
    num3 = GameWorld.ToIntDef(numList2[0], 0)
    num4 = GameWorld.ToIntDef(numList2[1], 0)
    
    if num3 < 0 or num3 > 24:
        return 
    if num4 < 0 or num4 > 60:
        return 
    
    return num1*1000000 + num2*10000 + num3*100 + num4
 
 
 
# ¼ì²éÊÇ·ñ¿ÉÒÔ¸öÍÆ£¬geTuiTypeСÓÚ0µÄ´ú±íĬÈÏ¿ÉÍÆ£¬ÎÞVIPÏÞÖÆ
def CheckCanGeTui(playerCache, geTuiType=-1):
        
    if not playerCache.get("VIPLV", 0):
        if geTuiType < 0:
            return True
        return False
    
    if geTuiType in [Def_GeTui_FMT, Def_GeTui_ZhuXianBoss]:
        # ·âħ̳ÊÜVIPµÄ¹Ø×¢BOSS¿ª¹ØÓ°Ïì
        geTuiType = Def_Onoff_Boss
    
    # ¼ì²éʱ¼äºÍ¿ª¹Ø
    if geTuiType >= 0 and playerCache.get(ChConfig.Def_PDict_GeTuiSet, 0)&pow(2, geTuiType) == 0:
        return False
 
    # Ã»ÓпªÆôÃâ´òÈÅ
    if playerCache.get(ChConfig.Def_PDict_GeTuiSet, 0)&pow(2, Def_Onoff_Time) == 0:
        return True
 
    limitTimt = playerCache.get(ChConfig.Def_PDict_NoGeTuiTime, 0)
    
    curTime = GameWorld.GetServerTime()
    dateStr = str(curTime).split()[0]
    #ʱ¼ä¸ñʽ '%Y-%m-%d %H:%M'
    try:
        startTimeStr = '%s %s:%s'%(dateStr, limitTimt/1000000, limitTimt/10000%100)
        startTime = datetime.datetime.strptime(startTimeStr, "%Y-%m-%d %H:%M")
        
        endTimeStr = '%s %s:%s'%(dateStr, limitTimt/100%100, limitTimt%100)
        endTime = datetime.datetime.strptime(endTimeStr, "%Y-%m-%d %H:%M")
    except:
        return False
    
    if startTime == endTime:
        # Ê±¼äÒ»Ö´ú±í²»ÏÞÖÆ
        return True
    
    # Èç 13:00-23:00
    elif startTime < endTime:
        if startTime <= curTime and curTime <= endTime:
            return False
    
    # Èç 23:00 - 8:00
    else:
        if endTime < curTime < startTime:
            return True
        else:
            return False
    
    return True
 
 
#===============================================================================
# import urllib
# getUrl = "http://127.0.0.1:53000/getui/index.php"
# curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(0)
# postInfo = urllib.urlencode({"PlayerName": curPlayer.GetName(), "NotifyMsg":"BOSS---", "RegID":"101d8559091575fb3da", "OSName":"ios"})
# GameWorld.GetGameWorld().EventReport_EventReport(postInfo, "", "", "", 1, getUrl)
#===============================================================================
 
 
# ÈºÍÆÀඨʱ»î¶¯Óɿͻ§¶Ë×Ô¼º´¦Àí
# ·þÎñ¶ËÈºÍÆÔݲ»ÓÉÓÎÏ··þÎñÆ÷ÍÆËÍ£¬¿É´ÓµÚÈý·½¸öÍÆÍøÕ¾ÍÆËÍ
# ÓÎÏ··þÎñÆ÷Ö»ÍÆË;ßÓб仯ÐÔµÄÄÚÈÝ
# Ö§³Öµ¥ÍƺͶàÈËÍÆËÍ
# appIDDict »ì·þʹÓöÔÓ¦²»Í¬key {ƽ̨ID£º[[Íæ¼Ò¸öÍÆID£¬ Íæ¼ÒÃû],[Íæ¼Ò¸öÍÆID2£¬ Íæ¼ÒÃû2]¡£¡£¡£]}
# Èç¹ûÍæ¼ÒÃû´æÔÚÔò±ØÐëÓë¸öÍÆIDÒ»Ò»¶ÔÓ¦£¬Èô²»´æÔÚÔòÊǶàÍÆ£¬Èô´æÔÚÔò»áÒ»Ò»µ¥ÍÆ
#                ´øÃû×ֻᱻ×éºÏ³É ¸ñʽÈç¡¾Íæ¼ÒÃû¡¿Äú¹Ø×¢µÄBOSSxxÒѸ´»î
# EventReport_EventReport ÏòÓÎÏ··þÎñÆ÷µÄ¸öÍÆÐ¡³ÌÐò·¢ËÍ webbottle
def GeTuiNotify(appIDDict, notifyMsg):
    if not appIDDict:
        return
    #osName = ReadChConfig.GetPyMongoConfig("GeTui", "OSName") »ì·þÎÞ·¨ÅäÖÃϵͳ
    geTuiUrl = ReadChConfig.GetPyMongoConfig("GeTui", "GeTuiUrl")
    
    playerInfo = json.dumps(appIDDict, ensure_ascii=False)
    #º¬ÖÐÎIJ¿·ÖÒªurlencode
    postInfo = urllib.urlencode({"PlayerInfo": playerInfo, "NotifyMsg":notifyMsg})
    
    GameWorld.GetGameWorld().EventReport_EventReport(postInfo, "", "", "", 1, geTuiUrl)
    return
 
 
# µ¹¼ÆÊ±Í¨Öª, ¸´»î֪ͨGeTuiBossReborn´¦Àí
def GeTuiBoss(bossID, rebornSecond):
    if GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_BossIsGeTui%bossID) == 1:
        return
    
    bossData = IpyGameDataPY.GetIpyGameData('BOSSInfo', bossID)
    if not bossData:
        return
 
    if bossData.GetRebornPreNotifyTime() == 0:
        return
 
    if bossData.GetRebornPreNotifyTime() < rebornSecond:
        return
 
    #¸öÍÆ
    BossAttentionGeTui(bossData, bossID)
    
    GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_BossIsGeTui%bossID, 1)
    return
    
    
# Íâ²ã±£Ö¤µ±Ç°¸´»îµÄ²»»á¶þ´Îµ÷ÓàDef_WorldKey_BossIsAlive
def GeTuiBossReborn(bossID):
    bossData = IpyGameDataPY.GetIpyGameData('BOSSInfo', bossID)
    if not bossData:
        return
    
    # ¸´»îµÄBOSS»Ö¸´Í¨Öª
    GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_BossIsGeTui%bossID, 0)
 
    if bossData.GetRebornPreNotifyTime() != 0:
        return
 
    #¸öÍÆ
    BossAttentionGeTui(bossData, bossID)
    return
    
    
 
 
# ÅжÏBOSSÊ£Óà´ÎÊý£¬ ±ÜÃâ֪ͨƵ·±
# ×¢ÒâÍæ¼Ò´ÎÊýÓÃÍêµÚ¶þÌìδÉÏÏßÔò²»»áͬ²½BOSS´ÎÊý£¬Ôò²»ÍÆËÍ
def CheckBossGeTuiCnt(playerID, bossID, geTuiType, cacheDict):
    global g_FMTGeTuiLimit
    
    if geTuiType == Def_GeTui_FMT:
        if not cacheDict.get("CntMark_%s"%ChConfig.Def_FBMapID_SealDemon, 0):
            return False
        
        # ·âħ̳±È½ÏƵ·±Ä¬ÈÏ1Сʱ֪ͨһ´Î
        if playerID not in g_FMTGeTuiLimit:
            g_FMTGeTuiLimit[playerID] = {}
        
        lastTime = g_FMTGeTuiLimit[playerID].get(bossID, 0)
        if lastTime != 0 and time.time() - lastTime < 3600:
            # ÀëÉÏ´Î֪ͨ»¹Ã»³¬¹ý1Сʱ
            return False
        
        g_FMTGeTuiLimit[playerID][bossID] = int(time.time())
    elif geTuiType == Def_GeTui_ZhuXianBoss:
        if not cacheDict.get("CntMark_%s"%ChConfig.Def_FBMapID_ZhuXianBoss, 0):
            return False
        
        # ±È½ÏƵ·±Ä¬ÈÏ1Сʱ֪ͨһ´Î
        if playerID not in g_FMTGeTuiLimit:
            g_FMTGeTuiLimit[playerID] = {}
        
        lastTime = g_FMTGeTuiLimit[playerID].get(bossID, 0)
        if lastTime != 0 and time.time() - lastTime < 3600:
            # ÀëÉÏ´Î֪ͨ»¹Ã»³¬¹ý1Сʱ
            return False
        
        g_FMTGeTuiLimit[playerID][bossID] = int(time.time())
       
    elif geTuiType == Def_Onoff_Boss:
        #ÖØÉúboss
        killBossCntLimitDict = IpyGameDataPY.GetFuncEvalCfg('KillBossCntLimit', 1, {})
        for bidlist, bkey in killBossCntLimitDict.items():
            if bossID not in bidlist:
                continue
            if not cacheDict.get("CntMark_%s"%bkey, 0):
                return False
            else:
                return True
    return True
    
# ¸öÍÆ»ù´¡Åж¨
def CanGeTuiByCache(curCache):
    if not curCache.GeTuiID:
        return False
    
    # ÀëÏß³¬¹ý24Сʱ²»ÔÙÍÆËÍ£¬Ä¿Ç°¼«¹âÍÆË͵ÄÌØµãÊÇÍÆËÍIDͬ»úÆ÷²»Í¬°ü¶¼ÊÇͬһ¸öID
    if time.time() - curCache.OffTime > 24*60*60:
        return False
    return True
    
def BossAttentionGeTui(bossData, bossID):
    if bossData.GetMapID() == ChConfig.Def_FBMapID_SealDemon:
        # ·ÇVIPÍæ¼Ò ·âħ̳¸öÍÆ
        geTuiType = Def_GeTui_FMT
    elif bossData.GetMapID() == ChConfig.Def_FBMapID_ZhuXianBoss:
        # ·ÇVIPÍæ¼Ò ÖïÏÉBOSS¸öÍÆ
        geTuiType = Def_GeTui_ZhuXianBoss
    else:
        geTuiType = Def_Onoff_Boss
        
    #ÕÒµ½¹Ø×¢ÕâÖ»BOSSµÄÍæ¼Ò
    pdict = PyDataManager.GetBossAttentionManager().GetBossAttentionDict()
    
    appIDDict = {}    # »ì·þÐèÒªÍÆµ½²»Í¬µÄ¸öÍÆÓ¦ÓÃ
    for playerID, bossAttentionData in pdict.items():
        curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
        if curPlayer and not PlayerControl.GetIsTJG(curPlayer):
            continue
        
        # ÀëÏßÍæ¼Ò
        curCache = PlayerViewCache.FindViewCache(playerID)
        if not curCache:
            continue
        
        if not CanGeTuiByCache(curCache):
            #ÎÞÍÆËÍ×ʸñ£¬¼õÉÙ¼ìË÷ºÍeval
            continue
        
        recordDict = eval(bossAttentionData.RecordData)
        if recordDict.get(bossID, 0) in [0, 9]:
            #0-ĬÈÏδ¹Ø×¢, 1-Ö÷¶¯¹Ø×¢, 2-×Ô¶¯¹Ø×¢, 9-Ö÷¶¯È¡Ïû¹Ø×¢
            continue
        
        cacheDict = PlayerViewCache.GetCachePropDataDict(curCache)
        if not CheckCanGeTui(cacheDict, geTuiType):
            # ¸öÍÆÂß¼­¼ì²é
            continue
        
        if not CheckBossGeTuiCnt(playerID, bossID, geTuiType, cacheDict):
            # ÅжÏBOSSÊ£Óà´ÎÊý£¬ ±ÜÃâ֪ͨƵ·±
            continue
        
        appID = cacheDict.get("AppID", "")
        if appID not in appIDDict:
            appIDDict[appID] = []
            
        appIDDict[appID].append([curCache.GeTuiID, cacheDict.get("Name", "")])
             
 
    if not appIDDict:
        return
    
    npcName = GameWorld.GetNPCData(bossID).GetNPCName()
    npcLV = GameWorld.GetNPCData(bossID).GetLV()
    
    if geTuiType == Def_GeTui_FMT:
        showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 1)%(npcName, npcLV))    # ÎÄ×ÖÐÅÏ¢
    elif geTuiType == Def_GeTui_ZhuXianBoss:
        showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 5)%(npcName, npcLV))    # ÎÄ×ÖÐÅÏ¢
    elif geTuiType == Def_Onoff_Boss:
        showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 2)%(bossData.GetSourceName(), npcName, npcLV))    # ÎÄ×ÖÐÅÏ¢
        
    GeTuiNotify(appIDDict, showStr)
    
 
# Ë½ÁÄ
def ChatMiGeTui(playerID, playerName, tagPlayerName):
    curCache = PlayerViewCache.FindViewCache(playerID)
    if not curCache:
        return
 
    if not CanGeTuiByCache(curCache):
        #ÎÞÍÆËÍ×ʸñ£¬»ù´¡Åж¨
        return
 
    cacheDict = PlayerViewCache.GetCachePropDataDict(curCache)
    if not CheckCanGeTui(cacheDict, Def_Onoff_Chat):
        # ¹ýÂ˸öÍÆ
        return
    
    showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 3))%(tagPlayerName)    # ÎÄ×ÖÐÅÏ¢
    GeTuiNotify({cacheDict.get("AppID", ""):[[curCache.GeTuiID, playerName]]}, showStr)
    return
 
# ÏÂÏßʱ£¬µÍ¼¶Íæ¼ÒûÓÐÀëÏßʱ¼äµÄÍæ¼ÒÌáʾ, ÉÏÏßÇå¿Õ
def NewGuyCallBackGeTui(curPlayer, tick):
    global g_NewGuyNoTJGTime
    if PlayerControl.GetTJGTime(curPlayer):
        return
    if curPlayer.GetLV() > 100:
        return
    playerID = curPlayer.GetID()
    g_NewGuyNoTJGTime[playerID] = [curPlayer.GetName(), curPlayer.GetGeTuiClientID(), tick, 
                                   GameWorld.GetPlayerPlatform(curPlayer)]  # curPlayer.GetGeTuiClientID()
    return
 
# ÉÏÏßÇå³ý
def CleanNewGuyCallBackGeTui(playerID):
    global g_NewGuyNoTJGTime
    if playerID not in g_NewGuyNoTJGTime:
        return
    
    g_NewGuyNoTJGTime.pop(playerID)
 
# ÑÓ³Ù5·ÖÖÓÌáʾ
def ProcessNewGuyCallBackGeTui(tick):
    if not GameWorld.SetWorldDictKey(ChConfig.TYPE_WorldNewGuyGeTuiTick, tick):
        #¼ä¸ôδµ½ 
        return
    
    global g_NewGuyNoTJGTime
    
    playerIDList = []
    appIDDict = {}
    
    for playerID, getuiInfo in g_NewGuyNoTJGTime.items():
        if tick - getuiInfo[2] < 300000:
            continue
        playerIDList.append(playerID)
        
        appID = getuiInfo[3]
        if appID not in appIDDict:
            appIDDict[appID] = []
            
        appIDDict[appID].append([getuiInfo[1],getuiInfo[0]])
        
        
    if not appIDDict:
        return
    showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 4))    # ÎÄ×ÖÐÅÏ¢
    GeTuiNotify(appIDDict, showStr)
        
    for playerID in playerIDList:
        CleanNewGuyCallBackGeTui(playerID)
    return