RuneHive-Game
Loading...
Searching...
No Matches
ToxicBlowpipe.java
Go to the documentation of this file.
1package com.runehive.content.itemaction.impl;
2
3import com.runehive.content.itemaction.ItemAction;
4import com.runehive.game.world.entity.combat.ranged.RangedAmmunition;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.Item;
7import com.runehive.net.packet.out.SendMessage;
8import com.runehive.util.Utility;
9
10import java.math.RoundingMode;
11import java.text.DecimalFormat;
12
13public class ToxicBlowpipe extends ItemAction {
14 private static final short FULL = 16_383;
15 private static final short ZULRAH_SCALES = 12_934;
16 private static final short UNCHARGED_BLOWPIPE = 12_924;
17 private static final short CHARGED_BLOWPIPE = 12_926;
18 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
19
20 public ToxicBlowpipe() {
21 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
22 }
23
24 @Override
25 public String name() {
26 return "Toxic Blowpipe";
27 }
28
29 @Override
30 public boolean itemOnItem(Player player, Item first, Item second) {
31 Item item = first;
32
33 if ((first.getId() == UNCHARGED_BLOWPIPE && second.getId() != ZULRAH_SCALES)
34 || (second.getId() == UNCHARGED_BLOWPIPE && first.getId() != ZULRAH_SCALES)) {
35 player.send(new SendMessage("You can't load an uncharged blowpipe!"));
36 return true;
37 }
38
39 if (first.getId() == UNCHARGED_BLOWPIPE || first.getId() == CHARGED_BLOWPIPE) {
40 item = second;
41 }
42
43 if (item.getId() == ZULRAH_SCALES) {
44 charge(player, item);
45 return true;
46 }
47
48 RangedAmmunition ammo = RangedAmmunition.find(null, item);
49 if (ammo == null || !ammo.isDart()) {
50 player.send(new SendMessage("You can't load your blowpipe with this!"));
51 return true;
52 }
53
54 load(player, item);
55 return true;
56 }
57
58 @Override
59 public boolean inventory(Player player, Item item, int opcode) {
60 if (opcode == 2) {
61 check(player);
62 } else if (opcode == 3) {
63 unload(player, item);
64 }
65 return true;
66 }
67
68 @Override
69 public boolean equipment(Player player, Item item, int opcode) {
70 if (opcode == 1) {
71 check(player);
72 }
73 return true;
74 }
75
76 @Override
77 public boolean drop(Player player, Item item) {
78 uncharge(player);
79 return true;
80 }
81
82 public static void check(Player player) {
83 String ammo = "None";
84 if (player.blowpipeDarts != null && player.blowpipeDarts.getAmount() > 0)
85 ammo = player.blowpipeDarts.getName() + " x " + player.blowpipeDarts.getAmount();
86 String scales = FORMATTER.format(player.blowpipeScales * 100 / FULL) + "%";
87 player.send(new SendMessage("Darts: <col=007F00>" + ammo + "</col>. Charges: <col=007F00>" + scales));
88 }
89
90 private static void unload(Player player, Item item) {
91 if (item.getId() == 12924) {
92 int current = player.inventory.computeAmountForId(ZULRAH_SCALES);
93 if (Integer.MAX_VALUE - current < 20_000) {
94 player.send(new SendMessage("You need to deposit some of your scales first."));
95 return;
96 }
97
98 player.inventory.remove(item);
99 player.inventory.add(new Item(ZULRAH_SCALES, 20_000));
100 player.send(new SendMessage("You dismantle your blowpipe and receive 20,000 of Zulra's scales."));
101 } else {
102 if (player.inventory.getFreeSlots() < 1) {
103 player.send(new SendMessage("You need at least one free slot to unload your blowpipe."));
104 return;
105 }
106
107 Item darts = player.blowpipeDarts;
108 if (darts == null) {
109 player.send(new SendMessage("You have no darts to unload."));
110 return;
111 }
112
113 player.inventory.add(darts);
114 player.blowpipeDarts = null;
115 player.send(new SendMessage("You unload the darts out of your blowpipe."));
116 }
117 }
118
119 private static void charge(Player player, Item scales) {
120 if (player.blowpipeScales >= FULL) {
121 player.send(new SendMessage("Your blowpipe is already fully charged."));
122 return;
123 }
124
125 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
126 scales = scales.copy();
127 scales.setAmount((int) (FULL - player.blowpipeScales));
128 }
129
130 if (player.blowpipeScales + scales.getAmount() > FULL) {
131 scales = scales.copy();
132 scales.setAmount((int) (FULL - player.blowpipeScales));
133 }
134
135 player.blowpipeScales += scales.getAmount();
136 player.inventory.remove(scales);
138 player.send(new SendMessage(String.format("You load %s scales into your blowpipe.", Utility.formatDigits(scales.getAmount()))));
139 }
140
141 private static void uncharge(Player player) {
142 if (player.blowpipeScales <= 0) {
143 player.send(new SendMessage("Your blowpipe doesn't have any charges."));
144 return;
145 }
146
147 if (player.blowpipeDarts != null && player.blowpipeDarts.getAmount() > 0) {
148 player.send(new SendMessage("You need to unload your blowpipe first."));
149 return;
150 }
151
152 Item scales = new Item(ZULRAH_SCALES, (int) player.blowpipeScales);
153 if (!player.inventory.hasCapacityFor(scales)) {
154 player.send(new SendMessage("You need more inventory space to do this."));
155 return;
156 }
157
158 player.blowpipeScales = 0;
159 player.inventory.add(scales);
161 player.send(new SendMessage(String.format("You uncharged your blowpipe and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount()))));
162 }
163
164 private static void load(Player player, Item ammo) {
165 if (player.blowpipeDarts != null && player.blowpipeDarts.getAmount() >= FULL) {
166 player.send(new SendMessage("Your blowpipe is already fully loaded."));
167 return;
168 }
169
170 if (ammo.getAmount() > FULL) {
171 ammo = new Item(ammo.getId(), FULL);
172 }
173
174 if (player.blowpipeDarts == null) {
175 player.blowpipeDarts = ammo;
176 player.inventory.remove(ammo);
177 player.send(new SendMessage(String.format("You load your blowpipe with %s %ss.", Utility.formatDigits(ammo.getAmount()), ammo.getName())));
178 return;
179 }
180
181 if (player.blowpipeDarts.getId() != ammo.getId()) {
182 player.send(new SendMessage("You need to unload your blowpipe before adding a different type of dart!"));
183 return;
184 }
185
186 int remove;
187 if (player.blowpipeDarts.getAmount() + ammo.getAmount() > FULL) {
188 remove = FULL - player.blowpipeDarts.getAmount();
189 } else {
190 remove = ammo.getAmount();
191 }
192
193 player.blowpipeDarts.incrementAmountBy(remove);
194 player.inventory.remove(ammo.getId(), remove);
195 player.send(new SendMessage(String.format("You load your blowpipe with %s %s.", Utility.formatDigits(ammo.getAmount()), ammo.getName())));
196 }
197
198}
Handles executing an item action.
boolean equipment(Player player, Item item, int opcode)
boolean itemOnItem(Player player, Item first, Item second)
static void unload(Player player, Item item)
static void load(Player player, Item ammo)
static void charge(Player player, Item scales)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void setAmount(int amount)
Sets the quantity of this item.
Definition Item.java:351
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
Item copy()
A substitute for Object#clone() that creates another 'copy' of this instance.
Definition Item.java:270
final void incrementAmountBy(int amount)
Increments the amount by amount.
Definition Item.java:293
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean add(Item item)
Attempts to deposit item into this container.
final boolean replace(int oldId, int newId, int index, boolean refresh)
Replaces the first occurrence of the Item having the identifier oldId with newId.
final boolean hasCapacityFor(Item... item)
Determines if this container has the capacity for item.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static RangedAmmunition find(Item weapon, Item item)