Skip to content

Commit

Permalink
Fix an issue with Sequence not selecting the right goals and an incor…
Browse files Browse the repository at this point in the history
…rect test
  • Loading branch information
fullwall committed Mar 9, 2018
1 parent a316340 commit ca2ffce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public abstract class BehaviorGoalAdapter implements Goal, Behavior {
@Override
public void run(GoalSelector selector) {
BehaviorStatus status = run();
if (status == BehaviorStatus.RESET_AND_REMOVE)
if (status == BehaviorStatus.RESET_AND_REMOVE) {
selector.finishAndRemove();
if (status == BehaviorStatus.FAILURE || status == BehaviorStatus.SUCCESS) {
} else if (status == BehaviorStatus.FAILURE || status == BehaviorStatus.SUCCESS) {
selector.finish();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/citizensnpcs/api/ai/tree/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private BehaviorStatus getContinuationStatus() {
public void reset() {
super.reset();
resetCurrent();
executingIndex = 0;
executingIndex = -1;
}

private void resetCurrent() {
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/net/citizensnpcs/api/ai/BehaviorTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public void failureSequence() {
test.addGoal(p, 1);
test.run();
test.run();
assertThat("Reset count", goal.resetCount, is(1));
assertThat("Run count", goal.runCount, is(1));
assertThat("Should execute count", goal.shouldExecuteCount, is(1));
assertThat("Reset count2", goal2.resetCount, is(1));
assertThat("Run count2", goal2.runCount, is(1));
assertThat("Should execute count2", goal2.shouldExecuteCount, is(1));
assertThat("Reset count", goal.resetCount, is(2));
assertThat("Run count", goal.runCount, is(2));
assertThat("Should execute count", goal.shouldExecuteCount, is(2));
assertThat("Reset count2", goal2.resetCount, is(0));
assertThat("Run count2", goal2.runCount, is(0));
assertThat("Should execute count2", goal2.shouldExecuteCount, is(0));
}

@Before
Expand Down

0 comments on commit ca2ffce

Please sign in to comment.