-
Notifications
You must be signed in to change notification settings - Fork 5
/
Craftizen.java
166 lines (139 loc) · 3.99 KB
/
Craftizen.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
import java.util.ArrayList;
import java.util.logging.*;
import java.util.Random;
import java.awt.Polygon;
public class Craftizen extends NonPlayerCharacter {
static final Logger log = Logger.getLogger("Minecraft");
private static Random random = new Random();
public String id;
public String name;
public int itemInHand;
private double speed;
private ArrayList<String> dialog;
RouteType routeType;
Polygon route;
int [] routeX;
int [] routeZ;
private int ctr = 10;
public Craftizen(String id, String name, double x, double y, double z, float rotation, float pitch, int itemInHand) {
super(Craftizens.NPC_PREFIX + name + Craftizens.NPC_SUFFIX, x, y, z, rotation, pitch, itemInHand);
this.id = id;
this.name = name;
this.itemInHand = itemInHand;
speed = 1;
}
public static Craftizen getCraftizen(String npcid) {
for (Craftizen c : Craftizens.npcs) {
if (c.getId().equals(npcid)) {
return c;
}
}
return null;
}
public void interact(Player player) {
if (Craftizens.DEBUG) log.info("NPC " + id + " interacting with " + player.getName() + "...");
if (Craftizens.QUESTS_ENABLED) {
// check for turn-ins
if (Craftizens.DEBUG) log.info("--checking for turn-ins...");
if (Craftizens.activeQuests.containsKey(player.getName())) {
ArrayList<Quest> quests = Craftizens.activeQuests.get(player.getName());
for (Quest q : quests) {
if (q.getTurnInNpc().equals(id) && q.isComplete()) {
q.complete();
Craftizens.data.saveCompletedQuest(player, q);
quests.remove(q);
return;
}
}
}
// get quests
if (Craftizens.DEBUG) log.info("--checking for available quests...");
ArrayList<QuestInfo> quests = Craftizens.data.getAvailableQuests(this, player);
if (quests != null && quests.size() > 0) {
if (Craftizens.DEBUG) log.info("--found " + quests.size() + "quests");
if (quests.size() == 1) {
// only one quest - display it
QuestInfo q = quests.get(0);
q.show(player);
Craftizens.pendingQuests.put(player.getName(), q);
} else {
// multiple quests - show list
player.sendMessage(Craftizens.TEXT_COLOR + "Available quests:");
for (int i = 0; i < quests.size(); i++) {
QuestInfo q = quests.get(i);
player.sendMessage(Craftizens.TEXT_COLOR + " " + (i+1) + ": " + q.getName());
}
player.sendMessage(Craftizens.TEXT_COLOR + "To view a quest type: /quest view #");
Craftizens.pendingQuests.put(player.getName(), quests);
}
return;
}
}
// get random statement
String d = getRandomDialog();
if (d != null) {
String [] stmt = d.split("@");
stmt[0] = name + " says, " + stmt[0];
for (String s : stmt) {
player.sendMessage(Craftizens.TEXT_COLOR + s);
}
}
}
public static void delete(String s) {
Craftizen found = null;
for (Craftizen npc : Craftizens.npcs) {
if (npc.getId().equals(s)) {
found = npc;
}
}
if (found != null) {
found.delete();
Craftizens.npcs.remove(found);
}
}
public void tick(int interval) {
// send spawns TODO: only send when necessary
if (++ctr > 10) {
broadcastPosition();
ctr = 0;
}
//broadcastMovement(); // send movements
// TODO: send carry block when necessary
/*for (Object user : Craftians.players) {
((ea)user).a.b(new fv(handler.a.c, 1));
}*/
// motion
//handler.a.b(handler.a.l+((double)interval/1000D*speed),handler.a.m,handler.a.n,handler.a.r,handler.a.s);
}
public void setDialog(ArrayList<String> d) {
this.dialog = d;
}
public String getRandomDialog() {
if (dialog != null && dialog.size() > 0) {
return dialog.get(random.nextInt(dialog.size()));
} else {
return null;
}
}
public void addDialog(String d) {
if (dialog == null) {
dialog = new ArrayList<String>();
}
dialog.add(d);
}
public String getId() {
return id;
}
public String getName() {
return name;
}
/**
* @return the speed
*/
public double getSpeed() {
return speed;
}
public enum RouteType {
NONE, WANDER, PATROL
}
}