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

@@ -467,7 +467,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

@@ -29,7 +29,6 @@ import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_REST;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
@@ -67,8 +66,6 @@ import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
*/
public class CreatureAI extends AbstractAI
{
private static final Logger LOGGER = Logger.getLogger(CreatureAI.class.getName());
public static class IntentionCommand
{
protected final CtrlIntention _crtlIntention;
@@ -474,9 +471,9 @@ public class CreatureAI extends AbstractAI
// Set the AI pick up target
setTarget(object);
if ((object.getX() == 0) && (object.getY() == 0)) // TODO: Find the drop&spawn bug
if ((object.getX() == 0) && (object.getY() == 0))
{
LOGGER.warning("Object in coords 0,0 - using a temporary fix");
// LOGGER.warning("Object in coords 0,0 - using a temporary fix");
object.setXYZ(getActor().getX(), getActor().getY(), getActor().getZ() + 5);
}
@@ -884,7 +881,7 @@ public class CreatureAI extends AbstractAI
{
if (worldPosition == null)
{
LOGGER.warning("maybeMoveToPosition: worldPosition == NULL!");
// LOGGER.warning("maybeMoveToPosition: worldPosition == NULL!");
return false;
}
@@ -954,7 +951,7 @@ public class CreatureAI extends AbstractAI
// Get the distance between the current position of the Creature and the target (x,y)
if (target == null)
{
LOGGER.warning("maybeMoveToPawn: target == NULL!");
// LOGGER.warning("maybeMoveToPawn: target == NULL!");
return false;
}
if (offsetValue < 0)
@@ -974,7 +971,7 @@ public class CreatureAI extends AbstractAI
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;
}

View File

@@ -2555,6 +2555,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;
@@ -2784,6 +2785,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();
@@ -2797,6 +2804,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();
@@ -2810,6 +2823,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();
@@ -2987,6 +3006,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
@@ -2996,14 +3016,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
@@ -3061,7 +3096,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
{
@@ -3211,6 +3253,11 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// called from AIAccessor only
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>
@@ -3236,12 +3283,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();
@@ -3468,6 +3516,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
{