RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.action.ActionManager Class Reference

The class which manages Actions executed by mobs. More...

Collaboration diagram for com.runehive.game.action.ActionManager:

Public Member Functions

void cancel ()
 Cancels the current Action for the underlying Mob.
void cancel (String name)
 Purges actions in the queue with a WalkablePolicy of NON_WALKABLE.
void clearNonWalkableActions ()
 Purges actions in the queue with a WalkablePolicy of NON_WALKABLE.
Action<?> getCurrentAction ()
 Gets the current action.
void reset ()
 Resets all the actions for the underlying Mob.
void sequence ()
 Sequences the pending actions, and as soon as the current action has stopped, it executes the head of the queue.
String toString ()

Package Functions

public< A extends Action<?> > void execute (A action)
public< A extends Action<?> > void execute (A action, boolean override)
 Adds an Action to the queue.
public< A extends Action<?> > void queue (A action)
 Queues the specified action.

Private Member Functions

void cancelQueuedActions ()
 Cancels all the queued actions by stopping them and removing all elements from the queue.

Private Attributes

Action<?> currentAction = null
 The current action.
final Queue< Action<?> > queuedActions = new ArrayDeque<>()
 A queue of Action object.

Detailed Description

The class which manages Actions executed by mobs.

Author
Stand Up

Definition at line 16 of file ActionManager.java.

Member Function Documentation

◆ cancel() [1/2]

void com.runehive.game.action.ActionManager.cancel ( )

Cancels the current Action for the underlying Mob.

Definition at line 74 of file ActionManager.java.

74 {
75 if (currentAction != null && currentAction.isRunning() && currentAction.prioritized()) {
76 currentAction.cancel();
77 currentAction = null;
78 }
79 }

References currentAction.

Referenced by reset().

Here is the caller graph for this function:

◆ cancel() [2/2]

void com.runehive.game.action.ActionManager.cancel ( String name)

Purges actions in the queue with a WalkablePolicy of NON_WALKABLE.

Definition at line 109 of file ActionManager.java.

109 {
110 if (currentAction != null && Objects.equals(currentAction.getName(), name)) {
111 currentAction.cancel();
112 currentAction = null;
113 }
114
115 for (Action<?> actionEvent : queuedActions) {
116 if (Objects.equals(actionEvent.getName(), name)) {
117 actionEvent.cancel();
118 queuedActions.remove(actionEvent);
119 }
120 }
121 }

References currentAction, and queuedActions.

◆ cancelQueuedActions()

void com.runehive.game.action.ActionManager.cancelQueuedActions ( )
private

Cancels all the queued actions by stopping them and removing all elements from the queue.

Definition at line 68 of file ActionManager.java.

68 {
69 queuedActions.forEach(Action::cancel);
70 queuedActions.clear();
71 }

References com.runehive.game.task.Task.cancel(), and queuedActions.

Referenced by reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearNonWalkableActions()

void com.runehive.game.action.ActionManager.clearNonWalkableActions ( )

Purges actions in the queue with a WalkablePolicy of NON_WALKABLE.

Definition at line 88 of file ActionManager.java.

88 {
89 final Action<?> currentAction = this.currentAction;
90 if (currentAction != null) {
91 if (!currentAction.cancellableInProgress()) {
92 return;
93 }
94 if (currentAction.getWalkablePolicy() == WalkablePolicy.NON_WALKABLE) {
95 currentAction.cancel();
96 this.currentAction = null;
97 }
98 }
99
100 for (Action<?> actionEvent : queuedActions) {
101 if (actionEvent.getWalkablePolicy() != WalkablePolicy.WALKABLE) {
102 actionEvent.cancel();
103 queuedActions.remove(actionEvent);
104 }
105 }
106 }

References currentAction, com.runehive.game.action.policy.WalkablePolicy.NON_WALKABLE, queuedActions, and com.runehive.game.action.policy.WalkablePolicy.WALKABLE.

Referenced by com.runehive.content.skill.impl.magic.spell.impl.HighAlchemy.execute(), and com.runehive.content.skill.impl.magic.spell.impl.LowAlchemy.execute().

Here is the caller graph for this function:

◆ execute() [1/2]

public< A extends Action<?> > void com.runehive.game.action.ActionManager.execute ( A action)
package

Definition at line 38 of file ActionManager.java.

38 {
39 execute(action, true);
40 }

References execute().

