RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.store.Store Class Referenceabstract

The class which holds support for further abstraction for shops. More...

Inheritance diagram for com.runehive.content.store.Store:
Collaboration diagram for com.runehive.content.store.Store:

Public Member Functions

abstract void close (Player player)
boolean decrementStock ()
final boolean equals (Object obj)
final int hashCode ()
abstract void itemContainerAction (Player player, int id, int slot, int action, boolean purchase)
void onPurchase (Player player, Item item)
abstract void open (Player player)
boolean purchase (Player player, Item item, int slot)
abstract void refresh (Player player)
abstract SellType sellType ()
 Store (String name, ItemContainer.StackPolicy policy, CurrencyType currencyType, int capacity)
abstract StoreType type ()

Static Public Member Functions

static void closeShop (Player player)
static void exchange (Player player, int id, int slot, int action, boolean purchase)

Public Attributes

ItemContainer container
 The current item container which contains the current items from this shop.
Map< Integer, Integer > itemCache
 The map of cached shop item identifications and their amounts.
final String name
 The name of this shop.
final Set< Playerplayers = new HashSet<>()
 The set of players that are currently viewing this shop.

Static Public Attributes

static Map< String, StoreSTORES = new HashMap<>()
 A mapping of each shop by it's name.

Protected Member Functions

final void sell (Player player, Item item, int slot, boolean addX)
void sendPurchaseValue (Player player, int slot)
final void sendSellValue (Player player, int slot)

Static Protected Member Functions

static List< PersonalStoregetFeaturedShops ()
static List< PersonalStoregetPersonalShops ()

Protected Attributes

final CurrencyType currencyType
 The currency for this shop.

Detailed Description

The class which holds support for further abstraction for shops.

Author
Stand Up
Since
4-1-2017.

Definition at line 20 of file Store.java.

Constructor & Destructor Documentation

◆ Store()

com.runehive.content.store.Store.Store ( String name,
ItemContainer.StackPolicy policy,
CurrencyType currencyType,
int capacity )

Definition at line 40 of file Store.java.

40 {
41 this.name = name;
42 this.currencyType = currencyType;
43 this.container = new ItemContainer(capacity, policy, new StoreItem[capacity]);
44 this.itemCache = new HashMap<>(container.capacity());
45 }

References container, currencyType, and name.

Referenced by com.runehive.content.store.impl.PersonalStore.changeName(), closeShop(), equals(), exchange(), and com.runehive.content.store.impl.PersonalStore.myShop().

Here is the caller graph for this function:

Member Function Documentation

◆ close()

◆ closeShop()

void com.runehive.content.store.Store.closeShop ( Player player)
static

Definition at line 47 of file Store.java.

47 {
48 if (!player.interfaceManager.isInterfaceOpen(StoreConstant.INTERFACE_ID) || !player.attributes.has("SHOP")) {
49 return;
50 }
51
52 Store store = STORES.get(player.attributes.get("SHOP"));
53
54 if (store == null) {
55 return;
56 }
57
58 store.close(player);
59 }

References com.runehive.game.world.entity.mob.Mob.attributes, com.runehive.util.generic.GenericAttributes.get(), com.runehive.util.generic.GenericAttributes.has(), com.runehive.content.store.StoreConstant.INTERFACE_ID, com.runehive.game.world.entity.mob.player.Player.interfaceManager, com.runehive.game.world.entity.mob.player.InterfaceManager.isInterfaceOpen(), Store(), and STORES.

Referenced by com.runehive.game.world.entity.mob.player.InterfaceManager.close().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrementStock()

boolean com.runehive.content.store.Store.decrementStock ( )

Reimplemented in com.runehive.content.store.impl.RecipeForDisasterStore, and com.runehive.content.store.impl.SkillcapeStore.

Definition at line 303 of file Store.java.

303 {
304 return true;
305 }

Referenced by purchase().

Here is the caller graph for this function:

◆ equals()

final boolean com.runehive.content.store.Store.equals ( Object obj)

