protected void ChasePlayer() { if (Owner.CurrentRegion != null) { if (!IsPlayerWithinChaseRadius()) { NextAction = null; } else { Vector2i currentPlayerPosition = GamestateManager.Instance.Player.Coords; if (LastPlayerPosition != currentPlayerPosition || !GamestateManager.Instance.Map.GetFieldFromRegion(TargetPosition).IsTraversible()) { LastPlayerPosition = currentPlayerPosition; TargetPosition = GetClosestValidShootingPositionToPlayer(); Path = null; } if (TargetPosition.IsValid()) { if (Path != null && Path.Count == 0) { Path = null; } Path ??= GeneratePath(GamestateManager.Instance.Map.GetNodesInRadius(Owner.Coords, SightDistance), new Vector2i(SightDistance, SightDistance), new Vector2i(SightDistance, SightDistance) + TargetPosition - Owner.Coords); NextAction = Path == null ? null : GetActionFromNextCoords(Path.Pop().Position + Owner.Coords - new Vector2i(SightDistance, SightDistance)); } else { NextAction = null; } } } else { NextAction = null; } }