Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.citizensnpcs.api.ai.tree; | ||
|
||
public class Empty extends BehaviorGoalAdapter { | ||
private Empty() { | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
} | ||
|
||
@Override | ||
public BehaviorStatus run() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean shouldExecute() { | ||
return false; | ||
} | ||
|
||
public static Empty INSTANCE = new Empty(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.citizensnpcs.api.ai.tree; | ||
|
||
public class IfElse extends BehaviorGoalAdapter { | ||
private final Condition condition; | ||
private Behavior executing; | ||
private final Behavior ifBehavior, elseBehavior; | ||
|
||
public IfElse(Condition condition, Behavior ifBehavior, Behavior elseBehavior) { | ||
this.condition = condition; | ||
this.ifBehavior = ifBehavior; | ||
this.elseBehavior = elseBehavior; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
if (executing != null) { | ||
executing.reset(); | ||
executing = null; | ||
} | ||
} | ||
|
||
@Override | ||
public BehaviorStatus run() { | ||
return executing.run(); | ||
} | ||
|
||
@Override | ||
public boolean shouldExecute() { | ||
boolean cond = condition.get(); | ||
if (cond) { | ||
executing = ifBehavior; | ||
} else { | ||
executing = elseBehavior; | ||
} | ||
if (executing == null || !executing.shouldExecute()) { | ||
executing = null; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static IfElse create(Condition condition, Behavior ifBehavior, Behavior elseBehavior) { | ||
return new IfElse(condition, ifBehavior, elseBehavior); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters