Fixed characters reaching targets with less speed.

Contributed by Sahar.
This commit is contained in:
MobiusDevelopment
2021-03-07 22:32:06 +00:00
parent 24bfda4669
commit f1eb56cafa
94 changed files with 1612 additions and 398 deletions

View File

@@ -530,7 +530,7 @@ public abstract class AbstractAI implements Ctrl
}
// Calculate movement data for a move to location action and add the actor to movingObjects of GameTimeController
_actor.moveToLocation(pawn.getX(), pawn.getY(), pawn.getZ(), offset);
_actor.moveToLocation(pawn, pawn.getX(), pawn.getY(), pawn.getZ(), offset);
if (!_actor.isMoving())
{

View File

@@ -971,7 +971,7 @@ public class CreatureAI extends AbstractAI
return true;
}
if (getFollowTarget() != null)
if (isFollowing())
{
stopFollow();
}
@@ -1019,10 +1019,10 @@ public class CreatureAI extends AbstractAI
if (!_actor.isInsideRadius2D(target, offsetWithCollision))
{
// Caller should be Playable and thinkAttack/thinkCast/thinkInteract/thinkPickUp
if (getFollowTarget() != null)
if (isFollowing())
{
// allow larger hit range when the target is moving (check is run only once per second)
if (!_actor.isInsideRadius2D(target, offsetWithCollision + 30))
if (!_actor.isInsideRadius2D(target, offsetWithCollision + 100))
{
return true;
}
@@ -1077,7 +1077,7 @@ public class CreatureAI extends AbstractAI
return true;
}
if (getFollowTarget() != null)
if (isFollowing())
{
stopFollow();
}

View File

@@ -3351,6 +3351,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// to recalculate position
public int _moveStartTime;
public int _moveTimestamp; // last update
public WorldObject _target;
public int _xDestination;
public int _yDestination;
public int _zDestination;
@@ -3716,6 +3717,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
final MoveData m = _move;
if (m != null)
{
final WorldObject target = m._target;
if (target != null)
{
return target.getX();
}
return m._xDestination;
}
return getX();
@@ -3729,6 +3736,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
final MoveData m = _move;
if (m != null)
{
final WorldObject target = m._target;
if (target != null)
{
return target.getY();
}
return m._yDestination;
}
return getY();
@@ -3742,6 +3755,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
final MoveData m = _move;
if (m != null)
{
final WorldObject target = m._target;
if (target != null)
{
return target.getZ();
}
return m._zDestination;
}
return getZ();
@@ -3931,6 +3950,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return false;
}
final WorldObject target = m._target;
final int xPrev = getX();
final int yPrev = getY();
final int zPrev = getZ(); // the z coordinate may be modified by coordinate synchronizations
@@ -3940,14 +3960,29 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
if (Config.COORD_SYNCHRONIZE == 1)
// the only method that can modify x,y while moving (otherwise _move would/should be set null)
{
dx = m._xDestination - xPrev;
dy = m._yDestination - yPrev;
if (target != null)
{
dx = target.getX() - xPrev;
dy = target.getY() - yPrev;
}
else
{
dx = m._xDestination - xPrev;
dy = m._yDestination - yPrev;
}
}
else
// otherwise we need saved temporary values to avoid rounding errors
else // otherwise we need saved temporary values to avoid rounding errors
{
dx = m._xDestination - m._xAccurate;
dy = m._yDestination - m._yAccurate;
if (target != null)
{
dx = target.getX() - m._xAccurate;
dy = target.getY() - m._yAccurate;
}
else
{
dx = m._xDestination - m._xAccurate;
dy = m._yDestination - m._yAccurate;
}
}
// Z coordinate will follow client values
@@ -4005,7 +4040,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
if (distFraction > 1)
{
// Set the position of the Creature to the destination
super.setXYZ(m._xDestination, m._yDestination, m._zDestination);
if (target != null)
{
super.setXYZ(target.getX(), target.getY(), target.getZ());
}
else
{
super.setXYZ(m._xDestination, m._yDestination, m._zDestination);
}
}
else
{
@@ -4153,6 +4195,11 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _target;
}
public void moveToLocation(int xValue, int yValue, int zValue, int offsetValue)
{
moveToLocation(null, xValue, yValue, zValue, offsetValue);
}
/**
* Calculate movement data for a move to location action and add the Creature to movingObjects of GameTimeController (only called by AI Accessor).<br>
* <br>
@@ -4178,12 +4225,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
* <li>AI : onIntentionMoveTo(Location), onIntentionPickUp(WorldObject), onIntentionInteract(WorldObject)</li>
* <li>FollowTask</li>
* </ul>
* @param target The target to follow, if any.
* @param xValue The X position of the destination
* @param yValue The Y position of the destination
* @param zValue The Y position of the destination
* @param offsetValue The size of the interaction area of the Creature targeted
*/
public void moveToLocation(int xValue, int yValue, int zValue, int offsetValue)
public void moveToLocation(WorldObject target, int xValue, int yValue, int zValue, int offsetValue)
{
// Get the Move Speed of the Creature
final double speed = _stat.getMoveSpeed();
@@ -4410,6 +4458,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Calculate the number of ticks between the current position and the destination
// One tick added for rounding reasons
final int ticksToMove = 1 + (int) ((GameTimeController.TICKS_PER_SECOND * distance) / speed);
m._target = target;
m._xDestination = x;
m._yDestination = y;
m._zDestination = z; // this is what was requested from client

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.ai.CreatureAI;
import org.l2jmobius.gameserver.ai.CtrlEvent;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Summon;
@@ -95,7 +96,8 @@ public class CreatureFollowTaskManager
}
final int followRange = range == -1 ? Rnd.get(50, 100) : range;
if (!creature.isInsideRadius3D(followTarget, followRange))
final int followRangeWithCollision = followRange + creature.getTemplate().getCollisionRadius() + ((Creature) followTarget).getTemplate().getCollisionRadius();
if (!creature.isInsideRadius3D(followTarget, followRangeWithCollision))
{
if (!creature.isInsideRadius3D(followTarget, 3000))
{
@@ -109,6 +111,10 @@ public class CreatureFollowTaskManager
}
ai.moveToPawn(followTarget, followRange);
}
else
{
ThreadPool.execute(() -> ai.notifyEvent(CtrlEvent.EVT_ARRIVED));
}
}
else
{