RuneHive-Game
Loading...
Searching...
No Matches
TridentOfTheSwamp.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.util.Utility;
7
8import java.math.RoundingMode;
9import java.text.DecimalFormat;
10
11public class TridentOfTheSwamp extends ItemAction {
12 private static final short TRIDENT_ID = 12899;
13 private static final short CHARGE_LIMIT = 2500;
14 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
15
17 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
18 }
19
20 @Override
21 public String name() {
22 return "Trident of the Seas";
23 }
24
25 @Override
26 public boolean itemOnItem(Player player, Item first, Item second) {
27 if (first.getId() != TRIDENT_ID && second.getId() != TRIDENT_ID) {
28 return false;
29 }
30
31 if (player.tridentSwampCharges >= CHARGE_LIMIT) {
32 player.message("Your Trident of the Swamp is already fully charged.");
33 return true;
34 }
35
36 int id1 = first.getId();
37 int id2 = second.getId();
38
39 if (id1 == TRIDENT_ID && id2 != TRIDENT_ID)
40 if (id2 != 560 && id2 != 562 && id2 != 554 && id2 != 12934)
41 return true;
42
43 if (id2 == TRIDENT_ID && id1 != TRIDENT_ID)
44 if (id1 != 560 && id1 != 562 && id1 != 554 && id1 != 12934)
45 return true;
46
47 int scales = player.inventory.computeAmountForId(12934);
48 int death = player.inventory.computeAmountForId(560);
49 int chaos = player.inventory.computeAmountForId(562);
50 int fire = player.inventory.computeAmountForId(554);
51
52 if (death >= 1 && chaos >= 1 && fire >= 5 && scales >= 1) {
53 int minF = fire / 5;
54 int charges = Math.min(Math.min(death, chaos), Math.min(scales, minF));
55
56 if (charges > CHARGE_LIMIT)
57 charges = CHARGE_LIMIT;
58
59 if (charges > CHARGE_LIMIT - player.tridentSwampCharges)
60 charges = CHARGE_LIMIT - player.tridentSwampCharges;
61
62 if (charges > 0) {
63 player.inventory.remove(new Item(560, charges), -1, false);
64 player.inventory.remove(new Item(562, charges), -1, false);
65 player.inventory.remove(new Item(554, charges * 5), -1, false);
66 player.inventory.remove(new Item(12934, charges), -1, false);
67 player.inventory.refresh();
68 player.tridentSwampCharges += charges;
69 player.message("You added " + charges + " charges to your Trident of the Swamp");
70 }
71 } else {
72 player.message("You need at least 1x zulrah scale, 1x death rune, 1x chaos rune, and 5x fire runes", "for one charge. Your Trident of the Swamp can hold 2,500 charges.");
73 }
74 return true;
75 }
76
77 @Override
78 public boolean inventory(Player player, Item item, int opcode) {
79 if (item.getId() != TRIDENT_ID) {
80 return false;
81 }
82 if (opcode == 2) {
83 check(player);
84 return true;
85 }
86 if (opcode == 3) {
87 uncharge(player);
88 return true;
89 }
90 return true;
91 }
92
93 @Override
94 public boolean equipment(Player player, Item item, int opcode) {
95 if (item.getId() != TRIDENT_ID) {
96 return false;
97 }
98 if (opcode == 1) {
99 check(player);
100 return true;
101 }
102 return true;
103 }
104
105 private static void check(Player player) {
106 player.message("You have " + Utility.formatDigits(player.tridentSwampCharges) + " charges in your Trident of the Swamp.");
107 }
108
109 private static void uncharge(Player player) {
110 if (player.tridentSwampCharges < 1) {
111 return;
112 }
113
114 int amount = player.tridentSwampCharges;
115 if (!player.inventory.hasCapacityFor(new Item(560, amount), new Item(562, amount), new Item(554, amount * 5))) {
116 player.message("You don't have enough inventory space to uncharge your trident.");
117 return;
118 }
119
120 player.inventory.add(new Item(560, amount), -1, false);
121 player.inventory.add(new Item(562, amount), -1, false);
122 player.inventory.add(new Item(554, amount * 5), -1, false);
123 player.inventory.refresh();
124 player.tridentSwampCharges = 0;
125 player.message("You uncharge your trident.");
126 }
127
128}
Handles executing an item action.
boolean itemOnItem(Player player, Item first, Item second)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
boolean equipment(Player player, Item item, int opcode)
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 int getId()
Gets the identification of this item.
Definition Item.java:324
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean add(Item item)
Attempts to deposit item into this container.
final boolean hasCapacityFor(Item... item)
Determines if this container has the capacity for item.
void refresh()
Refreshes the players inventory.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41