46 private static final short FULL = 16_383;
47 private static final short ZULRAH_SCALES = 12_934;
48 private static final short UNCHARGED_BLOWPIPE = 12_924;
49 private static final short CHARGED_BLOWPIPE = 12_926;
50 private static final DecimalFormat FORMATTER =
new DecimalFormat(
"#.#");
52 public ToxicBlowpipe() {
53 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
58 return "Toxic Blowpipe";
62 public boolean itemOnItem(
Player player, Item first, Item second) {
65 if ((first.getId() == UNCHARGED_BLOWPIPE && second.getId() != ZULRAH_SCALES)
66 || (second.getId() == UNCHARGED_BLOWPIPE && first.getId() != ZULRAH_SCALES)) {
67 player.send(
new SendMessage(
"You can't load an uncharged blowpipe!"));
71 if (first.getId() == UNCHARGED_BLOWPIPE || first.getId() == CHARGED_BLOWPIPE) {
75 if (item.getId() == ZULRAH_SCALES) {
80 RangedAmmunition ammo = RangedAmmunition.find(
null, item);
81 if (ammo ==
null || !ammo.isDart()) {
82 player.send(
new SendMessage(
"You can't load your blowpipe with this!"));
94 }
else if (opcode == 3) {
101 public boolean equipment(
Player player, Item item,
int opcode) {
109 public boolean drop(
Player player, Item item) {
114 public static void check(Player player) {
115 String ammo =
"None";
116 if (player.blowpipeDarts !=
null && player.blowpipeDarts.getAmount() > 0)
117 ammo = player.blowpipeDarts.getName() +
" x " + player.blowpipeDarts.getAmount();
118 String scales = FORMATTER.format(player.blowpipeScales * 100 / FULL) +
"%";
119 player.send(
new SendMessage(
"Darts: <col=007F00>" + ammo +
"</col>. Charges: <col=007F00>" + scales));
122 private static void unload(Player player, Item item) {
123 if (item.getId() == 12924) {
124 int current = player.inventory.computeAmountForId(ZULRAH_SCALES);
125 if (Integer.MAX_VALUE - current < 20_000) {
126 player.send(
new SendMessage(
"You need to deposit some of your scales first."));
130 player.inventory.remove(item);
131 player.inventory.add(
new Item(ZULRAH_SCALES, 20_000));
132 player.send(
new SendMessage(
"You dismantle your blowpipe and receive 20,000 of Zulra's scales."));
134 if (player.inventory.getFreeSlots() < 1) {
135 player.send(
new SendMessage(
"You need at least one free slot to unload your blowpipe."));
139 Item darts = player.blowpipeDarts;
141 player.send(
new SendMessage(
"You have no darts to unload."));
145 player.inventory.add(darts);
146 player.blowpipeDarts =
null;
147 player.send(
new SendMessage(
"You unload the darts out of your blowpipe."));
151 private static void charge(Player player, Item scales) {
152 if (player.blowpipeScales >= FULL) {
153 player.send(
new SendMessage(
"Your blowpipe is already fully charged."));
157 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
158 scales = scales.copy();
159 scales.setAmount((
int) (FULL - player.blowpipeScales));
162 if (player.blowpipeScales + scales.getAmount() > FULL) {
163 scales = scales.copy();
164 scales.setAmount((
int) (FULL - player.blowpipeScales));
167 player.blowpipeScales += scales.getAmount();
168 player.inventory.remove(scales);
169 player.inventory.replace(UNCHARGED_BLOWPIPE, CHARGED_BLOWPIPE,
true);
170 player.send(
new SendMessage(String.format(
"You load %s scales into your blowpipe.", Utility.formatDigits(scales.getAmount()))));
173 private static void uncharge(Player player) {
174 if (player.blowpipeScales <= 0) {
175 player.send(
new SendMessage(
"Your blowpipe doesn't have any charges."));
179 if (player.blowpipeDarts !=
null && player.blowpipeDarts.getAmount() > 0) {
180 player.send(
new SendMessage(
"You need to unload your blowpipe first."));
184 Item scales =
new Item(ZULRAH_SCALES, (
int) player.blowpipeScales);
185 if (!player.inventory.hasCapacityFor(scales)) {
186 player.send(
new SendMessage(
"You need more inventory space to do this."));
190 player.blowpipeScales = 0;
191 player.inventory.add(scales);
192 player.inventory.replace(CHARGED_BLOWPIPE, UNCHARGED_BLOWPIPE,
true);
193 player.send(
new SendMessage(String.format(
"You uncharged your blowpipe and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount()))));
196 private static void load(Player player, Item ammo) {
197 if (player.blowpipeDarts !=
null && player.blowpipeDarts.getAmount() >= FULL) {
198 player.send(
new SendMessage(
"Your blowpipe is already fully loaded."));
202 if (ammo.getAmount() > FULL) {
203 ammo =
new Item(ammo.getId(), FULL);
206 if (player.blowpipeDarts ==
null) {
207 player.blowpipeDarts = ammo;
208 player.inventory.remove(ammo);
209 player.send(
new SendMessage(String.format(
"You load your blowpipe with %s %ss.", Utility.formatDigits(ammo.getAmount()), ammo.getName())));
213 if (player.blowpipeDarts.getId() != ammo.getId()) {
214 player.send(
new SendMessage(
"You need to unload your blowpipe before adding a different type of dart!"));
219 if (player.blowpipeDarts.getAmount() + ammo.getAmount() > FULL) {
220 remove = FULL - player.blowpipeDarts.getAmount();
222 remove = ammo.getAmount();
225 player.blowpipeDarts.incrementAmountBy(
remove);
226 player.inventory.remove(ammo.getId(),
remove);
227 player.send(
new SendMessage(String.format(
"You load your blowpipe with %s %s.", Utility.formatDigits(ammo.getAmount()), ammo.getName())));