RuneHive-Game
Loading...
Searching...
No Matches
TridentOfTheSeas.java
Go to the documentation of this file.
1package com.runehive.content.itemaction.impl;
2
3import com.runehive.content.ItemCreation;
4import com.runehive.content.itemaction.ItemAction;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.Item;
7import com.runehive.util.Items;
8import com.runehive.util.Utility;
9
10import java.math.RoundingMode;
11import java.text.DecimalFormat;
12
13public class TridentOfTheSeas extends ItemAction {
14 private static final short TRIDENT_ID = 11907;
15 private static final short CHARGE_LIMIT = 2500;
16 private static final DecimalFormat FORMATTER = new DecimalFormat("#.#");
17
19 FORMATTER.setRoundingMode(RoundingMode.FLOOR);
20 }
21
22 @Override
23 public String name() {
24 return "Trident of the Seas";
25 }
26
27 @Override
28 public boolean itemOnItem(Player player, Item first, Item second) {
29 if (first.getId() != TRIDENT_ID && second.getId() != TRIDENT_ID) {
30 return false;
31 }
32
33 if (ItemCreation.CreationData.forItems(first, second).isPresent()) {
34 if (player.tridentSeasCharges > 0) {
35 player.message("You must empty your trident charges before doing this.");
36 return true;
37 }
38 return false;
39 }
40
41 if (player.tridentSeasCharges >= CHARGE_LIMIT) {
42 player.message("Your Trident of the Seas is already fully charged.");
43 return true;
44 }
45
46 int id1 = first.getId();
47 int id2 = second.getId();
48
49 if (id1 == TRIDENT_ID && id2 != TRIDENT_ID)
50 if (id2 != 560 && id2 != 562 && id2 != 554 && id2 != 995)
51 return true;
52
53 if (id2 == TRIDENT_ID && id1 != TRIDENT_ID)
54 if (id1 != 560 && id1 != 562 && id1 != 554 && id1 != 995)
55 return true;
56
57 int death = player.inventory.computeAmountForId(560);
58 int chaos = player.inventory.computeAmountForId(562);
59 int fire = player.inventory.computeAmountForId(554);
60 int coins = player.inventory.computeAmountForId(995);
61
62 if (death >= 1 && chaos >= 1 && fire >= 5 && coins >= 10) {
63 int minF = fire / 5;
64 int minC = coins / 10;
65 int charges = Math.min(Math.min(death, chaos), Math.min(minF, minC));
66
67 if (charges > CHARGE_LIMIT)
68 charges = CHARGE_LIMIT;
69
70 if (charges > CHARGE_LIMIT - player.tridentSeasCharges)
71 charges = CHARGE_LIMIT - player.tridentSeasCharges;
72
73 if (charges > 0) {
74 player.inventory.remove(new Item(560, charges), -1, false);
75 player.inventory.remove(new Item(562, charges), -1, false);
76 player.inventory.remove(new Item(554, charges * 5), -1, false);
77 player.inventory.remove(new Item(995, charges * 10), -1, false);
78 player.inventory.refresh();
79 player.tridentSeasCharges += charges;
80 player.message("You added " + charges + " charges to your Trident of the Seas");
81 }
82 } else {
83 player.message("You need at least 1 x death rune, 1 x chaos rune, 5 x fire runes and 10gp for one charge.", "Your Trident of the Seas can hold ");
84 }
85 return true;
86 }
87
88 @Override
89 public boolean inventory(Player player, Item item, int opcode) {
90 if (item.getId() != TRIDENT_ID) {
91 return false;
92 }
93 if (opcode == 2) {
94 check(player);
95 return true;
96 }
97 if (opcode == 3) {
98 uncharge(player);
99 return true;
100 }
101 return true;
102 }
103
104 @Override
105 public boolean equipment(Player player, Item item, int opcode) {
106 if (item.getId() != TRIDENT_ID) {
107 return false;
108 }
109 if (opcode == 1) {
110 check(player);
111 return true;
112 }
113 return true;
114 }
115
116 private static void check(Player player) {
117 player.message("You have " + Utility.formatDigits(player.tridentSeasCharges) + " charges in your Trident of the Seas.");
118 }
119
120 private static void uncharge(Player player) {
121 if (player.tridentSeasCharges < 1) {
122 return;
123 }
124
125 int amount = player.tridentSeasCharges;
126 if (!player.inventory.hasCapacityFor(new Item(560, amount), new Item(562, amount), new Item(554, amount * 5))) {
127 player.message("You don't have enough inventory space to uncharge your trident.");
128 return;
129 }
130
131 player.inventory.add(new Item(560, amount), -1, false);
132 player.inventory.add(new Item(562, amount), -1, false);
133 player.inventory.add(new Item(554, amount * 5), -1, false);
134 player.inventory.refresh();
135 player.tridentSeasCharges = 0;
136 player.message("You uncharge your trident.");
137 }
138
139}
Handles creating items with the use item packet listener.
Handles executing an item action.
boolean equipment(Player player, Item item, int opcode)
boolean itemOnItem(Player player, Item first, Item second)
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
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
static Optional< CreationData > forItems(Item first, Item second)
Handles finding the creation data based off the items used.