#!/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 # ·âħ̳  
 | 
  
 | 
# ÐÂÍæ¼Ò»¹Ã»ÓÐÍÑ»úʱ¼ä ÓÐÀûÓÚÍì»ØÁ÷Ê§Íæ¼Ò  
 | 
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("GeTuiClientID", ""):  
 | 
        return False  
 | 
      
 | 
    # ÀëÏß³¬¹ý24Сʱ²»ÔÙÍÆËÍ£¬Ä¿Ç°¼«¹âÍÆË͵ÄÌØµãÊÇÍÆËÍIDͬ»úÆ÷²»Í¬°ü¶¼ÊÇͬһ¸öID  
 | 
    if not playerCache.get("Time", 0):  
 | 
        return False  
 | 
    if time.time() - playerCache.get("Time", 0) > 24*60*60:  
 | 
        return False  
 | 
          
 | 
    if not playerCache.get("VIPLV", 0):  
 | 
        if geTuiType < 0:  
 | 
            return True  
 | 
        return False  
 | 
      
 | 
    if geTuiType == Def_GeTui_FMT:  
 | 
        # ·âħ̳ÊÜ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_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 BossAttentionGeTui(bossData, bossID):  
 | 
    if bossData.GetMapID() == ChConfig.Def_FBMapID_SealDemon:  
 | 
        # ·ÇVIPÍæ¼Ò ·âħ̳¸öÍÆ  
 | 
        geTuiType = Def_GeTui_FMT  
 | 
    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  
 | 
  
 | 
        recordDict = eval(bossAttentionData.RecordData)  
 | 
        if recordDict.get(bossID, 0) in [0, 9]:  
 | 
            #0-ĬÈÏδ¹Ø×¢, 1-Ö÷¶¯¹Ø×¢, 2-×Ô¶¯¹Ø×¢, 9-Ö÷¶¯È¡Ïû¹Ø×¢  
 | 
            continue  
 | 
        curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID)  
 | 
        if not curCache:  
 | 
            continue  
 | 
        cacheDict = eval(curCache.GetPropData())  
 | 
        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([cacheDict.get("GeTuiClientID", ""), 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_Onoff_Boss:  
 | 
        showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 2)%(bossData.GetSourceName(), npcName, npcLV))    # ÎÄ×ÖÐÅÏ¢  
 | 
          
 | 
    GeTuiNotify(appIDDict, showStr)  
 | 
      
 | 
  
 | 
# Ë½ÁÄ  
 | 
def ChatMiGeTui(playerID, playerName, tagPlayerName):  
 | 
    curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID)  
 | 
    if not curCache:  
 | 
        return  
 | 
  
 | 
    cacheDict = eval(curCache.GetPropData())  
 | 
    if not CheckCanGeTui(cacheDict, Def_Onoff_Chat):  
 | 
        # ¹ýÂ˸öÍÆ  
 | 
        return  
 | 
      
 | 
    showStr = GameWorld.GbkToCode(IpyGameDataPY.GetFuncCfg("GeTuiOffLine", 3))%(tagPlayerName)    # ÎÄ×ÖÐÅÏ¢  
 | 
    GeTuiNotify({cacheDict.get("AppID", ""):[[cacheDict.get("GeTuiClientID", ""), 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  
 | 
  
 |