1package com.runehive.content.store.impl;
3import com.runehive.Config;
4import com.runehive.content.dialogue.DialogueFactory;
5import com.runehive.content.store.*;
6import com.runehive.content.store.currency.CurrencyType;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.containers.ItemContainer;
11import com.runehive.net.packet.out.*;
12import com.runehive.util.GameSaver;
13import com.runehive.util.MessageColor;
14import com.runehive.util.Utility;
25 public static final Map<Integer, PersonalStore>
FEATURED_SHOPS =
new HashMap<>();
28 public static Map<String, Long>
SOLD_ITEMS =
new HashMap<>();
48 items.ifPresent(i -> this.
container.setItems(i,
false));
104 player.
send(
new SendMessage(
"You do not have a store. Set it up by first opening it from the previous menu."));
119 shop.caption = context;
121 shop.title = context;
125 player.
send(
new SendMessage(
"You have changed your shop " +
type +
" to: " + context +
"."));
137 },
"Change caption", () -> {
149 int size = personalShops.size() < 10 ? 10 : personalShops.size();
150 for (
int string = 53031, index = 0; index < size; index++) {
151 PersonalStore shop = index >= personalShops.size() ? null : personalShops.get(index);
152 String tooltip = shop ==
null ?
"" :
"View <col=ffb000>" + shop.name +
"<col=FFFFFF>'s shop";
153 String
name = shop ==
null ?
"" : shop.
name;
166 for (
int index = 0,
string = 53008; index < 10; index++,
string++) {
167 PersonalStore shop = index >= featured_shops.size() ? null : featured_shops.get(index);
168 String
name = shop ==
null ?
"" : shop.
name;
169 String tooltip = shop ==
null ?
"" :
"View <col=ffb000>" + shop.name +
"<col=FFFFFF>'s shop";
176 player.
send(
new SendString(
"Available stores: " + personalShops.size(), 53023));
187 player.
send(
new SendMessage(
"You can not sell untradeable items in your shop!"));
191 player.
send(
new SendMessage(
"You can not sell any currency in your shop!"));
200 setValue(player, invItem, storeItem, Integer.parseInt(value), slot);
206 player.
send(
new SendInputAmount(
"How much would you like to put in your shop?", 10, amount -> {
207 storeItem.
setAmount(Integer.parseInt(amount));
209 setValue(player, invItem, storeItem, Integer.parseInt(value), slot);
229 Optional<Item> contains =
container.stream().filter(i -> i !=
null && storeItem.
getId() == i.getId() && ((
StoreItem) i).getShopValue() == storeItem.
getShopValue()).findFirst();
231 if (contains.isPresent()) {
232 contains.get().incrementAmountBy(storeItem.
getAmount());
249 if (storeItem ==
null)
252 if (item.getAmount() > storeItem.
getAmount())
254 if (!player.inventory.hasCapacityFor(item)) {
255 item.setAmount(player.inventory.remaining());
256 if (item.getAmount() == 0) {
257 player.send(
new SendMessage(
"You do not have enough space in your inventory to withdraw this item!"));
262 if (player.inventory.remaining() >= item.getAmount() && !item.isStackable() || player.inventory.remaining() >= 1 && item.isStackable() || player.inventory.contains(item.getId()) && item.isStackable()) {
263 if ((storeItem.
getAmount() - item.getAmount()) < 1) {
269 player.inventory.add(item);
271 player.send(
new SendMessage(
"You don't have enough space in your inventory."));
303 player.dialogueFactory.clear();
330 int amount = action == 2 ? (
purchase ? 1 : 5) : action == 3 ? 10 : action == 4 ? count : -100;
334 this.
remove(player,
new Item(
id, amount),
slot);
344 this.
add(player,
new Item(
id, amount),
slot, amount == -100);
381 if (items.length != 0) {
382 for (
int i = 0; i < items.length; i++) {
383 player.
send(
new SendString(items[i] ==
null ?
"0" : items[i].getShopValue() +
"," + 0, 40052 + i));
387 final int scrollBarSize = lastItem <= 32 ? 0 : (lastItem / 8) * 72;
392 player.
send(
new SendString(
"Store size: " + items.length, 40007));
The class that contains setting-related constants for the server.
static final String[] BAD_STRINGS
Strings that are classified as bad.
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory onAction(Runnable action)
Sets an action so this action can be executed after dialogues are done.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
Class to execute all constants for Shops.
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.
static List< PersonalStore > getFeaturedShops()
static List< PersonalStore > getPersonalShops()
static Map< String, Store > STORES
A mapping of each shop by it's name.
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)
void setShopValue(int value)
static void openPanel(Player player)
Opens the panel where a player can search for shops.
static Map< String, Long > SOLD_ITEMS
A mapping of a player name with the amount of coins waiting for him.
static void openMenu(Player player)
String title
The title of this shop.
PersonalStore(String name, Optional< StoreItem[]> items, int rank, String title, String caption, CurrencyType currency)
Creates a new Store.
void add(Player player, Item item, int slot, boolean addX)
Handles adding an item to the player's personal shop.
static void changeName(Player player, String input, boolean caption)
Changes the name of the shop.
static void add(Player player, PersonalStore store)
void close(Player player)
final int rank
The rank of this shop on the featured list.
void modify(Player player, int slot)
Modifies the player's shop item.
static void myShop(Player player)
Creates the player's shops if non-existent or will enter.
static void claimCoins(Player player)
Handles claiming coins from the personal store.
void itemContainerAction(Player player, int id, int slot, int action, boolean purchase)
static void edit(Player player)
Handles editing the personal store.
String caption
The caption of this shop.
void onPurchase(Player player, Item item)
boolean isOwner(Player player)
Checks if the player is the owner of the shop.
void refresh(Player player)
static final Map< Integer, PersonalStore > FEATURED_SHOPS
The shops the player is currently viewing.
void setValue(Player player, Item invItem, StoreItem storeItem, int value, int slot)
boolean updating
The flag is the shop is being updated by the owner.
Represents the game world.
static Optional< Player > search(String name)
Gets a player by name.
final GenericAttributes attributes
void close(int interfaceId)
boolean isInterfaceOpen(int id)
Checks if a certain interface is enter.
void openInventory(int identification, int overlay)
Opens an inventory interface for the player.
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
final Inventory inventory
String getName()
Gets the name of this entity.
DialogueFactory dialogueFactory
final InterfaceManager interfaceManager
void send(OutgoingPacket encoder)
final Map< Integer, PersonalStore > viewing_shops
The container class that represents an item that can be interacted with.
final void setAmount(int amount)
Sets the quantity of this item.
final int getId()
Gets the identification of this item.
final int getAmount()
Gets the quantity of this item.
int getValue(PriceType type)
Gets the value for this item.
final void decrementAmountBy(int amount)
Decrements the amount by amount @endiliteral.
An abstraction game representing a group of Items.
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.
final Item get(int index)
Gets the Item located on index.
final Optional< Item > retrieve(int index)
Retrieves the item located on index.
final Item[] toArray()
Returns a shallow copy of the backing array.
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.
Created by Daniel on 2017-11-05.
static long PERSONAL_ITEM_WORTH
Handles miscellaneous methods.
static String formatName(final String input)
static String formatDigits(final int amount)
Formats digits for integers.
static String formatPrice(final long amount)
Formats a price for longs.
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.
NONE
No items can be sold in the shop.
The enumerated type whose elements represent constants that are used to differ between shops.
PERSONAL
The personal shop which is commonly owned by players.
The enumerated type whom holds all the currencies usable for a server.
static boolean isCurrency(int id)
static String getCrown(Player player)
Gets the crown display.
An enumerated type defining policies for stackable Items.
STANDARD
The STANDARD policy, items are only stacked if they are defined as stackable in their ItemDefinition ...
Holds an enum of colors for ease.