Core/Spells: fix wrong distance calculations in AoE spells
Port From (https://github.com/TrinityCore/TrinityCore/commit/5d076cfe291980bc5be9d44ffbae887e3dd5ad59)
This commit is contained in:
@@ -1406,7 +1406,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (x == 0.0f && y == 0.0f && z == 0.0f)
|
||||
{
|
||||
GetClosePoint(out x, out y, out z, GetObjectSize());
|
||||
GetClosePoint(out x, out y, out z, GetCombatReach());
|
||||
ang = GetOrientation();
|
||||
}
|
||||
Position pos = new Position();
|
||||
@@ -1434,7 +1434,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (x == 0 && y == 0 && z == 0)
|
||||
{
|
||||
GetClosePoint(out x, out y, out z, GetObjectSize());
|
||||
GetClosePoint(out x, out y, out z, GetCombatReach());
|
||||
ang = GetOrientation();
|
||||
}
|
||||
|
||||
@@ -1569,20 +1569,12 @@ namespace Game.Entities
|
||||
return playerList;
|
||||
}
|
||||
|
||||
public float GetObjectSize()
|
||||
{
|
||||
Unit thisUnit = ToUnit();
|
||||
if (thisUnit != null)
|
||||
return thisUnit.m_unitData.CombatReach;
|
||||
|
||||
return SharedConst.DefaultWorldObjectSize;
|
||||
}
|
||||
|
||||
public bool IsInPhase(WorldObject obj)
|
||||
{
|
||||
return GetPhaseShift().CanSee(obj.GetPhaseShift());
|
||||
}
|
||||
|
||||
|
||||
public virtual float GetCombatReach() { return 0.0f; } // overridden (only) in Unit
|
||||
public PhaseShift GetPhaseShift() { return _phaseShift; }
|
||||
public void SetPhaseShift(PhaseShift phaseShift) { _phaseShift = new PhaseShift(phaseShift); }
|
||||
public PhaseShift GetSuppressedPhaseShift() { return _suppressedPhaseShift; }
|
||||
@@ -1772,39 +1764,32 @@ namespace Game.Entities
|
||||
public float GetDistanceZ(WorldObject obj)
|
||||
{
|
||||
float dz = Math.Abs(GetPositionZ() - obj.GetPositionZ());
|
||||
float sizefactor = GetObjectSize() + obj.GetObjectSize();
|
||||
float sizefactor = GetCombatReach() + obj.GetCombatReach();
|
||||
float dist = dz - sizefactor;
|
||||
return (dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
public virtual bool _IsWithinDist(WorldObject obj, float dist2compare, bool is3D)
|
||||
public virtual bool _IsWithinDist(WorldObject obj, float dist2compare, bool is3D, bool incOwnRadius = true, bool incTargetRadius = true)
|
||||
{
|
||||
float sizefactor = GetObjectSize() + obj.GetObjectSize();
|
||||
float sizefactor = 0;
|
||||
sizefactor += incOwnRadius ? GetCombatReach() : 0.0f;
|
||||
sizefactor += incTargetRadius ? obj.GetCombatReach() : 0.0f;
|
||||
float maxdist = dist2compare + sizefactor;
|
||||
|
||||
Position thisOrTransport = this;
|
||||
Position objOrObjTransport = obj;
|
||||
|
||||
if (GetTransport() && obj.GetTransport() != null && obj.GetTransport().GetGUID() == GetTransport().GetGUID())
|
||||
{
|
||||
float dtx = m_movementInfo.transport.pos.posX - obj.m_movementInfo.transport.pos.posX;
|
||||
float dty = m_movementInfo.transport.pos.posY - obj.m_movementInfo.transport.pos.posY;
|
||||
float disttsq = dtx * dtx + dty * dty;
|
||||
if (is3D)
|
||||
{
|
||||
float dtz = m_movementInfo.transport.pos.posZ - obj.m_movementInfo.transport.pos.posZ;
|
||||
disttsq += dtz * dtz;
|
||||
}
|
||||
return disttsq < (maxdist * maxdist);
|
||||
thisOrTransport = m_movementInfo.transport.pos;
|
||||
objOrObjTransport = obj.m_movementInfo.transport.pos;
|
||||
}
|
||||
|
||||
float dx = GetPositionX() - obj.GetPositionX();
|
||||
float dy = GetPositionY() - obj.GetPositionY();
|
||||
float distsq = dx * dx + dy * dy;
|
||||
|
||||
if (is3D)
|
||||
{
|
||||
float dz = GetPositionZ() - obj.GetPositionZ();
|
||||
distsq += dz * dz;
|
||||
}
|
||||
|
||||
return distsq < maxdist * maxdist;
|
||||
return thisOrTransport.IsInDist(objOrObjTransport, maxdist);
|
||||
else
|
||||
return thisOrTransport.IsInDist2d(objOrObjTransport, maxdist);
|
||||
}
|
||||
|
||||
public bool IsWithinLOSInMap(WorldObject obj, ModelIgnoreFlags ignoreFlags = ModelIgnoreFlags.Nothing)
|
||||
@@ -1823,31 +1808,31 @@ namespace Game.Entities
|
||||
|
||||
public float GetDistance(WorldObject obj)
|
||||
{
|
||||
float d = GetExactDist(obj.GetPosition()) - GetObjectSize() - obj.GetObjectSize();
|
||||
float d = GetExactDist(obj.GetPosition()) - GetCombatReach() - obj.GetCombatReach();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
public float GetDistance(Position pos)
|
||||
{
|
||||
float d = GetExactDist(pos) - GetObjectSize();
|
||||
float d = GetExactDist(pos) - GetCombatReach();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
public float GetDistance(float x, float y, float z)
|
||||
{
|
||||
float d = GetExactDist(x, y, z) - GetObjectSize();
|
||||
float d = GetExactDist(x, y, z) - GetCombatReach();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
public float GetDistance2d(WorldObject obj)
|
||||
{
|
||||
float d = GetExactDist2d(obj.GetPosition()) - GetObjectSize() - obj.GetObjectSize();
|
||||
float d = GetExactDist2d(obj.GetPosition()) - GetCombatReach() - obj.GetCombatReach();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
public float GetDistance2d(float x, float y)
|
||||
{
|
||||
float d = GetExactDist2d(x, y) - GetObjectSize();
|
||||
float d = GetExactDist2d(x, y) - GetCombatReach();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
@@ -1868,22 +1853,22 @@ namespace Game.Entities
|
||||
|
||||
public bool IsWithinDist3d(float x, float y, float z, float dist)
|
||||
{
|
||||
return IsInDist(x, y, z, dist + GetObjectSize());
|
||||
return IsInDist(x, y, z, dist + GetCombatReach());
|
||||
}
|
||||
|
||||
public bool IsWithinDist3d(Position pos, float dist)
|
||||
{
|
||||
return IsInDist(pos, dist + GetObjectSize());
|
||||
return IsInDist(pos, dist + GetCombatReach());
|
||||
}
|
||||
|
||||
public bool IsWithinDist2d(float x, float y, float dist)
|
||||
{
|
||||
return IsInDist2d(x, y, dist + GetObjectSize());
|
||||
return IsInDist2d(x, y, dist + GetCombatReach());
|
||||
}
|
||||
|
||||
public bool IsWithinDist2d(Position pos, float dist)
|
||||
{
|
||||
return IsInDist2d(pos, dist + GetObjectSize());
|
||||
return IsInDist2d(pos, dist + GetCombatReach());
|
||||
}
|
||||
|
||||
public bool IsWithinDist(WorldObject obj, float dist2compare, bool is3D = true)
|
||||
@@ -1891,9 +1876,9 @@ namespace Game.Entities
|
||||
return obj != null && _IsWithinDist(obj, dist2compare, is3D);
|
||||
}
|
||||
|
||||
public bool IsWithinDistInMap(WorldObject obj, float dist2compare, bool is3D = true)
|
||||
public bool IsWithinDistInMap(WorldObject obj, float dist2compare, bool is3D = true, bool incOwnRadius = true, bool incTargetRadius = true)
|
||||
{
|
||||
return obj && IsInMap(obj) && IsInPhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
|
||||
return obj && IsInMap(obj) && IsInPhase(obj) && _IsWithinDist(obj, dist2compare, is3D, incOwnRadius, incTargetRadius);
|
||||
}
|
||||
|
||||
public bool IsWithinLOS(float ox, float oy, float oz, ModelIgnoreFlags ignoreFlags = ModelIgnoreFlags.Nothing)
|
||||
@@ -1916,7 +1901,7 @@ namespace Game.Entities
|
||||
{
|
||||
Vector3 vThis = new Vector3(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
Vector3 vObj = new Vector3(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
|
||||
Vector3 contactPoint = vThis + (vObj - vThis).directionOrZero() * Math.Min(dest.GetExactDist(GetPosition()), GetObjectSize());
|
||||
Vector3 contactPoint = vThis + (vObj - vThis).directionOrZero() * Math.Min(dest.GetExactDist(GetPosition()), GetCombatReach());
|
||||
|
||||
return new Position(contactPoint.X, contactPoint.Y, contactPoint.Z, GetAngle(contactPoint.X, contactPoint.Y));
|
||||
}
|
||||
@@ -1963,7 +1948,7 @@ namespace Game.Entities
|
||||
distsq += dz * dz;
|
||||
}
|
||||
|
||||
float sizefactor = GetObjectSize() + obj.GetObjectSize();
|
||||
float sizefactor = GetCombatReach() + obj.GetCombatReach();
|
||||
|
||||
// check only for real range
|
||||
if (minRange > 0.0f)
|
||||
@@ -1977,7 +1962,10 @@ namespace Game.Entities
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
public bool IsInBetween(WorldObject obj1, WorldObject obj2, float size = 0) { return obj1 && obj2 && IsInBetween(obj1.GetPosition(), obj2.GetPosition(), size); }
|
||||
public bool IsInBetween(WorldObject obj1, WorldObject obj2, float size = 0)
|
||||
{
|
||||
return obj1 && obj2 && IsInBetween(obj1.GetPosition(), obj2.GetPosition(), size);
|
||||
}
|
||||
bool IsInBetween(Position pos1, Position pos2, float size)
|
||||
{
|
||||
float dist = GetExactDist2d(pos1);
|
||||
@@ -1987,7 +1975,7 @@ namespace Game.Entities
|
||||
return false;
|
||||
|
||||
if (size == 0)
|
||||
size = GetObjectSize() / 2;
|
||||
size = GetCombatReach() / 2;
|
||||
|
||||
float angle = pos1.GetAngle(pos2);
|
||||
|
||||
@@ -2112,8 +2100,8 @@ namespace Game.Entities
|
||||
|
||||
public void GetNearPoint2D(out float x, out float y, float distance2d, float absAngle)
|
||||
{
|
||||
x = (float)(GetPositionX() + (GetObjectSize() + distance2d) * Math.Cos(absAngle));
|
||||
y = (float)(GetPositionY() + (GetObjectSize() + distance2d) * Math.Sin(absAngle));
|
||||
x = (float)(GetPositionX() + (GetCombatReach() + distance2d) * Math.Cos(absAngle));
|
||||
y = (float)(GetPositionY() + (GetCombatReach() + distance2d) * Math.Sin(absAngle));
|
||||
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
@@ -2184,7 +2172,7 @@ namespace Game.Entities
|
||||
public void GetContactPoint(WorldObject obj, out float x, out float y, out float z, float distance2d = 0.5f)
|
||||
{
|
||||
// angle to face `obj` to `this` using distance includes size of `obj`
|
||||
GetNearPoint(obj, out x, out y, out z, obj.GetObjectSize(), distance2d, GetAngle(obj));
|
||||
GetNearPoint(obj, out x, out y, out z, obj.GetCombatReach(), distance2d, GetAngle(obj));
|
||||
}
|
||||
|
||||
public void MovePosition(ref Position pos, float dist, float angle)
|
||||
|
||||
Reference in New Issue
Block a user