RuneHive-Game
Loading...
Searching...
No Matches
StoreItem.java
Go to the documentation of this file.
1package com.runehive.content.store;
2
3import com.runehive.content.store.currency.CurrencyType;
4import com.runehive.game.world.items.Item;
5
6import java.util.Optional;
7import java.util.OptionalInt;
8
9/**
10 * A simple wrapper class which holds extra attributes for the item object.
11 *
12 * @author <a href="http://www.rune-server.org/members/stand+up/">Stand Up</a>
13 * @since 4-1-2017.
14 */
15public final class StoreItem extends Item {
16
17 /**
18 * The time in minutes an item in the store has to wait before it can be reduced.
19 */
20 public static final int RESTOCK_RATE = 5;
21
22 /** Gets the optional value for this shop item. */
23 public OptionalInt value = OptionalInt.empty();
24
25 /** Gets the optional currency for this shop item. */
26 public Optional<CurrencyType> currency = Optional.empty();
27
28 /**
29 * The time in minutes it takes to restock this store item.
30 */
32
33 /** Creates a new {@link Item}. */
34 public StoreItem(int id, int amount, OptionalInt value, Optional<CurrencyType> currency) {
35 super(id, amount);
36 this.value = value;
37 this.currency = currency;
38 }
39
40 public StoreItem(int id, int amount, int value) {
41 this(id, amount, OptionalInt.of(value), Optional.of(CurrencyType.COINS));
42 }
43
44 public StoreItem(int id, int amount) {
45 this(id, amount, OptionalInt.empty(), Optional.empty());
46 }
47
48 public int getShopValue() {
49 return value.orElse((int)((double)getValue() * 1.20));
50 }
51
52 public void setShopValue(int value) {
53 this.value = OptionalInt.of(value);
54 }
55
57 return currency.orElse(store.currencyType);
58 }
59
60 public void setCurrency(CurrencyType type) {
61 this.currency = currency;
62 }
63
64 public boolean canReduce() {
65 if (--restockTimer <= 0) {
67 return true;
68 }
69 return false;
70 }
71
72 @Override
73 public StoreItem copy() {
74 return new StoreItem(getId(), getAmount(), value, currency);
75 }
76}
The class which holds support for further abstraction for shops.
Definition Store.java:20
Optional< CurrencyType > currency
Gets the optional currency for this shop item.
void setCurrency(CurrencyType type)
StoreItem(int id, int amount, int value)
CurrencyType getShopCurrency(Store store)
int restockTimer
The time in minutes it takes to restock this store item.
StoreItem(int id, int amount, OptionalInt value, Optional< CurrencyType > currency)
Creates a new Item.
OptionalInt value
Gets the optional value for this shop item.
StoreItem copy()
A substitute for Object#clone() that creates another 'copy' of this instance.
static final int RESTOCK_RATE
The time in minutes an item in the store has to wait before it can be reduced.
final int getId()
Gets the identification of this item.
Definition Item.java:324
int getValue()
Gets the value for this item.
Definition Item.java:125
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
int id
The identification of this item.
Definition Item.java:26
int amount
The quantity of this item.
Definition Item.java:31
Item(int id, int amount)
Creates a new Item.
Definition Item.java:36
The enumerated type whom holds all the currencies usable for a server.