@Override public int compareTo(GoalEntry o) { int priority = getPriority(); return o.getPriority() > priority ? 1 : o.getPriority() < priority ? -1 : 0; }
@Override public void finishAndRemove() { Goal toRemove = executingRootGoal; finish(); if (toRemove != null) { removeGoal(toRemove); } }
private void setupExecution(GoalEntry entry) { finishCurrentGoalExecution(); executingPriority = entry.getPriority(); executingRootGoal = entry.getGoal(); addGoalToExecution(entry.getGoal()); }
@Override public boolean shouldExecute() { boolean executing = !npc.getNavigator().isNavigating() && target != null; if (executing) { npc.getNavigator().setTarget(target); npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() { @Override public void onCompletion(CancelReason cancelReason) { finished = true; reason = cancelReason; } }); } return executing; } }
/** * Causes the NPC to immediately path over to a position. */ public void pathTo(Location target) { pauseWaypoints(); pathingTo = target; npc.getNavigator().getDefaultParameters().distanceMargin(1.5); getNPC().getNavigator().setTarget(target); chasing = null; needsSafeReturn = true; }
@Override public void reset() { npc.getNavigator().cancelNavigation(); target = null; finished = false; reason = null; }
@Override public void run(GoalSelector selector) { BehaviorStatus status = run(); if (status == BehaviorStatus.RESET_AND_REMOVE) { selector.finishAndRemove(); } else if (status == BehaviorStatus.FAILURE || status == BehaviorStatus.SUCCESS) { selector.finish(); } }
/** * Modifieds the given speed value based on the current parameters. * * @param toModify * The speed value to modify * @return The modified speed */ public float modifiedSpeed(float toModify) { return toModify * speedModifier(); }
@Override public void run() { if (possibleGoals.isEmpty() || paused) return; trySelectGoal(); for (int i = 0; i < executingGoals.size(); ++i) { Goal goal = executingGoals.get(i); goal.run(selector); } }
@Override public void removeBehavior(Behavior behavior) { for (int i = 0; i < possibleGoals.size(); ++i) { Goal test = possibleGoals.get(i).getGoal(); if (test.equals(behavior)) { possibleGoals.remove(i--); if (test == executingRootGoal) finishCurrentGoalExecution(); } } }
@Override public void cancelCurrentExecution() { finishCurrentGoalExecution(); }
private void finishCurrentGoalExecution() { if (executingRootGoal == null) return; resetGoalList(); executingPriority = -1; executingRootGoal = null; }
@Override public int compareTo(GoalEntry o) { return o.getPriority() > priority ? 1 : o.getPriority() < priority ? -1 : 0; }
/** * @return The {@link NPC} involved in this event */ public NPC getNPC() { return navigator.getNPC(); } }
/** * @return The modified movement speed as given by {@link #baseSpeed()} multiplied by {@link #speedModifier()} */ public float speed() { return modifiedSpeed(baseSpeed); }
@Override public int getPriority() { return goal.getPriority(); }
@Override public void remove() { itr.remove(); if (cur.getGoal() == executingRootGoal) { finishCurrentGoalExecution(); } } };
private void resetGoalList() { for (int i = 0; i < executingGoals.size(); ++i) { executingGoals.get(i).reset(); } executingGoals.clear(); }
@Override public void reset() { npc.getNavigator().cancelNavigation(); reason = null; finished = false; }
@Override public void clear() { finishCurrentGoalExecution(); possibleGoals.clear(); }