hxp
2019-05-09 59d00e9001195420f83a0a8e19ad799a34fa09a9
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCCustomRefresh.py
@@ -18,6 +18,7 @@
import ReadChConfig
import GameLogic_SealDemon
import GameLogic_ZhuXianBoss
import GameLogic_CrossDemonKing
import PlayerControl
import IPY_GameWorld
import IpyGameDataPY
@@ -307,6 +308,8 @@
        
    gameWorld = IPY_GameWorld.IPY_GameWorld(activityLineIndex)
    gameFB = gameWorld.GetGameFBByFbIndex(activityLineIndex)
    if not gameFB:
        return
    
    gameNPC = GameWorld.GetNPCManager() # NPC标识点的无所谓,哪条线都可以,因为都一样
    for i in xrange(gameNPC.GetCustomNPCRefreshCount()):
@@ -335,6 +338,9 @@
    isNeedShunt = 0
    if mapID == ChConfig.Def_FBMapID_SealDemon:
        bossID = GameLogic_SealDemon.CurFBLineBOSSID()
        stoneNPCID = 0
    elif mapID == ChConfig.Def_FBMapID_DemonKing:
        bossID = GameLogic_CrossDemonKing.GetCurFBLineBOSSID()
        stoneNPCID = 0
    elif mapID == ChConfig.Def_FBMapID_ZhuXianBoss:
        bossID = GameLogic_ZhuXianBoss.CurFBLineBOSSID()
@@ -481,24 +487,34 @@
    
    refreshMark = npcRefresh.GetRefreshMark()
    lineID = GameWorld.GetGameWorld().GetLineID()
    bossIpyData = IpyGameDataPY.GetIpyGameDataByCondition('BOSSInfo', {'RefreshMark':refreshMark, 'MapID':mapID}, isLogNone=False)
    if not bossIpyData:
        return
    stoneNPCID = bossIpyData.GetStoneNPCID()
    bossID = bossIpyData.GetNPCID()
    if not bossID and not stoneNPCID:
        return
    if mapID not in ChConfig.Def_CrossZoneMapTableName:
        return
    tableName = ChConfig.Def_CrossZoneMapTableName[mapID]
    realMapID = GameWorld.GetGameWorld().GetRealMapID()
    copyMapID = GameWorld.GetGameWorld().GetCopyMapID()
    zoneIpyData = IpyGameDataPY.GetIpyGameDataNotLog(tableName, realMapID, mapID, copyMapID)
    if not zoneIpyData:
    if mapID == ChConfig.Def_FBMapID_CrossDemonKing:
        bossID = GameLogic_CrossDemonKing.GetCurFBLineBOSSID()
        stoneNPCID = 0
        zoneID = GameLogic_CrossDemonKing.GetCurFBLineZoneID()
    else:
        bossIpyData = IpyGameDataPY.GetIpyGameDataByCondition('BOSSInfo', {'RefreshMark':refreshMark, 'MapID':mapID}, isLogNone=False)
        if not bossIpyData:
            return
        stoneNPCID = bossIpyData.GetStoneNPCID()
        bossID = bossIpyData.GetNPCID()
        if mapID not in ChConfig.Def_CrossZoneMapTableName:
            return
        tableName = ChConfig.Def_CrossZoneMapTableName[mapID]
        zoneIpyData = IpyGameDataPY.GetIpyGameDataNotLog(tableName, realMapID, mapID, copyMapID)
        if not zoneIpyData:
            return
        zoneID = zoneIpyData.GetZoneID()
    if not zoneID:
        return
    zoneID = zoneIpyData.GetZoneID()
    if not bossID and not stoneNPCID:
        return
    
    gameFB = GameWorld.GetGameFB()
    bosskey = ShareDefine.Def_Notify_WorldKey_GameWorldBossRebornCross % (zoneID, bossID)
