RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ToxicBlowpipe.java
1package com.osroyale.content.itemaction.impl;
2
3import com.osroyale.content.itemaction.ItemAction;
4import com.osroyale.game.world.entity.combat.ranged.RangedAmmunition;
5import com.osroyale.game.world.entity.mob.player.Player;
6import com.osroyale.game.world.items.Item;
7import com.osroyale.net.packet.out.SendMessage;
8import com.osroyale.util.Utility;
9
10import java.math.RoundingMode;
11import java.text.DecimalFormat;
12
44
45public class ToxicBlowpipe extends ItemAction {
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("#.#");
51
52 public ToxicBlowpipe() {
53 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
54 }
55
56 @Override
57 public String name() {
58 return "Toxic Blowpipe";
59 }
60
61 @Override
62 public boolean itemOnItem(Player player, Item first, Item second) {
63 Item item = first;
64
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!"));
68 return true;
69 }
70
71 if (first.getId() == UNCHARGED_BLOWPIPE || first.getId() == CHARGED_BLOWPIPE) {
72 item = second;
73 }
74
75 if (item.getId() == ZULRAH_SCALES) {
76 charge(player, item);
77 return true;
78 }
79
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!"));
83 return true;
84 }
85
86 load(player, item);
87 return true;
88 }
89
90 @Override
91 public boolean inventory(Player player, Item item, int opcode) {
92 if (opcode == 2) {
93 check(player);
94 } else if (opcode == 3) {
95 unload(player, item);
96 }
97 return true;
98 }
99
100 @Override
101 public boolean equipment(Player player, Item item, int opcode) {
102 if (opcode == 1) {
103 check(player);
104 }
105 return true;
106 }
107
108 @Override
109 public boolean drop(Player player, Item item) {
110 uncharge(player);
111 return true;
112 }
113
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));
120 }
121
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."));
127 return;
128 }
129
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."));
133 } else {
134 if (player.inventory.getFreeSlots() < 1) {
135 player.send(new SendMessage("You need at least one free slot to unload your blowpipe."));
136 return;
137 }
138
139 Item darts = player.blowpipeDarts;
140 if (darts == null) {
141 player.send(new SendMessage("You have no darts to unload."));
142 return;
143 }
144
145 player.inventory.add(darts);
146 player.blowpipeDarts = null;
147 player.send(new SendMessage("You unload the darts out of your blowpipe."));
148 }
149 }
150
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."));
154 return;
155 }
156
157 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
158 scales = scales.copy();
159 scales.setAmount((int) (FULL - player.blowpipeScales));
160 }
161
162 if (player.blowpipeScales + scales.getAmount() > FULL) {
163 scales = scales.copy();
164 scales.setAmount((int) (FULL - player.blowpipeScales));
165 }
166
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()))));
171 }
172
173 private static void uncharge(Player player) {
174 if (player.blowpipeScales <= 0) {
175 player.send(new SendMessage("Your blowpipe doesn't have any charges."));
176 return;
177 }
178
179 if (player.blowpipeDarts != null && player.blowpipeDarts.getAmount() > 0) {
180 player.send(new SendMessage("You need to unload your blowpipe first."));
181 return;
182 }
183
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."));
187 return;
188 }
189
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()))));
194 }
195
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."));
199 return;
200 }
201
202 if (ammo.getAmount() > FULL) {
203 ammo = new Item(ammo.getId(), FULL);
204 }
205
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())));
210 return;
211 }
212
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!"));
215 return;
216 }
217
218 int remove;
219 if (player.blowpipeDarts.getAmount() + ammo.getAmount() > FULL) {
220 remove = FULL - player.blowpipeDarts.getAmount();
221 } else {
222 remove = ammo.getAmount();
223 }
224
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())));
228 }
229
230}
boolean inventory(Player player, Item item, int opcode)