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

@@ -103,9 +103,9 @@ public abstract class AbstractAI implements Ctrl
return;
}
if (!_actor.isInsideRadius(followTarget, _range, true, false))
if (!_actor.isInsideRadius3D(followTarget, _range))
{
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

@@ -194,7 +194,7 @@ public class L2AttackableAI extends L2CharacterAI
}
// Check if the target isn't dead, is in the Aggro range and is at the same height
if (target.isAlikeDead() || (target.isPlayable() && !me.isInsideRadius(target, me.getAggroRange(), true, false)))
if (target.isAlikeDead() || (target.isPlayable() && !me.isInsideRadius3D(target, me.getAggroRange())))
{
return false;
}
@@ -277,7 +277,7 @@ public class L2AttackableAI extends L2CharacterAI
return false;
}
if (me.isChaos() && me.isInsideRadius(target, me.getAggroRange(), false, false))
if (me.isChaos() && me.isInsideRadius2D(target, me.getAggroRange()))
{
if (((L2Attackable) target).isInMyClan(me))
{
@@ -351,7 +351,7 @@ public class L2AttackableAI extends L2CharacterAI
{
intention = AI_INTENTION_ACTIVE;
}
else if ((npc.getSpawn() != null) && !npc.isInsideRadius(npc.getSpawn().getLocation(), Config.MAX_DRIFT_RANGE + Config.MAX_DRIFT_RANGE, true, false))
else if ((npc.getSpawn() != null) && !npc.isInsideRadius3D(npc.getSpawn().getLocation(), Config.MAX_DRIFT_RANGE + Config.MAX_DRIFT_RANGE))
{
intention = AI_INTENTION_ACTIVE;
}
@@ -502,7 +502,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;
@@ -521,7 +521,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);
}
@@ -681,7 +681,7 @@ public class L2AttackableAI extends L2CharacterAI
npc.setWalking();
}
if (npc.calculateDistance(leader, false, true) > (offset * offset))
if (npc.calculateDistanceSq2D(leader) > (offset * offset))
{
int x1 = Rnd.get(minRadius * 2, offset * 2); // x
int y1 = Rnd.get(x1, offset * 2); // distance
@@ -725,7 +725,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);
}
@@ -891,14 +891,14 @@ public class L2AttackableAI extends L2CharacterAI
{
for (L2Attackable nearby : L2World.getInstance().getVisibleObjects(npc, L2Attackable.class))
{
if (npc.isInsideRadius(nearby, collision, false, false) && (nearby != mostHate))
if (npc.isInsideRadius2D(nearby, collision) && (nearby != mostHate))
{
int newX = combinedCollision + Rnd.get(40);
newX = Rnd.nextBoolean() ? mostHate.getX() + newX : mostHate.getX() - newX;
int newY = combinedCollision + Rnd.get(40);
newY = Rnd.nextBoolean() ? mostHate.getY() + newY : mostHate.getY() - newY;
if (!npc.isInsideRadius(newX, newY, 0, collision, false, false))
if (!npc.isInsideRadius2D(newX, newY, 0, collision))
{
final int newZ = npc.getZ() + 30;
@@ -915,7 +915,7 @@ public class L2AttackableAI extends L2CharacterAI
if (Rnd.get(100) <= npc.getDodge())
{
// Micht: Keeping this one otherwise we should do 2 sqrt
double distance2 = npc.calculateDistance(mostHate, false, true);
double distance2 = npc.calculateDistanceSq2D(mostHate);
if (Math.sqrt(distance2) <= (60 + combinedCollision))
{
int posX = npc.getX();
@@ -1208,7 +1208,7 @@ public class L2AttackableAI extends L2CharacterAI
}
}
final double dist = npc.calculateDistance(mostHate, false, false);
final double dist = npc.calculateDistance2D(mostHate);
final int dist2 = (int) dist - collision;
int range = npc.getPhysicalAttackRange() + combinedCollision;
if (mostHate.isMoving())
@@ -1298,7 +1298,7 @@ public class L2AttackableAI extends L2CharacterAI
return false;
}
final double dist = caster.calculateDistance(attackTarget, false, false);
final double dist = caster.calculateDistance2D(attackTarget);
double dist2 = dist - attackTarget.getTemplate().getCollisionRadius();
final double range = caster.getPhysicalAttackRange() + caster.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
final double srange = sk.getCastRange() + caster.getTemplate().getCollisionRadius();
@@ -1761,7 +1761,7 @@ public class L2AttackableAI extends L2CharacterAI
npc.setTarget(target);
}
final double dist = npc.calculateDistance(target, false, false);
final double dist = npc.calculateDistance2D(target);
final int range = npc.getPhysicalAttackRange() + npc.getTemplate().getCollisionRadius() + target.getTemplate().getCollisionRadius();
// TODO(Zoey76): Review this "magic changes".
final int random = Rnd.get(100);
@@ -1896,7 +1896,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(obj, false, false);
dist = actor.calculateDistance2D(obj);
dist2 = dist - actor.getTemplate().getCollisionRadius();
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
if (obj.isMoving())
@@ -1925,7 +1925,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(obj, false, false);
dist = actor.calculateDistance2D(obj);
dist2 = dist;
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
if (obj.isMoving())
@@ -1964,7 +1964,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(targets, false, false);
dist = actor.calculateDistance2D(targets);
dist2 = dist - actor.getTemplate().getCollisionRadius();
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + targets.getTemplate().getCollisionRadius();
if (targets.isMoving())
@@ -1997,7 +1997,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(obj, false, false);
dist = actor.calculateDistance2D(obj);
dist2 = dist - actor.getTemplate().getCollisionRadius();
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
if (obj.isMoving())
@@ -2036,7 +2036,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(obj, false, false);
dist = actor.calculateDistance2D(obj);
dist2 = dist - actor.getTemplate().getCollisionRadius();
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
// if(obj.isMoving())
@@ -2060,7 +2060,7 @@ public class L2AttackableAI extends L2CharacterAI
try
{
actor.setTarget(getAttackTarget());
dist = actor.calculateDistance(target, false, false);
dist = actor.calculateDistance2D(target);
dist2 = dist;
range = sk.getCastRange() + actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
// if(obj.isMoving())
@@ -2113,7 +2113,7 @@ public class L2AttackableAI extends L2CharacterAI
}
try
{
dist = actor.calculateDistance(obj, false, false);
dist = actor.calculateDistance2D(obj);
dist2 = dist - actor.getTemplate().getCollisionRadius();
range = actor.getPhysicalAttackRange() + actor.getTemplate().getCollisionRadius() + obj.getTemplate().getCollisionRadius();
if (obj.isMoving())

View File

@@ -926,7 +926,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())
{
@@ -1003,13 +1003,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 (getFollowTarget() != null)
{
// 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

@@ -195,7 +195,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;
@@ -235,7 +235,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
}
_actor.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;
@@ -289,7 +289,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, getAttackTarget(), 1);
}
@@ -297,7 +297,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
}
_actor.setTarget(getAttackTarget());
final double dist2 = _actor.calculateDistance(getAttackTarget(), false, true);
final double dist2 = _actor.calculateDistanceSq2D(getAttackTarget());
final int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
int max_range = range;
@@ -394,7 +394,7 @@ public final class L2ControllableMobAI extends L2AttackableAI
}
final L2Attackable me = getActiveChar();
if (!me.isInsideRadius(target, me.getAggroRange(), false, false) || (Math.abs(_actor.getZ() - target.getZ()) > 100))
if (!me.isInsideRadius2D(target, me.getAggroRange()) || (Math.abs(_actor.getZ() - target.getZ()) > 100))
{
return false;
}