@@ -841,12 +857,13 @@
    ''' 地图自定义随机刷怪,支持多点随机刷多种怪,标试点不可重复,支持跨服地图
            注意:同个虚拟线路中,标试点不可重复!标试点不可重复!标试点不可重复!
    '''
    mapID = gameWorld.GetMapID()
    # {mapID:{编号:[[多个NPCID], [多个标试点], 单个点最大数量, 所有点总数量, 刷怪间隔秒, 每整X小时], ...}, ...}
    randRefreshNPCDict = IpyGameDataPY.GetFuncEvalCfg("RandomRefreshNPC", 1, {})
    if mapID not in randRefreshNPCDict:
    if gameWorld.GetOpenState() != IPY_GameWorld.fbosOpen:
        #已经关闭了
        return
    mapRandRefreshNPCDict = randRefreshNPCDict[mapID]
    mapID = gameWorld.GetMapID()
    refreshIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("MapRefreshNPC", mapID)
    if not refreshIpyDataList:
        return
    
    #copyMapID = gameWorld.GetCopyMapID()
    
@@ -858,21 +875,28 @@
    
    serverTime = GameWorld.GetCurrentTime()
    curHour, curMinute = serverTime.hour, serverTime.minute
    refreshNumList = []
    for num, refreshInfo in mapRandRefreshNPCDict.items():
        refreshCD = refreshInfo[4]
    minuteTotal = curHour * 60 + curMinute
    needRefreshIpyDataList = []
    for ipyData in refreshIpyDataList:
        num = ipyData.GetRefreshNum()
        numLastTick = gameFB.GetGameFBDictByKey(ChConfig.Def_RMark_RandomRefreshNPCNumTime % num)
        perHours = refreshInfo[5]
        if numLastTick and perHours:
            if curHour % perHours != 0 or curMinute != 0:
        if numLastTick:
            perMinutes = ipyData.GetRefreshPerMinutes()
            if perMinutes:
                if minuteTotal % perMinutes != 0:
                    continue
                refreshCD = 60 # 1分钟内不重复刷新
            else:
                refreshCD = ipyData.GetRefreshSeconds()
            if not refreshCD:
                continue
            refreshCD = 65 # 1分钟内不重复刷新
        if numLastTick and tick - numLastTick < refreshCD * 1000:
            continue
            if tick - numLastTick < refreshCD * 1000:
                continue
        gameFB.SetGameFBDict(ChConfig.Def_RMark_RandomRefreshNPCNumTime % num, tick)
        refreshNumList.append(num)
        needRefreshIpyDataList.append(ipyData)
        
    if not refreshNumList:
    if not needRefreshIpyDataList:
        #GameWorld.DebugLog("没有需要刷怪的", copyMapID)
        return
    npcCountDict = {}  # 标识点对应NPC数量
@@ -887,9 +911,12 @@
        npcCountDict[rMark] = npcCountDict.get(rMark, 0) + npcCount
        rMarkNPCRefreshDict[rMark] = npcRefresh
        
    #GameWorld.DebugLog("npcCountDict=%s" % npcCountDict, copyMapID)
    for num in refreshNumList:
        npcIDList, markList, maxCount, totalMaxCount = mapRandRefreshNPCDict[num][:4]
    #GameWorld.DebugLog("标试点怪物数: minuteTotal=%s,npcCountDict=%s" % (minuteTotal, npcCountDict), copyMapID)
    for ipyData in needRefreshIpyDataList:
        npcIDList = ipyData.GetNPCIDList()
        markList = ipyData.GetRefreshMarkList()
        maxCount = ipyData.GetPointMaxCount()
        totalMaxCount = ipyData.GetTotalMaxCount()
        
        curTotalCount = 0
        for rMark in markList:
