hxp
2019-11-04 d7f8d55a035e5351c6af9f6c49ec5339c844d903
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_HorsePetBoss.py
@@ -26,27 +26,20 @@
import ShareDefine
import PlayerActivity
import NPCCustomRefresh
import ItemControler
import PlayerWeekParty
import EventReport
import NPCCommon
import GameObj
import EventShell
FBDict_StartTick = 'FBDict_StartTick%s' #开始时间
FBDict_Speed = 'FBDict_Speed%s' #掉血速度 /s
FBDict_RemainHP = 'FBDict_RemainHP%s' #剩余时间
FBPlayerDict_EncourageLV = 'FBPlayerDict_EncourageLV'   # 鼓舞等级
FBDict_IsOver = 'FBDict_IsOver' #是否已结算, 结算时的tick
FBDict_IsReduceing = 'FBDict_IsReduceing%s' #是否掉血中
FBPlayerDict_Rank = "FBPlayerDict_Rank" # 玩家排名
FBDict_BossTotalHP = 'FBDict_BossTotalHP%s' #BOSS血量
FBDict_LastHurtTick = 'FBDict_LastHurtTick'  #上次伤害时间
FBDict_LastHPNotify = 'FBDict_LastHPNotify'  #上一个血量广播
Map_FB_StartTick = 'Map_FB_StartTick' #活动开始时间
(
Def_BossTime,  #BOSS时间
Def_LeaveTime,  #离开时间
Def_HPSpeed,  #掉血速度公式
) = range(3)
) = range(2)
    
#当前副本地图的状态
(
@@ -56,11 +49,6 @@
FB_Step_Close,  # 副本关闭
) = range(4)
    
def OnFBPlayerOnLogin(curPlayer):
    return
def OnFBPlayerOnDay(curPlayer):
    return
## 是否能够通过活动查询进入
@@ -105,8 +93,6 @@
    if not bossID:
        return
    NPCCustomRefresh.SetNPCRefresh(101, [bossID])
    BossTime = FBCommon.GetFBLineStepTime(ChConfig.Def_FBMapID_HorsePetBoss, lineID)[Def_BossTime]
    GameWorld.GetGameWorld().SetGameWorldDict(FBDict_BossTotalHP%lineID, BossTime * 1000)
    return
def OnHorsePetBossStateChange(state, tick):
@@ -115,12 +101,23 @@
    if mapID != ChConfig.Def_FBMapID_HorsePetBoss:
        return
    GameWorld.DebugLog('    骑宠BOSS活动状态变更 state=%s' % state)
    if not state:
    if state:
        if not GameWorld.GetGameWorld().GetGameWorldDictByKey(Map_FB_StartTick):
            GameWorld.GetGameWorld().SetGameWorldDict(Map_FB_StartTick, tick)
    else:
        GameWorld.GetGameWorld().SetGameWorldDict(Map_FB_StartTick, 0)
        if GameWorld.GetGameFB().GetFBStep() == FB_Step_Fighting:
            GameWorld.GetGameFB().SetGameFBDict(FBDict_IsOver, tick)
            __DoLogicHorsePetBossOver(0, tick, 0, 0)
    return
def __GetRemainTick(tick):
    ##活动剩余毫秒
    mapID = GameWorld.GetMap().GetMapID()
    startTick = GameWorld.GetGameWorld().GetGameWorldDictByKey(Map_FB_StartTick)
    closeFB_RemainTick = max(0, FBCommon.GetFBLineStepTime(mapID)[Def_BossTime] * 1000 - (tick - startTick))
    return closeFB_RemainTick
