/Code/src/com/game/AI/ResetDecorator.java

https://bitbucket.org/DeveloperUX/behaviortree · Java · 45 lines · 21 code · 3 blank · 21 comment · 1 complexity · 36d442a8e6c92e59704692f7450c64d6 MD5 · raw file

  1. package com.game.AI;
  2. /**
  3. * Decorator that resets to "Started" the task it is applied to, each time said
  4. * task finishes.
  5. *
  6. * @author Ying
  7. *
  8. */
  9. public class ResetDecorator extends TaskDecorator
  10. {
  11. /**
  12. * Creates a new instance of the ResetDecorator class
  13. * @param blackboard Reference to the AI Blackboard data
  14. * @param task Task to decorate
  15. * @param name Name of the class, used for debugging
  16. */
  17. public ResetDecorator(Blackboard blackboard, Task task, String name)
  18. {
  19. super(blackboard, task, name);
  20. }
  21. /**
  22. * Creates a new instance of the ResetDecorator class
  23. * @param blackboard Reference to the AI Blackboard data
  24. * @param task Task to decorate
  25. */
  26. public ResetDecorator(Blackboard blackboard, Task task)
  27. {
  28. super(blackboard, task);
  29. }
  30. /**
  31. * Does the decorated task's action, and if it's done, resets it.
  32. */
  33. @Override
  34. public void DoAction()
  35. {
  36. this.task.DoAction();
  37. if(this.task.GetControl().Finished())
  38. {
  39. this.task.GetControl().Reset();
  40. }
  41. }
  42. }