Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CooldownDecorator example

j-o-phillips opened this issue · comments

Hi,
This package is really useful but I'm struggling to implement a cooldown Decorator. Could you advise me why this doesn't work:
First i register the task:

BehaviorTree.register(
    "fire",
    new Task({
      run: function (enemyShip) {
        enemyShip.fireMissile();
        return SUCCESS;
      },
    })
  );

Then i decorate it:

const decoratedTask = new CooldownDecorator({
    node: "fire",
    config: 5,
  });

Then I use it in the tree:

const tree = new Selector({
    nodes: [
      new Sequence({
        nodes: [
          new Task({
            run: function (enemyShip) {
              return enemyShip.checkIsInMissileRange(environmentDetails)
                ? SUCCESS
                : FAILURE;
            },
          }),
          new Task({
            run: function (enemyShip) {
              enemyShip.haltToStop(environmentDetails, setTargetShipDetails);
              return SUCCESS;
            },
          }),
          decoratedTask,
        ],
      }),
      new Sequence({
        nodes: [
          new Task({
            run: function (enemyShip) {
              enemyShip.moveToTarget(environmentDetails, setTargetShipDetails);
              return SUCCESS;
            },
          }),
        ],
      }),
    ],
  });

However the task 'fire' is still called for every step of the behaviour tree. Thanks in advance!