PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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