Core/AreaTriggers: Fix triggering of client areatriggers for some shapes

Port From (https://github.com/TrinityCore/TrinityCore/commit/b070e63fa867f7f25e73e9ef3aafbe18902a50e9)
This commit is contained in:
Hondacrx
2024-08-25 19:11:12 -04:00
parent a21c82d0c0
commit c2409af60b
11 changed files with 218 additions and 111 deletions
@@ -678,7 +678,7 @@ namespace Game.Entities
SearchUnits(targetList, GetMaxSearchRadius(), false);
targetList.RemoveAll(unit => unit.GetPositionZ() < minZ || unit.GetPositionZ() > maxZ || !CheckIsInPolygon2D(unit));
targetList.RemoveAll(unit => unit.GetPositionZ() < minZ || unit.GetPositionZ() > maxZ || !unit.IsInPolygon2D(this, _polygonVertices));
}
void SearchUnitInCylinder(List<Unit> targetList)
@@ -857,7 +857,7 @@ namespace Game.Entities
if (MathFunctions.fuzzyEq(_verticesUpdatePreviousOrientation, newOrientation) && shape.PolygonVerticesTarget.Empty())
return;
_polygonVertices = shape.PolygonVertices;
_polygonVertices.AddRange(shape.PolygonVertices.Select(p => new Position(p.X, p.Y)));
if (!shape.PolygonVerticesTarget.Empty())
{
@@ -890,75 +890,6 @@ namespace Game.Entities
_verticesUpdatePreviousOrientation = newOrientation;
}
bool CheckIsInPolygon2D(Position pos)
{
float testX = pos.GetPositionX();
float testY = pos.GetPositionY();
//this method uses the ray tracing algorithm to determine if the point is in the polygon
bool locatedInPolygon = false;
for (int vertex = 0; vertex < _polygonVertices.Count; ++vertex)
{
int nextVertex;
//repeat loop for all sets of points
if (vertex == (_polygonVertices.Count - 1))
{
//if i is the last vertex, let j be the first vertex
nextVertex = 0;
}
else
{
//for all-else, let j=(i+1)th vertex
nextVertex = vertex + 1;
}
float vertX_i = GetPositionX() + _polygonVertices[vertex].X;
float vertY_i = GetPositionY() + _polygonVertices[vertex].Y;
float vertX_j = GetPositionX() + _polygonVertices[nextVertex].X;
float vertY_j = GetPositionY() + _polygonVertices[nextVertex].Y;
// following statement checks if testPoint.Y is below Y-coord of i-th vertex
bool belowLowY = vertY_i > testY;
// following statement checks if testPoint.Y is below Y-coord of i+1-th vertex
bool belowHighY = vertY_j > testY;
/* following statement is true if testPoint.Y satisfies either (only one is possible)
-.(i).Y < testPoint.Y < (i+1).Y OR
-.(i).Y > testPoint.Y > (i+1).Y
(Note)
Both of the conditions indicate that a point is located within the edges of the Y-th coordinate
of the (i)-th and the (i+1)- th vertices of the polygon. If neither of the above
conditions is satisfied, then it is assured that a semi-infinite horizontal line draw
to the right from the testpoint will NOT cross the line that connects vertices i and i+1
of the polygon
*/
bool withinYsEdges = belowLowY != belowHighY;
if (withinYsEdges)
{
// this is the slope of the line that connects vertices i and i+1 of the polygon
float slopeOfLine = (vertX_j - vertX_i) / (vertY_j - vertY_i);
// this looks up the x-coord of a point lying on the above line, given its y-coord
float pointOnLine = (slopeOfLine * (testY - vertY_i)) + vertX_i;
//checks to see if x-coord of testPoint is smaller than the point on the line with the same y-coord
bool isLeftToLine = testX < pointOnLine;
if (isLeftToLine)
{
//this statement changes true to false (and vice-versa)
locatedInPolygon = !locatedInPolygon;
}//end if (isLeftToLine)
}//end if (withinYsEdges
}
return locatedInPolygon;
}
bool HasOverridePosition()
{
return m_areaTriggerData.OverrideMoveCurveX.GetValue().OverrideActive
@@ -1491,9 +1422,9 @@ namespace Game.Entities
float _verticesUpdatePreviousOrientation;
bool _isRemoved;
Vector3 _rollPitchYaw;
Vector3 _targetRollPitchYaw;
List<Vector2> _polygonVertices;
Position _rollPitchYaw;
Position _targetRollPitchYaw;
List<Position> _polygonVertices;
Spline<int> _spline;
bool _reachedDestination;