Core/AI: AreaBoundary refactor
Port From (https://github.com/TrinityCore/TrinityCore/commit/3f79c9f69674618a7d7e2bf8484f9ec6ce15b2df)
This commit is contained in:
@@ -384,6 +384,18 @@ namespace Game.AI
|
|||||||
return me.SummonCreature(entry, pos, summonType, despawnTime);
|
return me.SummonCreature(entry, pos, summonType, despawnTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsInBounds(List<AreaBoundary> boundary, Position pos)
|
||||||
|
{
|
||||||
|
if (boundary == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
foreach (AreaBoundary areaBoundary in boundary)
|
||||||
|
if (!areaBoundary.IsWithinBoundary(pos))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetBoundary(List<AreaBoundary> boundary)
|
public void SetBoundary(List<AreaBoundary> boundary)
|
||||||
{
|
{
|
||||||
_boundary = boundary;
|
_boundary = boundary;
|
||||||
|
|||||||
@@ -21,50 +21,36 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
public class AreaBoundary
|
public class AreaBoundary
|
||||||
{
|
{
|
||||||
public AreaBoundary(BoundaryType bType, bool isInverted)
|
public AreaBoundary(bool isInverted)
|
||||||
{
|
{
|
||||||
m_boundaryType = bType;
|
_isInvertedBoundary = isInverted;
|
||||||
m_isInvertedBoundary = isInverted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoundaryType GetBoundaryType() { return m_boundaryType; }
|
public bool IsWithinBoundary(Position pos) { return IsWithinBoundaryArea(pos) != _isInvertedBoundary; }
|
||||||
|
|
||||||
public bool IsWithinBoundary(Position pos) { return (IsWithinBoundaryArea(pos) != m_isInvertedBoundary); }
|
|
||||||
|
|
||||||
public virtual bool IsWithinBoundaryArea(Position pos) { return false; }
|
public virtual bool IsWithinBoundaryArea(Position pos) { return false; }
|
||||||
|
|
||||||
BoundaryType m_boundaryType;
|
bool _isInvertedBoundary;
|
||||||
bool m_isInvertedBoundary;
|
|
||||||
|
|
||||||
public enum BoundaryType
|
|
||||||
{
|
|
||||||
Rectangle, // Rectangle Aligned With The Coordinate Axis
|
|
||||||
Circle,
|
|
||||||
Ellipse,
|
|
||||||
Triangle,
|
|
||||||
Parallelogram,
|
|
||||||
ZRange,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DoublePosition : Position
|
public class DoublePosition : Position
|
||||||
{
|
{
|
||||||
public DoublePosition(double x = 0.0, double y = 0.0, double z = 0.0, float o = 0f) : base((float)x, (float)y, (float)z, o)
|
public DoublePosition(double x = 0.0, double y = 0.0, double z = 0.0, float o = 0f) : base((float)x, (float)y, (float)z, o)
|
||||||
{
|
{
|
||||||
d_positionX = x;
|
doublePosX = x;
|
||||||
d_positionY = y;
|
doublePosY = y;
|
||||||
d_positionZ = z;
|
doublePosZ = z;
|
||||||
}
|
}
|
||||||
public DoublePosition(float x, float y = 0f, float z = 0f, float o = 0f) : base(x, y, z, o)
|
public DoublePosition(float x, float y = 0f, float z = 0f, float o = 0f) : base(x, y, z, o)
|
||||||
{
|
{
|
||||||
d_positionX = x;
|
doublePosX = x;
|
||||||
d_positionY = y;
|
doublePosY = y;
|
||||||
d_positionZ = z;
|
doublePosZ = z;
|
||||||
}
|
}
|
||||||
public DoublePosition(Position pos) : this(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation()) { }
|
public DoublePosition(Position pos) : this(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation()) { }
|
||||||
|
|
||||||
public double GetDoublePositionX() { return d_positionX; }
|
public double GetDoublePositionX() { return doublePosX; }
|
||||||
public double GetDoublePositionY() { return d_positionY; }
|
public double GetDoublePositionY() { return doublePosY; }
|
||||||
public double GetDoublePositionZ() { return d_positionZ; }
|
public double GetDoublePositionZ() { return doublePosZ; }
|
||||||
|
|
||||||
public double GetDoubleExactDist2dSq(DoublePosition pos)
|
public double GetDoubleExactDist2dSq(DoublePosition pos)
|
||||||
{
|
{
|
||||||
@@ -75,22 +61,22 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public Position Sync()
|
public Position Sync()
|
||||||
{
|
{
|
||||||
posX = (float)d_positionX;
|
posX = (float)doublePosX;
|
||||||
posY = (float)d_positionY;
|
posY = (float)doublePosY;
|
||||||
posZ = (float)d_positionZ;
|
posZ = (float)doublePosZ;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
double d_positionX;
|
double doublePosX;
|
||||||
double d_positionY;
|
double doublePosY;
|
||||||
double d_positionZ;
|
double doublePosZ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RectangleBoundary : AreaBoundary
|
public class RectangleBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
// X axis is north/south, Y axis is east/west, larger values are northwest
|
// X axis is north/south, Y axis is east/west, larger values are northwest
|
||||||
public RectangleBoundary(float southX, float northX, float eastY, float westY, bool isInverted = false) : base(BoundaryType.Rectangle, isInverted)
|
public RectangleBoundary(float southX, float northX, float eastY, float westY, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_minX = southX;
|
_minX = southX;
|
||||||
_maxX = northX;
|
_maxX = northX;
|
||||||
@@ -114,17 +100,15 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public class CircleBoundary : AreaBoundary
|
public class CircleBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public CircleBoundary(Position center, double radius, bool isInverted = false) : this(new DoublePosition(center), radius, isInverted) { }
|
public CircleBoundary(Position center, double radius, bool isInverted = false) : base(isInverted)
|
||||||
public CircleBoundary(Position center, Position pointOnCircle, bool isInverted = false) : this(new DoublePosition(center), new DoublePosition(pointOnCircle), isInverted) { }
|
|
||||||
public CircleBoundary(DoublePosition center, double radius, bool isInverted = false) : base(BoundaryType.Circle, isInverted)
|
|
||||||
{
|
{
|
||||||
_center = center;
|
_center = new DoublePosition(center);
|
||||||
_radiusSq = radius * radius;
|
_radiusSq = radius * radius;
|
||||||
}
|
}
|
||||||
public CircleBoundary(DoublePosition center, DoublePosition pointOnCircle, bool isInverted = false) : base(BoundaryType.Circle, isInverted)
|
public CircleBoundary(Position center, Position pointOnCircle, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_center = center;
|
_center = new DoublePosition(center);
|
||||||
_radiusSq = center.GetDoubleExactDist2dSq(pointOnCircle);
|
_radiusSq = _center.GetDoubleExactDist2dSq(new DoublePosition(pointOnCircle));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
@@ -143,10 +127,9 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public class EllipseBoundary : AreaBoundary
|
public class EllipseBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public EllipseBoundary(Position center, double radiusX, double radiusY, bool isInverted = false) : this(new DoublePosition(center), radiusX, radiusY, isInverted) { }
|
public EllipseBoundary(Position center, double radiusX, double radiusY, bool isInverted = false) : base(isInverted)
|
||||||
public EllipseBoundary(DoublePosition center, double radiusX, double radiusY, bool isInverted = false) :base(BoundaryType.Ellipse, isInverted)
|
|
||||||
{
|
{
|
||||||
_center = center;
|
_center = new DoublePosition(center);
|
||||||
_radiusYSq = radiusY * radiusY;
|
_radiusYSq = radiusY * radiusY;
|
||||||
_scaleXSq = _radiusYSq / (radiusX * radiusX);
|
_scaleXSq = _radiusYSq / (radiusX * radiusX);
|
||||||
}
|
}
|
||||||
@@ -167,13 +150,12 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public class TriangleBoundary : AreaBoundary
|
public class TriangleBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public TriangleBoundary(Position pointA, Position pointB, Position pointC, bool isInverted = false)
|
public TriangleBoundary(Position pointA, Position pointB, Position pointC, bool isInverted = false) : base(isInverted)
|
||||||
: this(new DoublePosition(pointA), new DoublePosition(pointB), new DoublePosition(pointC), isInverted) { }
|
|
||||||
public TriangleBoundary(DoublePosition pointA, DoublePosition pointB, DoublePosition pointC, bool isInverted = false) : base(BoundaryType.Triangle, isInverted)
|
|
||||||
{
|
{
|
||||||
_a = pointA;
|
_a = new DoublePosition(pointA);
|
||||||
_b = pointB;
|
_b = new DoublePosition(pointB);
|
||||||
_c = pointC;
|
_c = new DoublePosition(pointC);
|
||||||
|
|
||||||
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
||||||
_bcx = _c.GetDoublePositionX() - _b.GetDoublePositionX();
|
_bcx = _c.GetDoublePositionX() - _b.GetDoublePositionX();
|
||||||
_cax = _a.GetDoublePositionX() - _c.GetDoublePositionX();
|
_cax = _a.GetDoublePositionX() - _c.GetDoublePositionX();
|
||||||
@@ -210,13 +192,11 @@ namespace Game.Maps
|
|||||||
public class ParallelogramBoundary : AreaBoundary
|
public class ParallelogramBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
// Note: AB must be orthogonal to AD
|
// Note: AB must be orthogonal to AD
|
||||||
public ParallelogramBoundary(Position cornerA, Position cornerB, Position cornerD, bool isInverted = false)
|
public ParallelogramBoundary(Position cornerA, Position cornerB, Position cornerD, bool isInverted = false) : base(isInverted)
|
||||||
: this(new DoublePosition(cornerA), new DoublePosition(cornerB), new DoublePosition(cornerD), isInverted) { }
|
|
||||||
public ParallelogramBoundary(DoublePosition cornerA, DoublePosition cornerB, DoublePosition cornerD, bool isInverted = false) : base(BoundaryType.Parallelogram, isInverted)
|
|
||||||
{
|
{
|
||||||
_a = cornerA;
|
_a = new DoublePosition(cornerA);
|
||||||
_b = cornerB;
|
_b = new DoublePosition(cornerB);
|
||||||
_d = cornerD;
|
_d = new DoublePosition(cornerD);
|
||||||
_c = new DoublePosition(_d.GetDoublePositionX() + (_b.GetDoublePositionX() - _a.GetDoublePositionX()), _d.GetDoublePositionY() + (_b.GetDoublePositionY() - _a.GetDoublePositionY()));
|
_c = new DoublePosition(_d.GetDoublePositionX() + (_b.GetDoublePositionX() - _a.GetDoublePositionX()), _d.GetDoublePositionY() + (_b.GetDoublePositionY() - _a.GetDoublePositionY()));
|
||||||
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
||||||
_dax = _a.GetDoublePositionX() - _d.GetDoublePositionX();
|
_dax = _a.GetDoublePositionX() - _d.GetDoublePositionX();
|
||||||
@@ -251,7 +231,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public class ZRangeBoundary : AreaBoundary
|
public class ZRangeBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public ZRangeBoundary(float minZ, float maxZ, bool isInverted = false) : base(BoundaryType.ZRange, isInverted)
|
public ZRangeBoundary(float minZ, float maxZ, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_minZ = minZ;
|
_minZ = minZ;
|
||||||
_maxZ = maxZ;
|
_maxZ = maxZ;
|
||||||
|
|||||||
@@ -470,16 +470,6 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.Anubarak
|
|||||||
_backstabTimer = 6 * Time.InMilliseconds;
|
_backstabTimer = 6 * Time.InMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsInBounds(Position jumpTo, List<AreaBoundary> boundary)
|
|
||||||
{
|
|
||||||
if (boundary == null)
|
|
||||||
return true;
|
|
||||||
foreach (var it in boundary)
|
|
||||||
if (!it.IsWithinBoundary(jumpTo))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Position GetRandomPositionAround(Creature anubarak)
|
Position GetRandomPositionAround(Creature anubarak)
|
||||||
{
|
{
|
||||||
float DISTANCE_MIN = 10.0f;
|
float DISTANCE_MIN = 10.0f;
|
||||||
@@ -498,7 +488,7 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.Anubarak
|
|||||||
Position jumpTo;
|
Position jumpTo;
|
||||||
do
|
do
|
||||||
jumpTo = GetRandomPositionAround(anubarak);
|
jumpTo = GetRandomPositionAround(anubarak);
|
||||||
while (!IsInBounds(jumpTo, boundary));
|
while (!IsInBounds(boundary, jumpTo));
|
||||||
me.GetMotionMaster().MoveJump(jumpTo, 40.0f, 40.0f);
|
me.GetMotionMaster().MoveJump(jumpTo, 40.0f, 40.0f);
|
||||||
DoCastSelf(SpellIds.AssassinVisual, true);
|
DoCastSelf(SpellIds.AssassinVisual, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user