44 static Map<String, Cannon> ACTIVE_CANNONS =
new HashMap<>();
55 public enum Rotation {
66 public static void test(
Player player) {
71 if (ACTIVE_CANNONS.containsKey(player.
getName())) {
72 player.send(
new SendMessage(
"You already have a cannon active!"));
75 if(
Area.inCatacombs(player)) {
76 player.send(
new SendMessage(
"You cannot set up a cannon here!"));
80 if (cannon.getStage().ordinal() != 0) {
81 player.send(
new SendMessage(
"You have already started setting up a cannon!"));
85 for (
Cannon other : ACTIVE_CANNONS.values()) {
86 if (other.getPosition().isWithinDistance(player.
getPosition(), 5)) {
87 player.send(
new SendMessage(
"You are trying to build too close to another cannon!"));
95 public static void pickup(
Player player) {
99 player.send(
new SendMessage(
"This is not your cannon!"));
103 if (!cannon.getOwner().equalsIgnoreCase(player.
getName())) {
104 player.send(
new SendMessage(
"This is not your cannon!"));
110 if(cannon.getAmmunition() != 0)
111 player.inventory.
add(
new Item(2, cannon.getAmmunition()));
113 int[] ids = { 6, 8, 10, 12 };
114 for(
int index = 0; index < ids.length; index++)
115 player.inventory.
add(
new Item(ids[index]));
118 ACTIVE_CANNONS.remove(player.
getName());
121 public static void empty(
Player player) {
124 if (cannon ==
null) {
125 player.send(
new SendMessage(
"This is not your cannon!"));
129 if (!cannon.getOwner().equalsIgnoreCase(player.
getName())) {
130 player.send(
new SendMessage(
"This is not your cannon!"));
134 if(cannon.getAmmunition() != 0)
135 player.inventory.
add(
new Item(2, cannon.getAmmunition()));
137 cannon.setFiring(
false);
138 cannon.setAmmunition(0);
141 public static void logout(
Player player) {
144 if(cannon ==
null)
return;
147 if(cannon.getAmmunition() != 0)
148 player.inventory.
add(
new Item(2, cannon.getAmmunition()));
150 int[] ids = { 6, 8, 10, 12 };
151 for(
int index = 0; index < ids.length; index++)
152 player.inventory.
add(
new Item(ids[index]));
155 ACTIVE_CANNONS.remove(player.
getName());
158 public static void load(
Player player) {
161 if (cannon ==
null) {
162 player.send(
new SendMessage(
"This is not your cannon!"));
166 if (!cannon.getOwner().equalsIgnoreCase(player.
getName())) {
167 player.send(
new SendMessage(
"This is not your cannon!"));
171 if (!player.inventory.
contains(2)) {
172 player.send(
new SendMessage(
"You do not have any Cannon balls."));
176 int needed = 30 - cannon.getAmmunition();
179 player.send(
new SendMessage(
"Your cannon is full."));
185 if (cannon_balls <= needed) {
186 player.inventory.
remove(2, cannon_balls);
187 player.send(
new SendMessage(
"You load the last of your cannon balls"));
188 cannon.setAmmunition(cannon.getAmmunition() + cannon_balls);
190 player.inventory.
remove(2, needed);
191 player.send(
new SendMessage(
"You load " + needed +
" balls into the cannon."));
192 cannon.setAmmunition(cannon.getAmmunition() + needed);
195 if (cannon.isFiring()) {
196 player.send(
new SendMessage(
"The cannon is already firing!"));
200 cannon.setFiring(
true);
206 p.setStartHeight(50);
211 public static Npc[] getNpc(
Cannon cannon) {
212 ArrayList<Npc> attack =
new ArrayList<>();
219 if (!
Utility.withinDistance(npc, cannon,
Region.VIEW_DISTANCE)) {
223 if (!npc.definition.isAttackable()) {
230 Npc[] npc =
new Npc[attack.size()];
232 for (
int i = 0; i < npc.
length; i++) {
233 npc[i] = attack.get(i);
239 public static void rotate(
Cannon cannon) {
240 switch (cannon.getRotation()) {