RuneHive-Game
Loading...
Searching...
No Matches
SkillcapeStore.java
Go to the documentation of this file.
1package com.runehive.content.store.impl;
2
3
4import com.runehive.content.emote.Skillcape;
5import com.runehive.content.store.*;
6import com.runehive.content.store.currency.CurrencyType;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.skill.Skill;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.containers.ItemContainer;
11import com.runehive.net.packet.out.SendItemOnInterface;
12import com.runehive.net.packet.out.SendScrollbar;
13import com.runehive.net.packet.out.SendString;
14
15import java.util.Arrays;
16import java.util.Objects;
17
18import static com.runehive.content.store.currency.CurrencyType.COINS;
19
20/**
21 * Handles the recipe for disaster store
22 *
23 * @author Daniel
24 */
25public class SkillcapeStore extends Store {
26
27 private final StoreItem[] items = Skillcape.getItems();
28
29 public SkillcapeStore() {
30 super("Skillcape Store", ItemContainer.StackPolicy.ALWAYS, COINS, Skill.SKILL_COUNT);
31 this.container.setItems(items, true);
32 Arrays.stream(items).filter(Objects::nonNull).forEach(item -> itemCache.put(item.getId(), item.getAmount()));
33 }
34
35 @Override
36 public void itemContainerAction(Player player, int id, int slot, int action, boolean purchase) {
37 switch (action) {
38 case 1:
39 if (purchase) {
40 this.sendPurchaseValue(player, slot);
41 }
42 break;
43 default:
44 int amount = action == 2 ? 1 : action == 3 ? 10 : action == 4 ? 100 : -100;
45 if (amount == -100) {
46 throw new IllegalArgumentException("The action given was invalid. [ACTION=" + action + "]");
47 }
48 if (purchase) {
49 this.purchase(player, new Item(id, amount), slot);
50 }
51 break;
52 }
53 }
54
55 @Override
56 public boolean purchase(Player player, Item item, int slot) {
57 Skillcape cape = Skillcape.forId(item.getId());
58
59 if (cape == null) {
60 player.message("Something went wrong with your purchase!");
61 return false;
62 }
63
64 if (player.skills.getMaxLevel(cape.getSkill()) < 99) {
65 player.message("You need a " + Skill.getName(cape.getSkill()) + " level of 99 to purchase this cape!");
66 return false;
67 }
68
69 if (super.purchase(player, item, slot)) {
70 player.inventory.addOrDrop(new Item(item.getId() + 1, 1));
71 refresh(player);
72 return true;
73 }
74
75 return false;
76 }
77
78 @Override
79 public void refresh(Player player) {
80 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
81 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
82 }
83
84 @Override
85 public void open(Player player) {
86 player.attributes.set("SHOP", name);
87
88 if (!STORES.containsKey(name)) {
89 STORES.put(name, this);
90 }
91
92 for (int index = 0; index < Skill.SKILL_COUNT; index++) {
93 player.send(new SendString(100000 + "," + currencyType.getId(), 47552 + index));
94 }
95
96 player.send(new SendString(name, 47502));
97 player.send(new SendString("Store size: " + Skill.SKILL_COUNT, 47507));
98 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
99 player.send(new SendItemOnInterface(47551, items));
100 player.send(new SendScrollbar(47550, 0));
101 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
103 }
104
105 @Override
106 public void close(Player player) {
107// players.remove(player);
108 player.attributes.remove("SHOP");
109 }
110
111 @Override
112 public StoreType type() {
113 return StoreType.DEFAULT;
114 }
115
116 @Override
118 return SellType.NONE;
119 }
120
121 @Override
122 public boolean decrementStock() {
123 return false;
124 }
125}
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
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
A simple wrapper class which holds extra attributes for the item object.
void itemContainerAction(Player player, int id, int slot, int action, boolean purchase)
boolean purchase(Player player, Item item, int slot)
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
Represents a trainable and usable skill.
Definition Skill.java:18
static String getName(int skill)
Gets the name for a skill id.
Definition Skill.java:465
static final int SKILL_COUNT
The amount of available skills.
Definition Skill.java:90
int getMaxLevel(int id)
Gets the highest possible level of a skill.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
An abstraction game representing a group of Items.
final Item[] toArray()
Returns a shallow copy of the backing array.
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
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.
Holds the data for skillcape emotes.
static Skillcape forId(int id)
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.