RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
MagmaHelm.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 MagmaHelm 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_198;
53 private static final short CHARGED_HELM = 13_199;
54
55 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
56
57 public MagmaHelm() {
58 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
59 }
60
61 @Override
62 public String name() {
63 return "Magma 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 return true;
87 }
88
89 if (opcode == 2) {
90 check(player);
91 }
92
93 return true;
94 }
95
96 @Override
97 public boolean equipment(Player player, Item item, int opcode) {
98 if (opcode == 1) {
99 check(player);
100 }
101 return true;
102 }
103
104 @Override
105 public boolean drop(Player player, Item item) {
106 if (item.matchesId(CHARGED_HELM)) {
107 uncharge(player);
108 return true;
109 }
110 return false;
111 }
112
113 public static void check(Player player) {
114 String scales = FORMATTER.format(player.magmaHelmCharges * 100 / FULL) + "%";
115 player.message("Charges: <col=007F00>" + scales);
116 }
117
118 private static void charge(Player player, Item helm, Item scales) {
119 if (player.magmaHelmCharges >= FULL) {
120 if (helm.matchesId(UNCHARGED_HELM)) {
121 player.inventory.replace(UNCHARGED_HELM, CHARGED_HELM, true);
122 }
123 player.message("Your Magma helm is already fully charged.");
124 return;
125 }
126
127 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
128 scales = scales.copy();
129 scales.setAmount(FULL - player.magmaHelmCharges);
130 }
131
132 if (player.magmaHelmCharges + scales.getAmount() > FULL) {
133 scales = scales.copy();
134 scales.setAmount(FULL - player.magmaHelmCharges);
135 }
136
137 player.magmaHelmCharges += scales.getAmount();
138 player.inventory.remove(scales);
139 player.inventory.replace(UNCHARGED_HELM, CHARGED_HELM, true);
140 player.message(String.format("You load %s scales into your Magma helm.", Utility.formatDigits(scales.getAmount())));
141 }
142
143 private static void uncharge(Player player) {
144 Item scales = new Item(ZULRAH_SCALES, player.magmaHelmCharges);
145
146 if (!player.inventory.hasCapacityFor(scales)) {
147 player.send(new SendMessage("You need more inventory space to do this."));
148 return;
149 }
150
151 player.magmaHelmCharges = 0;
152 player.inventory.add(scales);
153 player.inventory.replace(CHARGED_HELM, UNCHARGED_HELM, true);
154 player.message(String.format("You uncharged your Magma helm and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount())));
155 }
156
157 private static void restore(Player player, Item item) {
158 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
159 player.send(new SendString("Are you sure you want to restore this item?", 14174));
160 player.send(new SendString("Yes.", 14175));
161 player.send(new SendString("No.", 14176));
162 player.send(new SendString("", 14177));
163 player.send(new SendString("This will replace your helm with the original Serpentine helm.", 14182));
164 player.send(new SendString("", 14183));
165 player.send(new SendString(item.getName(), 14184));
166 player.send(new SendChatBoxInterface(14170));
167 player.attributes.set("RESTORE_HELM_KEY", item);
168 }
169
170}
boolean inventory(Player player, Item item, int opcode)