RuneHive-Game
Loading...
Searching...
No Matches
NpcFaceAction.java
Go to the documentation of this file.
1
2package com.runehive.game.action.impl;
3
4import com.runehive.game.action.Action;
5import com.runehive.game.action.policy.WalkablePolicy;
6import com.runehive.game.world.entity.mob.npc.Npc;
7import com.runehive.content.pet.PetData;
8import com.runehive.game.world.position.Position;
9
10import java.util.Arrays;
11
12/**
13 * An action that faces an npc, but resets their facing to their default facing
14 * direction after 15 seconds.
15 *
16 * @author Daniel
17 * @author Michael | Chex
18 */
19public final class NpcFaceAction extends Action<Npc> {
20 /**
21 * The npc identifications to check if face action is allowed.
22 */
23 private int[] identification;
24
25 /**
26 * The array list of all the first option npcs that can not face.
27 */
28 private final int[] FIRST_OPTION = {};
29
30 /**
31 * The array list of all the second option npcs that can not face.
32 */
33 private final int[] SECOND_OPTION = {3080, 3010};
34
35 /**
36 * The array list of all the third option npcs that can not face.
37 */
38 private final int[] THIRD_OPTION = {};
39
40 private final int[] FOURTH_OPTION = {};
41
42 /**
43 * Constructs a new <code>NpcFaceAction</code>.
44 *
45 * @param npc The npc.
46 * @param face The face position.
47 * @param option The option id.
48 */
49 public NpcFaceAction(Npc npc, Position face, int option) {
50 super(npc, 25);
51 if (option == 0) identification = FIRST_OPTION;
52 else if (option == 1) identification = SECOND_OPTION;
53 else if (option == 2) identification = THIRD_OPTION;
54 else if (option == 3) identification = FOURTH_OPTION;
55
56 if (Arrays.stream(PetData.values()).anyMatch(p -> npc.id == p.getNpc())) {
57 cancel();
58 return;
59 }
60
61 if (identification != null && Arrays.stream(identification).anyMatch($it -> npc.id == $it)) {
62 cancel();
63 return;
64 }
65
66 getMob().face(face);
67 }
68
69 @Override
70 public void execute() {
71 Npc npc = getMob().getNpc();
72
73 if (npc.walk) {
74 getMob().face(getMob().faceDirection);
75 }
76
77 cancel();
78 }
79
80 @Override
81 public String getName() {
82 return "Npc face";
83 }
84
85 @Override
86 public boolean prioritized() {
87 return false;
88 }
89
90 @Override
94
95}
T getMob()
Gets the player.
Definition Action.java:44
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
final int[] THIRD_OPTION
The array list of all the third option npcs that can not face.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
void execute()
A function representing the unit of work that will be carried out.
NpcFaceAction(Npc npc, Position face, int option)
Constructs a new NpcFaceAction.
final int[] SECOND_OPTION
The array list of all the second option npcs that can not face.
final int[] FIRST_OPTION
The array list of all the first option npcs that can not face.
int[] identification
The npc identifications to check if face action is allowed.
boolean prioritized()
Determines if this action is prioritized.
String getName()
Gets the name of this action.
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Represents a non-player character in the in-game world.
Definition Npc.java:29
Represents a single tile on the game world.
Definition Position.java:14
Holds the data for pets.
Definition PetData.java:14
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.