88import static com .google .common .base .Preconditions .checkState ;
99
1010/**
11- * An enum representing movement directions .
11+ * Represents a cardinal, diagonal, or stationary movement direction .
1212 *
1313 * @author lare96
1414 * @author Graham
@@ -25,7 +25,9 @@ public enum Direction {
2525 SOUTH_EAST (7 , 1 , -1 );
2626
2727 /**
28- * A list of directions representing all possible directions of the NPC view cone, in order.
28+ * Ordered directions used when evaluating the NPC view cone.
29+ * <p>
30+ * The order is significant, as adjacent entries represent neighboring directions in the cone calculation.
2931 */
3032 public static final ImmutableList <Direction > VIEW_CONE = ImmutableList .of (
3133 Direction .NORTH ,
@@ -37,51 +39,91 @@ public enum Direction {
3739 Direction .EAST ,
3840 Direction .NORTH_EAST
3941 );
42+
43+ /**
44+ * The four cardinal directions in north-east-south-west order.
45+ */
46+ public static final ImmutableList <Direction > NESW = ImmutableList .of (NORTH , EAST , SOUTH , WEST );
47+
4048 /**
41- * An array of directions without any diagonal directions.
49+ * The four cardinal directions in west-north-east-south order.
50+ * <p>
51+ * This ordering matches the client collision mapping layout.
4252 */
43- public final static ImmutableList <Direction > NESW = ImmutableList .of (NORTH , EAST , SOUTH , WEST );
53+ public static final ImmutableList <Direction > WNES = ImmutableList .of (WEST , NORTH , EAST , SOUTH );
4454
4555 /**
46- * An array of directions without any diagonal directions, and one step counter-clockwise, as used by
47- * the clients collision mapping.
56+ * The four diagonal directions in the ordering used by the client collision mapping.
4857 */
49- public final static ImmutableList <Direction > WNES = ImmutableList .of (WEST , NORTH , EAST , SOUTH );
58+ public static final ImmutableList <Direction > WNES_DIAGONAL = ImmutableList .of (NORTH_WEST , NORTH_EAST , SOUTH_EAST , SOUTH_WEST );
5059
5160 /**
52- * An array of diagonal directions, and one step counter-clockwise, as used by the clients collision
53- * mapping.
61+ * All defined directions, including {@link #NONE}.
5462 */
55- public final static ImmutableList <Direction > WNES_DIAGONAL = ImmutableList .of (NORTH_WEST , NORTH_EAST , SOUTH_EAST , SOUTH_WEST );
5663 public static final ImmutableList <Direction > ALL = ImmutableList .copyOf (values ());
64+
65+ /**
66+ * All defined directions except {@link #NONE}.
67+ */
5768 public static final ImmutableList <Direction > ALL_EXCEPT_NONE = ImmutableList .copyOf (values ()).stream ().
5869 filter (it -> it != Direction .NONE ).collect (ImmutableList .toImmutableList ());
5970
60-
71+ /**
72+ * Cardinal components for {@link #NORTH_EAST}.
73+ */
6174 private static final ImmutableList <Direction > NORTH_EAST_COMPONENTS = ImmutableList .of (NORTH , EAST );
75+
76+ /**
77+ * Cardinal components for {@link #NORTH_WEST}.
78+ */
6279 private static final ImmutableList <Direction > NORTH_WEST_COMPONENTS = ImmutableList .of (NORTH , WEST );
80+
81+ /**
82+ * Cardinal components for {@link #SOUTH_EAST}.
83+ */
6384 private static final ImmutableList <Direction > SOUTH_EAST_COMPONENTS = ImmutableList .of (SOUTH , EAST );
64- private static final ImmutableList <Direction > SOUTH_WEST_COMPONENTS = ImmutableList .of (SOUTH , WEST );
6585
86+ /**
87+ * Cardinal components for {@link #SOUTH_WEST}.
88+ */
89+ private static final ImmutableList <Direction > SOUTH_WEST_COMPONENTS = ImmutableList .of (SOUTH , WEST );
6690
6791 /**
68- * The direction identifier.
92+ * The client-facing direction identifier.
6993 */
7094 private final int id ;
95+
96+ /**
97+ * The x-axis translation applied by this direction.
98+ */
7199 private final int translateX ;
100+
101+ /**
102+ * The y-axis translation applied by this direction.
103+ */
72104 private final int translateY ;
73105
74106 /**
75- * Creates a new {@link Direction} .
107+ * Creates a new direction .
76108 *
77- * @param id The direction identifier.
109+ * @param id The client-facing direction identifier.
110+ * @param translateX The x-axis translation for this direction.
111+ * @param translateY The y-axis translation for this direction.
78112 */
79113 Direction (int id , int translateX , int translateY ) {
80114 this .id = id ;
81115 this .translateX = translateX ;
82116 this .translateY = translateY ;
83117 }
84118
119+ /**
120+ * Selects a random non-biased movement direction.
121+ * <p>
122+ * If {@link #NONE} is initially selected, a second roll is performed against either the cardinal or diagonal
123+ * direction groups so that a movement direction is always returned.
124+ *
125+ * @return A random direction other than {@link #NONE}.
126+ */
85127 public static Direction random () {
86128 Direction selected = RandomUtils .random (ALL );
87129 if (selected == Direction .NONE ) {
@@ -95,9 +137,13 @@ public static Direction random() {
95137 }
96138
97139 /**
98- * Gets the direction as an integer as used orientation in the client maps (WNES as opposed to NESW).
140+ * Converts this direction into the forced movement orientation value used by the client.
141+ * <p>
142+ * This mapping uses the client's west-north-east-south orientation scheme rather than the direction enum ordinal
143+ * ordering.
99144 *
100- * @return The direction as an integer.
145+ * @return The forced movement orientation identifier.
146+ * @throws IllegalStateException If called for {@link #NONE}.
101147 */
102148 public int toForcedMovementId () {
103149 switch (this ) {
@@ -119,15 +165,29 @@ public int toForcedMovementId() {
119165
120166 }
121167
122-
168+ /**
169+ * @return The x translation.
170+ */
123171 public int getTranslateX () {
124172 return translateX ;
125173 }
126174
175+ /**
176+ * @return The y translation.
177+ */
127178 public int getTranslateY () {
128179 return translateY ;
129180 }
130181
182+ /**
183+ * Gets all directions visible from the supplied facing direction within the three-direction NPC view cone.
184+ * <p>
185+ * The returned set contains the supplied direction and its two adjacent directions in {@link #VIEW_CONE}.
186+ *
187+ * @param from The base facing direction.
188+ * @return The visible directions for that facing direction.
189+ * @throws IllegalStateException If the supplied direction does not exist in {@link #VIEW_CONE}.
190+ */
131191 public static Set <Direction > getAllVisible (Direction from ) {
132192 int baseIndex = -1 ;
133193 for (int index = 0 ; index < VIEW_CONE .size (); index ++) {
@@ -147,10 +207,13 @@ public static Set<Direction> getAllVisible(Direction from) {
147207 }
148208
149209 /**
150- * Get the 2 directions which make up a diagonal direction (i.e., NORTH and EAST for NORTH_EAST).
210+ * Gets the two cardinal directions that compose a diagonal direction.
211+ * <p>
212+ * For example, {@link #NORTH_EAST} resolves to {@link #NORTH} and {@link #EAST}.
151213 *
152- * @param direction The direction to get the components for.
153- * @return The components for the given direction.
214+ * @param direction The diagonal direction to decompose.
215+ * @return The two cardinal component directions.
216+ * @throws IllegalArgumentException If {@code direction} is not diagonal.
154217 */
155218 public static ImmutableList <Direction > diagonalComponents (Direction direction ) {
156219 switch (direction ) {
@@ -167,6 +230,11 @@ public static ImmutableList<Direction> diagonalComponents(Direction direction) {
167230 throw new IllegalArgumentException ("Must provide a diagonal direction." );
168231 }
169232
233+ /**
234+ * Gets the opposite of this direction.
235+ *
236+ * @return The opposite direction, or {@link #NONE} if this direction is {@link #NONE}.
237+ */
170238 public Direction opposite () {
171239 switch (this ) {
172240 case NORTH_WEST :
@@ -191,13 +259,19 @@ public Direction opposite() {
191259 }
192260
193261 /**
194- * Returns the direction between two sets of coordinates.
262+ * Resolves the direction from one coordinate pair to another.
263+ * <p>
264+ * Both coordinate differences must normalize to the range {@code [-1, 1]}. This is intended for adjacent-tile
265+ * movement and stationary comparisons.
195266 *
196- * @param currentX The current x coordinate.
197- * @param currentY The current y coordinate.
198- * @param nextX The next x coordinate.
199- * @param nextY The next y coordinate.
200- * @return The direction between the current and next coordinates.
267+ * @param currentX The starting x coordinate.
268+ * @param currentY The starting y coordinate.
269+ * @param nextX The destination x coordinate.
270+ * @param nextY The destination y coordinate.
271+ * @return The direction from the starting coordinates to the destination
272+ * coordinates.
273+ * @throws IllegalArgumentException If the normalized difference falls outside the valid adjacent-step
274+ * range.
201275 */
202276 @ SuppressWarnings ("Duplicates" )
203277 public static Direction between (int currentX , int currentY , int nextX , int nextY ) {
@@ -233,11 +307,11 @@ public static Direction between(int currentX, int currentY, int nextX, int nextY
233307 }
234308
235309 /**
236- * Returns the direction between two positions .
310+ * Resolves the direction from one position to another .
237311 *
238- * @param current The current step .
239- * @param next The next step .
240- * @return The direction between the current and next steps .
312+ * @param current The starting position .
313+ * @param next The destination position .
314+ * @return The direction from {@code current} to {@code next} .
241315 */
242316 public static Direction between (Position current , Position next ) {
243317 return between (current .getX (), current .getY (), next .getX (), next .getY ());
@@ -250,6 +324,9 @@ public final int getId() {
250324 return id ;
251325 }
252326
327+ /**
328+ * @return {@code true} if this direction is diagonal, otherwise {@code false}.
329+ */
253330 public boolean isDiagonal () {
254331 switch (this ) {
255332 case NORTH_EAST :
0 commit comments