#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#  
 | 
##@package PlayerGameWallow  
 | 
#  
 | 
# @todo:   
 | 
#  
 | 
# @author: Alee  
 | 
# @date 2018-3-15 ÏÂÎç08:32:14  
 | 
# @version 1.0  
 | 
#  
 | 
# @note:   
 | 
#  
 | 
#---------------------------------------------------------------------  
 | 
  
 | 
  
 | 
import ChConfig  
 | 
import GameWorld  
 | 
import IPY_GameWorld  
 | 
import ReadChConfig  
 | 
import PlayerControl  
 | 
import PlayerTJG  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
#------------------------------------------------------------------------------  
 | 
  
 | 
  
 | 
#·À³ÁÃÔ¾ÑéϵÊý  
 | 
Def_GameWallow_ExpDict = {ChConfig.Def_GameWallow_LV_1_1:1,  
 | 
                            ChConfig.Def_GameWallow_LV_1_2:1,  
 | 
                            ChConfig.Def_GameWallow_LV_First:1,  
 | 
                            ChConfig.Def_GameWallow_LV_Second:0,  
 | 
                            ChConfig.Def_GameWallow_LV_2_1:0,  
 | 
                            ChConfig.Def_GameWallow_LV_2_2:0,  
 | 
                            ChConfig.Def_GameWallow_LV_2_3:0,  
 | 
                            ChConfig.Def_GameWallow_LV_Third:0,  
 | 
                           }  
 | 
  
 | 
# ·À³ÁÃÔÔÚÏßʱ¼ä·ÖÖÓ¶ÔÓ¦½×¶Î  
 | 
Def_WallowLV_Time_Dict = [  
 | 
                          [60, ChConfig.Def_GameWallow_LV_1_2],  
 | 
                          [120, ChConfig.Def_GameWallow_LV_First],  
 | 
                          [180, ChConfig.Def_GameWallow_LV_Second],  
 | 
                          [210, ChConfig.Def_GameWallow_LV_2_1],  
 | 
                          [240, ChConfig.Def_GameWallow_LV_2_2],  
 | 
                          [270, ChConfig.Def_GameWallow_LV_2_3],  
 | 
                          [300, ChConfig.Def_GameWallow_LV_Third],  
 | 
                          ]  
 | 
  
 | 
# µÈ¼¶£¬Ìáʾ  
 | 
Def_WallowLV_Notify_Dict = {  
 | 
                            ChConfig.Def_GameWallow_LV_1_2:["AvoidSink02", [1]],  
 | 
                            ChConfig.Def_GameWallow_LV_First:["AvoidSink02", [2]],  
 | 
                            ChConfig.Def_GameWallow_LV_Second:["AvoidSink03", [3]],  
 | 
                            ChConfig.Def_GameWallow_LV_2_1:["AvoidSink03", ['3.5']],  
 | 
                            ChConfig.Def_GameWallow_LV_2_2:["AvoidSink03", [4]],  
 | 
                            ChConfig.Def_GameWallow_LV_2_3:["AvoidSink03", ['4.5']],  
 | 
                            ChConfig.Def_GameWallow_LV_Third:["AvoidSink05", [5]],  
 | 
                            }  
 | 
  
 | 
  
 | 
#·À³ÁÃÔ¿ªÆô  
 | 
Def_GameWallow_Open = 1  
 | 
  
 | 
#·À³ÁÃÔÀëÏßÀÛ»ýʱ¼äÉÏÏÞ´ïµ½XСʱ£¬Îª½¡¿µ×´Ì¬  
 | 
Def_Wallow_Offline_HealthTime = 5 * 60  
 | 
#------------------------------------------------------------------------------  
 | 
  
 | 
# Í¨Öª¿Í»§¶Ë·À³ÁÃÔÔÚÏßʱ¼ä  
 | 
def NotifyWallowTime(curPlayer):  
 | 
    sendPack = ChPyNetSendPack.tagMCPlayerWallow()  
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        sendPack.Open = 0  
 | 
        sendPack.OnlineTime = 0  
 | 
    else:  
 | 
        sendPack.Open = 1  
 | 
        sendPack.OnlineTime = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_OnlineTime)/1000  
 | 
          
 | 
    NetPackCommon.SendFakePack(curPlayer, sendPack)  
 | 
      
 | 
      
 | 
      
 | 