## 进副本
#  @param curPlayer
@@ -145,13 +142,13 @@
    if not hadDelTicket:
        FBCommon.SetHadDelTicket(curPlayer)
        PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_HorsePetBoss, 1)
        PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_HorsePetBoss, 1)
        EventReport.WriteEvent_FB(curPlayer, ChConfig.Def_FBMapID_HorsePetBoss, 0, ChConfig.CME_Log_Start)
        EventShell.EventRespons_HorsePetBoss(curPlayer)
        if fbStep == FB_Step_Open:
            FBCommon.SetFBStep(FB_Step_Fighting, tick)
    UpdateHurtInfo(curPlayer, 0, True)
    UpdateHPReduceSpeed(tick)
    gameFB = GameWorld.GetGameFB()
    # 上鼓舞buff
    encourageLV = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_EncourageLV)
@@ -159,7 +156,9 @@
        FBCommon.AddFbEncourageBuff(curPlayer, FBPlayerDict_EncourageLV, tick)
    else:
        FBCommon.SendFBEncourageInfo(curPlayer, encourageLV)
    closeFB_RemainTick = __GetRemainTick(tick)
    curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, closeFB_RemainTick, True)
    DoFBHelp(curPlayer, tick)
    return
@@ -170,10 +169,7 @@
def OnCloseFB(tick):
    gameWorld = GameWorld.GetGameWorld()
    lineID = gameWorld.GetPropertyID() - 1
    gameWorld.SetGameWorldDict(FBDict_StartTick % lineID, 0)
    gameWorld.SetGameWorldDict(FBDict_Speed % lineID, 0)
    gameWorld.SetGameWorldDict(FBDict_RemainHP % lineID, 0)
    PyGameData.g_horsePetBossPlayerHurtDict[lineID] = {}
    gameWorld.SetPropertyID(0)
    return
@@ -194,8 +190,6 @@
#        GameWorldProcess.CloseFB(tick)
#        return
        
    UpdateHPReduceSpeed(tick, True)
    return
##玩家主动离开副本.
@@ -209,8 +203,6 @@
    playerHurtDict = PyGameData.g_horsePetBossPlayerHurtDict.get(lineID, {})
    playerHurtDict.pop(curPlayer.GetPlayerID(), 0)
    PyGameData.g_horsePetBossPlayerHurtDict[lineID] = playerHurtDict
    if not playerHurtDict: #榜上没人,停止掉血
        StopReduceHP(lineID, tick)
    return
##玩家切换地图
@@ -251,18 +243,9 @@
            hurtDict["hurt"] = hurt % ChConfig.Def_PerPointValue
            hurtDict["hurtEx"] = hurt / ChConfig.Def_PerPointValue
            hurtInfo.append(hurtDict)
    curSpeed = GameWorld.GetGameWorld().GetGameWorldDictByKey(FBDict_Speed % lineID)
    isReduceing = GameWorld.GetGameWorld().GetGameWorldDictByKey(FBDict_IsReduceing % lineID)
    remainHP = GetBossRemainHP(lineID, tick)
    totalHP = __GetBossTotalHP(lineID)
    hpReduceSpeed = curSpeed * 10000 / totalHP if totalHP else 0
    remainHPPer = min(1000000, remainHP * 1000000 / totalHP) if totalHP else 0
    fbHelpDict = {FBCommon.Help_lineID:lineID, "hurtInfo":hurtInfo, 'hpReduceSpeed':hpReduceSpeed,
                  'remainHPPer':remainHPPer, 'isReduceing':isReduceing,'myHurt':myHurt % ChConfig.Def_PerPointValue,
                  'myHurtEx':myHurt / ChConfig.Def_PerPointValue, 'myRank':myRank
    remainHPPer = GetBossRemainHPPer(GameWorld.GetGameWorld().GetCopyMapID(), lineID, tick)
    fbHelpDict = {FBCommon.Help_lineID:lineID, "hurtInfo":hurtInfo, 'myHurt':myHurt % ChConfig.Def_PerPointValue,
                  'myHurtEx':myHurt / ChConfig.Def_PerPointValue, 'myRank':myRank, 'remainHPPer':remainHPPer
                  }
    GameWorld.DebugLog("DoFBHelp: %s" % fbHelpDict, curPlayer.GetPlayerID())
    FBCommon.Notify_FBHelp(curPlayer, fbHelpDict)
@@ -289,10 +272,6 @@
#  @return None
def DoFB_Player_HurtNPC(curPlayer, curNPC, hurtHP):
    UpdateHurtInfo(curPlayer, hurtHP)
    #有人上榜开始掉血
    lineID = GameWorld.GetGameWorld().GetPropertyID() - 1
    StartReduceHP(lineID, GameWorld.GetGameWorld().GetTick())
    GameWorld.GetGameFB().SetGameFBDict(FBDict_LastHurtTick, GameWorld.GetGameWorld().GetTick())
    return
#
def UpdateHurtInfo(curPlayer, hurtHP, isAdd=False):
@@ -333,17 +312,11 @@
            return
    
    elif fbStep == FB_Step_Fighting:
        startTick = gameWorld.GetGameWorldDictByKey(FBDict_StartTick % lineID)
        if not startTick or overTick:
        if overTick:
            return
        lastHurtTick = gameFB.GetGameFBDictByKey(FBDict_LastHurtTick)
        if lastHurtTick and tick - lastHurtTick >= 2000:
            StopReduceHP(lineID, tick)
            gameFB.SetGameFBDict(FBDict_LastHurtTick, 0)
        FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 5000)
        __CheckBossHP(tick)
    return
