Skip to content

Commit

Permalink
fix: players auto-turning towards targets at map borders (#1947)
Browse files Browse the repository at this point in the history
> Adjusted player's DirectionToTarget method to properly handle directions near map borders and across different maps.
  • Loading branch information
Arufonsu authored Oct 14, 2023
1 parent 9974996 commit 9ebe17f
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions Intersect.Client/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2168,32 +2168,13 @@ protected Direction DirectionToTarget(Entity en)
return Dir;
}

int originY = Y;
int originX = X;
int targetY = en.Y;
int targetX = en.X;
var originMapController = MapInstance;
var targetMapController = en.MapInstance;

// Calculate Y and X offset between origin and target if they're not on the same map instance.
if (en.MapInstance.Id != MapInstance.Id)
{
if (en.MapInstance.GridY < MapInstance.GridY)
{
originY += Options.MapHeight - 1;
}
else if (en.MapInstance.GridY > MapInstance.GridY)
{
targetY += Options.MapHeight - 1;
}

if (en.MapInstance.GridX < MapInstance.GridX)
{
originX += Options.MapWidth - 1;
}
else if (en.MapInstance.GridX > MapInstance.GridX)
{
targetX += (Options.MapWidth - 1);
}
}
var originY = Y + originMapController.GridY * Options.MapHeight;
var originX = X + originMapController.GridX * Options.MapWidth;
var targetY = en.Y + targetMapController.GridY * Options.MapHeight;
var targetX = en.X + targetMapController.GridX * Options.MapWidth;

// Calculate the offset between origin and target along both of their axis.
var yDiff = originY - targetY;
Expand Down

0 comments on commit 9ebe17f

Please sign in to comment.