/
Behavior.java
73 lines (58 loc) · 2.12 KB
/
Behavior.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
package cn.nukkit.entity.ai.behavior;
import cn.nukkit.entity.EntityIntelligent;
import cn.nukkit.entity.ai.evaluator.IBehaviorEvaluator;
import cn.nukkit.entity.ai.executor.IBehaviorExecutor;
import lombok.Getter;
/**
* 单个的行为对象,包含一个执行器和一个评估器,行为对象委托了它们的方法
* <p>
* A single behavior object, containing an executor and an evaluator, with the behavior object delegating their methods
*/
@Getter
public class Behavior extends AbstractBehavior {
protected final int priority;
protected final int weight;
protected final int period;
protected IBehaviorExecutor executor;
protected IBehaviorEvaluator evaluator;
public Behavior(IBehaviorExecutor executor, IBehaviorEvaluator evaluator) {
this(executor, evaluator, 1);
}
public Behavior(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority) {
this(executor, evaluator, priority, 1);
}
public Behavior(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority, int weight) {
this(executor, evaluator, priority, weight, 1);
}
public Behavior(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority, int weight, int period) {
this.executor = executor;
this.evaluator = evaluator;
this.priority = priority;
this.weight = weight;
this.period = period;
}
@Override
public boolean evaluate(EntityIntelligent entity) {
return evaluator.evaluate(entity);
}
@Override
public boolean execute(EntityIntelligent entity) {
return executor.execute(entity);
}
@Override
public void onStart(EntityIntelligent entity) {
executor.onStart(entity);
}
@Override
public void onInterrupt(EntityIntelligent entity) {
executor.onInterrupt(entity);
}
@Override
public void onStop(EntityIntelligent entity) {
executor.onStop(entity);
}
@Override
public String toString() {
return "[" + priority + "] " + executor.getClass().getSimpleName() + " | " + evaluator.getClass().getSimpleName();
}
}