private Point GetRandomPosition()
{
// Single position
if (_points.Length == 1 || (_points.All(a => a.X == _points[0].X) && _points.All(a => a.Y == _points[0].Y)))
return _points[0];
var rnd = RandomProvider.Get();
// Line
if (_points.Length == 2)
{
var d = rnd.NextDouble();
var x = _points[0].X + (_points[1].X - _points[0].X) * d;
var y = _points[0].Y + (_points[1].Y - _points[0].Y) * d;
return new Point((int)x, (int)y);
}
// Polygon
var region = ChannelServer.Instance.World.GetRegion(this.RegionId);
var result = new Point();
for (int i = 0; i < 10; ++i)
{
while (!this.IsPointInside(result = new Point(rnd.Next(_minX, _maxX), rnd.Next(_minY, _maxY))))
{
}
// Check if position is inside a prop.
// Iterating over all props is not ideal, but a viable hot-fix.
// The region's quadtree should take the entities instead,
// so we can get only the props in a specific location.
if (region.GetProp(a => a.IsCollision && a.IsInside(result.X, result.Y)) == null)
break;
}
return result;
}