/
NavigatorParameters.java
279 lines (249 loc) · 7.18 KB
/
NavigatorParameters.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package net.citizensnpcs.api.ai;
import java.util.List;
import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.ai.event.NavigatorCallback;
import net.citizensnpcs.api.astar.pathfinder.BlockExaminer;
import com.google.common.collect.Lists;
public class NavigatorParameters implements Cloneable {
private AttackStrategy attackStrategy;
private boolean avoidWater;
private float baseSpeed = 1F;
private final List<NavigatorCallback> callbacks = Lists.newArrayListWithExpectedSize(3);
private double distanceMargin = 2F;
private final List<BlockExaminer> examiners = Lists.newArrayList();
private float range;
private float speedModifier = 1F;
private int stationaryTicks = -1;
private StuckAction stuckAction;
/**
* Adds a {@link NavigatorCallback} that will be removed
* <em>immediately</em> after being called.
*
* @param callback
* The callback
*/
public NavigatorParameters addSingleUseCallback(NavigatorCallback callback) {
callbacks.add(callback);
return this;
}
public void addSingleUseCallback(Object callback) {
}
/**
* @return The {@link AttackStrategy} currently in use (may be null)
*/
public AttackStrategy attackStrategy() {
return attackStrategy;
}
/**
* Sets the {@link AttackStrategy} for use when attacking entity targets.
*
* @param strategy
* The strategy to use
*/
public void attackStrategy(AttackStrategy strategy) {
attackStrategy = strategy;
}
/**
* @return Whether to avoid water while pathfinding
*/
public boolean avoidWater() {
return avoidWater;
}
/**
* Sets whether to avoid water while pathfinding
*
* @param avoidWater
* Whether to avoid water
*/
public NavigatorParameters avoidWater(boolean avoidWater) {
this.avoidWater = avoidWater;
return this;
}
/**
* @return The base movement speed
*/
public float baseSpeed() {
return baseSpeed;
}
/**
* Sets the base movement speed of the {@link Navigator}. Note that this is
* mob-specific and may not always be sane. Using {@link #speedModifier()}
* is preferred.
*
* @see #speedModifier()
* @param speed
* The new movement speed
*/
public NavigatorParameters baseSpeed(float speed) {
this.baseSpeed = speed;
return this;
}
/**
* @return All callbacks currently registered
*/
public Iterable<NavigatorCallback> callbacks() {
return callbacks;
}
/**
* Clears all current {@link BlockExaminer}s.
*/
public NavigatorParameters clearExaminers() {
examiners.clear();
return this;
}
@Override
public NavigatorParameters clone() {
try {
return (NavigatorParameters) super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
/**
* Returns the distance margin that the {@link Navigator} will be able to
* stop from the target. The margin will be measured against the block
* distance squared.
*
* @return The distance margin
*/
public double distanceMargin() {
return distanceMargin;
}
/**
* Sets the distance margin.
*
* @see #distanceMargin()
* @param newMargin
* The new distance margin
*/
public NavigatorParameters distanceMargin(double newMargin) {
distanceMargin = newMargin;
return this;
}
/**
* Adds the given {@link BlockExaminer}.
*
* @param examiner
* The BlockExaminer to add
*/
public NavigatorParameters examiner(BlockExaminer examiner) {
examiners.add(examiner);
return this;
}
/**
* Gets a copy of all current {@link BlockExaminer}s.
*
* @return An array of all current examiners
*/
public BlockExaminer[] examiners() {
return examiners.toArray(new BlockExaminer[examiners.size()]);
}
/**
* 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();
}
/**
* @return The pathfinding range of the navigator in blocks.
* @see #range(float)
*/
public float range() {
return range;
}
/**
* Sets the pathfinding range in blocks. The pathfinding range determines
* how far away the {@link Navigator} will attempt to pathfind before giving
* up to save computation.
*
* @param range
* The new range
*/
public NavigatorParameters range(float range) {
this.range = range;
return this;
}
/**
* @return The modified movement speed as given by {@link #baseSpeed()}
* multiplied by {@link #speedModifier()}
*/
public float speed() {
return modifiedSpeed(baseSpeed);
}
/**
* Sets the base movement speed of the {@link Navigator}. Note that this is
* mob-specific and may not always be sane. Using {@link #speedModifier()}
* is preferred.
*
* @see #speedModifier()
* @param speed
* The new movement speed
* @deprecated @see {@link #baseSpeed(float)}
*/
@Deprecated
public NavigatorParameters speed(float speed) {
this.baseSpeed = speed;
return this;
}
/**
* @return The movement speed modifier
* @see #speedModifier(float)
*/
public float speedModifier() {
return speedModifier;
}
/**
* Sets the movement speed modifier of the {@link Navigator}. This is a
* percentage modifier that alters the movement speed returned in
* {@link #speed()}.
*
* @param percent
* The new speed modifier
*/
public NavigatorParameters speedModifier(float percent) {
speedModifier = percent;
return this;
}
/**
* @return The number of stationary ticks
* @see #stationaryTicks(int)
*/
public int stationaryTicks() {
return stationaryTicks;
}
/**
* Sets the number of stationary ticks before navigation is cancelled with a
* {@link CancelReason} of STUCK.
*
* @param ticks
* The new number of stationary ticks
*/
public NavigatorParameters stationaryTicks(int ticks) {
stationaryTicks = ticks;
return this;
}
/**
* Gets the {@link StuckAction} of these parameters. This will be run when
* the navigation is stuck and must either be fixed up or cancelled.
*
* @return The current stuck action
*/
public StuckAction stuckAction() {
return stuckAction;
}
/**
* Sets the {@link StuckAction} of the parameters.
*
* @param action
* The new stuck action
* @see #stuckAction()
*/
public NavigatorParameters stuckAction(StuckAction action) {
stuckAction = action;
return this;
}
}