@@ -368,8 +341,8 @@
    if not playerHurtList:
        GameWorld.Log(' __DoLogicHorsePetBossOver, 伤害榜上没有人!!lineID=%s'%lineID)
        return
    event = ["HorsePetBoss", False, {}]
    bossID = CurFBLineBOSSID(lineID)
    #event = ["HorsePetBoss", False, {}]
    batchPlayerIDList, batchAddItemList, batchParamList, batchDetailList = [], [], [], []
    playerManager = GameWorld.GetMapCopyPlayerManager()
    worldLV = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_WorldAverageLv)
@@ -379,7 +352,7 @@
            auctionItemList, itemList = __GetHorsePetBossAward(lineID, rank, worldLV)
        else:
            auctionItemList, itemList = [], []
        GameWorld.Log('auctionItemList=%s,itemList=%s'%(auctionItemList, itemList))
        GameWorld.Log('auctionItemList=%s,itemList=%s, rank=%s'%(auctionItemList, itemList, rank), playerID)
        giveItemList = auctionItemList+itemList
        player = playerManager.FindPlayerByID(playerID)
        if player:
@@ -389,9 +362,8 @@
            if itemList:
                overDict[FBCommon.Over_itemInfo] = FBCommon.GetJsonItemList(itemList)
            if giveItemList:
                NPCCommon.DoVirtualItemDrop(player, giveItemList, dropPosX, dropPosY)
                ItemControler.GivePlayerItemOrMail(player, giveItemList, 'QCBOSS1', event)
                NPCCommon.DoGiveItemByVirtualDrop(player, giveItemList, bossID, dropPosX, dropPosY, mailTypeKey='QCBOSS1')
            player.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTick, True)
            FBCommon.NotifyFBOver(player, ChConfig.Def_FBMapID_HorsePetBoss, lineID, isPass, overDict)
        elif giveItemList:
@@ -429,141 +401,58 @@
        if len(itemInfo) != 3:
            GameWorld.ErrLog('骑宠Boss奖励表 配置错误 itemInfo=%s' % itemInfo)
            continue
        if not itemInfo[0]:
            continue
        if itemInfo[2]:
            auctionItemList.append(itemInfo)
        else:
            itemList.append(itemInfo)
    
    for doCnt, awardPieRateList in awardPieRateDict.items():
        for _ in xrange(doCnt):
            resultItem = GameWorld.GetResultByRandomList(awardPieRateList)
            if len(resultItem) != 3:
                GameWorld.ErrLog('骑宠Boss奖励表配置错误 itemInfo=%s' % resultItem)
                continue
            if resultItem[2]:
                auctionItemList.append(resultItem)
            else:
                itemList.append(resultItem)
    for awardPieRateList in awardPieRateDict:
        resultItem = GameWorld.GetResultByRandomList(awardPieRateList)
        if len(resultItem) != 3:
            GameWorld.ErrLog('骑宠Boss奖励表配置错误 itemInfo=%s' % resultItem)
            continue
        if not resultItem[0]:
            continue
        if resultItem[2]:
            auctionItemList.append(resultItem)
        else:
            itemList.append(resultItem)
    return auctionItemList, itemList
