RuneHive-Game
Loading...
Searching...
No Matches
TanzaniteHelm.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 TanzaniteHelm 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_196;
21 private static final short CHARGED_HELM = 13_197;
22
23 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
24
25 public TanzaniteHelm() {
26 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
27 }
28
29 @Override
30 public String name() {
31 return "Tanzanite 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 } else if (opcode == 2) {
55 check(player);
56 }
57
58 return true;
59 }
60
61 @Override
62 public boolean equipment(Player player, Item item, int opcode) {
63 if (opcode == 1) {
64 check(player);
65 }
66 return true;
67 }
68
69 @Override
70 public boolean drop(Player player, Item item) {
71 if (item.matchesId(CHARGED_HELM)) {
72 uncharge(player);
73 return true;
74 }
75 return false;
76 }
77
78 public static void check(Player player) {
79 String scales = FORMATTER.format(player.tanzaniteHelmCharges * 100 / FULL) + "%";
80 player.message("Charges: <col=007F00>" + scales);
81 }
82
83 private static void charge(Player player, Item helm, Item scales) {
84 if (player.tanzaniteHelmCharges >= FULL) {
85 if (helm.matchesId(UNCHARGED_HELM)) {
87 }
88 player.message("Your Tanzanite helm is already fully charged.");
89 return;
90 }
91
92 if (Integer.MAX_VALUE - scales.getAmount() < FULL) {
93 scales = scales.copy();
94 scales.setAmount(FULL - player.tanzaniteHelmCharges);
95 }
96
97 if (player.tanzaniteHelmCharges + scales.getAmount() > FULL) {
98 scales = scales.copy();
99 scales.setAmount(FULL - player.tanzaniteHelmCharges);
100 }
101
102 player.tanzaniteHelmCharges += scales.getAmount();
103 player.inventory.remove(scales);
105 player.message(String.format("You load %s scales into your Tanzanite helm.", Utility.formatDigits(scales.getAmount())));
106 }
107
108 private static void uncharge(Player player) {
109 Item scales = new Item(ZULRAH_SCALES, player.tanzaniteHelmCharges);
110
111 if (!player.inventory.hasCapacityFor(scales)) {
112 player.send(new SendMessage("You need more inventory space to do this."));
113 return;
114 }
115
116 player.tanzaniteHelmCharges = 0;
117 player.inventory.add(scales);
119 player.message(String.format("You uncharged your Tanzanite helm and received %s of Zulra's scales.", Utility.formatDigits(scales.getAmount())));
120 }
121
122 private static void restore(Player player, Item item) {
123 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
124 player.send(new SendString("Are you sure you want to restore this item?", 14174));
125 player.send(new SendString("Yes.", 14175));
126 player.send(new SendString("No.", 14176));
127 player.send(new SendString("", 14177));
128 player.send(new SendString("This will replace your helm with the original Serpentine helm.", 14182));
129 player.send(new SendString("", 14183));
130 player.send(new SendString(item.getName(), 14184));
131 player.send(new SendChatBoxInterface(14170));
132 player.attributes.set("RESTORE_HELM_KEY", item);
133 }
134
135}
Handles executing an item action.
boolean equipment(Player player, Item item, int opcode)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
static void charge(Player player, Item helm, Item scales)
boolean itemOnItem(Player player, Item first, Item second)
static void restore(Player player, Item item)
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.