RuneHive-Game
Loading...
Searching...
No Matches
RecipeForDisasterStore.java
Go to the documentation of this file.
1package com.runehive.content.store.impl;
2
3
4import com.runehive.content.store.*;
5import com.runehive.content.store.currency.CurrencyType;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.items.Item;
8import com.runehive.game.world.items.containers.ItemContainer;
9import com.runehive.net.packet.out.SendItemOnInterface;
10import com.runehive.net.packet.out.SendScrollbar;
11import com.runehive.net.packet.out.SendString;
12
13import java.util.Arrays;
14import java.util.Objects;
15import java.util.Optional;
16import java.util.OptionalInt;
17
18/**
19 * Handles the recipe for disaster store
20 *
21 * @author Daniel
22 */
23public class RecipeForDisasterStore extends Store {
24
25 public final StoreItem[] items = {
26 new StoreItem(7453, 1, OptionalInt.of(10000), Optional.of(CurrencyType.COINS)),
27 new StoreItem(7454, 1, OptionalInt.of(20000), Optional.of(CurrencyType.COINS)),
28 new StoreItem(7455, 1, OptionalInt.of(30000), Optional.of(CurrencyType.COINS)),
29 new StoreItem(7456, 1, OptionalInt.of(40000), Optional.of(CurrencyType.COINS)),
30 new StoreItem(7457, 1, OptionalInt.of(50000), Optional.of(CurrencyType.COINS)),
31 new StoreItem(7458, 1, OptionalInt.of(60000), Optional.of(CurrencyType.COINS)),
32 new StoreItem(7459, 1, OptionalInt.of(70000), Optional.of(CurrencyType.COINS)),
33 new StoreItem(7460, 1, OptionalInt.of(80000), Optional.of(CurrencyType.COINS)),
34 new StoreItem(7461, 1, OptionalInt.of(90000), Optional.of(CurrencyType.COINS)),
35 new StoreItem(7462, 1, OptionalInt.of(100000), Optional.of(CurrencyType.COINS))
36 };
37
39 super("Recipe For Disaster Store", ItemContainer.StackPolicy.ALWAYS, CurrencyType.COINS, 10);
40 this.container.setItems(items, true);
41 Arrays.stream(items).filter(Objects::nonNull).forEach(item -> itemCache.put(item.getId(), item.getAmount()));
42 }
43
44 @Override
45 public void itemContainerAction(Player player, int id, int slot, int action, boolean purchase) {
46 switch (action) {
47 case 1:
48 if (purchase) {
49 this.sendPurchaseValue(player, slot);
50 }
51 break;
52 default:
53 int amount = action == 2 ? 1 : action == 3 ? 10 : action == 4 ? 100 : -100;
54 if (amount == -100) {
55 throw new IllegalArgumentException("The action given was invalid. [ACTION=" + action + "]");
56 }
57 if (purchase) {
58 this.purchase(player, new Item(id, amount), slot);
59 }
60 break;
61 }
62 }
63
64 @Override
65 public void refresh(Player player) {
66 player.send(new SendString("Store size: " + items.length, 47507));
67 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
68 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
69 players.stream().filter(Objects::nonNull).forEach(p -> player.send(new SendItemOnInterface(47551, container.toArray())));
70 }
71
72 @Override
73 public void open(Player player) {
74 player.attributes.set("SHOP", name);
75
76 if (!STORES.containsKey(name)) {
77 STORES.put(name, this);
78 }
79
80 StoreItem[] storeItems = new StoreItem[10];
81
82 int unlocked = player.glovesTier;
83
84 int lastItem = 0;
85 for (int index = 0; index < unlocked; index++) {
86 if (index > unlocked)
87 break;
88 storeItems[index] = items[index];
89 lastItem = index;
90 }
91 for (int i = 0; i < unlocked; i++) {
92 player.send(new SendString(storeItems[i].getShopValue() + "," + currencyType.getId(), 47552 + i));
93 }
94 player.send(new SendString(name, 47502));
95 player.send(new SendString("Store size: " + unlocked, 47507));
96 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
97 player.send(new SendItemOnInterface(47551, storeItems));
98 final int scrollBarSize = lastItem <= 32 ? 0 : (lastItem / 8) * 72;
99 player.send(new SendScrollbar(47550, scrollBarSize));
100 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
102 }
103
104 @Override
105 public void close(Player player) {
106 players.remove(player);
107 player.attributes.remove("SHOP");
108 }
109
110 @Override
111 public StoreType type() {
112 return StoreType.DEFAULT;
113 }
114
115 @Override
117 return SellType.NONE;
118 }
119
120 @Override
121 public boolean decrementStock() {
122 return false;
123 }
124}
Class to execute all constants for Shops.
static final int INTERFACE_ID
The identification for the shop itemcontainer.
void sendPurchaseValue(Player player, int slot)
Definition Store.java:277
final String name
The name of this shop.
Definition Store.java:26
Store(String name, ItemContainer.StackPolicy policy, CurrencyType currencyType, int capacity)
Definition Store.java:40
final Set< Player > players
The set of players that are currently viewing this shop.
Definition Store.java:38
Map< Integer, Integer > itemCache
The map of cached shop item identifications and their amounts.
Definition Store.java:35
static Map< String, Store > STORES
A mapping of each shop by it's name.
Definition Store.java:23
final CurrencyType currencyType
The currency for this shop.
Definition Store.java:32
ItemContainer container
The current item container which contains the current items from this shop.
Definition Store.java:29
boolean purchase(Player player, Item item, int slot)
Definition Store.java:89
A simple wrapper class which holds extra attributes for the item object.
void itemContainerAction(Player player, int id, int slot, int action, boolean purchase)
final GenericAttributes attributes
Definition Mob.java:95
void openInventory(int identification, int overlay)
Opens an inventory interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
An abstraction game representing a group of Items.
final Item[] toArray()
Returns a shallow copy of the backing array.
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.
Definition SellType.java:8
NONE
No items can be sold in the shop.
Definition SellType.java:13
The enumerated type whose elements represent constants that are used to differ between shops.
Definition StoreType.java:9
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)
An enumerated type defining policies for stackable Items.
ALWAYS
The ALWAYS policy, items are always stacked regardless of their ItemDefinition table.