-
Notifications
You must be signed in to change notification settings - Fork 5
/
GatherQuest.java
81 lines (68 loc) · 1.94 KB
/
GatherQuest.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
import java.util.ArrayList;
public class GatherQuest extends Quest {
ArrayList<Integer> types;
String [] names;
int [] quantities;
public GatherQuest(QuestInfo info, Player player, boolean newQuest) {
super(info, player, newQuest);
// get harvest 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];
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]);
}
}
public boolean isComplete() {
for (int i = 0; i < types.size(); i++) {
if (countItems(types.get(i)) < quantities[i]) {
return false;
}
}
return true;
}
public int countItems(int itemId) {
Inventory inv = player.getInventory();
int amt = 0;
for (int i = 0; i < inv.getArray().length; i++) {
Item item = inv.getItemFromSlot(i);
if (item != null && item.getItemId() == itemId) {
amt += item.getAmount();
}
}
return amt;
}
public void complete() {
Inventory inv = player.getInventory();
for (int i = 0; i < types.size(); i++) {
inv.removeItem(new Item(types.get(i), quantities[i]));
}
inv.updateInventory();
super.complete();
}
public String getProgress() {
String prog = "";
if (isComplete()) {
prog += "Complete!";
} else if (types.size() == 1) {
int amt = countItems(types.get(0));
prog += (amt>quantities[0]?quantities[0]:amt) + "/" + quantities[0] + " " + names[0];
} else {
for (int i = 0; i < types.size(); i++) {
int amt = countItems(types.get(i));
prog += "@" + (amt>quantities[i]?quantities[i]:amt) + "/" + quantities[i] + " " + names[i];
}
}
return prog;
}
public void loadProgress(String s) {
// no progress to load
}
public void saveProgress() {
// no need to save progress
}
}