-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathQuest.java
166 lines (136 loc) · 3.56 KB
/
Quest.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.awt.Polygon;
public abstract class Quest {
protected QuestInfo info;
protected Player player;
protected Polygon boundary;
public Quest(QuestInfo info, Player player, boolean newQuest) {
this.info = info;
this.player = player;
// get boundary
if (info.location != null && !info.location.equals("")) {
String [] points = info.location.split(":");
int [] x = new int [points.length];
int [] z = new int [points.length];
for (int i = 0; i < points.length; i++) {
String [] coords = points[i].split(",");
x[i] = Integer.parseInt(coords[0]);
z[i] = Integer.parseInt(coords[1]);
}
boundary = new Polygon(x,z,points.length);
}
if (newQuest) {
giveItemsProvided();
}
}
private void giveItemsProvided() {
if (info.itemsProvided != null) {
for (Integer i : info.itemsProvided.keySet()) {
player.giveItem(i, info.itemsProvided.get(i));
}
}
}
protected void giveRewards() {
if (info.rewards != null) {
for (Integer i : info.rewards.keySet()) {
player.giveItem(i, info.rewards.get(i));
}
}
if (info.rankReward != null) {
setRank(player, info.rankReward);
}
}
private void setRank(Player p, String rank) {
etc.getInstance();
Group g = etc.getDataSource().getGroup(rank);
if (g != null) {
String[] arrayOfString = { g.Name };
p.setGroups(arrayOfString);
p.setIgnoreRestrictions(g.IgnoreRestrictions);
p.setAdmin(g.Administrator);
int i = 0;
if (!etc.getDataSource().doesPlayerExist(p.getName())) {
i = 1;
}
if (i != 0)
etc.getDataSource().addPlayer(p);
else
etc.getDataSource().modifyPlayer(p);
} else {
p.sendMessage("Error setting rank. Please contact your local admin.");
}
}
protected void complete() {
giveRewards();
String [] text;
if (info.completionText != null && !info.completionText.equals("")) {
text = info.completionText.split("@");
} else {
text = new String [] {"Quest completed!"};
}
for (String s : text) {
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);
}
}
public boolean compass() {
if (boundary != null) {
int [] x = boundary.xpoints;
int [] y = boundary.ypoints;
int i, j;
int n = x.length;
// first calculate area
double area = 0;
for (i = 0; i < n; i++) {
j = (i+1) % n;
area += ((x[i]*y[j]) - (x[j]*y[i]));
}
area /= 2;
// get cx and cy
int cx = 0, cy = 0;
for (i = 0; i < n; i++) {
j = (i+1) % n;
cx += ((x[i]+x[j]) * (x[i]*y[j] - x[j]*y[i]));
cy += ((y[i]+y[j]) * (x[i]*y[j] - x[j]*y[i]));
}
cx /= (6*area);
cy /= (6*area);
player.getUser().a.b(new co((int)cx, (int)player.getY(), (int)cy));
return true;
} else {
return false;
}
}
abstract boolean isComplete();
abstract String getProgress();
abstract void loadProgress(String s);
abstract void saveProgress();
void show(Player player) {
info.show(player);
}
boolean onBlockCreate(Player player, Block placed, Block clicked, int itemInHand) {
return false;
}
boolean onBlockDestroy(Player player, Block block) {
return false;
}
void onPlayerMove(Player player, Location from, Location to) {
return;
}
void onArmSwing(Player player) {
return;
}
String getId() {
return info.getId();
}
String getName() {
return info.getName();
}
String getTurnInNpc() {
return info.turnIn;
}
}