Distance checking methods rework.

This commit is contained in:
MobiusDev
2018-09-05 01:50:44 +00:00
parent 0299a04d9b
commit b4be2cc560
1001 changed files with 2372 additions and 1802 deletions

View File

@ -748,9 +748,9 @@ public abstract class AbstractAI implements Ctrl
return;
}
if (!_actor.isInsideRadius(followTarget, followRange, true, false))
if (!_actor.isInsideRadius3D(followTarget, followRange))
{
if (!_actor.isInsideRadius(followTarget, 3000, true, false))
if (!_actor.isInsideRadius3D(followTarget, 3000))
{
// if the target is too far (maybe also teleported)
if (_actor.isSummon())

View File

@ -120,7 +120,7 @@ public class FriendlyNpcAI extends L2AttackableAI
{
for (L2Attackable nearby : L2World.getInstance().getVisibleObjects(npc, L2Attackable.class))
{
if (npc.isInsideRadius(nearby, collision, false, false) && (nearby != originalAttackTarget))
if (npc.isInsideRadius2D(nearby, collision) && (nearby != originalAttackTarget))
{
int newX = combinedCollision + Rnd.get(40);
if (Rnd.nextBoolean())
@ -141,7 +141,7 @@ public class FriendlyNpcAI extends L2AttackableAI
newY = originalAttackTarget.getY() - newY;
}
if (!npc.isInsideRadius(newX, newY, 0, collision, false, false))
if (!npc.isInsideRadius2D(newX, newY, 0, collision))
{
final int newZ = npc.getZ() + 30;
if (GeoEngine.getInstance().canMoveToTarget(npc.getX(), npc.getY(), npc.getZ(), newX, newY, newZ, npc.getInstanceWorld()))
@ -158,7 +158,7 @@ public class FriendlyNpcAI extends L2AttackableAI
{
if (Rnd.get(100) <= npc.getTemplate().getDodge())
{
final double distance2 = npc.calculateDistance(originalAttackTarget, false, true);
final double distance2 = npc.calculateDistanceSq2D(originalAttackTarget);
if (Math.sqrt(distance2) <= (60 + combinedCollision))
{
int posX = npc.getX();
@ -192,7 +192,7 @@ public class FriendlyNpcAI extends L2AttackableAI
}
}
final double dist = npc.calculateDistance(originalAttackTarget, false, false);
final double dist = npc.calculateDistance2D(originalAttackTarget);
final int dist2 = (int) dist - collision;
int range = npc.getPhysicalAttackRange() + combinedCollision;
if (originalAttackTarget.isMoving())

View File

@ -239,7 +239,7 @@ public class L2AttackableAI extends L2CharacterAI
final Location loc = npc.getSpawn().getLocation();
final int range = Config.MAX_DRIFT_RANGE;
if (!npc.isInsideRadius(loc, range + range, true, false))
if (!npc.isInsideRadius3D(loc, range + range))
{
intention = AI_INTENTION_ACTIVE;
}
@ -369,7 +369,7 @@ public class L2AttackableAI extends L2CharacterAI
|| (Config.FAKE_PLAYER_AGGRO_PLAYERS && t.isPlayer()))
{
final int hating = npc.getHating(t);
final double distance = npc.calculateDistance(t, false, false);
final double distance = npc.calculateDistance2D(t);
if ((hating == 0) && (closestDistance > distance))
{
nearestTarget = t;
@ -388,7 +388,7 @@ public class L2AttackableAI extends L2CharacterAI
final L2ItemInstance droppedItem = npc.getFakePlayerDrops().get(itemIndex);
if ((droppedItem != null) && droppedItem.isSpawned())
{
if (npc.calculateDistance(droppedItem, false, false) > 50)
if (npc.calculateDistance2D(droppedItem) > 50)
{
moveTo(droppedItem);
}
@ -542,7 +542,7 @@ public class L2AttackableAI extends L2CharacterAI
npc.setWalking();
}
if (npc.calculateDistance(leader, false, true) > (offset * offset))
if (npc.calculateDistanceSq2D(leader) > (offset * offset))
{
int x1, y1, z1;
x1 = Rnd.get(minRadius * 2, offset * 2); // x
@ -607,7 +607,7 @@ public class L2AttackableAI extends L2CharacterAI
y1 = npc.getSpawn().getY();
z1 = npc.getSpawn().getZ();
if (!npc.isInsideRadius(x1, y1, 0, range, false, false))
if (!npc.isInsideRadius2D(x1, y1, 0, range))
{
npc.setisReturningToSpawnPoint(true);
}
@ -752,7 +752,7 @@ public class L2AttackableAI extends L2CharacterAI
{
for (L2Attackable nearby : L2World.getInstance().getVisibleObjects(npc, L2Attackable.class))
{
if (npc.isInsideRadius(nearby, collision, false, false) && (nearby != target))
if (npc.isInsideRadius2D(nearby, collision) && (nearby != target))
{
int newX = combinedCollision + Rnd.get(40);
if (Rnd.nextBoolean())
@ -773,7 +773,7 @@ public class L2AttackableAI extends L2CharacterAI
newY = target.getY() - newY;
}
if (!npc.isInsideRadius(newX, newY, 0, collision, false, false))
if (!npc.isInsideRadius2D(newX, newY, 0, collision))
{
final int newZ = npc.getZ() + 30;
@ -790,7 +790,7 @@ public class L2AttackableAI extends L2CharacterAI
if (Rnd.get(100) <= npc.getTemplate().getDodge())
{
// Micht: kepping this one otherwise we should do 2 sqrt
final double distance2 = npc.calculateDistance(target, false, true);
final double distance2 = npc.calculateDistanceSq2D(target);
if (Math.sqrt(distance2) <= (60 + combinedCollision))
{
int posX = npc.getX();
@ -971,7 +971,7 @@ public class L2AttackableAI extends L2CharacterAI
// Check if target is within range or move.
final int range = npc.getPhysicalAttackRange() + combinedCollision;
if (npc.calculateDistance(target, false, false) > range)
if (npc.calculateDistance2D(target) > range)
{
if (checkTarget(target))
{
@ -1070,7 +1070,7 @@ public class L2AttackableAI extends L2CharacterAI
if (npc.isMovementDisabled())
{
if (!npc.isInsideRadius(target, npc.getPhysicalAttackRange() + npc.getTemplate().getCollisionRadius() + ((L2Character) target).getTemplate().getCollisionRadius(), false, true))
if (!npc.isInsideRadius2D(target, npc.getPhysicalAttackRange() + npc.getTemplate().getCollisionRadius() + ((L2Character) target).getTemplate().getCollisionRadius()))
{
return false;
}

View File

@ -876,7 +876,7 @@ public class L2CharacterAI extends AbstractAI
return false; // skill radius -1
}
if (!_actor.isInsideRadius(worldPosition, offset + _actor.getTemplate().getCollisionRadius(), false, false))
if (!_actor.isInsideRadius2D(worldPosition, offset + _actor.getTemplate().getCollisionRadius()))
{
if (_actor.isMovementDisabled() || (_actor.getMoveSpeed() <= 0))
{
@ -953,13 +953,13 @@ public class L2CharacterAI extends AbstractAI
offset += ((L2Character) target).getTemplate().getCollisionRadius();
}
if (!_actor.isInsideRadius(target, offset, false, false))
if (!_actor.isInsideRadius2D(target, offset))
{
// Caller should be L2Playable and thinkAttack/thinkCast/thinkInteract/thinkPickUp
if (isFollowing())
{
// allow larger hit range when the target is moving (check is run only once per second)
if (!_actor.isInsideRadius(target, offset + 100, false, false))
if (!_actor.isInsideRadius2D(target, offset + 100))
{
return true;
}

View File

@ -196,7 +196,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
final L2ControllableMobAI ctrlAi = (L2ControllableMobAI) theTarget.getAI();
ctrlAi.forceAttack(_actor);
final double dist2 = _actor.calculateDistance(target, false, true);
final double dist2 = _actor.calculateDistanceSq2D(target);
final int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + target.getTemplate().getCollisionRadius();
int max_range = range;
@ -236,7 +236,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
}
setTarget(getForcedTarget());
final double dist2 = _actor.calculateDistance(getForcedTarget(), false, true);
final double dist2 = _actor.calculateDistanceSq2D(getForcedTarget());
final int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + getForcedTarget().getTemplate().getCollisionRadius();
int max_range = range;
@ -295,7 +295,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
return;
}
if (_actor.isInsideRadius(npc, npc.getTemplate().getClanHelpRange(), true, true))
if (_actor.isInsideRadius3D(npc, npc.getTemplate().getClanHelpRange()))
{
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
}
@ -303,7 +303,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
}
setTarget(target);
final double dist2 = _actor.calculateDistance(target, false, true);
final double dist2 = _actor.calculateDistanceSq2D(target);
final int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + target.getTemplate().getCollisionRadius();
int max_range = range;
@ -403,7 +403,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
return false;
}
if (target.isAlikeDead() || !me.isInsideRadius(target, me.getAggroRange(), false, false) || (Math.abs(_actor.getZ() - target.getZ()) > 100))
if (target.isAlikeDead() || !me.isInsideRadius2D(target, me.getAggroRange()) || (Math.abs(_actor.getZ() - target.getZ()) > 100))
{
return false;
}

View File

@ -158,7 +158,7 @@ public class L2DoorAI extends L2CharacterAI
{
L2World.getInstance().forEachVisibleObject(_door, L2DefenderInstance.class, guard ->
{
if (_actor.isInsideRadius(guard, guard.getTemplate().getClanHelpRange(), true, true))
if (_actor.isInsideRadius3D(guard, guard.getTemplate().getClanHelpRange()))
{
guard.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attacker, 15);
}

View File

@ -259,7 +259,7 @@ public class L2SummonAI extends L2PlayableAI implements Runnable
final L2Character owner = getActor().getOwner();
// trying to avoid if summon near owner
if ((owner != null) && (owner != attacker) && owner.isInsideRadius(_actor, 2 * AVOID_RADIUS, true, false))
if ((owner != null) && (owner != attacker) && owner.isInsideRadius3D(_actor, 2 * AVOID_RADIUS))
{
_startAvoid = true;
}
@ -274,7 +274,7 @@ public class L2SummonAI extends L2PlayableAI implements Runnable
}
final L2Summon summon = getActor();
if ((summon.getOwner() != null) && (summon.getOwner() != attacker) && !summon.isMoving() && summon.canAttack(attacker, false) && summon.getOwner().isInsideRadius(_actor, 2 * AVOID_RADIUS, true, false))
if ((summon.getOwner() != null) && (summon.getOwner() != attacker) && !summon.isMoving() && summon.canAttack(attacker, false) && summon.getOwner().isInsideRadius3D(_actor, 2 * AVOID_RADIUS))
{
summon.doAutoAttack(attacker);
}

View File

@ -456,7 +456,7 @@ public final class CommissionManager
final L2Npc npc = player.getLastFolkNPC();
if ((npc != null) && (npc instanceof CommissionManagerInstance))
{
return npc.calculateDistance(player, true, false) <= INTERACTION_DISTANCE;
return npc.calculateDistance3D(player) <= INTERACTION_DISTANCE;
}
return false;
}

View File

@ -106,7 +106,7 @@ public final class FakePlayerChatManager implements IGameXmlReader
final L2Npc npc = spawn.getLastSpawn();
if (npc != null)
{
if (npc.calculateDistance(player, false, false) < 3000)
if (npc.calculateDistance2D(player) < 3000)
{
if (GeoEngine.getInstance().canSeeTarget(npc, player) && !player.isInvisible())
{

View File

@ -121,7 +121,7 @@ public final class SiegeGuardManager
*/
public boolean isTooCloseToAnotherTicket(L2PcInstance player)
{
return _droppedTickets.stream().filter(g -> g.calculateDistance(player, true, false) < 25).findFirst().orElse(null) != null;
return _droppedTickets.stream().filter(g -> g.calculateDistance3D(player) < 25).findFirst().orElse(null) != null;
}
/**

View File

@ -283,9 +283,9 @@ public final class WalkingManager implements IGameXmlReader
node = walk.getCurrentNode();
}
if (!npc.isInsideRadius(node, 3000, true, false))
if (!npc.isInsideRadius3D(node, 3000))
{
LOGGER.warning("Route '" + routeName + "': NPC (id=" + npc.getId() + ", x=" + npc.getX() + ", y=" + npc.getY() + ", z=" + npc.getZ() + ") is too far from starting point (node x=" + node.getX() + ", y=" + node.getY() + ", z=" + node.getZ() + ", range=" + npc.calculateDistance(node, true, true) + "). Teleporting to proper location.");
LOGGER.warning("Route '" + routeName + "': NPC (id=" + npc.getId() + ", x=" + npc.getX() + ", y=" + npc.getY() + ", z=" + npc.getZ() + ") is too far from starting point (node x=" + node.getX() + ", y=" + node.getY() + ", z=" + node.getZ() + ", range=" + npc.calculateDistance3D(node) + "). Teleporting to proper location.");
npc.teleToLocation(node);
}
@ -431,7 +431,7 @@ public final class WalkingManager implements IGameXmlReader
if ((walk.getCurrentNodeId() >= 0) && (walk.getCurrentNodeId() < walk.getRoute().getNodesCount()))
{
final L2NpcWalkerNode node = walk.getRoute().getNodeList().get(walk.getCurrentNodeId());
if (npc.isInsideRadius(node, 10, false, false))
if (npc.isInsideRadius2D(node, 10))
{
walk.calculateNextNode(npc);
walk.setBlocked(true); // prevents to be ran from walk check task, if there is delay in this node.

View File

@ -757,30 +757,91 @@ public abstract class L2Object extends ListenersContainer implements IIdentifiab
}
/**
* Calculates distance between this L2Object and given x, y , z.
* Calculates 2D distance between this L2Object and given x, y, z.
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @param includeZAxis if {@code true} Z axis will be included
* @param squared if {@code true} return will be squared
* @return distance between object and given x, y, z.
*/
public final double calculateDistance(int x, int y, int z, boolean includeZAxis, boolean squared)
public double calculateDistance2D(int x, int y, int z)
{
final double distance = Math.pow(x - _x.get(), 2) + Math.pow(y - _y.get(), 2) + (includeZAxis ? Math.pow(z - _z.get(), 2) : 0);
return squared ? distance : Math.sqrt(distance);
return Math.sqrt(Math.pow(x - _x.get(), 2) + Math.pow(y - _y.get(), 2));
}
/**
* Calculates distance between this L2Object and given location.
* Calculates the 2D distance between this L2Object and given location.
* @param loc the location object
* @param includeZAxis if {@code true} Z axis will be included
* @param squared if {@code true} return will be squared
* @return distance between object and given location.
*/
public final double calculateDistance(ILocational loc, boolean includeZAxis, boolean squared)
public double calculateDistance2D(ILocational loc)
{
return calculateDistance(loc.getX(), loc.getY(), loc.getZ(), includeZAxis, squared);
return calculateDistance2D(loc.getX(), loc.getY(), loc.getZ());
}
/**
* Calculates the 3D distance between this L2Object and given x, y, z.
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @return distance between object and given x, y, z.
*/
public double calculateDistance3D(int x, int y, int z)
{
return Math.sqrt(Math.pow(x - _x.get(), 2) + Math.pow(y - _y.get(), 2) + Math.pow(z - _z.get(), 2));
}
/**
* Calculates 3D distance between this L2Object and given location.
* @param loc the location object
* @return distance between object and given location.
*/
public double calculateDistance3D(ILocational loc)
{
return calculateDistance3D(loc.getX(), loc.getY(), loc.getZ());
}
/**
* Calculates the non squared 2D distance between this L2Object and given x, y, z.
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @return distance between object and given x, y, z.
*/
public double calculateDistanceSq2D(int x, int y, int z)
{
return Math.pow(x - _x.get(), 2) + Math.pow(y - _y.get(), 2);
}
/**
* Calculates the non squared 2D distance between this L2Object and given location.
* @param loc the location object
* @return distance between object and given location.
*/
public double calculateDistanceSq2D(ILocational loc)
{
return calculateDistanceSq2D(loc.getX(), loc.getY(), loc.getZ());
}
/**
* Calculates the non squared 3D distance between this L2Object and given x, y, z.
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @return distance between object and given x, y, z.
*/
public double calculateDistanceSq3D(int x, int y, int z)
{
return Math.pow(x - _x.get(), 2) + Math.pow(y - _y.get(), 2) + Math.pow(z - _z.get(), 2);
}
/**
* Calculates the non squared 3D distance between this L2Object and given location.
* @param loc the location object
* @return distance between object and given location.
*/
public double calculateDistanceSq3D(ILocational loc)
{
return calculateDistanceSq3D(loc.getX(), loc.getY(), loc.getZ());
}
/**
@ -790,7 +851,7 @@ public abstract class L2Object extends ListenersContainer implements IIdentifiab
* @param target the object to which to calculate the angle
* @return the angle this object has to turn to have the given object in front of it
*/
public final double calculateDirectionTo(ILocational target)
public double calculateDirectionTo(ILocational target)
{
int heading = Util.calculateHeadingFrom(this, target) - _heading.get();
if (heading < 0)

View File

@ -631,7 +631,7 @@ public final class L2World
continue;
}
if (visibleObject.calculateDistance(object, true, false) <= range)
if (visibleObject.calculateDistance3D(object) <= range)
{
c.accept(clazz.cast(visibleObject));
}

View File

@ -396,8 +396,8 @@ public class L2Attackable extends L2Npc
final L2CommandChannel command = party.getCommandChannel();
//@formatter:off
final List<L2PcInstance> members = command != null ?
command.getMembers().stream().filter(p -> p.calculateDistance(this, true, false) < Config.ALT_PARTY_RANGE).collect(Collectors.toList()) :
player.getParty().getMembers().stream().filter(p -> p.calculateDistance(this, true, false) < Config.ALT_PARTY_RANGE).collect(Collectors.toList());
command.getMembers().stream().filter(p -> p.calculateDistance3D(this) < Config.ALT_PARTY_RANGE).collect(Collectors.toList()) :
player.getParty().getMembers().stream().filter(p -> p.calculateDistance3D(this) < Config.ALT_PARTY_RANGE).collect(Collectors.toList());
//@formatter:on
members.forEach(p ->

View File

@ -3483,32 +3483,51 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
/**
* Check if this object is inside the given radius around the given point.
* Check if this object is inside the given 2D radius around the given point.
* @param loc Location of the target
* @param radius the radius around the target
* @param checkZAxis should we check Z axis also
* @param strictCheck true if (distance < radius), false if (distance <= radius)
* @return true if the L2Character is inside the radius.
*/
public final boolean isInsideRadius(ILocational loc, int radius, boolean checkZAxis, boolean strictCheck)
public final boolean isInsideRadius2D(ILocational loc, int radius)
{
return isInsideRadius(loc.getX(), loc.getY(), loc.getZ(), radius, checkZAxis, strictCheck);
return isInsideRadius2D(loc.getX(), loc.getY(), loc.getZ(), radius);
}
/**
* Check if this object is inside the given radius around the given point.
* Check if this object is inside the given 2D radius around the given point.
* @param x X position of the target
* @param y Y position of the target
* @param z Z position of the target
* @param radius the radius around the target
* @param checkZAxis should we check Z axis also
* @param strictCheck true if (distance < radius), false if (distance <= radius)
* @return true if the L2Character is inside the radius.
*/
public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZAxis, boolean strictCheck)
public final boolean isInsideRadius2D(int x, int y, int z, int radius)
{
final double distance = calculateDistance(x, y, z, checkZAxis, true);
return (strictCheck) ? (distance < (radius * radius)) : (distance <= (radius * radius));
return calculateDistanceSq2D(x, y, z) < (radius * radius);
}
/**
* Check if this object is inside the given 3D radius around the given point.
* @param loc Location of the target
* @param radius the radius around the target
* @return true if the L2Character is inside the radius.
*/
public final boolean isInsideRadius3D(ILocational loc, int radius)
{
return isInsideRadius3D(loc.getX(), loc.getY(), loc.getZ(), radius);
}
/**
* Check if this object is inside the given 3D radius around the given point.
* @param x X position of the target
* @param y Y position of the target
* @param z Z position of the target
* @param radius the radius around the target
* @return true if the L2Character is inside the radius.
*/
public final boolean isInsideRadius3D(int x, int y, int z, int radius)
{
return calculateDistanceSq3D(x, y, z) < (radius * radius);
}
/**
@ -5301,16 +5320,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
_reputation = reputation;
}
/**
* Gets the distance to target.
* @param target the target
* @return distance to target
*/
public double distFromMe(L2Character target)
{
return calculateDistance(target, true, false);
}
public boolean isChargedShot(ShotType type)
{
return _chargedShots.contains(type);

View File

@ -507,7 +507,7 @@ public class L2Npc extends L2Character
{
return false;
}
else if (!isInsideRadius(player, INTERACTION_DISTANCE, true, false))
else if (!isInsideRadius3D(player, INTERACTION_DISTANCE))
{
return false;
}
@ -1025,7 +1025,7 @@ public class L2Npc extends L2Character
{
for (L2PcInstance member : party.getMembers())
{
if ((member != killerPlayer) && (member.calculateDistance(getX(), getY(), getZ(), true, false) <= Config.ALT_PARTY_RANGE))
if ((member != killerPlayer) && (member.calculateDistance3D(getX(), getY(), getZ()) <= Config.ALT_PARTY_RANGE))
{
new MpRewardTask(member, this);
for (L2Summon summon : member.getServitors().values())

View File

@ -100,7 +100,7 @@ public class L2DefenderInstance extends L2Attackable
{
return;
}
if (!isInsideRadius(getSpawn(), 40, false, false))
if (!isInsideRadius2D(getSpawn(), 40))
{
setisReturningToSpawnPoint(true);
clearAggroList();

View File

@ -96,7 +96,7 @@ public class L2FortCommanderInstance extends L2DefenderInstance
@Override
public void returnHome()
{
if (!isInsideRadius(getSpawn(), 200, false, false))
if (!isInsideRadius2D(getSpawn(), 200))
{
setisReturningToSpawnPoint(true);
clearAggroList();

View File

@ -38,7 +38,7 @@ public final class L2ObservationInstance extends L2Npc
{
String filename = null;
if (isInsideRadius(-79884, 86529, 0, 50, false, true) || isInsideRadius(-78858, 111358, 0, 50, false, true) || isInsideRadius(-76973, 87136, 0, 50, false, true) || isInsideRadius(-75850, 111968, 0, 50, false, true))
if (isInsideRadius2D(-79884, 86529, 0, 50) || isInsideRadius2D(-78858, 111358, 0, 50) || isInsideRadius2D(-76973, 87136, 0, 50) || isInsideRadius2D(-75850, 111968, 0, 50))
{
if (val == 0)
{

View File

@ -1456,7 +1456,7 @@ public final class L2PcInstance extends L2Playable
final L2Npc target = _lastFolkNpc;
if ((target != null) && isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
if ((target != null) && isInsideRadius2D(target, L2Npc.INTERACTION_DISTANCE))
{
quest.notifyEvent(event, target, this);
}
@ -1464,7 +1464,7 @@ public final class L2PcInstance extends L2Playable
{
final L2Object object = L2World.getInstance().findObject(getLastQuestNpcObject());
if (object.isNpc() && isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
if (object.isNpc() && isInsideRadius2D(object, L2Npc.INTERACTION_DISTANCE))
{
final L2Npc npc = (L2Npc) object;
quest.notifyEvent(event, npc, this);
@ -4202,7 +4202,7 @@ public final class L2PcInstance extends L2Playable
L2World.getInstance().forEachVisibleObject(this, L2PcInstance.class, player ->
{
if (!isVisibleFor(player) || (calculateDistance(player, true, false) >= radiusInKnownlist))
if (!isVisibleFor(player) || (calculateDistance3D(player) >= radiusInKnownlist))
{
return;
}

View File

@ -94,7 +94,7 @@ public class L2RaidBossInstance extends L2MonsterInstance
if (!isInCombat() && !isMovementDisabled())
{
if (!isInsideRadius(spawnX, spawnY, spawnZ, Math.max(Config.MAX_DRIFT_RANGE, 200), true, false))
if (!isInsideRadius3D(spawnX, spawnY, spawnZ, Math.max(Config.MAX_DRIFT_RANGE, 200)))
{
teleToLocation(spawnX, spawnY, spawnZ);
}

View File

@ -576,7 +576,7 @@ public class L2ServitorInstance extends L2Summon implements Runnable
sendPacket(new SetSummonRemainTime(_lifeTime, _lifeTimeRemaining));
// Using same task to check if owner is in visible range
if (calculateDistance(getOwner(), true, false) > 2000)
if (calculateDistance3D(getOwner()) > 2000)
{
getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, getOwner());
}

View File

@ -295,7 +295,7 @@ public final class L2TamedBeastInstance extends L2FeedableBeastInstance
public boolean isTooFarFromHome()
{
return !isInsideRadius(_homeX, _homeY, _homeZ, MAX_DISTANCE_FROM_HOME, true, true);
return !isInsideRadius3D(_homeX, _homeY, _homeZ, MAX_DISTANCE_FROM_HOME);
}
@Override
@ -335,7 +335,7 @@ public final class L2TamedBeastInstance extends L2FeedableBeastInstance
return;
}
// if the owner is too far away, stop anything else and immediately run towards the owner.
if (!_owner.isInsideRadius(this, MAX_DISTANCE_FROM_OWNER, true, true))
if (!_owner.isInsideRadius3D(this, MAX_DISTANCE_FROM_OWNER))
{
getAI().startFollow(_owner);
return;
@ -507,7 +507,7 @@ public final class L2TamedBeastInstance extends L2FeedableBeastInstance
return;
}
// if the owner is too far away, stop anything else and immediately run towards the owner.
if (!isInsideRadius(owner, MAX_DISTANCE_FROM_OWNER, true, true))
if (!isInsideRadius3D(owner, MAX_DISTANCE_FROM_OWNER))
{
getAI().startFollow(owner);
return;

View File

@ -40,6 +40,6 @@ public class ConditionMinDistance extends Condition
@Override
public boolean testImpl(L2Character effector, L2Character effected, Skill skill, L2Item item)
{
return (effected != null) && (effector.calculateDistance(effected, true, true) >= _sqDistance);
return (effected != null) && (effector.calculateDistanceSq3D(effected) >= _sqDistance);
}
}

View File

@ -35,6 +35,6 @@ public class RangeCondition implements ICubicCondition
@Override
public boolean test(CubicInstance cubic, L2Character owner, L2Object target)
{
return owner.calculateDistance(target, false, false) <= _range;
return owner.calculateDistance2D(target) <= _range;
}
}

View File

@ -906,7 +906,7 @@ public class Duel
}
// Are the players too far apart?
if (!_playerA.isInsideRadius(_playerB, 1600, false, false))
if (!_playerA.isInsideRadius2D(_playerB, 1600))
{
return DuelResult.CANCELED;
}

View File

@ -1542,7 +1542,7 @@ public class Siege implements Siegable
continue;
}
distance = ct.calculateDistance(spawn, true, true);
distance = ct.calculateDistanceSq3D(spawn);
if (distance < distanceClosest)
{

View File

@ -347,7 +347,7 @@ public final class Instance implements IIdentifiable, INamable
*/
public Set<L2PcInstance> getPlayersInsideRadius(ILocational object, int radius)
{
return _players.stream().filter(p -> p.isInsideRadius(object, radius, true, true)).collect(Collectors.toSet());
return _players.stream().filter(p -> p.isInsideRadius3D(object, radius)).collect(Collectors.toSet());
}
/**

View File

@ -38,6 +38,6 @@ public final class ConditionDistance extends Condition
public boolean test(L2PcInstance player, L2Npc npc)
{
final int distance = getParameters().getInt("distance", 1000);
return player.isInsideRadius(npc, distance, true, true);
return player.isInsideRadius3D(npc, distance);
}
}

View File

@ -2506,7 +2506,7 @@ public class Quest extends AbstractScript implements IIdentifiable
continue;
}
temp = partyMember.getQuestState(getName());
if ((temp != null) && (temp.get(var) != null) && (temp.get(var)).equalsIgnoreCase(value) && partyMember.isInsideRadius(target, 1500, true, false))
if ((temp != null) && (temp.get(var) != null) && (temp.get(var)).equalsIgnoreCase(value) && partyMember.isInsideRadius3D(target, 1500))
{
candidates.add(partyMember);
}
@ -2569,7 +2569,7 @@ public class Quest extends AbstractScript implements IIdentifiable
continue;
}
temp = partyMember.getQuestState(getName());
if ((temp != null) && (temp.getState() == state) && partyMember.isInsideRadius(target, 1500, true, false))
if ((temp != null) && (temp.getState() == state) && partyMember.isInsideRadius3D(target, 1500))
{
candidates.add(partyMember);
}

View File

@ -292,7 +292,7 @@ public class SkillCaster implements Runnable
// Send MoveToPawn packet to trigger Blue Bubbles on target become Red, but don't do it while (double) casting, because that will screw up animation... some fucked up stuff, right?
if (caster.isPlayer() && !caster.isCastingNow() && target.isCharacter())
{
caster.sendPacket(new MoveToPawn(caster, target, (int) caster.calculateDistance(target, false, false)));
caster.sendPacket(new MoveToPawn(caster, target, (int) caster.calculateDistance2D(target)));
caster.sendPacket(ActionFailed.STATIC_PACKET);
}
}

View File

@ -656,7 +656,7 @@ public final class Formulas
final double sphericBarrierRange = target.getStat().getValue(Stats.SPHERIC_BARRIER_RANGE, 0);
if (!resisted && (sphericBarrierRange > 0))
{
resisted = attacker.calculateDistance(target, true, false) > sphericBarrierRange;
resisted = attacker.calculateDistance3D(target) > sphericBarrierRange;
}
if (resisted)

View File

@ -63,7 +63,7 @@ public class AnswerCoupleAction implements IClientIncomingPacket
}
else if (_answer == 1) // approve
{
final int distance = (int) activeChar.calculateDistance(target, false, false);
final int distance = (int) activeChar.calculateDistance2D(target);
if ((distance > 125) || (distance < 15) || (activeChar.getObjectId() == target.getObjectId()))
{
client.sendPacket(SystemMessageId.THE_REQUEST_CANNOT_BE_COMPLETED_BECAUSE_THE_TARGET_DOES_NOT_MEET_LOCATION_REQUIREMENTS);

View File

@ -653,7 +653,7 @@ public class MultiSellChoose implements IClientIncomingPacket
{
return false;
}
else if (list.isNpcOnly() && (!list.checkNpcObjectId(npc.getObjectId()) || (npc.getInstanceWorld() != player.getInstanceWorld()) || !player.isInsideRadius(npc, L2Npc.INTERACTION_DISTANCE, true, false)))
else if (list.isNpcOnly() && (!list.checkNpcObjectId(npc.getObjectId()) || (npc.getInstanceWorld() != player.getInstanceWorld()) || !player.isInsideRadius3D(npc, L2Npc.INTERACTION_DISTANCE)))
{
return false;
}

View File

@ -105,7 +105,7 @@ public final class RequestBuyItem implements IClientIncomingPacket
L2MerchantInstance merchant = null;
if (!player.isGM() && (_listId != CUSTOM_CB_SELL_LIST))
{
if (!(target instanceof L2MerchantInstance) || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) || (player.getInstanceWorld() != target.getInstanceWorld()))
if (!(target instanceof L2MerchantInstance) || (!player.isInsideRadius3D(target, INTERACTION_DISTANCE)) || (player.getInstanceWorld() != target.getInstanceWorld()))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -161,7 +161,7 @@ public final class RequestBypassToServer implements IClientIncomingPacket
{
final L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
if ((object != null) && object.isNpc() && (endOfId > 0) && activeChar.isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
if ((object != null) && object.isNpc() && (endOfId > 0) && activeChar.isInsideRadius2D(object, L2Npc.INTERACTION_DISTANCE))
{
((L2Npc) object).onBypassFeedback(activeChar, _command.substring(endOfId + 1));
}

View File

@ -153,7 +153,7 @@ public final class RequestDropItem implements IClientIncomingPacket
return;
}
if (!activeChar.isInsideRadius(_x, _y, 0, 150, false, false) || (Math.abs(_z - activeChar.getZ()) > 50))
if (!activeChar.isInsideRadius2D(_x, _y, 0, 150) || (Math.abs(_z - activeChar.getZ()) > 50))
{
activeChar.sendPacket(SystemMessageId.YOU_CANNOT_DISCARD_SOMETHING_THAT_FAR_AWAY_FROM_YOU);
return;

View File

@ -130,7 +130,7 @@ public final class RequestDuelStart implements IClientIncomingPacket
return;
}
// Players may not be too far apart
else if (!activeChar.isInsideRadius(targetChar, 250, false, false))
else if (!activeChar.isInsideRadius2D(targetChar, 250))
{
final SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_TOO_FAR_AWAY_TO_RECEIVE_A_DUEL_CHALLENGE);
msg.addString(targetChar.getName());

View File

@ -49,7 +49,7 @@ public final class RequestGetOffVehicle implements IClientIncomingPacket
{
return;
}
if (!activeChar.isInBoat() || (activeChar.getBoat().getObjectId() != _boatId) || activeChar.getBoat().isMoving() || !activeChar.isInsideRadius(_x, _y, _z, 1000, true, false))
if (!activeChar.isInBoat() || (activeChar.getBoat().getObjectId() != _boatId) || activeChar.getBoat().isMoving() || !activeChar.isInsideRadius3D(_x, _y, _z, 1000))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -69,7 +69,7 @@ public final class RequestGetOnVehicle implements IClientIncomingPacket
else
{
boat = BoatManager.getInstance().getBoat(_boatId);
if ((boat == null) || boat.isMoving() || !activeChar.isInsideRadius(boat, 1000, true, false))
if ((boat == null) || boat.isMoving() || !activeChar.isInsideRadius3D(boat, 1000))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -113,7 +113,7 @@ public final class RequestMoveToLocationInVehicle implements IClientIncomingPack
else
{
boat = BoatManager.getInstance().getBoat(_boatId);
if ((boat == null) || !boat.isInsideRadius(activeChar, 300, true, false))
if ((boat == null) || !boat.isInsideRadius3D(activeChar, 300))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -85,7 +85,7 @@ public class RequestPackageSend implements IClientIncomingPacket
}
final L2Npc manager = player.getLastFolkNPC();
if (((manager == null) || !player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false)))
if (((manager == null) || !player.isInsideRadius2D(manager, L2Npc.INTERACTION_DISTANCE)))
{
return;
}

View File

@ -29,8 +29,8 @@ import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.buylist.ProductList;
import com.l2jmobius.gameserver.model.buylist.Product;
import com.l2jmobius.gameserver.model.buylist.ProductList;
import com.l2jmobius.gameserver.model.itemcontainer.Inventory;
import com.l2jmobius.gameserver.model.items.L2Armor;
import com.l2jmobius.gameserver.model.items.L2Item;
@ -137,7 +137,7 @@ public final class RequestPreviewItem implements IClientIncomingPacket
final L2Object target = activeChar.getTarget();
if (!activeChar.isGM() && ((target == null // No target (i.e. GM Shop)
) || !((target instanceof L2MerchantInstance)) // Target not a merchant
|| !activeChar.isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false) // Distance is too far
|| !activeChar.isInsideRadius2D(target, L2Npc.INTERACTION_DISTANCE) // Distance is too far
))
{
return;

View File

@ -116,7 +116,7 @@ public final class RequestPrivateStoreBuy implements IClientIncomingPacket
}
final L2PcInstance storePlayer = (L2PcInstance) object;
if (!player.isInsideRadius(storePlayer, INTERACTION_DISTANCE, true, false))
if (!player.isInsideRadius3D(storePlayer, INTERACTION_DISTANCE))
{
return;
}

View File

@ -113,7 +113,7 @@ public final class RequestPrivateStoreSell implements IClientIncomingPacket
}
final L2PcInstance storePlayer = L2World.getInstance().getPlayer(_storePlayerId);
if ((storePlayer == null) || !player.isInsideRadius(storePlayer, INTERACTION_DISTANCE, true, false))
if ((storePlayer == null) || !player.isInsideRadius3D(storePlayer, INTERACTION_DISTANCE))
{
return;
}

View File

@ -88,7 +88,7 @@ public final class RequestRefundItem implements IClientIncomingPacket
L2MerchantInstance merchant = null;
if (!player.isGM() && (_listId != CUSTOM_CB_SELL_LIST))
{
if (!(target instanceof L2MerchantInstance) || !player.isInsideRadius(target, INTERACTION_DISTANCE, true, false) || (player.getInstanceId() != target.getInstanceId()))
if (!(target instanceof L2MerchantInstance) || !player.isInsideRadius3D(target, INTERACTION_DISTANCE) || (player.getInstanceId() != target.getInstanceId()))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -107,7 +107,7 @@ public final class RequestSellItem implements IClientIncomingPacket
L2MerchantInstance merchant = null;
if (!player.isGM() && (_listId != CUSTOM_CB_SELL_LIST))
{
if ((target == null) || !player.isInsideRadius(target, INTERACTION_DISTANCE, true, false) || (player.getInstanceId() != target.getInstanceId()))
if ((target == null) || !player.isInsideRadius3D(target, INTERACTION_DISTANCE) || (player.getInstanceId() != target.getInstanceId()))
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

@ -91,7 +91,7 @@ public final class TradeDone implements IClientIncomingPacket
return;
}
if (player.calculateDistance(trade.getPartner(), true, false) > 150)
if (player.calculateDistance3D(trade.getPartner()) > 150)
{
player.cancelActiveTrade();
return;

View File

@ -222,7 +222,7 @@ public final class TradeRequest implements IClientIncomingPacket
return;
}
if (player.calculateDistance(partner, true, false) > 150)
if (player.calculateDistance3D(partner) > 150)
{
client.sendPacket(SystemMessageId.YOUR_TARGET_IS_OUT_OF_RANGE);
return;

View File

@ -54,13 +54,13 @@ public class RequestShuttleGetOn implements IClientIncomingPacket
// TODO: better way?
for (L2ShuttleInstance shuttle : L2World.getInstance().getVisibleObjects(activeChar, L2ShuttleInstance.class))
{
if (shuttle.calculateDistance(activeChar, true, false) < 1000)
if (shuttle.calculateDistance3D(activeChar) < 1000)
{
shuttle.addPassenger(activeChar);
activeChar.getInVehiclePosition().setXYZ(_x, _y, _z);
break;
}
LOGGER.info(getClass().getSimpleName() + ": range between char and shuttle: " + shuttle.calculateDistance(activeChar, true, false));
LOGGER.info(getClass().getSimpleName() + ": range between char and shuttle: " + shuttle.calculateDistance3D(activeChar));
}
}
}

View File

@ -611,7 +611,7 @@ public final class Util
public static boolean isInsideRangeOfObjectId(L2Object obj, int targetObjId, int radius)
{
final L2Object target = L2World.getInstance().findObject(targetObjId);
return (target != null) && (obj.calculateDistance(target, true, false) <= radius);
return (target != null) && (obj.calculateDistance3D(target) <= radius);
}
public static String readAllLines(File file, Charset cs, String newLineDelimiter) throws IOException