seeAndMoveToAlly method

void seeAndMoveToAlly({
  1. required dynamic closeAlly(
    1. Ally
    ),
  2. VoidCallback? notObserved,
  3. VoidCallback? observed,
  4. double radiusVision = 32,
  5. double margin = 10,
  6. bool runOnlyVisibleInScreen = true,
})

Checks whether the ally is within range. If so, move to it.

Implementation

void seeAndMoveToAlly({
  required Function(Ally) closeAlly,
  VoidCallback? notObserved,
  VoidCallback? observed,
  double radiusVision = 32,
  double margin = 10,
  bool runOnlyVisibleInScreen = true,
}) {
  if (runOnlyVisibleInScreen && !this.isVisible) return;

  seeComponentType<Ally>(
    radiusVision: radiusVision,
    observed: (ally) {
      observed?.call();
      this.followComponent(
        ally.first,
        dtUpdate,
        closeComponent: (comp) => closeAlly(comp as Ally),
        margin: margin,
      );
    },
    notObserved: () {
      if (!this.isIdle) {
        this.idle();
      }
      notObserved?.call();
    },
  );
}