Referenced by com.runehive.content.skill.impl.magic.teleport.Teleportation.activateOverride(), com.runehive.content.skill.impl.magic.teleport.Teleportation.activateOverride(), com.runehive.content.wintertodt.Wintertodt.chopRoot(), com.runehive.content.skill.impl.crafting.impl.Jewellery.click(), com.runehive.content.skill.impl.crafting.impl.Spinning.click(), com.runehive.content.skill.impl.firemaking.Firemaking.clickObject(), com.runehive.content.skill.impl.hunter.Hunter.clickObject(), com.runehive.content.skill.impl.woodcutting.Woodcutting.clickObject(), com.runehive.content.skill.impl.crafting.impl.Glass.craft(), com.runehive.content.skill.impl.crafting.impl.Stringing.craft(), com.runehive.content.emote.Emote.execute(), execute(), com.runehive.content.wintertodt.Wintertodt.feedBrazier(), com.runehive.content.wintertodt.Wintertodt.fixBrazier(), com.runehive.content.wintertodt.Wintertodt.fletch(), com.runehive.content.wintertodt.Wintertodt.lightBrazier(), com.runehive.content.shootingstar.ShootingStar.mine(), com.runehive.content.wintertodt.Wintertodt.mixHerb(), sequence(), com.runehive.content.wintertodt.Wintertodt.shootFlame(), com.runehive.content.skill.impl.smithing.Smelting.smelt(), com.runehive.content.skill.impl.crafting.Crafting.start(), com.runehive.content.skill.impl.fishing.Fishing.start(), com.runehive.content.skill.impl.fletching.Fletching.start(), com.runehive.content.skill.impl.mining.Mining.start(), com.runehive.content.wintertodt.Wintertodt.takeHerb(), com.runehive.content.skill.impl.magic.teleport.Teleportation.teleport(), com.runehive.content.skill.impl.thieving.WallSafe.thieve(), com.runehive.content.skill.impl.cooking.Cooking.useItem(), com.runehive.content.skill.impl.firemaking.Firemaking.useItem(), com.runehive.content.skill.impl.herblore.Herblore.useItem(), and com.runehive.content.skill.impl.prayer.BoneSacrifice.useItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute() [2/2]

public< A extends Action<?> > void com.runehive.game.action.ActionManager.execute ( A action,
boolean override )
package

Adds an Action to the queue.

Definition at line 43 of file ActionManager.java.

43 {
44 //if current action is priorized stop.
45 if (currentAction != null && currentAction.isRunning() && currentAction.prioritized()) {
46 return;
47 }
48
49 //if there is already an action active and we don't want to override
50 //we ignore.
51 //if u don't want to override but you also dont want to ignore
52 //queue the action.
53 if (currentAction != null && currentAction.isRunning() && !override) {
54 return;
55 }
56
57 //if there is an action active, make sure we stop it before running
58 //another action.
59 if (currentAction != null && currentAction.isRunning()) {
60 currentAction.cancel();
61 }
62
63 //finally submit the action.
64 World.schedule(currentAction = action);
65 }

References currentAction, and com.runehive.game.world.World.schedule().

Here is the call graph for this function:

◆ getCurrentAction()

Action<?> com.runehive.game.action.ActionManager.getCurrentAction ( )

Gets the current action.

Definition at line 124 of file ActionManager.java.

124 {
125 return currentAction;
126 }

References currentAction.

◆ queue()

public< A extends Action<?> > void com.runehive.game.action.ActionManager.queue ( A action)
package

Queues the specified action.

Definition at line 34 of file ActionManager.java.

34 {
35 queuedActions.add(action);
36 }

References queuedActions.

◆ reset()

void com.runehive.game.action.ActionManager.reset ( )

Resets all the actions for the underlying Mob.

Definition at line 82 of file ActionManager.java.

82 {
83 cancel();
84 cancelQueuedActions();
85 }

References cancel(), and cancelQueuedActions().

Here is the call graph for this function:

◆ sequence()

void com.runehive.game.action.ActionManager.sequence ( )

Sequences the pending actions, and as soon as the current action has stopped, it executes the head of the queue.

Definition at line 25 of file ActionManager.java.

25 {
26 if (queuedActions.isEmpty() || (currentAction != null && currentAction.isRunning())) {
27 return;
28 }
29
30 execute(this.currentAction = queuedActions.poll(), true);
31 }

References currentAction, execute(), and queuedActions.

Here is the call graph for this function:

◆ toString()

String com.runehive.game.action.ActionManager.toString ( )

Definition at line 129 of file ActionManager.java.

129 {
130 return String.format("ActionManager[size=%s, action=%s]", queuedActions.size(), currentAction);
131 }

References currentAction, and queuedActions.

Member Data Documentation

◆ currentAction

Action<?> com.runehive.game.action.ActionManager.currentAction = null
private

The current action.

Definition at line 22 of file ActionManager.java.

Referenced by cancel(), cancel(), clearNonWalkableActions(), execute(), getCurrentAction(), sequence(), and toString().

◆ queuedActions

final Queue<Action<?> > com.runehive.game.action.ActionManager.queuedActions = new ArrayDeque<>()
private

A queue of Action object.

Definition at line 19 of file ActionManager.java.

Referenced by cancel(), cancelQueuedActions(), clearNonWalkableActions(), queue(), sequence(), and toString().


The documentation for this class was generated from the following file: