#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#  
 | 
#  
 | 
##@package GameWorldAverageLv.py  
 | 
#  
 | 
# @todo:ÊÀ½çµÈ¼¶  
 | 
#  
 | 
# @author zhangxi  
 | 
# @date 2012-07-06  
 | 
# @version 1.5  
 | 
# @note:  
 | 
# @change: "2012-07-09 15:40" zhangxi ÐÞ¸ÄÅäÖñí¶ÁÈ¡  
 | 
# @change: "2012-07-17 14:30" zhangxi ÐÞ¸ÄÅÅÐаñΪ¿ÕʱµÄÅÐ¶Ï  
 | 
# @change: "2012-07-19 19:30" zhangxi ÐÞ¸´µÚ9Ìì²Å¿ªÆô  
 | 
# @change: "2012-12-03 10:00" wdb ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ  
 | 
# @change: "2015-02-02 12:00" hxp ÊÀ½çµÈ¼¶¼ÆËãȡֵÐÞ¸Ä(µÈ¼¶°ñ´æÖµ±ä¸ü)  
 | 
#------------------------------------------------------------------------------------------------------------   
 | 
"""Version = 2015-02-02 12:00"""       
 | 
#------------------------------------------------------------------------------   
 | 
import GameWorld  
 | 
import ShareDefine  
 | 
import PlayerDBGSEvent  
 | 
import ChConfig  
 | 
import IpyGameDataPY  
 | 
  
 | 
import datetime  
 | 
#------------------------------------------------------------------------------  
 | 
  
 | 
          
 | 
## ¿ªÆôÊÀ½çµÈ¼¶  
 | 
#  @param None:   
 | 
#  @return: None  
 | 
def OpenWorldAverageLv():  
 | 
    if not __IsWorldAverageLv():  
 | 
        return  
 | 
      
 | 
    beforeLv = PlayerDBGSEvent.GetDBGSTrig_ByKey(ShareDefine.Def_Notify_WorldKey_WorldAverageLv)  
 | 
      
 | 
    #ÉèÖÃÊÀ½çµÈ¼¶  
 | 
    worldAverageLv = __GetWorldAverageLv(beforeLv)  
 | 
    if worldAverageLv != beforeLv:  
 | 
        PlayerDBGSEvent.SetDBGSTrig_ByKey(ShareDefine.Def_Notify_WorldKey_WorldAverageLv, worldAverageLv)  
 | 
      
 | 
    #֪ͨµØÍ¼·þÎñÆ÷µ±Ç°ÊÀ½çµÈ¼¶  
 | 
    if GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_WorldAverageLv) != worldAverageLv:  
 | 
        GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_WorldAverageLv, worldAverageLv)  
 | 
        GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_WorldAverageLv, worldAverageLv)  
 | 
          
 | 
        GameWorld.Log("WorldAverageLv Change:beforeLv = %s, curLv = %s"%(beforeLv, worldAverageLv))  
 | 
    return  
 | 
  
 | 
  
 | 
## ÊÇ·ñ¿ªÆôÊÀ½çµÈ¼¶  
 | 
#  @param None:   
 | 
#  @return:   
 | 
def __IsWorldAverageLv():  
 | 
    # ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ  
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
    return True  
 | 
  
 | 
  
 | 
## »ñÈ¡ÊÀ½çµÈ¼¶  
 | 
#  @param None:   
 | 
#  @return:   
 | 
def __GetWorldAverageLv(beforeLv):  
 | 
    worldLV = 0  
 | 
    initOpenServerTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_InitOpenServerTime)  
 | 
    if initOpenServerTime <= 0:  
 | 
        return beforeLv  
 | 
    diffSecond = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_WorldLVExtraTime) #¶îÍâʱ¼ä²ÎÊý  
 | 
    initOpenServerTime = GameWorld.ChangeTimeNumToDatetime(initOpenServerTime, ChConfig.TYPE_Time_Format)  
 | 
    openServerSecond = max(0, GameWorld.GetPastSeconds(str(initOpenServerTime)) + diffSecond)  
 | 
    maxCnt = IpyGameDataPY.IPY_Data().GetWorldLVCount()  
 | 
    for i in xrange(max(0, beforeLv-1), maxCnt):  
 | 
        curIpyData = IpyGameDataPY.IPY_Data().GetWorldLVByIndex(i)  
 | 
        if i == maxCnt - 1:  
 | 
            worldLV = curIpyData.GetWorldLV()  
 | 
        else:  
 | 
            nextIpyData = IpyGameDataPY.IPY_Data().GetWorldLVByIndex(i+1)  
 | 
            if curIpyData.GetOpenServerSecond() <= openServerSecond < nextIpyData.GetOpenServerSecond():  
 | 
                worldLV = curIpyData.GetWorldLV()  
 | 
                break  
 | 
            if openServerSecond < curIpyData.GetOpenServerSecond():  
 | 
                #·Àֹʱ¼äÍù»Øµ÷µÄÇé¿ö£¬µ¼ÖÂÊÀ½çµÈ¼¶Òì³£  
 | 
                worldLV = beforeLv  
 | 
                break  
 | 
      
 | 
    return worldLV  
 | 
  
 | 
def GetWorldLVListByTime(startTime, day=1):  
 | 
    ##¸ù¾Ýʱ¼ä¼ÆËã¶à¸öÊÀ½çµÈ¼¶  
 | 
    initOpenServerTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_InitOpenServerTime)  
 | 
    if initOpenServerTime <= 0:  
 | 
        return []  
 | 
    worldlvList = []  
 | 
    diffSecond = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_WorldLVExtraTime) #¶îÍâʱ¼ä²ÎÊý  
 | 
    initOpenServerTime = GameWorld.ChangeTimeNumToDatetime(initOpenServerTime, ChConfig.TYPE_Time_Format)  
 | 
    if startTime < initOpenServerTime:  
 | 
        return []  
 | 
    ipyMgr = IpyGameDataPY.IPY_Data()  
 | 
    for dayIndex in xrange(day):  
 | 
        nextTime = startTime + datetime.timedelta(days=dayIndex)  
 | 
        pastTimeDelta = nextTime - initOpenServerTime  
 | 
        pastSeconds = max(0, pastTimeDelta.days * 24 * 60 * 60 + pastTimeDelta.seconds + diffSecond)  
 | 
        maxCnt = ipyMgr.GetWorldLVCount()  
 | 
        worldLV = 0  
 | 
        for i in xrange(maxCnt):  
 | 
            curIpyData = ipyMgr.GetWorldLVByIndex(i)  
 | 
            if i == maxCnt - 1:  
 | 
                worldLV = curIpyData.GetWorldLV()  
 | 
            else:  
 | 
                nextIpyData = ipyMgr.GetWorldLVByIndex(i+1)  
 | 
                if curIpyData.GetOpenServerSecond() <= pastSeconds < nextIpyData.GetOpenServerSecond():  
 | 
                    worldLV = curIpyData.GetWorldLV()  
 | 
                    break  
 | 
        worldlvList.append(worldLV)  
 | 
          
 | 
    GameWorld.DebugLog('    GetWorldLVByTime startTime=%s,day=%s,worldlvList=%s'%(str(startTime), day, worldlvList))  
 | 
    return worldlvList 
 |