##ÉÏÏß/ÇеØÍ¼·À³ÁÃÔÅж¨  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return None  
 | 
def DoLogic_CheckWallow(curPlayer, tick):  
 | 
    NotifyWallowTime(curPlayer)  
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        #·Ç³ÁÃÔ£¬É¾³ý³ÁÃÔ״̬  
 | 
        Del_Wallow(curPlayer)  
 | 
        return  
 | 
      
 | 
    wallowLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV)  
 | 
      
 | 
    if wallowLV != ChConfig.Def_GameWallow_LV_None:  
 | 
        return  
 | 
      
 | 
    #µÚÒ»´Î½øÈë·À³ÁÃÔ£¬ÉèÖÃ1¼¶³ÁÃÔ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_LV, ChConfig.Def_GameWallow_LV_1_1)  
 | 
    PlayerControl.NotifyCode(curPlayer, "AvoidSink01")  
 | 
      
 | 
    return  
 | 
      
 | 
##ɾ³ýBUFF£¬È¥µô³ÁÃÔ±êʶ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return ÎÞ   
 | 
def Del_Wallow(curPlayer):  
 | 
    if curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV) == ChConfig.Def_GameWallow_LV_None:  
 | 
        return  
 | 
      
 | 
    #Çå¿Õ±êʶ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_LV, ChConfig.Def_GameWallow_LV_None)  
 | 
    #ÔÚÏßʱ¼äÇå¿Õ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OnlineTime, 0)  
 | 
    #ÀëÏßÇå¿Õ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OfflineTime, 0)  
 | 
  
 | 
    return  
 | 
  
 | 
  
 | 
##ÉÏÏß¼ÆËãÀÛ»ýÀëÏßʱ¼ä´¦Àí·À³ÁÃÔ  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return None  
 | 
def Calc_Wallow_OfflineTime(curPlayer, tick):  
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        return  
 | 
      
 | 
    PlayerControl.NotifyCode(curPlayer, "AvoidSink01")  
 | 
      
 | 
    offMin = PlayerControl.GetPlayerLeaveServerMinute(curPlayer)  
 | 
    noteOffMin = offMin + curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_OfflineTime)  
 | 
      
 | 
    #ÍÑ»ú¹Òʱ¼ä£¬ÍÑ»ú¹Òʱ¼äÇå³ý±ØÐëÔÚÕâÖ®ºó  
 | 
    tjgtime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Time, 0, ChConfig.Def_PDictType_TJGNotify)/60  
 | 
    noteOffMin += tjgtime  
 | 
      
 | 
    if noteOffMin < Def_Wallow_Offline_HealthTime:  
 | 
        #δ´ïµ½½¡¿µÀëÏߣ¬¼Ç¼ʱ¼ä,Í˳ö  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OfflineTime, noteOffMin)  
 | 
        return  
 | 
      
 | 
    #ÉèÖÃΪ½¡¿µ×´Ì¬  
 | 
    RevertHealthGame(curPlayer, tick)  
 | 
  
 | 
  
 | 
##»Ö¸´ÎªÒ»¼¶³ÁÃÔ£¬½¡¿µÓÎÏ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return None  
 | 
def RevertHealthGame(curPlayer, tick):  
 | 
    #ÉèÖÃ1¼¶³ÁÃÔ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OfflineTime, 0)  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_LV, ChConfig.Def_GameWallow_LV_1_1)  
 | 
      
 | 
    #ÔÚÏßʱ¼äÇå¿Õ  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OnlineTime, 0)  
 | 
      
 | 
    PlayerControl.NotifyCode(curPlayer, "AvoidSink01")  
 | 
      
 | 
    return  
 | 
  
 | 
  
 | 
##»ñµÃÊÇ·ñΪ·À³ÁÃÔ½ÇÉ«  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @return bool  
 | 
def GetIsWallowRole(curPlayer):  
 | 
    if ReadChConfig.GetEvalChConfig("HealthGame_CountWallow") != Def_GameWallow_Open:  
 | 
        return False  
 | 
      
 | 
    if curPlayer.IsAdult() == 1:  
 | 
        return False  
 | 
      
 | 
    return True  
 | 
  
 | 
##»Ö¸´ÎªÒ»¼¶³ÁÃÔ£¬½¡¿µÓÎÏ·  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return None  
 | 
