RuneHive-Game
Loading...
Searching...
No Matches
ItemCurrency.java
Go to the documentation of this file.
1package com.runehive.content.store.currency.impl;
2
3import com.runehive.content.store.currency.Currency;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.items.Item;
6import com.runehive.game.world.items.ItemDefinition;
7
8/**
9 * The currency that provides basic functionality for all tangible currencies.
10 *
11 * @author lare96 <http://github.com/lare96>
12 */
13public final class ItemCurrency implements Currency {
14
15 /** The item id for this currency. */
16 public final int itemId;
17
18 /** Constructs a new {@link ItemCurrency}. */
19 public ItemCurrency(int itemId) {
20 this.itemId = itemId;
21 }
22
23 @Override
24 public boolean tangible() {
25 return true;
26 }
27
28 @Override
29 public boolean takeCurrency(Player player, int amount) {
30 return player.inventory.remove(new Item(itemId, amount));
31 }
32
33 @Override
34 public void recieveCurrency(Player player, int amount) {
35 player.inventory.add(new Item(itemId, amount));
36 }
37
38 @Override
39 public int currencyAmount(Player player) {
40 return player.inventory.computeAmountForId(itemId);
41 }
42
43 @Override
44 public boolean canRecieveCurrency(Player player) {
45 return player.inventory.contains(itemId);
46 }
47
48 @Override
49 public String toString() {
51 }
52}
boolean tangible()
Determines if this currency is tangible.
ItemCurrency(int itemId)
Constructs a new ItemCurrency.
void recieveCurrency(Player player, int amount)
The method executed when the currency is given to player.
boolean takeCurrency(Player player, int amount)
The method executed when the currency is taken from player.
String toString()
Gets the name of the currency.
final int itemId
The item id for this currency.
boolean canRecieveCurrency(Player player)
Determines if the currency can be received when player's inventory is full.
int currencyAmount(Player player)
The method that retrieves the amount of currency player currently has.
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 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.
The parent class of all currencies that provides basic functionality for any general currency.
Definition Currency.java:11