@@ -897,13 +924,16 @@
            
        refreshCount = totalMaxCount - curTotalCount
        
        #GameWorld.DebugLog("    num=%s,markList=%s,curTotalCount=%s,totalMaxCount=%s,refreshCount=%s"
        #                   % (num, markList, curTotalCount, totalMaxCount, refreshCount), copyMapID)
        #GameWorld.DebugLog("    npcIDList=%s,markList=%s,curTotalCount=%s,totalMaxCount=%s,refreshCount=%s"
        #                   % (npcIDList, markList, curTotalCount, totalMaxCount, refreshCount), copyMapID)
        if refreshCount <= 0:
            continue
        
        random.shuffle(markList) # 随机打乱顺序
        #GameWorld.DebugLog("    markList=%s" % markList, copyMapID)
        isNeedRandom = len(markList) != totalMaxCount
        if isNeedRandom:
            markList = list(markList)
            random.shuffle(markList) # 随机打乱顺序,如果需要随机的话就用多个不同的标试点
        #GameWorld.DebugLog("    markList=%s" % str(markList), copyMapID)
        for rMark in markList:
            if rMark not in rMarkNPCRefreshDict:
                #GameWorld.DebugLog("        标试点不存在: rMark=%s" % rMark, copyMapID)
@@ -926,3 +956,57 @@
            
    return
def GetCopyMapRandomRefreshNPCInfo():
    ## 获取当前虚拟线路随机刷怪点NPC信息
    gameWorld = GameWorld.GetGameWorld()
    mapID = gameWorld.GetMapID()
    refreshIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("MapRefreshNPC", mapID)
    if not refreshIpyDataList:
        return
    lastRefreshTickDict = {}
    gameFB = GameWorld.GetGameFB()
    for ipyData in refreshIpyDataList:
        num = ipyData.GetRefreshNum()
        lastRefreshTickDict[num] = gameFB.GetGameFBDictByKey(ChConfig.Def_RMark_RandomRefreshNPCNumTime % num)
    markNPCDict = {}  # 标识点对应NPC数量
    gameNPC = GameWorld.GetNPCManager()
    for i in xrange(gameNPC.GetCustomNPCRefreshCount()):
        npcRefresh = gameNPC.GetCustomNPCRefreshAt(i)
        npcCount = npcRefresh.GetCount()
        if not npcCount:
            continue
        rMark = npcRefresh.GetRefreshMark()
        npcIDCountDict = {}
        for j in xrange(npcCount):
            curNPC = npcRefresh.GetAt(j)
            npcID = curNPC.GetNPCID()
            npcIDCountDict[npcID] = npcIDCountDict.get(npcID, 0) + 1
        markNPCDict[rMark] = npcIDCountDict
    return lastRefreshTickDict, markNPCDict
def OnFBOpenSetRandomRefreshNPCInfo(refreshNPCInfo, tick):
    ## 副本虚拟线路启动时,根据保存的标试点刷怪信息设置刷怪
    lastRefreshTickDict, markNPCDict = refreshNPCInfo
    gameFB = GameWorld.GetGameFB()
    gameFB.SetGameFBDict(ChConfig.Def_RMark_RandomRefreshNPCTick, tick)
    for num, setTick in lastRefreshTickDict.items():
        gameFB.SetGameFBDict(ChConfig.Def_RMark_RandomRefreshNPCNumTime % num, setTick)
    gameNPC = GameWorld.GetNPCManager()
    for i in xrange(gameNPC.GetCustomNPCRefreshCount()):
        npcRefresh = gameNPC.GetCustomNPCRefreshAt(i)
        rMark = npcRefresh.GetRefreshMark()
        if rMark not in markNPCDict:
            continue
        npcIDCountDict = markNPCDict[rMark]
        for npcID, count in npcIDCountDict.items():
            GameWorld.DebugLog("    副本启动刷怪: rMark=%s,npcID=%s,count=%s" % (rMark, npcID, count))
            npcRefresh.Refresh(npcID, ChConfig.Def_NormalNPCAngryCount, count, False)
            __InitNewBornNPC(npcRefresh , tick)
    return