RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
RecipeForDisasterStore.java
1package com.osroyale.content.store.impl;
2
3
4import com.osroyale.content.store.*;
5import com.osroyale.content.store.currency.CurrencyType;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.items.Item;
8import com.osroyale.game.world.items.containers.ItemContainer;
9import com.osroyale.net.packet.out.SendItemOnInterface;
10import com.osroyale.net.packet.out.SendScrollbar;
11import com.osroyale.net.packet.out.SendString;
12
13import java.util.Arrays;
14import java.util.Objects;
15import java.util.Optional;
16import java.util.OptionalInt;
17
53
54public class RecipeForDisasterStore extends Store {
55
56 public final StoreItem[] items = {
57 new StoreItem(7453, 1, OptionalInt.of(10000), Optional.of(CurrencyType.COINS)),
58 new StoreItem(7454, 1, OptionalInt.of(20000), Optional.of(CurrencyType.COINS)),
59 new StoreItem(7455, 1, OptionalInt.of(30000), Optional.of(CurrencyType.COINS)),
60 new StoreItem(7456, 1, OptionalInt.of(40000), Optional.of(CurrencyType.COINS)),
61 new StoreItem(7457, 1, OptionalInt.of(50000), Optional.of(CurrencyType.COINS)),
62 new StoreItem(7458, 1, OptionalInt.of(60000), Optional.of(CurrencyType.COINS)),
63 new StoreItem(7459, 1, OptionalInt.of(70000), Optional.of(CurrencyType.COINS)),
64 new StoreItem(7460, 1, OptionalInt.of(80000), Optional.of(CurrencyType.COINS)),
65 new StoreItem(7461, 1, OptionalInt.of(90000), Optional.of(CurrencyType.COINS)),
66 new StoreItem(7462, 1, OptionalInt.of(100000), Optional.of(CurrencyType.COINS))
67 };
68
69 public RecipeForDisasterStore() {
70 super("Recipe For Disaster Store", ItemContainer.StackPolicy.ALWAYS, CurrencyType.COINS, 10);
71 this.container.setItems(items, true);
72 Arrays.stream(items).filter(Objects::nonNull).forEach(item -> itemCache.put(item.getId(), item.getAmount()));
73 }
74
75 @Override
76 public void itemContainerAction(Player player, int id, int slot, int action, boolean purchase) {
77 switch (action) {
78 case 1:
79 if (purchase) {
80 this.sendPurchaseValue(player, slot);
81 }
82 break;
83 default:
84 int amount = action == 2 ? 1 : action == 3 ? 10 : action == 4 ? 100 : -100;
85 if (amount == -100) {
86 throw new IllegalArgumentException("The action given was invalid. [ACTION=" + action + "]");
87 }
88 if (purchase) {
89 this.purchase(player, new Item(id, amount), slot);
90 }
91 break;
92 }
93 }
94
95 @Override
96 public void refresh(Player player) {
97 player.send(new SendString("Store size: " + items.length, 47507));
98 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
99 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
100 players.stream().filter(Objects::nonNull).forEach(p -> player.send(new SendItemOnInterface(47551, container.toArray())));
101 }
102
103 @Override
104 public void open(Player player) {
105 player.attributes.set("SHOP", name);
106
107 if (!STORES.containsKey(name)) {
108 STORES.put(name, this);
109 }
110
111 StoreItem[] storeItems = new StoreItem[10];
112
113 int unlocked = player.glovesTier;
114
115 int lastItem = 0;
116 for (int index = 0; index < unlocked; index++) {
117 if (index > unlocked)
118 break;
119 storeItems[index] = items[index];
120 lastItem = index;
121 }
122 for (int i = 0; i < unlocked; i++) {
123 player.send(new SendString(storeItems[i].getShopValue() + "," + currencyType.getId(), 47552 + i));
124 }
125 player.send(new SendString(name, 47502));
126 player.send(new SendString("Store size: " + unlocked, 47507));
127 player.send(new SendString(CurrencyType.getValue(player, currencyType), 47508));
128 player.send(new SendItemOnInterface(47551, storeItems));
129 final int scrollBarSize = lastItem <= 32 ? 0 : (lastItem / 8) * 72;
130 player.send(new SendScrollbar(47550, scrollBarSize));
131 player.send(new SendItemOnInterface(3823, player.inventory.toArray()));
132 player.interfaceManager.openInventory(StoreConstant.INTERFACE_ID, 3822);
133 }
134
135 @Override
136 public void close(Player player) {
137 players.remove(player);
138 player.attributes.remove("SHOP");
139 }
140
141 @Override
142 public StoreType type() {
143 return StoreType.DEFAULT;
144 }
145
146 @Override
147 public SellType sellType() {
148 return SellType.NONE;
149 }
150
151 @Override
152 public boolean decrementStock() {
153 return false;
154 }
155}