Definition at line 316 of file Store.java.

316 {
317 if (this == obj)
318 return true;
319 if (obj == null)
320 return false;
321 if (!(obj instanceof Store))
322 return false;
323 Store other = (Store) obj;
324 if (name == null) {
325 if (other.name != null)
326 return false;
327 } else if (!name.equals(other.name))
328 return false;
329 return true;
330 }

References name, and Store().

Referenced by purchase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exchange()

void com.runehive.content.store.Store.exchange ( Player player,
int id,
int slot,
int action,
boolean purchase )
static

Definition at line 61 of file Store.java.

61 {
62 if (!player.interfaceManager.isInterfaceOpen(StoreConstant.INTERFACE_ID) || !player.attributes.has("SHOP")) {
63 return;
64 }
65
66 Store store = STORES.get(player.attributes.get("SHOP"));
67
68 if (store == null) {
69 return;
70 }
71
72 store.itemContainerAction(player, id, slot, action, purchase);
73 }

References com.runehive.game.world.entity.mob.Mob.attributes, com.runehive.util.generic.GenericAttributes.get(), com.runehive.util.generic.GenericAttributes.has(), com.runehive.content.store.StoreConstant.INTERFACE_ID, com.runehive.game.world.entity.mob.player.Player.interfaceManager, com.runehive.game.world.entity.mob.player.InterfaceManager.isInterfaceOpen(), purchase(), Store(), and STORES.

Here is the call graph for this function:

◆ getFeaturedShops()

List< PersonalStore > com.runehive.content.store.Store.getFeaturedShops ( )
staticprotected

Definition at line 81 of file Store.java.

81 {
82 List<PersonalStore> featured_shops = new ArrayList<>();
83 STORES.values().stream().filter(s -> s.type().equals(StoreType.PERSONAL) && ((PersonalStore) s).rank > 0).forEach(s -> featured_shops.add((PersonalStore) s));
84 return featured_shops;
85 }

References com.runehive.content.store.impl.PersonalStore.add(), com.runehive.content.store.StoreType.PERSONAL, and STORES.

Referenced by com.runehive.content.store.impl.PersonalStore.openPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPersonalShops()

List< PersonalStore > com.runehive.content.store.Store.getPersonalShops ( )
staticprotected

Definition at line 75 of file Store.java.

75 {
76 List<PersonalStore> personal_shops = new ArrayList<>();
77 STORES.values().stream().filter(s -> s.type().equals(StoreType.PERSONAL)).forEach(s -> personal_shops.add((PersonalStore) s));
78 return personal_shops;
79 }

References com.runehive.content.store.StoreType.PERSONAL, and STORES.

Referenced by com.runehive.content.store.impl.PersonalStore.openMenu(), and com.runehive.content.store.impl.PersonalStore.openPanel().

Here is the caller graph for this function:

◆ hashCode()

final int com.runehive.content.store.Store.hashCode ( )

Definition at line 308 of file Store.java.

308 {
309 final int prime = 31;
310 int result = 1;
311 result = prime * result + ((name == null) ? 0 : name.hashCode());
312 return result;
313 }

References name.

◆ itemContainerAction()

abstract void com.runehive.content.store.Store.itemContainerAction ( Player player,
int id,
int slot,
int action,
boolean purchase )
abstract

Reimplemented in com.runehive.content.store.impl.DefaultStore, com.runehive.content.store.impl.PersonalStore, com.runehive.content.store.impl.RecipeForDisasterStore, and com.runehive.content.store.impl.SkillcapeStore.

References purchase().

Here is the call graph for this function:

◆ onPurchase()

void com.runehive.content.store.Store.onPurchase ( Player player,
Item item )

Reimplemented in com.runehive.content.store.impl.PersonalStore.

Definition at line 172 of file Store.java.

172 {
173
174 }

Referenced by purchase().

Here is the caller graph for this function:

◆ open()

◆ purchase()