def RevertHealthGame_OnDay(curPlayer):  
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        #·Ç³ÁÃÔ£¬É¾³ý³ÁÃÔ״̬  
 | 
        Del_Wallow(curPlayer)  
 | 
        return  
 | 
      
 | 
    tick = GameWorld.GetGameWorld().GetTick()  
 | 
      
 | 
    #ÉèÖÃΪ½¡¿µ×´Ì¬  
 | 
    RevertHealthGame(curPlayer, tick)  
 | 
      
 | 
  
 | 
##·µ»Ø³ÁÃÔºóµÄ¾Ñé  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param addExp Ôö¼Ó¾ÑéÖµ  
 | 
# @return ¼ÆËãºóµÄ¾Ñé  
 | 
def ChangeExpByWallow(curPlayer, addExp):  
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        return addExp  
 | 
      
 | 
    wallowLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV)  
 | 
    expMulNum = Def_GameWallow_ExpDict.get(wallowLV, 1)  
 | 
          
 | 
    if expMulNum == None:  
 | 
        GameWorld.ErrLog("ÎÞ·¨ÕÒµ½¾ÑéϵÊý£¬µ±Ç°³ÁÃԵȼ¶%s ¶ÔÓ¦±í%s"%(wallowLV, Def_GameWallow_ExpDict))  
 | 
        return addExp  
 | 
      
 | 
    return int(addExp*expMulNum)  
 | 
      
 | 
      
 | 
##³ÁÃÔÔÚÏßʱ¼ä  
 | 
# @param curPlayer Íæ¼ÒʵÀý  
 | 
# @param pastTick ¾¹ýµÄʱ¼ä  
 | 
# @param tick Ê±¼ä´Á  
 | 
# @return none  
 | 
def DoLogic_WallowOnlineTime(curPlayer, tick):  
 | 
    if PlayerTJG.GetIsTJG(curPlayer):  
 | 
        return  
 | 
      
 | 
    if not GetIsWallowRole(curPlayer):  
 | 
        return  
 | 
      
 | 
    lastDealTick = curPlayer.GetTickByType(ChConfig.TYPE_Player_Tick_PlayerWallow)  
 | 
      
 | 
    if lastDealTick <= 0:  
 | 
        #Çл»µØÍ¼£¬ÎÞÐÅÏ¢£¬ÖØÐ¼Ç¼  
 | 
        curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_PlayerWallow, tick)  
 | 
        return  
 | 
      
 | 
    curTimePassed = tick - lastDealTick  
 | 
      
 | 
    #ˢмä¸ôûÓе½  
 | 
    checkInterval = ChConfig.TYPE_Player_Tick_Time[ChConfig.TYPE_Player_Tick_PlayerWallow]  
 | 
    if curTimePassed < checkInterval:  
 | 
        return   
 | 
      
 | 
    curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_PlayerWallow, tick)  
 | 
      
 | 
    onlineTick = min(curTimePassed + curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_OnlineTime), 24*60*60*1000)  
 | 
  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_OnlineTime, onlineTick)  
 | 
      
 | 
    wallowLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV)  
 | 
    onlineMin = onlineTick/1000/60  
 | 
      
 | 
    findLv = ChConfig.Def_GameWallow_LV_1_1  
 | 
    for timeList in Def_WallowLV_Time_Dict:  
 | 
        if onlineMin >= timeList[0]:  
 | 
            findLv = timeList[1]  
 | 
      
 | 
    # Ìá¸ßµ½¸ü¸ßµÈ¼¶ÐèÌáʾ  
 | 
    if findLv > wallowLV:  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_Wallow_LV, findLv)  
 | 
        notifyInfo = Def_WallowLV_Notify_Dict.get(findLv, ["AvoidSink05", [5]])  
 | 
        PlayerControl.NotifyCode(curPlayer, notifyInfo[0], notifyInfo[1])  
 | 
        NotifyWallowTime(curPlayer)  
 | 
        return  
 | 
      
 | 
    #  5Сʱºóÿ15·ÖÖÓÌáʾһ´Î  
 | 
    if onlineMin > 300 and (onlineMin - 300)%15 == 0:  
 | 
        PlayerControl.NotifyCode(curPlayer, "AvoidSink05", [5])  
 | 
        NotifyWallowTime(curPlayer)  
 | 
        return  
 | 
          
 | 
    return  
 | 
  
 |