From f06241bab7f037a68dedef888db548951a2bfdcb Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 21 一月 2025 14:09:21 +0800
Subject: [PATCH] 10263 【越南】【英文】【BT】【砍树】后端支持NPC仿真实玩家战斗和快速战斗(优化镜像玩家移动)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/MirrorAttack.py | 74 ++++++++++++++++++++++++++----------
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py | 7 ++-
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/AttackLogic/AttackCommon.py | 6 ++-
3 files changed, 62 insertions(+), 25 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/AttackLogic/AttackCommon.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/AttackLogic/AttackCommon.py
index 6e4731d..af0f829 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/AttackLogic/AttackCommon.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/AttackLogic/AttackCommon.py
@@ -1139,7 +1139,7 @@
# @param useSkill 使用的技能(无->传入None)
# @return True or False
# @remarks 函数详细说明.
-def CheckPlayerAttackDist(curPlayer, curTag, useSkill):
+def CheckPlayerAttackDist(curPlayer, curTag, useSkill, preciseAtkDict=False):
#攻击起点取缓存的坐标
atkStartPosX = curPlayer.GetAttackTargetPosX()
atkStartPosY = curPlayer.GetAttackTargetPosY()
@@ -1158,7 +1158,9 @@
return True
skillDist += PassiveBuffEffMng.GetPassiveSkillValueByTriggerType(curPlayer, curTag, useSkill, ChConfig.TriggerType_SkillDist)
- if dist > skillDist + ChConfig.Def_PlayerAttackDistZoom:
+ if not preciseAtkDict:
+ skillDist += ChConfig.Def_PlayerAttackDistZoom # 非精确距离验证的,加容错距离
+ if dist > skillDist:
#PlayerControl.NotifyCode(curPlayer, "XW_SF_DistanceFarness")
#GameWorld.GodLog(curPlayer, '技能距离超远 = %s, 技能攻击距离 = %s'%( dist, skillDist ))
return False
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/MirrorAttack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/MirrorAttack.py
index acd08bd..5f12948 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/MirrorAttack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/MirrorAttack.py
@@ -43,8 +43,10 @@
import GameObj
import time
+import math
Def_StateTimeList = [3, 60, 10] # 默认阶段时长,秒
+Mirror_StartMoveTick = "Mirror_StartMoveTick"
class MirrorBattle():
## 某场战斗
@@ -705,7 +707,7 @@
isOK = False
actionObj = PlayerState.__GetCanAttack_ObjDetel(curPlayer, tick)
if actionObj:
- isOK = PlayerAttack(curPlayer, actionObj, tick, autoUseSkillList)
+ isOK = PlayerAttack(curPlayer, actionObj, tick, autoUseSkillList, battle.isQuick)
if not isOK:
curFaction = curPlayer.GetFaction()
@@ -716,7 +718,7 @@
if actionObj and actionObj.GetID() == batPlayerID:
continue
tagObj = playerMgr.FindPlayerByID(batPlayerID)
- isOK = PlayerAttack(curPlayer, tagObj, tick, autoUseSkillList)
+ isOK = PlayerAttack(curPlayer, tagObj, tick, autoUseSkillList, battle.isQuick)
if isOK:
break
@@ -726,7 +728,7 @@
return
-def PlayerAttack(curPlayer, tagObj, tick, autoUseSkillList):
+def PlayerAttack(curPlayer, tagObj, tick, autoUseSkillList, isQuick=False):
## 玩家攻击, 参考技能使用 #def UseSkillEx(index, clientData, tick):
if not tagObj or GameObj.GetHP(tagObj) <= 0:
return
@@ -760,7 +762,7 @@
if SkillCommon.RefreshSkillRemainTime(curSkill, tick) != 0:
continue
- if not AttackCommon.CheckPlayerAttackDist(curPlayer, tagObj, curSkill):
+ if not AttackCommon.CheckPlayerAttackDist(curPlayer, tagObj, curSkill, True):
needMoveto = True
continue
@@ -784,18 +786,20 @@
curPlayer.SetAttackTick(tick)
else:
if needMoveto:
- MoveToObj(curPlayer, tagObj, tick)
+ MoveToObj(curPlayer, tagObj, tick, isQuick)
return
+ curPlayer.SetDict(Mirror_StartMoveTick, 0)
return useSkillResult
-def MoveToObj(curPlayer, tagObj, tick):
+def MoveToObj(curPlayer, tagObj, tick, isQuick=False):
#不可移动行为状态, 服务端限制
if not OperControlManager.IsObjCanDoAction(curPlayer,
ChConfig.Def_Obj_ActState_ServerAct,
IPY_GameWorld.oalMove):
return
+ curPosX, curPosY = curPlayer.GetPosX(), curPlayer.GetPosX()
destX = tagObj.GetPosX()
destY = tagObj.GetPosY()
# 缩小两格子用于前方一小片区域
@@ -803,27 +807,53 @@
moveDestX = resultPos.GetPosX()
moveDestY = resultPos.GetPosY()
- if (tick - curPlayer.GetDictByKey("MoveTick")) < 1000:
- # .Move( 接口调用太快会导致移动时间不够长(不足一格)导致无法移动 或者移动过慢问题
- # SetDestPos 调用会导致反向移动偏快
- #curPlayer.SetDestPos(moveDestX, moveDestY)
+ if isQuick:
+ curPlayer.ChangePos(moveDestX, moveDestY)
+ #GameWorld.DebugLog("---直接设置坐标: %s,%s to %s,%s, %s,%s" % (curPosX, curPosY, moveDestX, moveDestY, curPlayer.GetPosX(), curPlayer.GetPosY()), curPlayer.GetID())
return
- curPlayer.SetDict("MoveTick", tick)
- #return curPlayer.Move(moveDestX, moveDestY)
- # 执行一次重置位置,避免快速发包导致无法移动
- curPlayer.ChangePos(moveDestX, moveDestY)
+ startMoveTick = curPlayer.GetDictByKey(Mirror_StartMoveTick)
+ if not startMoveTick:
+ curPlayer.SetDict(Mirror_StartMoveTick, tick)
+ #GameWorld.DebugLog("---设置开始移动: %s,%s to %s,%s, tick=%s" % (curPosX, curPosY, moveDestX, moveDestY, tick), curPlayer.GetID())
+ return
+
+ speed = curPlayer.GetSpeed()
+ if not speed:
+ return
+
+ interval = tick - startMoveTick
+ moveDist = interval / float(speed)
+ #GameWorld.DebugLog("---计算位移: moveDist=%s,speed=%s,interval=%s(%s-%s)" % (moveDist, speed, interval, tick, startMoveTick), curPlayer.GetID())
+ if moveDist <= 0:
+ return
+
+ m_DestPosX, m_DestPosY = moveDestX, moveDestY
+ m_StartPosX, m_StartPosY = curPosX, curPosY
+ m_DestDist = GameWorld.GetDistEx(m_StartPosX, m_StartPosY, m_DestPosX, m_DestPosY, False)
+ updPosX = int(math.ceil(moveDist * (m_DestPosX - m_StartPosX) / m_DestDist + m_StartPosX))
+ updPosY = int(math.ceil(moveDist * (m_DestPosY - m_StartPosY) / m_DestDist + m_StartPosY))
+
+ cDist = GameWorld.GetDistEx(curPosX, curPosY, updPosX, updPosY, False)
+ if cDist <= 1:
+ #GameWorld.DebugLog("--------------------暂不移动: cDist=%s,updPos(%s,%s),curPos(%s,%s),m_DestPos(%s,%s),m_DestDist=%s"
+ # % (cDist, updPosX, updPosY, curPosX, curPosY, moveDestX, moveDestY, m_DestDist), curPlayer.GetID())
+ return
+ #GameWorld.DebugLog("--------------------更新坐标: cDist=%s,updPos(%s,%s),curPos(%s,%s),m_DestPos(%s,%s),m_DestDist=%s"
+ # % (cDist, updPosX, updPosY, curPosX, curPosY, moveDestX, moveDestY, m_DestDist), curPlayer.GetID())
+ curPlayer.ChangePos(updPosX, updPosY)
+ curPlayer.SetDict(Mirror_StartMoveTick, tick)
sendPack = ChNetSendPack.tagObjMove()
sendPack.Clear()
sendPack.ObjID = curPlayer.GetID()
- sendPack.ObjType = IPY_GameWorld.gotNPC
- sendPack.MoveType = IPY_GameWorld.gotPlayer
- sendPack.DestPosX = moveDestX
- sendPack.DestPosY = moveDestY
- sendPack.Speed = curPlayer.GetSpeed()
- sendPack.StartPosX = curPlayer.GetPosX()
- sendPack.StartPosY = curPlayer.GetPosY()
+ sendPack.ObjType = curPlayer.GetGameObjType()
+ sendPack.MoveType = IPY_GameWorld.mtNormal
+ sendPack.DestPosX = updPosX
+ sendPack.DestPosY = updPosY
+ sendPack.Speed = speed
+ sendPack.StartPosX = curPosX
+ sendPack.StartPosY = curPosY
curPlayer.NotifyAll(sendPack.GetBuffer(), sendPack.GetLength())
return
@@ -852,6 +882,7 @@
playerMgr = GameWorld.GetMapCopyPlayerManager()
perLoopTick = 100 # 每次循环视为已过毫秒
maxLoopCount = battle.stateTickRemain / perLoopTick # 循环次数上限
+ GameWorld.DebugLog("------------------------ 镜像PK快速结算 ------------------------", battleID)
GameWorld.DebugLog("镜像PK快速结算: isLogout=%s,maxLoopCount=%s,tick=%s,stateTickRemain=%s"
% (isLogout, maxLoopCount, tick, battle.stateTickRemain), battleID)
@@ -976,6 +1007,7 @@
player = playerMgr.FindPlayerByID(playerID)
if not player:
continue
+ player.StopMove()
realPlayerID = player.GetRealPlayerID()
hp = GameObj.GetHP(player)
hpMax = GameObj.GetMaxHP(player)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
index edea7e9..0cc8438 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
@@ -493,8 +493,11 @@
# @param tagY 目标Y
# @return 返回值, 距离
# @remarks 获得2点间距离(勾股定理)
-def GetDistEx(posX, posY, tagX, tagY):
- return GetFloatUpper(math.sqrt(pow(posX - tagX, 2) + pow(posY - tagY, 2)))
+def GetDistEx(posX, posY, tagX, tagY, toInt=True):
+ dist = math.sqrt(pow(posX - tagX, 2) + pow(posY - tagY, 2))
+ if not toInt:
+ return dist
+ return GetFloatUpper(dist)
#---------------------------------------------------------------------
##概率相关, 这个事件是否能够出现
--
Gitblit v1.8.0