boolean com.runehive.content.store.Store.purchase ( Player player,
Item item,
int slot )

Reimplemented in com.runehive.content.store.impl.SkillcapeStore.

Definition at line 89 of file Store.java.

89 {
90 if (item == null || !Item.valid(item)) {
91 return false;
92 }
93
94 Optional<Item> find = container.retrieve(slot);
95
96 if (!find.isPresent()) {
97 return false;
98 }
99
100 Item found = find.get();
101
102 if (!(found instanceof StoreItem)) {
103 return false;
104 }
105
106 if (!found.matchesId(item.getId())) {
107 player.send(new SendMessage("Something went wrong."));
108 return false;
109 }
110
111 StoreItem storeItem = (StoreItem) find.get();
112
113 if (storeItem.getAmount() < 1) {
114 player.send(new SendMessage("There is none of this item left in stock!"));
115 return false;
116 }
117 if(PlayerRight.isIronman(player)) {
118 player.send(new SendMessage("Ironman-players cannot buy items sold by players."));
119 return false;
120 }
121
122 if (item.getAmount() > storeItem.getAmount())
123 item.setAmount(storeItem.getAmount());
124 if (!player.inventory.hasCapacityFor(item)) {
125 item.setAmount(player.inventory.remaining());
126
127 if (item.getAmount() == 0) {
128 player.send(new SendMessage("You do not have enough space in your inventory to buy this item!"));
129 return false;
130 }
131 }
132
133 final int value = storeItem.getShopValue();
134
135 if (!(currencyType.currency.currencyAmount(player) >= (value * item.getAmount()))) {
136 player.send(new SendMessage("You do not have enough " + currencyType.toString() + " to buy this item."));
137 return false;
138 }
139
140 if (player.inventory.remaining() >= item.getAmount() && !item.isStackable()
141 || player.inventory.remaining() >= 1 && item.isStackable()
142 || player.inventory.contains(item.getId()) && item.isStackable()) {
143
144 if (value > 0 && !currencyType.currency.takeCurrency(player, item.getAmount() * value)) {
145 return false;
146 }
147
148 if (type().equals(StoreType.PERSONAL) && container.retrieve(slot).isPresent() && (container.retrieve(slot).get().getAmount() - item.getAmount() > 0)) {
149 container.retrieve(slot).get().decrementAmountBy(item.getAmount());
150 } else if (itemCache.containsKey(item.getId()) && container.retrieve(slot).isPresent()) {
151 if (decrementStock()) {
152 container.retrieve(slot).get().decrementAmountBy(item.getAmount());
153 }
154 } else if (!itemCache.containsKey(item.getId())) {
155 if (decrementStock()) {
156 container.remove(item);
157 }
158 if (type().equals(StoreType.PERSONAL)) {
159 container.shift();
160 }
161 }
162 player.inventory.add(new Item(item.getId(), item.getAmount()));
163 } else {
164 player.send(new SendMessage("You don't have enough space in your inventory."));
165 return false;
166 }
167 onPurchase(player, new Item(item.getId(), item.getAmount() * value));
168 refresh(player);
169 return true;
170 }

