RuneHive-Game
Loading...
Searching...
No Matches
CrawsBow.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.game.world.items.ItemDefinition;
7import com.runehive.net.packet.out.SendInputAmount;
8import com.runehive.util.Utility;
9
10public class CrawsBow extends ItemAction {
11
12 public static final short CRAWS_UNCHARGED_ID = 22547;
13 public static final short CRAWS_CHARGED_ID = 22550;
14 public static final short ETHER_ID = 21820;
15
16 @Override
17 public String name() {
18 return "Craw's bow";
19 }
20
21 @Override
22 public boolean itemOnItem(Player player, Item first, Item second) {
23 if ((first.getId() != CRAWS_UNCHARGED_ID && second.getId() != CRAWS_UNCHARGED_ID) && (first.getId() != CRAWS_CHARGED_ID && second.getId() != CRAWS_CHARGED_ID)) {
24 return false;
25 }
26
27 if(first.getId() == ETHER_ID || second.getId() == ETHER_ID) {
28 if (first.getId() == CRAWS_UNCHARGED_ID || second.getId() == CRAWS_UNCHARGED_ID) {
29 if(!player.inventory.contains(ETHER_ID, 1000)) {
30 player.message("You need at least 1000 "+ ItemDefinition.get(ETHER_ID).getName() +" to charge the "+name()+".");
31 return true;
32 }
33 player.inventory.remove(ETHER_ID, 1000);
36 player.inventory.refresh();
37 } else {
38 System.out.println("Recharge craws bow");
39 player.send(new SendInputAmount("How many charges would you like add? (0-"+player.inventory.computeAmountForId(ETHER_ID)+")", 10, input -> charge(player, Integer.parseInt(input))));
40 }
41 return true;
42 }
43
44 return false;
45 }
46
47 @Override
48 public boolean inventory(Player player, Item item, int opcode) {
49 if (item.getId() != CRAWS_CHARGED_ID) {
50 return false;
51 }
52
53 if (opcode == 2) {
54 check(player);
55 return true;
56 }
57
58 return false;
59 }
60
61 @Override
62 public boolean equipment(Player player, Item item, int opcode) {
63 if (item.getId() != CRAWS_CHARGED_ID) {
64 return false;
65 }
66 if (opcode == 1) {
67 check(player);
68 return true;
69 }
70 return true;
71 }
72
73 @Override
74 public boolean drop(Player player, Item item) {
75 if (item.getId() != CRAWS_CHARGED_ID) {
76 return false;
77 }
78
81 player.inventory.add(ETHER_ID, 1000 + player.crawsBowCharges);
82 player.crawsBowCharges = 0;
83
84 player.message("You uncharge your "+name()+".");
85
86 return true;
87 }
88
89 private void check(Player player) {
90 player.message("You have " + Utility.formatDigits(player.crawsBowCharges) + " charges in your "+name()+".");
91 }
92
93 private void charge(Player player, int amount) {
94 if (amount > player.inventory.computeAmountForId(ETHER_ID)) {
95 amount = player.inventory.computeAmountForId(ETHER_ID);
96 }
97 if (amount > 0) {
98 player.inventory.remove(ETHER_ID, amount);
99 player.inventory.refresh();
100 player.crawsBowCharges += amount;
101 player.message("You added " + amount + " charges to your "+name()+"");
102 }
103 }
104
105}
Handles executing an item action.
String name()
The name of the action.
Definition CrawsBow.java:17
boolean drop(Player player, Item item)
Definition CrawsBow.java:74
boolean inventory(Player player, Item item, int opcode)
The execution method of the action.
Definition CrawsBow.java:48
boolean equipment(Player player, Item item, int opcode)
Definition CrawsBow.java:62
boolean itemOnItem(Player player, Item first, Item second)
Definition CrawsBow.java:22
void charge(Player player, int amount)
Definition CrawsBow.java:93
This class represents a character controlled by a player.
Definition Player.java:125
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
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.
boolean contains(int id)
Determines if this container contains id.
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