View File

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

@@ -152,12 +152,12 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
if (target.isSummon())
{
final L2PcInstance owner = ((L2Summon) target).getOwner();
if (_actor.isInsideRadius(owner, 1000, true, false))
if (_actor.isInsideRadius3D(owner, 1000))
{
target = owner;
}
}
return (!target.isPlayable() || !((L2Playable) target).isSilentMovingAffected() || _actor.isInsideRadius(target, 250, false, false)) && _actor.isAutoAttackable(target) && GeoEngine.getInstance().canSeeTarget(_actor, target);
return (!target.isPlayable() || !((L2Playable) target).isSilentMovingAffected() || _actor.isInsideRadius2D(target, 250)) && _actor.isAutoAttackable(target) && GeoEngine.getInstance().canSeeTarget(_actor, target);
}
/**
@@ -398,7 +398,7 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
if (npc.getAI() != null) // TODO: possibly check not needed
{
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600) && ((npc.getAI()._intention == AI_INTENTION_IDLE) || (npc.getAI()._intention == AI_INTENTION_ACTIVE)) && target.isInsideRadius(npc, 1500, true, false) && GeoEngine.getInstance().canSeeTarget(npc, target))
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600) && ((npc.getAI()._intention == AI_INTENTION_IDLE) || (npc.getAI()._intention == AI_INTENTION_ACTIVE)) && target.isInsideRadius3D(npc, 1500) && GeoEngine.getInstance().canSeeTarget(npc, target))
{
// Notify the L2Object AI with EVT_AGGRESSION
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
@@ -446,7 +446,7 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
{
_actor.setTarget(attackTarget);
skills = _actor.getAllSkills();
dist_2 = _actor.calculateDistance(attackTarget, false, true);
dist_2 = _actor.calculateDistanceSq2D(attackTarget);
range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
if (attackTarget.isMoving())
{

View File

@@ -137,14 +137,14 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
if (target.isSummon())
{
final L2PcInstance owner = ((L2Summon) target).getOwner();
if (_actor.isInsideRadius(owner, 1000, true, false))
if (_actor.isInsideRadius3D(owner, 1000))
{
target = owner;
}
}
// Check if the target isn't in silent move mode AND too far (>100)
if (target.isPlayable() && ((L2Playable) target).isSilentMovingAffected() && !_actor.isInsideRadius(target, 250, false, false))
if (target.isPlayable() && ((L2Playable) target).isSilentMovingAffected() && !_actor.isInsideRadius2D(target, 250))
{
return false;
}
@@ -391,7 +391,7 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
if (npc.getAI() != null) // TODO: possibly check not needed
{
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600) && ((npc.getAI()._intention == AI_INTENTION_IDLE) || (npc.getAI()._intention == AI_INTENTION_ACTIVE)) && target.isInsideRadius(npc, 1500, true, false) && GeoEngine.getInstance().canSeeTarget(npc, target))
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600) && ((npc.getAI()._intention == AI_INTENTION_IDLE) || (npc.getAI()._intention == AI_INTENTION_ACTIVE)) && target.isInsideRadius3D(npc, 1500) && GeoEngine.getInstance().canSeeTarget(npc, target))
{
// Notify the L2Object AI with EVT_AGGRESSION
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
@@ -440,7 +440,7 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
{
_actor.setTarget(attackTarget);
skills = _actor.getAllSkills();
dist_2 = _actor.calculateDistance(attackTarget, false, true);
dist_2 = _actor.calculateDistanceSq2D(attackTarget);
range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
if (attackTarget.isMoving())
{

View File

@@ -226,7 +226,7 @@ public class L2SummonAI extends L2PlayableAI implements Runnable
private void avoidAttack(L2Character attacker)
{
// trying to avoid if summon near owner
if ((((L2Summon) _actor).getOwner() != null) && (((L2Summon) _actor).getOwner() != attacker) && ((L2Summon) _actor).getOwner().isInsideRadius(_actor, 2 * AVOID_RADIUS, true, false))
if ((((L2Summon) _actor).getOwner() != null) && (((L2Summon) _actor).getOwner() != attacker) && ((L2Summon) _actor).getOwner().isInsideRadius3D(_actor, 2 * AVOID_RADIUS))
{
_startAvoid = true;
}

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

@@ -254,9 +254,9 @@ public final class WalkingManager implements IGameXmlReader
node = walk.getCurrentNode();
}
if (!npc.isInsideRadius(node, 3000, true, false))
if (!npc.isInsideRadius3D(node, 3000))
{
LOGGER.warning(getClass().getSimpleName() + ": " + "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(getClass().getSimpleName() + ": " + "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);
}
@@ -394,7 +394,7 @@ public final class WalkingManager implements IGameXmlReader
}
final L2NpcWalkerNode node = walk.getRoute().getNodeList().get(walk.getCurrentNodeId());
if (!npc.isInsideRadius(node, 10, false, false))
if (!npc.isInsideRadius2D(node, 10))
{
return;
}

View File

@@ -802,30 +802,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());
}
/**
@@ -835,7 +896,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

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

@@ -1137,7 +1137,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Bows Ranged Damage Formula (Damage gradually decreases when 60% or lower than full hit range, and increases when 60% or higher).
// full hit range is 500 which is the base bow range, and the 60% of this is 800.
damage1 *= (calculateDistance(target, true, false) / 4000) + 0.8;
damage1 *= (calculateDistance3D(target) / 4000) + 0.8;
}
// Check if the L2Character is a L2PcInstance
@@ -4482,32 +4482,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);
}
/**
@@ -5222,7 +5241,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
{
if (target.isCharacter())
{
if (!isInsideRadius(target.getX(), target.getY(), target.getZ(), escapeRange + _template.getCollisionRadius(), true, false))
if (!isInsideRadius3D(target.getX(), target.getY(), target.getZ(), escapeRange + _template.getCollisionRadius()))
{
skipRange++;
continue;

View File

@@ -555,7 +555,7 @@ public class L2Npc extends L2Character
{
return false;
}
else if (!isInsideRadius(player, INTERACTION_DISTANCE, true, false))
else if (!isInsideRadius3D(player, INTERACTION_DISTANCE))
{
return false;
}

View File

@@ -222,7 +222,7 @@ public final class L2BabyPetInstance extends L2PetInstance
final boolean previousFollowStatus = getFollowStatus();
// pet not following and owner outside cast range
if (!previousFollowStatus && !isInsideRadius(getOwner(), skill.getCastRange(), true, true))
if (!previousFollowStatus && !isInsideRadius3D(getOwner(), skill.getCastRange()))
{
return;
}

View File

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

View File

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

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

@@ -1474,7 +1474,7 @@ public final class L2PcInstance extends L2Playable
if (_questNpcObject > 0)
{
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);
@@ -4154,7 +4154,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;
}
@@ -8837,7 +8837,7 @@ public final class L2PcInstance extends L2Playable
// Calculate the distance between the L2PcInstance and the target
if (sklTargetType == L2TargetType.GROUND)
{
if (!isInsideRadius(_currentSkillWorldPosition.getX(), _currentSkillWorldPosition.getY(), _currentSkillWorldPosition.getZ(), skill.getCastRange() + getTemplate().getCollisionRadius(), false, false))
if (!isInsideRadius2D(_currentSkillWorldPosition.getX(), _currentSkillWorldPosition.getY(), _currentSkillWorldPosition.getZ(), skill.getCastRange() + getTemplate().getCollisionRadius()))
{
// Send a System Message to the caster
sendPacket(SystemMessageId.YOUR_TARGET_IS_OUT_OF_RANGE);
@@ -8847,7 +8847,7 @@ public final class L2PcInstance extends L2Playable
return false;
}
}
else if ((skill.getCastRange() > 0) && !isInsideRadius(target, skill.getCastRange() + getTemplate().getCollisionRadius(), false, false))
else if ((skill.getCastRange() > 0) && !isInsideRadius2D(target, skill.getCastRange() + getTemplate().getCollisionRadius()))
{
// Send a System Message to the caster
sendPacket(SystemMessageId.YOUR_TARGET_IS_OUT_OF_RANGE);

View File

@@ -130,7 +130,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, false);
}

View File

@@ -294,7 +294,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
@@ -334,7 +334,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;
@@ -510,7 +510,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

@@ -175,7 +175,7 @@ public final class L2TrapInstance extends L2Npc
public boolean checkTarget(L2Character target)
{
// Range seems to be reduced from Freya(300) to H5(150)
if (!target.isInsideRadius(this, 150, false, false))
if (!target.isInsideRadius2D(this, 150))
{
return false;
}

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

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

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

View File

@@ -2232,7 +2232,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);
}
@@ -2279,7 +2279,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

@@ -514,7 +514,7 @@ public final class Formulas
}
// Check the distance between the player and the player spawn point, in the center of the arena.
final double distToCenter = activeChar.calculateDistance(festivalCenter[0], festivalCenter[1], 0, false, false);
final double distToCenter = activeChar.calculateDistance2D(festivalCenter[0], festivalCenter[1], 0);
return 1.0 - (distToCenter * 0.0005); // Maximum Decreased Regen of ~ -65%;
}

View File

@@ -273,7 +273,7 @@ public class L2BossZone extends L2ZoneType
{
continue;
}
if (!raid.isInsideRadius(raid.getSpawn(), 150, false, false))
if (!raid.isInsideRadius2D(raid.getSpawn(), 150))
{
raid.returnHome();
}

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

@@ -127,7 +127,7 @@ public class MultiSellChoose implements IClientIncomingPacket
if (!player.isGM() && (npc != null))
{
if (!player.isInsideRadius(npc, INTERACTION_DISTANCE, true, false) || (player.getInstanceId() != npc.getInstanceId()))
if (!player.isInsideRadius3D(npc, INTERACTION_DISTANCE) || (player.getInstanceId() != npc.getInstanceId()))
{
player.setMultiSell(null);
return;

View File

@@ -1070,7 +1070,7 @@ public final class RequestActionUse implements IClientIncomingPacket
return false;
}
if (!activeChar.isSitting() && (target instanceof L2StaticObjectInstance) && (((L2StaticObjectInstance) target).getType() == 1) && activeChar.isInsideRadius(target, L2StaticObjectInstance.INTERACTION_DISTANCE, false, false))
if (!activeChar.isSitting() && (target instanceof L2StaticObjectInstance) && (((L2StaticObjectInstance) target).getType() == 1) && activeChar.isInsideRadius2D(target, L2StaticObjectInstance.INTERACTION_DISTANCE))
{
final ChairSit cs = new ChairSit(activeChar, target.getId());
_client.sendPacket(cs);
@@ -1315,7 +1315,7 @@ public final class RequestActionUse implements IClientIncomingPacket
return;
}
final int distance = (int) requester.calculateDistance(target, false, false);
final int distance = (int) requester.calculateDistance2D(target);
if ((distance > 125) || (distance < 15) || (requester.getObjectId() == target.getObjectId()))
{
_client.sendPacket(SystemMessageId.THE_REQUEST_CANNOT_BE_COMPLETED_BECAUSE_THE_TARGET_DOES_NOT_MEET_LOCATION_REQUIREMENTS);

View File

@@ -105,7 +105,7 @@ public final class RequestBuyItem implements IClientIncomingPacket
L2Character 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

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

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

@@ -73,7 +73,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_CANNOT_RECEIVE_A_DUEL_CHALLENGE_BECAUSE_C1_IS_TOO_FAR_AWAY);
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))
{
activeChar.sendPacket(ActionFailed.STATIC_PACKET);
return;

View File

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

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

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

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

View File

@@ -95,7 +95,7 @@ public final class RequestRefundItem implements IClientIncomingPacket
L2Character 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
L2Character 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

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

View File

@@ -716,7 +716,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 int min(int value1, int value2, int... values)