-
Notifications
You must be signed in to change notification settings - Fork 5
/
BuildQuest.java
79 lines (68 loc) · 2.04 KB
/
BuildQuest.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
import java.util.ArrayList;
public class BuildQuest extends Quest {
ArrayList<Integer> types;
String [] names;
int [] quantities;
int [] progress;
public BuildQuest(QuestInfo info, Player player, boolean newQuest) {
super(info, player, newQuest);
// get build info data: format: item name,id,quantity:item name,id,quantity,etc
String [] data = info.getData().split(":");
types = new ArrayList<Integer>();
names = new String [data.length];
quantities = new int [data.length];
progress = new int [data.length];
for (int i = 0; i < data.length; i++) {
String [] item = data[i].split(",");
types.add(Integer.parseInt(item[1]));
names[i] = item[0];
quantities[i] = Integer.parseInt(item[2]);
progress[i] = 0;
}
}
public boolean isComplete() {
for (int i = 0; i < types.size(); i++) {
if (progress[i] < quantities[i]) {
return false;
}
}
return true;
}
public String getProgress() {
String prog = "";
if (isComplete()) {
prog += "Complete!";
} else if (types.size() == 1) {
prog += (progress[0]<quantities[0]?progress[0]:quantities[0]) + "/" + quantities[0] + " " + names[0];
} else {
for (int i = 0; i < progress.length; i++) {
prog += "@" + (progress[i]<quantities[i]?progress[i]:quantities[i]) + "/" + quantities[i] + " " + names[i];
}
}
return prog;
}
public void loadProgress(String s) {
if (s != null) {
String [] prog = s.split(",");
for (int i = 0; i < prog.length; i++) {
progress[i] = Integer.parseInt(prog[i]);
}
} else {
saveProgress();
}
}
public void saveProgress() {
String s = "";
for (int i = 0; i < progress.length; i++) {
s += progress[i] + ",";
}
s = s.substring(0,s.length()-1);
Craftizens.data.saveQuestProgress(player, this, s);
}
boolean onBlockCreate(Player player, Block placed, Block clicked, int itemInHand) {
if (types.contains(placed.getType()) && clicked.getType() == 2 && (boundary == null || boundary.contains(placed.getX(),placed.getZ()))) {
progress[types.indexOf(placed.getType())] += 1;
}
return false;
}
}