RuneHive-Game
Loading...
Searching...
No Matches
CelestialRing.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.SendInputAmount;
7import com.runehive.util.Utility;
8
9public class CelestialRing extends ItemAction {
10
11 public static final short UNCHARGED_RING = 25539;
12 public static final short CHARGED_RING = 25541;
13 public static final short STARDUST = 25527;
14
15 @Override
16 public String name() {
17 return "Celestial ring";
18 }
19
20 @Override
21 public boolean itemOnItem(Player player, Item first, Item second) {
22 if ((first.getId() != UNCHARGED_RING && second.getId() != UNCHARGED_RING) && (first.getId() != CHARGED_RING && second.getId() != CHARGED_RING)) {
23 return false;
24 }
25
26 if(first.getId() == STARDUST || second.getId() == STARDUST) {
27 if (first.getId() == UNCHARGED_RING || second.getId() == UNCHARGED_RING) {
28 player.send(new SendInputAmount("How many charges would you like add? (0-"+player.inventory.computeAmountForId(STARDUST)+")", 10, input -> charge(player, Integer.parseInt(input), UNCHARGED_RING)));
29 } else {
30 player.send(new SendInputAmount("How many charges would you like add? (0-"+player.inventory.computeAmountForId(STARDUST)+")", 10, input -> charge(player, Integer.parseInt(input), CHARGED_RING)));
31 }
32 return true;
33 }
34
35 return false;
36 }
37
38 @Override
39 public boolean inventory(Player player, Item item, int opcode) {
40 if (item.getId() != UNCHARGED_RING && item.getId() != CHARGED_RING) {
41 return false;
42 }
43
44 if (opcode == 1 && item.getId() == CHARGED_RING) {
45 player.equipment.equip(new Item(CHARGED_RING));
46 return true;
47 }
48 if (opcode == 2) {
49 player.send(new SendInputAmount("How many charges would you like add? (0-"+player.inventory.computeAmountForId(STARDUST)+")", 10, input -> charge(player, Integer.parseInt(input), item.getId())));
50 return true;
51 }
52
53 return false;
54 }
55
56 @Override
57 public boolean equipment(Player player, Item item, int opcode) {
58 if (item.getId() != CHARGED_RING) {
59 return false;
60 }
61 if (opcode == 1) {
62 check(player);
63 return true;
64 }
65 return true;
66 }
67
68 @Override
69 public boolean drop(Player player, Item item) {
70 if (item.getId() != CHARGED_RING) {
71 return false;
72 }
73 if (player.celestialRingCharges > 0) {
75 player.inventory.add(UNCHARGED_RING, 1);
77 player.celestialRingCharges = 0;
78 player.message("You uncharge your "+name()+".");
79 }
80
81 return true;
82 }
83
84 public static void check(Player player) {
85 player.message("You have " + Utility.formatDigits(player.celestialRingCharges) + " charges in your Celestial ring.");
86 }
87
88 private void charge(Player player, int amount, int itemId) {
89 if (amount > player.inventory.computeAmountForId(STARDUST)) {
90 amount = player.inventory.computeAmountForId(STARDUST);
91 }
92 if (amount > 0) {
93 if (itemId == UNCHARGED_RING) {
95 player.inventory.add(CHARGED_RING, 1);
96 }
97 player.inventory.remove(STARDUST, amount);
98 player.inventory.refresh();
99 player.celestialRingCharges += amount;
100 player.message("You added " + amount + " charges to your "+name()+"");
101 }
102 }
103
104}
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.
boolean itemOnItem(Player player, Item first, Item second)
void charge(Player player, int amount, int itemId)
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.
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