-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuestInfo.java
301 lines (264 loc) · 7.17 KB
/
QuestInfo.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import java.util.HashMap;
public class QuestInfo {
public String id;
public String type;
public String name;
public String desc;
public String pickUp;
public String turnIn;
public String prereq;
public String rankReq;
public String rankReward;
public String itemsProvidedStr;
public HashMap<Integer,Integer> itemsProvided = new HashMap<Integer, Integer>();
public String rewardsStr;
public HashMap<Integer,Integer> rewards = new HashMap<Integer, Integer>();
public String location;
public String data;
public String completionText;
public boolean allowCompass;
public QuestInfo(String id) {
this.id = id;
this.desc = "";
}
public QuestInfo(String id, String type, String name, String desc, String pickUp, String turnIn, String prereq, String itemsProvided, String rewards, String location, String data, String completionText, String rankReq, String rankReward) {
// get normal data
this.id = id;
this.type = type;
this.name = name;
this.desc = desc;
this.pickUp = pickUp;
this.turnIn = turnIn;
this.prereq = prereq;
// set up items provided
if (itemsProvided != null && !itemsProvided.equals("")) {
// format: items desc string:id quantity,id quantity,id quantity,etc
this.itemsProvidedStr = itemsProvided;
String itemdata [] = itemsProvided.split(":");
String [] items = itemdata[1].split(",");
this.itemsProvided = new HashMap<Integer,Integer>();
for (String i : items) {
String [] item = i.split(" ");
this.itemsProvided.put(Integer.parseInt(item[0]),Integer.parseInt(item[1]));
}
} else {
this.itemsProvidedStr = "";
this.itemsProvided = null;
}
// set up rewards
if (rewards != null && !rewards.equals("")) {
// format: items desc string:id quantity,id quantity,id quantity,etc
this.rewardsStr = rewards;
String itemdata [] = rewards.split(":");
String [] items = itemdata[1].split(",");
this.rewards = new HashMap<Integer,Integer>();
for (String i : items) {
String [] item = i.split(" ");
this.rewards.put(Integer.parseInt(item[0]),Integer.parseInt(item[1]));
}
} else {
this.rewardsStr = "";
this.rewards = null;
}
this.location = location;
this.data = data;
this.completionText = completionText;
this.rankReq = rankReq;
this.rankReward = rankReward;
}
public void show(Player player) {
player.sendMessage(" ");
player.sendMessage(Craftizens.TEXT_COLOR + "Quest: " + name);
player.sendMessage(" ");
String [] descLines = desc.split("@");
for (String s : descLines) {
String temp = s;
while (temp.length() > 60) {
int lastSpace = temp.substring(0,60).lastIndexOf(' ');
player.sendMessage(Craftizens.TEXT_COLOR + temp.substring(0,lastSpace));
temp = temp.substring(lastSpace+1);
}
player.sendMessage(Craftizens.TEXT_COLOR + temp);
}
if (!itemsProvidedStr.equals("")) {
player.sendMessage(Craftizens.TEXT_COLOR + " Provided: " + itemsProvidedStr.split(":")[0]);
}
if (!rewardsStr.equals("")) {
player.sendMessage(Craftizens.TEXT_COLOR + " Reward: " + rewardsStr.split(":")[0]);
}
player.sendMessage(Craftizens.TEXT_COLOR + "Type '/quest accept' to accept this quest.");
}
public Quest createQuest(Player player, boolean newQuest) {
Quest q = null;
if (type.equals("harvest")) {
q = new HarvestQuest(this, player, newQuest);
} else if (type.equals("build")) {
q = new BuildQuest(this, player, newQuest);
} else if (type.equals("gather")) {
q = new GatherQuest(this, player, newQuest);
} else if (type.equals("findloc")) {
q = new FindLocQuest(this, player, newQuest);
} else if (type.equals("fetchblock")) {
q = new FetchBlockQuest(this, player, newQuest);
}
return q;
}
public boolean setId(String id) {
if (id.matches("^[a-zA-Z0-9]+$")) {
this.id = id;
return true;
} else {
return false;
}
}
public boolean setType(String t) {
if (!t.equals("harvest") && !t.equals("build") && !t.equals("gather") && !t.equals("findloc") && !t.equals("fetchblock")) {
return false;
} else {
type = t;
return true;
}
}
public boolean setName(String n) {
if (n.matches("^[a-zA-Z0-9 \\-]+$")) {
this.name = n;
return true;
} else {
return false;
}
}
public boolean setPickUp(String npc) {
if (npc.matches("^[a-zA-Z0-9]+$")) {
this.pickUp = npc;
return true;
} else {
return false;
}
}
public boolean setTurnIn(String npc) {
if (npc.matches("^[a-zA-Z0-9]+$")) {
this.turnIn = npc;
return true;
} else {
return false;
}
}
public boolean setPrereq(String q) {
if (q.matches("^[a-zA-Z0-9]+$")) {
this.prereq = q;
return true;
} else {
return false;
}
}
/**
* @param rankReq the rankReq to set
*/
public boolean setRankReq(String rankReq) {
if (rankReq.matches("^[a-zA-Z0-9]+$")) {
this.rankReq = rankReq;
return true;
} else {
return false;
}
}
/**
* @param rankReward the rankReward to set
*/
public boolean setRankReward(String rankReward) {
if (rankReward.matches("^[a-zA-Z0-9]+$")) {
etc.getInstance();
Group g = etc.getDataSource().getGroup(rankReward);
if (g != null) {
this.rankReward = rankReward;
return true;
}
return false;
} else {
return false;
}
}
public boolean setItemsProvided(String i) {
if (i.matches("[a-zA-Z0-9\\- ]+:([0-9]+ [0-9]+,)*[0-9]+ [0-9]+")) {
this.itemsProvidedStr = i;
return true;
} else {
return false;
}
}
public boolean setRewards(String i) {
if (i.matches("[a-zA-Z0-9\\- ]+:([0-9]+ [0-9]+,)*[0-9]+ [0-9]+")) {
this.rewardsStr = i;
return true;
} else {
return false;
}
}
public boolean setData(String d) {
if (type == null || type.equals("")) {
return false;
} else {
String regex;
if (type.equals("gather") || type.equals("harvest") || type.equals("build")) {
regex = "([a-zA-Z0-9 ]+,[0-9]+,[0-9]+:)*[a-zA-Z0-9 ]+,[0-9]+,[0-9]+";
} else if (type.equals("findloc")) {
regex = ".+";
} else if (type.equals("fetchblock")) {
regex = "([0-9]+ [0-9]+,[0-9]+,[0-9]+:)*[0-9]+ [0-9]+,[0-9]+,[0-9]+";
} else {
return false;
}
if (d.matches(regex)) {
data = d;
return true;
} else {
return false;
}
}
}
public boolean save(Player p) {
if (id == null || id.equals("")) {
p.sendMessage("Missing id");
return false;
} else if (name == null || name.equals("")) {
p.sendMessage("Missing name");
return false;
} else if (type == null || type.equals("")) {
p.sendMessage("Missing type");
return false;
} else if (desc == null || desc.equals("")) {
p.sendMessage("Missing desc");
return false;
} else if (pickUp == null || pickUp.equals("")) {
p.sendMessage("Missing start npc");
return false;
} else if (turnIn == null || turnIn.equals("")) {
p.sendMessage("Missing end npc");
return false;
} else {
Craftizens.data.saveQuest(this);
return true;
}
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getDesc() {
return desc;
}
public String getItemsProvidedStr() {
return itemsProvidedStr;
}
public String getRewardsStr() {
return rewardsStr;
}
public String getLocation() {
return location;
}
public String getData() {
return data;
}
}