Skip to content

Commit 0aff765

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # src/main/java/io/luna/game/model/mob/combat/CombatAction.java # src/main/java/io/luna/game/model/mob/combat/CombatDamage.java
2 parents 5b93114 + 177c3a5 commit 0aff765

28 files changed

+3622
-338
lines changed

data/game/def/spells.json

Lines changed: 2047 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/io/luna/game/action/ActionQueue.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ public void submit(Action<?> action) {
9191
types.add(action.getClass());
9292
}
9393

94+
/**
95+
* Submits {@code action} only if no other action of the same concrete type is currently being processed.
96+
* <p>
97+
* This method uses the action's runtime class as a uniqueness key. If that type has not already been registered,
98+
* the action is submitted as normal.
99+
* <p>
100+
* If an action of the same class is already present, this method does nothing.
101+
*
102+
* @param action The action to submit if its concrete type is not already active.
103+
*/
104+
public void submitIfAbsent(Action<?> action) {
105+
Class<?> type = action.getClass();
106+
if (types.add(type)) {
107+
processing.put(action.actionType, action);
108+
action.setState(ActionState.PROCESSING);
109+
action.onSubmit();
110+
}
111+
}
112+
94113
/**
95114
* Returns whether this queue currently contains an action whose concrete class is exactly {@code type}.
96115
* <p>
@@ -103,6 +122,26 @@ public boolean contains(Class<? extends Action<?>> type) {
103122
return types.contains(type);
104123
}
105124

125+
/**
126+
* Returns all processing and executing actions assignable to {@code type}.
127+
*
128+
* @param type The action base type.
129+
* @return All matching actions.
130+
*/
131+
public <T extends Action<?>> T first(Class<T> type) {
132+
for (Action<?> action : processing.values()) {
133+
if (type.isAssignableFrom(action.getClass())) {
134+
return (T) action;
135+
}
136+
}
137+
for (Action<?> action : executing) {
138+
if (type.isAssignableFrom(action.getClass())) {
139+
return (T) action;
140+
}
141+
}
142+
return null;
143+
}
144+
106145
/**
107146
* Returns all processing and executing actions assignable to {@code type}.
108147
*

src/main/java/io/luna/game/model/Direction.java

Lines changed: 108 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import 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:

src/main/java/io/luna/game/model/item/Equipment.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,36 @@ public enum EquipmentBonus {
103103
*/
104104
PRAYER(11);
105105

106+
static {
107+
STAB_ATTACK.opposite = STAB_DEFENCE;
108+
SLASH_ATTACK.opposite = SLASH_DEFENCE;
109+
CRUSH_ATTACK.opposite = CRUSH_DEFENCE;
110+
MAGIC_ATTACK.opposite = MAGIC_DEFENCE;
111+
RANGED_ATTACK.opposite = RANGED_DEFENCE;
112+
113+
STAB_DEFENCE.opposite = STAB_ATTACK;
114+
SLASH_DEFENCE.opposite = SLASH_ATTACK;
115+
CRUSH_DEFENCE.opposite = CRUSH_ATTACK;
116+
MAGIC_DEFENCE.opposite = MAGIC_ATTACK;
117+
RANGED_DEFENCE.opposite = RANGED_ATTACK;
118+
119+
STRENGTH.opposite = STRENGTH;
120+
PRAYER.opposite = PRAYER;
121+
}
122+
106123
/**
107124
* The fixed array index for this bonus type.
108125
*/
109126
private final int index;
110127

128+
/**
129+
* The logical opposite of this bonus.
130+
* <p>
131+
* Attack bonuses map to their corresponding defence bonuses, and vice versa. Bonus types that
132+
* do not have a natural opposite return themselves.
133+
*/
134+
private EquipmentBonus opposite;
135+
111136
/**
112137
* Creates a new {@link EquipmentBonus}.
113138
*
@@ -125,6 +150,31 @@ public enum EquipmentBonus {
125150
public int getIndex() {
126151
return index;
127152
}
153+
154+
/**
155+
* Returns the logical opposite of this bonus type.
156+
* <p>
157+
* Examples:
158+
* <ul>
159+
* <li>{@link #STAB_ATTACK} returns {@link #STAB_DEFENCE}</li>
160+
* <li>{@link #STAB_DEFENCE} returns {@link #STAB_ATTACK}</li>
161+
* <li>{@link #STRENGTH} returns {@link #STRENGTH}</li>
162+
* </ul>
163+
*
164+
* @return The opposite bonus type, or this bonus itself if no paired opposite exists.
165+
*/
166+
public EquipmentBonus getOpposite() {
167+
return opposite;
168+
}
169+
170+
/**
171+
* Returns whether this bonus has a distinct opposite bonus rather than mapping to itself.
172+
*
173+
* @return {@code true} if this bonus maps to a different bonus type, otherwise {@code false}.
174+
*/
175+
public boolean hasDistinctOpposite() {
176+
return opposite != this;
177+
}
128178
}
129179

130180
/**

0 commit comments

Comments
 (0)