public void TryMove()
{
if (this.IsMoving && this.CanMove)
{
var mapManager = ServiceLocator.WorldManager.MapManager;
int x = this.Position.X;
int y = this.Position.Y;
switch (this.Direction)
{
case Directions.Down:
// Client side check to see if the tile is blocked.
if (y < (mapManager.Map.Height - 1) && !mapManager.Map.GetTile(x, y + 1).Blocked && !mapManager.Map.GetTile(x, y + 1).IsOccupied)
{
mapManager.Map.GetTile(x, y).IsOccupied = false;
y += 1;
this.SendMovement(x, y, this.Direction);
this.CanMove = false;
}
break;
case Directions.Up:
// Client side check to see if the tile is blocked.
if (y > 0 && !mapManager.Map.GetTile(x, y - 1).Blocked && !mapManager.Map.GetTile(x, y - 1).IsOccupied)
{
mapManager.Map.GetTile(x, y).IsOccupied = false;
y -= 1;
this.SendMovement(x, y, this.Direction);
this.CanMove = false;
}
break;
case Directions.Right:
// Client side check to see if the tile is blocked.
if (x < (mapManager.Map.Width - 1) && !mapManager.Map.GetTile(x + 1, y).Blocked && !mapManager.Map.GetTile(x + 1, y).IsOccupied)
{
mapManager.Map.GetTile(x, y).IsOccupied = false;
x += 1;
this.SendMovement(x, y, this.Direction);
this.CanMove = false;
}
break;
case Directions.Left:
// Client side check to see if the tile is blocked.
if (x > 0 && !mapManager.Map.GetTile(x - 1, y).Blocked && !mapManager.Map.GetTile(x - 1, y).IsOccupied)
{
mapManager.Map.GetTile(x, y).IsOccupied = false;
x -= 1;
this.SendMovement(x, y, this.Direction);
this.CanMove = false;
}
break;
}
this.Position = new Vector2i(x, y);
}
}