References com.runehive.game.world.items.containers.ItemContainer.add(), container, com.runehive.game.world.items.containers.ItemContainer.contains(), currencyType, decrementStock(), equals(), com.runehive.game.world.items.Item.getAmount(), com.runehive.game.world.items.Item.getId(), com.runehive.content.store.StoreItem.getShopValue(), com.runehive.game.world.items.containers.ItemContainer.hasCapacityFor(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.PlayerRight.isIronman(), com.runehive.game.world.items.Item.isStackable(), itemCache, com.runehive.game.world.items.Item.matchesId(), onPurchase(), com.runehive.content.store.StoreType.PERSONAL, refresh(), com.runehive.game.world.items.containers.ItemContainer.remaining(), com.runehive.game.world.entity.mob.player.Player.send(), com.runehive.game.world.items.Item.setAmount(), type(), and com.runehive.game.world.items.Item.valid().

Referenced by exchange(), com.runehive.content.store.impl.DefaultStore.itemContainerAction(), com.runehive.content.store.impl.PersonalStore.itemContainerAction(), com.runehive.content.store.impl.RecipeForDisasterStore.itemContainerAction(), and itemContainerAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh()

abstract void com.runehive.content.store.Store.refresh ( Player player)
abstract

Reimplemented in com.runehive.content.store.impl.DefaultStore, com.runehive.content.store.impl.PersonalStore, com.runehive.content.store.impl.RecipeForDisasterStore, and com.runehive.content.store.impl.SkillcapeStore.

Referenced by purchase(), and sell().

Here is the caller graph for this function:

◆ sell()

final void com.runehive.content.store.Store.sell ( Player player,
Item item,
int slot,
boolean addX )
protected

Definition at line 176 of file Store.java.

176 {
177 if (item == null || !Item.valid(item)) {
178 return;
179 }
180
181 final Item inventoryItem = player.inventory.get(slot);
182
183 if (inventoryItem == null) {
184 player.send(new SendMessage("This item does not exist."));
185 return;
186 }
187
188 if (sellType() == SellType.NONE) {
189 player.send(new SendMessage("This store won't buy any items."));
190 return;
191 }
192
193 if (!item.isTradeable()) {
194 player.send(new SendMessage("This item can't be sold to shops."));
195 return;
196 }
197
198 final boolean contains = container.contains(item.getId());
199
200 if (!contains && sellType() == SellType.CONTAINS) {
201 player.send(new SendMessage("You can't sell " + item.getName() + " to this shop."));
202 return;
203 }
204 if (!container.hasCapacityFor(item)) {
205 player.send(new SendMessage("There is no room in this store for the item you are trying to sell!"));
206 return;
207 }
208
209 if (player.inventory.remaining() == 0 && !currencyType.currency.canRecieveCurrency(player) && inventoryItem.getAmount() > 1) {
210 player.send(new SendMessage("You do not have enough space in your inventory to sell this item!"));
211 return;
212 }
213
214 if (CurrencyType.isCurrency(item.getId())) {
215 player.send(new SendMessage("You can not sell currency to this shop!"));
216 return;
217 }
218
219 final int sellValue = item.getSellValue();
220
221 if (sellValue >= StoreConstant.MAXIMUM_SELL_VALUE) {
222 player.send(new SendMessage("This item can not be sold as it has a value greater than 500,000 coins!"));
223 return;
224 }
225
226 final int amount = player.inventory.computeAmountForId(item.getId());
227
228 if (item.getAmount() > amount && !item.isStackable()) {
229 item.setAmount(amount);
230 } else if (item.getAmount() > inventoryItem.getAmount() && item.isStackable()) {
231 item.setAmount(inventoryItem.getAmount());
232 }
233
234 player.inventory.remove(item, slot);
235
236 if (sellValue > 0) {
237 currencyType.currency.recieveCurrency(player, item.getAmount() * sellValue);
238 }
239
240 final StoreItem converted = new StoreItem(item.getId(), item.getAmount());
241
242 container.add(converted);
243
244 refresh(player);
245 }

References com.runehive.game.world.items.containers.ItemContainer.computeAmountForId(), container, com.runehive.content.store.SellType.CONTAINS, currencyType, com.runehive.game.world.items.containers.ItemContainer.get(), com.runehive.game.world.items.Item.getAmount(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.items.Item.getName(), com.runehive.game.world.items.Item.getSellValue(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.content.store.currency.CurrencyType.isCurrency(), com.runehive.game.world.items.Item.isStackable(), com.runehive.game.world.items.Item.isTradeable(), com.runehive.content.store.StoreConstant.MAXIMUM_SELL_VALUE, com.runehive.content.store.SellType.NONE, refresh(), com.runehive.game.world.items.containers.ItemContainer.remaining(), com.runehive.game.world.items.containers.ItemContainer.remove(), sellType(), com.runehive.game.world.entity.mob.player.Player.send(), com.runehive.game.world.items.Item.setAmount(), and com.runehive.game.world.items.Item.valid().

Referenced by com.runehive.content.store.impl.DefaultStore.itemContainerAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sellType()

abstract SellType com.runehive.content.store.Store.sellType ( )
abstract

Reimplemented in com.runehive.content.store.impl.DefaultStore, com.runehive.content.store.impl.PersonalStore, com.runehive.content.store.impl.RecipeForDisasterStore, and com.runehive.content.store.impl.SkillcapeStore.

Referenced by sell(), and sendSellValue().

Here is the caller graph for this function:

◆ sendPurchaseValue()

void com.runehive.content.store.Store.sendPurchaseValue ( Player player,
int slot )
protected

Definition at line 277 of file Store.java.

277 {
278 Optional<Item> find = container.retrieve(slot);
279
280 if (!find.isPresent()) {
281 return;
282 }
283
284 Item item = find.get();
285
286 if (item instanceof StoreItem) {
287 StoreItem storeItem = (StoreItem) item;
288 final int value = storeItem.getShopValue();
289 String message = "This store will sell " + item.getName() + " for " + (value <= 0 ? "free!" : Utility.formatDigits(value) + " " + storeItem.getShopCurrency(this).toString() + ".");
290 player.message(message);
291 }
292
293 }

References container, com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.Item.getName(), com.runehive.content.store.StoreItem.getShopCurrency(), com.runehive.content.store.StoreItem.getShopValue(), com.runehive.game.world.entity.mob.player.Player.message(), and com.runehive.content.store.currency.CurrencyType.toString().

Referenced by com.runehive.content.store.impl.DefaultStore.itemContainerAction(), com.runehive.content.store.impl.PersonalStore.itemContainerAction(), com.runehive.content.store.impl.RecipeForDisasterStore.itemContainerAction(), and com.runehive.content.store.impl.SkillcapeStore.itemContainerAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendSellValue()

final void com.runehive.content.store.Store.sendSellValue ( Player player,
int slot )
protected

Definition at line 249 of file Store.java.

249 {
250 Item item = player.inventory.get(slot);
251
252 if (item == null) {
253 return;
254 }
255
256 if (!item.isTradeable()) {
257 player.send(new SendMessage("This item can't be sold to shops."));
258 return;
259 }
260
261 if (CurrencyType.isCurrency(item.getId())) {
262 player.send(new SendMessage("You can not sell currency to this shop!"));
263 return;
264 }
265
266 final int value = item.getSellValue();
267
268 if (value <= 0) {
269 player.send(new SendMessage(String.format("This store will buy %s for free!", item.getName())));
270 return;
271 }
272
273 final String message = this.sellType() != SellType.NONE ? String.format("This store will buy %s for %s %s.", item.getName(), Utility.formatDigits(value), currencyType.toString()) : String.format("[%s] will not buy any items.", name);
274 player.send(new SendMessage(message));
275 }

References currencyType, com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.containers.ItemContainer.get(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.items.Item.getName(), com.runehive.game.world.items.Item.getSellValue(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.content.store.currency.CurrencyType.isCurrency(), com.runehive.game.world.items.Item.isTradeable(), name, com.runehive.content.store.SellType.NONE, sellType(), and com.runehive.game.world.entity.mob.player.Player.send().

Referenced by com.runehive.content.store.impl.DefaultStore.itemContainerAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type()

abstract StoreType com.runehive.content.store.Store.type ( )
abstract

Reimplemented in com.runehive.content.store.impl.DefaultStore, com.runehive.content.store.impl.PersonalStore, com.runehive.content.store.impl.RecipeForDisasterStore, and com.runehive.content.store.impl.SkillcapeStore.

Referenced by purchase().

Here is the caller graph for this function:

Member Data Documentation

◆ container

◆ currencyType

◆ itemCache

◆ name

◆ players

◆ STORES


The documentation for this class was generated from the following file: