RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
StoreItem.java
1package com.osroyale.content.store;
2
3import com.osroyale.content.store.currency.CurrencyType;
4import com.osroyale.game.world.items.Item;
5
6import java.util.Optional;
7import java.util.OptionalInt;
8
41
42* A simple wrapper class which holds extra attributes for the item object.
43 *
44 * @author <a href="http://www.rune-server.org/members/stand+up/">Stand Up</a>
45 * @since 4-1-2017.
46 */
47public final class StoreItem extends Item {
48
52 public static final int RESTOCK_RATE = 5;
53
55 public OptionalInt value = OptionalInt.empty();
56
58 public Optional<CurrencyType> currency = Optional.empty();
59
63 private int restockTimer = RESTOCK_RATE;
64
66 public StoreItem(int id, int amount, OptionalInt value, Optional<CurrencyType> currency) {
67 super(id, amount);
68 this.value = value;
69 this.currency = currency;
70 }
71
72 public StoreItem(int id, int amount, int value) {
73 this(id, amount, OptionalInt.of(value), Optional.of(CurrencyType.COINS));
74 }
75
76 public StoreItem(int id, int amount) {
77 this(id, amount, OptionalInt.empty(), Optional.empty());
78 }
79
80 public int getShopValue() {
81 return value.orElse((int)((double)getValue() * 1.20));
82 }
83
84 public void setShopValue(int value) {
85 this.value = OptionalInt.of(value);
86 }
87
88 public CurrencyType getShopCurrency(Store store) {
89 return currency.orElse(store.currencyType);
90 }
91
92 public void setCurrency(CurrencyType type) {
93 this.currency = currency;
94 }
95
96 public boolean canReduce() {
97 if (--restockTimer <= 0) {
98 restockTimer = RESTOCK_RATE;
99 return true;
100 }
101 return false;
102 }
103
104 @Override
105 public StoreItem copy() {
106 return new StoreItem(getId(), getAmount(), value, currency);
107 }
108}