def DoFB_Npc_KillNPC(attacker, curNPC, tick):
    __FBNPCOnKilled(curNPC, tick)
    return
def DoFB_Player_KillNPC(curPlayer, curNPC, tick):
    __FBNPCOnKilled(curNPC, tick)
    return
def __CheckBossHP(tick):
    gameFB = GameWorld.GetGameFB()
    isOver = gameFB.GetGameFBDictByKey(FBDict_IsOver)
## 执行副本杀怪逻辑
def __FBNPCOnKilled(curNPC, tick):
    lineID = GameWorld.GetGameWorld().GetPropertyID() - 1
    if not isOver:
        bossID = CurFBLineBOSSID(lineID)
        if GetBossRemainHP(lineID, tick) == 0:
            curBoss = GameWorld.FindNPCByNPCID(bossID)
            dropPosX, dropPosY = 0, 0
            if curBoss:
                dropPosX, dropPosY = curBoss.GetPosX(), curBoss.GetPosY()
            #结束 设置BOSS死亡
            FBCommon.ClearFBNPC()
            FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0)
            GameWorld.DebugLog('结束 设置BOSS死亡 lineID=%s' % lineID)
            __DoLogicHorsePetBossOver(1, tick, dropPosX, dropPosY)
            gameFB.SetGameFBDict(FBDict_IsOver, tick)
        else:
            #血量广播
            needNotifyHPPerList = [50, 20]
            lastIndex = gameFB.GetGameFBDictByKey(FBDict_LastHPNotify)
            if lastIndex >= len(needNotifyHPPerList):
                return
            remainPer = GetBossRemainHPPer(lineID, tick)
            notifyHPPer = needNotifyHPPerList[lastIndex]
            if remainPer == notifyHPPer or remainPer - 1 == notifyHPPer:
                gameFB.SetGameFBDict(FBDict_LastHPNotify, lastIndex + 1)
                lineID = GameWorld.GetGameWorld().GetPropertyID() - 1
                msgMark = 'QCBOSSHP1'
                PlayerControl.WorldNotify(0, msgMark, [bossID, remainPer])
    return
def UpdateHPReduceSpeed(tick, isExit=False):
    gameWorld = GameWorld.GetGameWorld()
    playerCnt = gameWorld.GetMapCopyPlayerManager().GetPlayerCount()
    playerCnt = playerCnt - 1 if isExit else playerCnt
    if playerCnt <=0:
        return
    lineID = GameWorld.GetGameWorld().GetPropertyID() - 1
    if lineID < 0:
    bossID = CurFBLineBOSSID(lineID)
    if curNPC.GetNPCID() != bossID:
        return
    curSpeed = eval(FBCommon.GetFBLineStepTime(ChConfig.Def_FBMapID_HorsePetBoss, lineID)[Def_HPSpeed])
    gameWorld.SetGameWorldDict(FBDict_Speed % lineID, curSpeed)
    if not gameWorld.GetGameWorldDictByKey(FBDict_IsReduceing%lineID):
        return
    dropPosX, dropPosY = curNPC.GetPosX(), curNPC.GetPosY()
    
    startTick = gameWorld.GetGameWorldDictByKey(FBDict_StartTick % lineID)
    remainHP = gameWorld.GetGameWorldDictByKey(FBDict_RemainHP % lineID)
    lastSpeed = gameWorld.GetGameWorldDictByKey(FBDict_Speed % lineID)
    if not startTick:
        startTick = tick
        lastSpeed = curSpeed
        remainHP = __GetBossTotalHP(lineID)
    remainHP = max(0, int((remainHP - (tick - startTick) / 1000.0 * lastSpeed)))
    gameWorld.SetGameWorldDict(FBDict_StartTick % lineID, tick)
    gameWorld.SetGameWorldDict(FBDict_RemainHP % lineID, remainHP)
    GameWorld.DebugLog('    curSpeed=%s, remainHP=%s, passTime=%s, lastSpeed=%s' % (curSpeed, remainHP, tick - startTick, lastSpeed))
    #结束 设置BOSS死亡
    FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0)
    return
