RuneHive-Game
Loading...
Searching...
No Matches
MagmaHelm.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.mob.player.Player;
5import com.runehive.game.world.items.Item;
6import com.runehive.net.packet.out.SendChatBoxInterface;
7import com.runehive.net.packet.out.SendItemOnInterfaceSlot;
8import com.runehive.net.packet.out.SendMessage;
9import com.runehive.net.packet.out.SendString;
10import com.runehive.util.Utility;
11
12import java.math.RoundingMode;
13import java.text.DecimalFormat;
14
15public class MagmaHelm extends ItemAction {
16 private static final short FULL = 11_000;
17
18 private static final short ZULRAH_SCALES = 12_934;
19
20 private static final short UNCHARGED_HELM = 13_198;
21 private static final short CHARGED_HELM = 13_199;
22
23 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
24
25 public MagmaHelm() {
26 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
27 }
28
29 @Override
30 public String name() {
31 return "Magma helm";
32 }
33
34 @Override
35 public boolean itemOnItem(Player player, Item first, Item second) {
36 Item item = first;
37
38 if (first.getId() == UNCHARGED_HELM || first.getId() == CHARGED_HELM) {
39 item = second;
40 }
41
42 if (item.getId() == ZULRAH_SCALES) {
43 charge(player, item.equals(first) ? second : first, item);
44 return true;
45 }
46
47 return false;
48 }
49
50 @Override
51 public boolean inventory(Player player, Item item, int opcode) {
52 if (opcode == 3) {
53 restore(player, item);
54 return true;
55 }
56
57 if (opcode == 2) {
58 check(player);
59 }
60
61 return true;
62 }
63
64 @Override
65 public boolean equipment(Player player, Item item, int opcode) {
66 if (opcode == 1) {
67 check(player);
68 }
69 return true;
70 }
71
72 @Override
73 public boolean drop(Player player, Item item) {
74 if (item.matchesId(CHARGED_HELM)) {
75 uncharge(player);
76 return true;
77 }
78 return false;
79 }
80
81 public static void check(Player player) {
82 String scales = FORMATTER.format(player.magmaHelmCharges * 100 / FULL) + "%";
83 player.message("Charges: <col=007F00>" + scales);
84 }
85
86 private static void charge(Player player, Item helm, Item scales) {
87 if (player.magmaHelmCharges >= FULL) {
88 if (helm.matchesId(UNCHARGED_HELM)) {
90 }
91 player.message("Your Magma helm is already fully charged.");
92 return;
93 }
94
95 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
96 scales = scales.copy();
97 scales.setAmount(FULL - player.magmaHelmCharges);
98 }
99
100 if (player.magmaHelmCharges + scales.getAmount() > FULL) {
101 scales = scales.copy();
102 scales.setAmount(FULL - player.magmaHelmCharges);
103 }
104
105 player.magmaHelmCharges += scales.getAmount();
106 player.inventory.remove(scales);
108 player.message(String.format("You load %s scales into your Magma helm.", Utility.formatDigits(scales.getAmount())));
109 }
110
111 private static void uncharge(Player player) {
112 Item scales = new Item(ZULRAH_SCALES, player.magmaHelmCharges);
113
114 if (!player.inventory.hasCapacityFor(scales)) {
115 player.send(new SendMessage("You need more inventory space to do this."));
116 return;
117 }
118
119 player.magmaHelmCharges = 0;
120 player.inventory.add(scales);
122 player.message(String.format("You uncharged your Magma helm and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount())));
123 }
124
125 private static void restore(Player player, Item item) {
126 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
127 player.send(new SendString("Are you sure you want to restore this item?", 14174));
128 player.send(new SendString("Yes.", 14175));
129 player.send(new SendString("No.", 14176));
130 player.send(new SendString("", 14177));
131 player.send(new SendString("This will replace your helm with the original Serpentine helm.", 14182));
132 player.send(new SendString("", 14183));
133 player.send(new SendString(item.getName(), 14184));
134 player.send(new SendChatBoxInterface(14170));
135 player.attributes.set("RESTORE_HELM_KEY", item);
136 }
137
138}
Handles executing an item action.
boolean equipment(Player player, Item item, int opcode)
boolean drop(Player player, Item item)
static void restore(Player player, Item item)
boolean itemOnItem(Player player, Item first, Item second)
String name()
The name of the action.
static void charge(Player player, Item helm, Item scales)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
final GenericAttributes attributes
Definition Mob.java:95
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
boolean equals(Object obj)
Definition Item.java:475
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.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
public< K, E > void set(K key, E attribute)
Sets a generic attribute.