RuneHive-Game
Loading...
Searching...
No Matches
SerpentineHelm.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 SerpentineHelm 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 = 12_929;
21 private static final short CHARGED_HELM = 12_931;
22
23 private static final short TANZ_MUTAGEN = 13200;
24 private static final short MAGMA_MUTAGEN = 13201;
25
26 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
27
28 public SerpentineHelm() {
29 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
30 }
31
32 @Override
33 public String name() {
34 return "Serpentine helm";
35 }
36
37 @Override
38 public boolean itemOnItem(Player player, Item first, Item second) {
39 Item item = first;
40
41 if (first.getId() == UNCHARGED_HELM || first.getId() == CHARGED_HELM) {
42 item = second;
43 }
44
45 if ((first.matchesId(CHARGED_HELM) && second.matchesId(TANZ_MUTAGEN))
46 || (second.matchesId(CHARGED_HELM) && first.matchesId(TANZ_MUTAGEN))) {
47 player.message("You need to uncharge your Serpentine helm first.");
48 return true;
49 }
50
51 if ((first.matchesId(CHARGED_HELM) && second.matchesId(MAGMA_MUTAGEN))
52 || (second.matchesId(CHARGED_HELM) && first.matchesId(MAGMA_MUTAGEN))) {
53 player.message("You need to uncharge your Serpentine helm first.");
54 return true;
55 }
56
57 if ((first.matchesId(UNCHARGED_HELM) && second.matchesId(TANZ_MUTAGEN))
58 || (second.matchesId(UNCHARGED_HELM) && first.matchesId(TANZ_MUTAGEN))) {
60 player.inventory.replace(UNCHARGED_HELM, 13_196, true);
61 player.message(true, "You recolor your Serpentine helm into a Tanzanite helm!");
62 return true;
63 }
64
65 if ((first.matchesId(UNCHARGED_HELM) && second.matchesId(MAGMA_MUTAGEN))
66 || (second.matchesId(UNCHARGED_HELM) && first.matchesId(MAGMA_MUTAGEN))) {
68 player.inventory.replace(UNCHARGED_HELM, 13_198, true);
69 player.message(true, "You recolor your Serpentine helm into a Magma helm!");
70 return true;
71 }
72
73 if (item.getId() == ZULRAH_SCALES) {
74 charge(player, item.equals(first) ? second : first, item);
75 return true;
76 }
77
78 return false;
79 }
80
81 @Override
82 public boolean inventory(Player player, Item item, int opcode) {
83 if (opcode == 3 && item.matchesId(UNCHARGED_HELM)) {
84 dismantle(player, item);
85 return true;
86 }
87
88 if (opcode == 2) {
89 check(player);
90 }
91
92 return true;
93 }
94
95 @Override
96 public boolean equipment(Player player, Item item, int opcode) {
97 if (opcode == 1) {
98 check(player);
99 }
100 return true;
101 }
102
103 @Override
104 public boolean drop(Player player, Item item) {
105 if (item.matchesId(CHARGED_HELM)) {
106 uncharge(player);
107 return true;
108 }
109 if (item.matchesId(UNCHARGED_HELM)) {
110 dismantle(player, item);
111 return true;
112 }
113 return false;
114 }
115
116 public static void check(Player player) {
117 String scales = FORMATTER.format(player.serpentineHelmCharges * 100 / FULL) + "%";
118 player.message("Charges: <col=007F00>" + scales);
119 }
120
121 private static void charge(Player player, Item helm, Item scales) {
122 if (player.serpentineHelmCharges >= FULL) {
123 if (helm.matchesId(UNCHARGED_HELM)) {
125 }
126 player.message("Your Serpentine helm is already fully charged.");
127 return;
128 }
129
130 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
131 scales = scales.copy();
132 scales.setAmount(FULL - player.serpentineHelmCharges);
133 }
134
135 if (player.serpentineHelmCharges + scales.getAmount() > FULL) {
136 scales = scales.copy();
137 scales.setAmount(FULL - player.serpentineHelmCharges);
138 }
139
140 player.serpentineHelmCharges += scales.getAmount();
141 player.inventory.remove(scales);
143 player.message(String.format("You load %s scales into your Serpentine helm.", Utility.formatDigits(scales.getAmount())));
144 }
145
146 private static void uncharge(Player player) {
147 Item scales = new Item(ZULRAH_SCALES, player.serpentineHelmCharges);
148
149 if (!player.inventory.hasCapacityFor(scales)) {
150 player.send(new SendMessage("You need more inventory space to do this."));
151 return;
152 }
153
154 player.serpentineHelmCharges = 0;
155 player.inventory.add(scales);
157 player.message(String.format("You uncharged your Serpentine helm and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount())));
158 }
159
160 private static void dismantle(Player player, Item item) {
161 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
162 player.send(new SendString("Are you sure you want to uncharge this item?", 14174));
163 player.send(new SendString("Yes.", 14175));
164 player.send(new SendString("No.", 14176));
165 player.send(new SendString("", 14177));
166 player.send(new SendString("This will replace your helm with 20,000 Zulrah's scales.", 14182));
167 player.send(new SendString("", 14183));
168 player.send(new SendString(item.getName(), 14184));
169 player.send(new SendChatBoxInterface(14170));
170 player.attributes.set("UNCHARGE_HELM_KEY", item);
171 }
172
173}
Handles executing an item action.
static void dismantle(Player player, Item item)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
boolean equipment(Player player, Item item, int opcode)
static void charge(Player player, Item helm, Item scales)
boolean itemOnItem(Player player, Item first, Item second)
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.