RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TanzaniteHelm.java
1package com.osroyale.content.itemaction.impl;
2
3import com.osroyale.content.itemaction.ItemAction;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.items.Item;
6import com.osroyale.net.packet.out.SendChatBoxInterface;
7import com.osroyale.net.packet.out.SendItemOnInterfaceSlot;
8import com.osroyale.net.packet.out.SendMessage;
9import com.osroyale.net.packet.out.SendString;
10import com.osroyale.util.Utility;
11
12import java.math.RoundingMode;
13import java.text.DecimalFormat;
14
46
47public class TanzaniteHelm extends ItemAction {
48 private static final short FULL = 11_000;
49
50 private static final short ZULRAH_SCALES = 12_934;
51
52 private static final short UNCHARGED_HELM = 13_196;
53 private static final short CHARGED_HELM = 13_197;
54
55 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
56
57 public TanzaniteHelm() {
58 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
59 }
60
61 @Override
62 public String name() {
63 return "Tanzanite Helm";
64 }
65
66 @Override
67 public boolean itemOnItem(Player player, Item first, Item second) {
68 Item item = first;
69
70 if (first.getId() == UNCHARGED_HELM || first.getId() == CHARGED_HELM) {
71 item = second;
72 }
73
74 if (item.getId() == ZULRAH_SCALES) {
75 charge(player, item.equals(first) ? second : first, item);
76 return true;
77 }
78
79 return false;
80 }
81
82 @Override
83 public boolean inventory(Player player, Item item, int opcode) {
84 if (opcode == 3) {
85 restore(player, item);
86 } else if (opcode == 2) {
87 check(player);
88 }
89
90 return true;
91 }
92
93 @Override
94 public boolean equipment(Player player, Item item, int opcode) {
95 if (opcode == 1) {
96 check(player);
97 }
98 return true;
99 }
100
101 @Override
102 public boolean drop(Player player, Item item) {
103 if (item.matchesId(CHARGED_HELM)) {
104 uncharge(player);
105 return true;
106 }
107 return false;
108 }
109
110 public static void check(Player player) {
111 String scales = FORMATTER.format(player.tanzaniteHelmCharges * 100 / FULL) + "%";
112 player.message("Charges: <col=007F00>" + scales);
113 }
114
115 private static void charge(Player player, Item helm, Item scales) {
116 if (player.tanzaniteHelmCharges >= FULL) {
117 if (helm.matchesId(UNCHARGED_HELM)) {
118 player.inventory.replace(UNCHARGED_HELM, CHARGED_HELM, true);
119 }
120 player.message("Your Tanzanite helm is already fully charged.");
121 return;
122 }
123
124 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
125 scales = scales.copy();
126 scales.setAmount(FULL - player.tanzaniteHelmCharges);
127 }
128
129 if (player.tanzaniteHelmCharges + scales.getAmount() > FULL) {
130 scales = scales.copy();
131 scales.setAmount(FULL - player.tanzaniteHelmCharges);
132 }
133
134 player.tanzaniteHelmCharges += scales.getAmount();
135 player.inventory.remove(scales);
136 player.inventory.replace(UNCHARGED_HELM, CHARGED_HELM, true);
137 player.message(String.format("You load %s scales into your Tanzanite helm.", Utility.formatDigits(scales.getAmount())));
138 }
139
140 private static void uncharge(Player player) {
141 Item scales = new Item(ZULRAH_SCALES, player.tanzaniteHelmCharges);
142
143 if (!player.inventory.hasCapacityFor(scales)) {
144 player.send(new SendMessage("You need more inventory space to do this."));
145 return;
146 }
147
148 player.tanzaniteHelmCharges = 0;
149 player.inventory.add(scales);
150 player.inventory.replace(CHARGED_HELM, UNCHARGED_HELM, true);
151 player.message(String.format("You uncharged your Tanzanite helm and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount())));
152 }
153
154 private static void restore(Player player, Item item) {
155 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
156 player.send(new SendString("Are you sure you want to restore this item?", 14174));
157 player.send(new SendString("Yes.", 14175));
158 player.send(new SendString("No.", 14176));
159 player.send(new SendString("", 14177));
160 player.send(new SendString("This will replace your helm with the original Serpentine helm.", 14182));
161 player.send(new SendString("", 14183));
162 player.send(new SendString(item.getName(), 14184));
163 player.send(new SendChatBoxInterface(14170));
164 player.attributes.set("RESTORE_HELM_KEY", item);
165 }
166
167}
boolean inventory(Player player, Item item, int opcode)