1package com.runehive.content.store.impl;
3import com.runehive.content.store.*;
4import com.runehive.content.store.currency.CurrencyType;
5import com.runehive.game.task.TickableTask;
6import com.runehive.game.world.World;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.mob.player.PlayerRight;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.containers.ItemContainer;
11import com.runehive.net.packet.out.*;
13import java.util.Arrays;
14import java.util.Objects;
47 Arrays.stream(
items).filter(Objects::nonNull).forEach(item ->
itemCache.put(item.getId(), item.getAmount()));
52 return container.stream().filter(Objects::nonNull).anyMatch(i -> !
itemCache.containsKey(i.getId()) || (
itemCache.containsKey(i.getId()) && i.getAmount() <
itemCache.get(i.getId())));
57 return container.stream().filter(Objects::nonNull).allMatch(i -> {
60 }
else if (!
itemCache.containsKey(i.getId())) {
82 this.
sell(player,
new Item(
id, Integer.parseInt(amount)),
slot,
true);
112 player.
send(
new SendMessage(
"As an iron man you do not have access to this store!"));
144 for (
int i = 0; i <
items.length; i++) {
158 final int scrollBarSize = lastItem <= 32 ? 0 : (lastItem / 8) * 72;
206 boolean restocked =
false;
219 if (player !=
null) {
235 final int reduceAmount = item.
getAmount() > 100 ? (int) ((
double) item.
getAmount() * 0.05D) : 1;
247 final boolean originalItem =
container.itemCache.containsKey(item.
getId());
250 if (originalItem && item.
getAmount() < originalAmount) {
253 }
else if (originalItem && item.
getAmount() > originalAmount) {
Class to execute all constants for Shops.
static final String[] IRON_MAN_STORES
Allowed shops for Iron man accounts.
static final int INTERFACE_ID
The identification for the shop itemcontainer.
void sendPurchaseValue(Player player, int slot)
final String name
The name of this shop.
Store(String name, ItemContainer.StackPolicy policy, CurrencyType currencyType, int capacity)
final Set< Player > players
The set of players that are currently viewing this shop.
Map< Integer, Integer > itemCache
The map of cached shop item identifications and their amounts.
final void sell(Player player, Item item, int slot, boolean addX)
final void sendSellValue(Player player, int slot)
static Map< String, Store > STORES
A mapping of each shop by it's name.
final CurrencyType currencyType
The currency for this shop.
ItemContainer container
The current item container which contains the current items from this shop.
boolean purchase(Player player, Item item, int slot)
A simple wrapper class which holds extra attributes for the item object.
CurrencyType getShopCurrency(Store store)
The task that will restock items in shop containers when needed.
boolean restock(StoreItem item)
Attempts to restock item for the container.
final DefaultStore container
The container that will be restocked.
StoreRestockTask(DefaultStore container)
Creates a new StoreRestockTask.
final ItemContainer original
The original item container this shop started with.
final StoreItem[] items
The items in this shop.
DefaultStore(StoreItem[] items, String name, SellType sellType, boolean restock, CurrencyType currency)
Creates a new Store.
void refresh(Player player)
void itemContainerAction(Player player, int id, int slot, int action, boolean purchase)
void close(Player player)
boolean needsRestock()
Determines if the items in the container need to be restocked.
boolean restockCompleted()
Determines if the items in the container no longer need to be restocked.
final boolean restock
Determines if this shop restocks.
StoreRestockTask restockTask
The shop restock task that will restock the shops.
synchronized final void cancel()
Cancels all subsequent executions.
TickableTask(boolean instant, int delay)
Represents the game world.
static void schedule(Task task)
Submits a new event.
final GenericAttributes attributes
void openInventory(int identification, int overlay)
Opens an inventory interface for the player.
This class represents a character controlled by a player.
final Inventory inventory
final InterfaceManager interfaceManager
void send(OutgoingPacket encoder)
The container class that represents an item that can be interacted with.
final int getId()
Gets the identification of this item.
final int getAmount()
Gets the quantity of this item.
final void decrementAmountBy(int amount)
Decrements the amount by amount @endiliteral.
final void incrementAmount()
Increments the amount by 1.
An abstraction game representing a group of Items.
final void setItems(Item[] items, boolean copy)
Sets the container of items to items.
final Item[] toArray()
Returns a shallow copy of the backing array.
void refresh()
Refreshes the players inventory.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
public< K > void remove(K key)
Removes a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
Represents ways items can be sold in a shop.
ANY
Can sell any items to the shop.
The enumerated type whose elements represent constants that are used to differ between shops.
DEFAULT
The default shop which is commonly owned by the server.
The enumerated type whom holds all the currencies usable for a server.
static String getValue(Player player, CurrencyType currency)
Holds all the player right data.
static boolean isIronman(Player player)
Checks if the player is an ironman.
An enumerated type defining policies for stackable Items.
ALWAYS
The ALWAYS policy, items are always stacked regardless of their ItemDefinition table.