def StopReduceHP(lineID, tick):
    ##暂停BOSS血量减少
    gameWorld = GameWorld.GetGameWorld()
    if not gameWorld.GetGameWorldDictByKey(FBDict_IsReduceing%lineID):
        return
    remainHP = GetBossRemainHP(lineID, tick)
    if not remainHP:
        return
    gameWorld.SetGameWorldDict(FBDict_IsReduceing % lineID, 0)
    gameWorld.SetGameWorldDict(FBDict_RemainHP % lineID, remainHP)
    return
def StartReduceHP(lineID, tick):
    ##开始BOSS掉血
    gameWorld = GameWorld.GetGameWorld()
    if gameWorld.GetGameWorldDictByKey(FBDict_IsReduceing%lineID):
        return
    gameWorld.SetGameWorldDict(FBDict_IsReduceing % lineID, 1)
    startTick = gameWorld.GetGameWorldDictByKey(FBDict_StartTick % lineID)
    if not startTick:
        gameWorld.SetGameWorldDict(FBDict_RemainHP % lineID, __GetBossTotalHP(lineID))
    gameWorld.SetGameWorldDict(FBDict_StartTick % lineID, tick)
    FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0)
    return
def __GetBossTotalHP(lineID):return GameWorld.GetGameWorld().GetGameWorldDictByKey(FBDict_BossTotalHP%lineID)
    GameWorld.DebugLog('结束 设置BOSS死亡 lineID=%s' % lineID)
    
    __DoLogicHorsePetBossOver(1, tick, dropPosX, dropPosY)
    GameWorld.GetGameFB().SetGameFBDict(FBDict_IsOver, tick)
    return
def GetBossRemainHP(lineID, tick):
    gameWorld = GameWorld.GetGameWorld()
    startTick = gameWorld.GetGameWorldDictByKey(FBDict_StartTick % lineID)
    lastSpeed = gameWorld.GetGameWorldDictByKey(FBDict_Speed % lineID)
    remainHP = gameWorld.GetGameWorldDictByKey(FBDict_RemainHP % lineID)
    if not gameWorld.GetGameWorldDictByKey(FBDict_IsReduceing%lineID):
        return remainHP
    if not startTick:
        startTick = tick
        remainHP = __GetBossTotalHP(lineID)
    else:
        remainHP = max(0, int((remainHP - (tick - startTick) / 1000.0 * lastSpeed)))
    return remainHP
def GetBossRemainHPPer(lineID, tick):
    remainHP = GetBossRemainHP(lineID, tick)
    totalHP = __GetBossTotalHP(lineID)
    if not totalHP:
def GetBossRemainHPPer(copyMapID, funcLineID, tick):
    bossID = CurFBLineBOSSID(funcLineID)
    curBoss = GameWorld.FindNPCByNPCIDEx(copyMapID, bossID)
    if not curBoss:
        return 100
    return remainHP * 100 / totalHP
    return GameObj.GetHP(curBoss) * 100 / GameObj.GetMaxHP(curBoss)
def CurFBLineBOSSID(lineID= -1):
    #该分线刷的BOSSID