Jump to content

The RuneLocus forum has been archived and does not accept new registrations.
Click here for more information, and click here to join the community on Discord.

562 New ShopHandler


Steve
 Share

Recommended Posts

Shophandler.java

[CODE]package com.rs2hd.content;

import java.util.HashMap;

import com.rs2hd.GameEngine;
import com.rs2hd.model.Player;
import com.rs2hd.content.Shop;
import com.rs2hd.util.log.Logger;

/**
* Handles the shops, loads them, and opens them
*
* @author Stephen Moyer <[email protected]>
*
*/
public class ShopHandler {

private HashMap<Integer, Shop> shops = new HashMap<Integer, Shop>();

/**
* Load up the shops
*/
public void loadShops() {
shops.put(1, new Shop(1, true, new int[] { 4151, 10551 }, new int[] {
1000, 1000 }));
shops.put(2, new Shop(2, false, GameEngine.shops.ShopN,
GameEngine.shops.ShopN));
shops.put(3, new Shop(3, false, GameEngine.shops.Shop2N,
GameEngine.shops.Shop2N));
shops.put(4, new Shop(4, false, GameEngine.shops.shop3N,
GameEngine.shops.shop3N));
shops.put(5, new Shop(5, false, GameEngine.shops.shop4N,
GameEngine.shops.shop4N));
shops.put(6, new Shop(6, false, GameEngine.shops.shop5N,
GameEngine.shops.shop5N));
shops.put(7, new Shop(7, false, GameEngine.shops.shop6N,
GameEngine.shops.shop6N));
shops.put(8, new Shop(8, false, GameEngine.shops.shop7N,
GameEngine.shops.shop7N));
shops.put(9, new Shop(9, false, GameEngine.shops.shop8N,
GameEngine.shops.shop8N));
shops.put(10, new Shop(10, false, GameEngine.shops.shop9N,
GameEngine.shops.shop9N));
shops.put(11, new Shop(11, false, GameEngine.shops.shop10N,
GameEngine.shops.shop10N));
shops.put(12, new Shop(12, false, GameEngine.shops.shop11N,
GameEngine.shops.shop11N));
shops.put(13, new Shop(13, false, GameEngine.shops.shop12N,
GameEngine.shops.shop12N));
shops.put(14, new Shop(14, false, GameEngine.shops.shop13N,
GameEngine.shops.shop13N));
shops.put(15, new Shop(15, false, GameEngine.shops.shop14N,
GameEngine.shops.shop14N));
shops.put(16, new Shop(16, false, GameEngine.shops.shop15N,
GameEngine.shops.shop15N));
shops.put(17, new Shop(17, false, GameEngine.shops.shop16N,
GameEngine.shops.shop16N));
Logger.getInstance().info("Loaded Shops");

}

/**
* Open a shop for the player, by the specified id
*
* @param player
* The player to open for
* @param id
* The id of the shop
*/
public void openShop(Player player, int id) {
player.shopId = id;
shops.get(id).openForPlayer(player);
shops.get(id).addPlayer(player);
}

/**
* Return the shop instance of the specified id
*
* @param id
* The shop's id
* @return The shop instance
*/
public Shop getShop(int id) {
return shops.get(id);
}

/**
* For people that are lazy to convert, and use proper conventions.
*
* @param p
* The player that opened the shop
* @param id
* The shops id
*/
public void openshop(Player p, int id) {
openShop(p, id);
}

}[/CODE]

Shop[B][COLOR="Red"]s[/COLOR][/B].java
[CODE]package com.rs2hd.content;

/**
* Created by IntelliJ IDEA.
* User: Sere but dragnkk converted to rs2hd and gotta remake for 562
* Date: 6-mrt-2009
* Time: 10:33:19
*/
public class Shops {
public int maxItems = 40;
/*init shops */
public int[] Generalshoplumb = {1755, 590, 5605, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 227};
public int[] GeneralshoplumbN = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
public int[] Generalshopvarrock = {1755, 590, 5605, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 227};
public int[] GeneralshopvarrockN = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
public int[] Generalshopfalador = {1755, 590, 5605, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 227};
public int[] GeneralshopfaladorN = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
public int[] Shop = {4151, 1540, 10828, 1079, 1127, 1163, 1201, 1067, 1115, 1153, 1191, 11732, 6585, 7462, 1712, 15308, 15312, 15316, 15320, 15324, 15332, 15272, 15241, 15243, 9185, 1321, 1323, 1325, 1327, 1329, 1331, 1333, 4587};
public int[] ShopN = {4151, 1540, 10828, 1079, 1127, 1163, 1201, 1067, 1115, 1153, 1191, 11732, 6585, 7462, 1712, 15308, 15312, 15316, 15320, 15324, 15332, 15272, 15241, 15243, 9185, 1321, 1323, 1325, 1327, 1329, 1331, 1333, 4587};
public int[] Shop2 = {526, 2859, 528, 3179, 530, 532, 3125, 10977, 10976, 4812, 3123, 534, 6812, 536, 4830, 4832, 6729, 4834}; // the items
public int[] Shop2N = {100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000}; // the amount
public int[] shop3 = {199, 201, 203, 205, 207, 209, 211, 213, 215};
public int[] shop3N = {10000, 9999999, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop4 = {303, 305, 317, 335, 331, 349, 377, 371, 383, 389, 395, 315, 333, 329, 379, 373, 385, 391, 397};
public int[] shop4N = {1000, 1000, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop5 = {1755, 1625, 1627, 1629, 1623, 1621, 1619, 1617, 1631, 6571, 1609, 1611, 1613, 1607, 1605, 1603, 1601, 1615, 6573};
public int[] shop5N = {1000, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop6 = {5318, 5322, 5324, 5323, 5321, 5291, 5293, 5295, 5294, 5296, 5297, 5298, 5299, 5300, 5301, 5302, 5303, 5304, 5292};
public int[] shop6N = {1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000};
public int[] shop7 = {1351, 1349, 1353, 1355, 1357, 1359, 6739, 590, 1511, 1521, 1519, 1517, 1515, 1513};
public int[] shop7N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop8 = {1265, 1267, 1269, 1273, 1271, 1275, 15259, 436, 438, 440, 442, 453, 447, 449, 451};
public int[] shop8N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop9 = {10400, 10402, 10404, 10406, 10408, 10410, 10412, 10414, 10416, 10418, 10420, 10422, 7319, 7321, 7323, 7325, 7327, 2639, 2641, 2643, 9470};
public int[] shop9N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop10 = {2460, 2462, 2464, 2466, 2468, 2470, 2472, 2474, 2476, 2904, 2914, 2924, 2934, 3791, 1837, 2912, 2922, 2932, 2942, 3799, 775, 3840, 3842, 3844};
public int[] shop10N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop11 = {9748, 9751, 9754, 9757, 9760, 9763, 9766, 9769, 9772, 9775, 9778, 9781, 9784, 9787, 9790, 9793, 9796, 9799, 9802, 9805, 9808, 9811, 9949, 9813, 9814};
public int[] shop11N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop12 = {9747, 9750, 9753, 9756, 9759, 9762, 9765, 9768, 9771, 9774, 9777, 9780, 9783, 9786, 9789, 9792, 9795, 9798, 9801, 9804, 9807, 9810, 9948, 9813, 9814};
public int[] shop12N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop13 = {9749, 9752, 9755, 9758, 9761, 9764, 9767, 9770, 9773, 9776, 9779, 9782, 9785, 9788, 9791, 9794, 9797, 9800, 9803, 9806, 9809, 9812, 9950};
public int[] shop13N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop14 = {1379, 1381, 1383, 1385, 1387, 4675, 4089, 4091, 4093, 4095, 4097, 4099, 4101, 4103, 4105, 4107, 4109, 4111, 4113, 4115, 4117, 6916, 6918, 6920, 6922, 6924, 6889, 1409, 4170};
public int[] shop14N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] shop15 = {1917, 5763, 1913, 1905, 1909, 1907, 1911, 2955, 5755, 5759, 8940, 1993, 7157, 1915, 2021, 2015, 2017, 5751};
public int[] shop15N = {999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999};
public int[] shop16 = {6106, 6107, 6108, 6109, 6110, 6111, 2581, 2577, 1323, 1333, 4587, 15312, 15308, 2434, 1191, 4153, 1215, 5698, 11235, 11212, 9185, 4675, 3842, 3840, 3844, 7459, 6585, 6527, 11128, 542, 544, 1067, 1115, 1153, 868, 6528};
public int[] shop16N = {10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
public int[] Summoningshop = {12155,12183, 12790, 12007, 12029, 12083, 12093, 12158, 12159, 12160, 12163, 12527, 10818, 2859, 2363, 1115};
public int[] SummoningshopN = {999999999,999999999, 1000, 1000, 1000, 1000, 1000, 999999999, 999999999, 999999999, 999999999, 999999999, 1000, 10000, 999999999, 999999999};
public int[] Range = {887, 878, 881, 8882, 9140, 9141, 9142, 9144, 9242, 9243, 9244, 9245, 13280, 886, 837, 841, 843, 845, 849, 853, 857, 861, 1065, 1135, 1099, 2487, 2489, 2491, 2493, 2495, 2497, 2499, 2501, 2503, 11235, 11212, 884, 888, 890, 892, 868};
public int[] RangeN ={100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
public int[] Skillcapes = {9748, 9751, 9754, 9757, 9760, 9763, 9769, 9775, 9787, 9802, 9805, 9949, 12170};
public int[] SkillcapesN = {100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000};

/*init shops */
public Shops() {

System.out.println("Loaded Tony-Scape 562 Shops");
}
}[/CODE]

Shop.java

[CODE]package com.rs2hd.content;

import java.text.NumberFormat;
import java.util.ArrayList;

import com.rs2hd.GameEngine;
import com.rs2hd.event.Event;
import com.rs2hd.model.Container;
import com.rs2hd.model.Item;
import com.rs2hd.model.ItemDefinition;
import com.rs2hd.model.Player;
import com.rs2hd.model.World;

/**
* Creates a new shop.
*
* @author Stephen Moyer <[email protected]>
*
*/
public class Shop {

private int restockTime = 0;
private int STORE_SIZE = 40;
private Container<Item> itemsInShop = new Container<Item>(STORE_SIZE, true);
private ArrayList<Player> playersViewing = new ArrayList<Player>(); // Not
// sure.
private boolean generalStore = false;
Object[] sellOptions = new Object[] { "Sell 50", "Sell 10", "Sell 1",
"Value", -1, 1, 7, 4, 93, 40697856 };
Object[] invParams = new Object[] { "", "", "", "", "Sell 50", "Sell 10",
"Sell 5", "Sell 1", "Value", -1, 0, 7, 4, 93, 40697856 };
Object[] shopParams = new Object[] { "", "", "", "", "Buy 50", "Buy 10",
"Buy 5", "Buy 1", "Value", -1, 0, 4, 10, 556, 40632345 };
int[] unsellableItems = new int[] { 995 };
/**
* Forgot what i was going to use this for
*/
@SuppressWarnings("unused")
private int shopId = 0;

/**
* Create a new shop and add the items to it.
*
* @param id
*
* @param generalStore
* Whether you want it to be a general store or not.
*/
public Shop(int id, boolean isGeneralStore, int[] items, int[] amounts) {
this.shopId = id;
this.generalStore = isGeneralStore;
for (int itemSlot = 0; itemSlot < items.length; itemSlot++) {
itemsInShop.set(itemsInShop.getFreeSlot(), new Item(
items[itemSlot], amounts[itemSlot]));
}
// startRestocking();
}

/**
* Little thing to restock every x amount of seconds. I wasn't sure about it
* so i didn't use it.
*/
@SuppressWarnings("unused")
private void startRestocking() {
World.getInstance().registerEvent(new Event(restockTime) {
public void execute() {
for (int i = 0; i < itemsInShop.getSize(); i++) {
if (itemsInShop.get(i) != null) {
itemsInShop
.add(new Item(itemsInShop.get(i).getId(), 1));
}
}
update();
}
});

}

/**
* Open a shop for the specified player, then this shop will add the players
* to it's list of currently viewing players
*
* @param p
* The player to open for
*/
public void openForPlayer(Player p) {
p.getActionSender().sendConfig(199, -1);
p.getActionSender().sendConfig2(118, 17);
p.getActionSender().sendInterface(620, true);
p.getActionSender().sendInventoryInterface(621);
p.getActionSender().sendTab(146, 449);
p.getActionSender().sendRunScript(149, sellOptions, "IviiiIsssss");
p.getActionSender().sendRunScript(150, invParams, "IviiiIsssssssss");
p.getActionSender().sendRunScript(150, shopParams, "IviiiIsssssssss");
p.getActionSender().sendAccessMask(1278, 621, 0, 0, 28);
p.getActionSender().sendAccessMask(1278, 620, 25, 0, 40);
p.getActionSender().sendAccessMask(1278, 620, 26, 0, 40);
p.getActionSender().sendItems(-1, 64209, 93,
p.getInventory().getContainer());
p.getActionSender().sendItems(-1, 63746, 556, itemsInShop);
}

/**
* Add a player to the list of currently viewing players
*
* @param player
* The player to add
*/
public void addPlayer(Player player) {
playersViewing.add(player);
}

/**
* Remove a player from the list of players viewing
*
* @param player
* The player to remove
*/
public void removePlayer(Player player) {
playersViewing.remove(player);
}

/**
* Handle options sent from the client
*
* @param p
* The player that did the option
* @param interfaceId
* The interface they're on
* @param buttonId
* The button they clicked
* @param buttonId2
* Could be another button they clicked
* @param packetId
* The packet sent to us.
*/
public void handleOption(Player p, int interfaceId, int buttonId,
int buttonId2, int packetId) {
switch (interfaceId) {
case 620:
switch (buttonId) {
case 18:
removePlayer(p);
p.shopId = -1;
p.getActionSender().sendCloseInterface();
p.getActionSender().sendCloseInventoryInterface();
break;
default:
switch (packetId) {
case 216:
p.sm(itemsInShop.get(buttonId2).getDefinition().getName()
+ " costs "
+ formatPrice(GameEngine.prices
.getMaximumPrice(itemsInShop.get(buttonId2)
.getDefinition().getId()))
+ " coins.");
break;
case 19:
buyItem(p, itemsInShop.get(buttonId2).getId(), 1);
break;
case 193:
buyItem(p, itemsInShop.get(buttonId2).getId(), 5);
break;
case 76:
buyItem(p, itemsInShop.get(buttonId2).getId(), 10);
break;
case 173:
buyItem(p, itemsInShop.get(buttonId2).getId(), 50);
break;
case 3:
p.sm(itemsInShop.get(buttonId2).getDefinition()
.getExamine());
break;
}
}
break;
case 621:
if (buttonId == 0) {
Item definition = p.getInventory().getContainer()
.get(buttonId2);
int itemId = definition.getId();
switch (packetId) {
case 216:
p.sm(definition.getDefinition().getName()
+ " costs "
+ formatPrice(GameEngine.prices
.getMinimumPrice(itemId)) + " coins.");
break;
case 19:
sellItem(p, itemId, 1);
break;
case 193:
sellItem(p, itemId, 5);
break;
case 76:
sellItem(p, itemId, 10);
break;
case 173:
sellItem(p, itemId, 50);
break;
case 3:
p.sm(definition.getDefinition().getExamine());
break;
}
}
break;
}
}

/**
* Sells an item to the store
*
* @param p
* the player who sold
* @param itemId
* The item they're selling
* @param amount
* The amount of the item they're selling
*/
private void sellItem(Player p, int itemId, int amount) {
int price = GameEngine.prices.getMinimumPrice(itemId) * amount;
if (!p.getInventory().contains(itemId)) {
return;
}
if (!p.getInventory().hasRoomFor(995, price)) {
p.sm("Not enough space in your inventory");
return;
}
// One more calculation for if you have notes of the item and regular
// items needs to be here.
if (p.getInventory().getContainer().getNumberOff(itemId) < amount) {
if (ItemDefinition.forId(itemId).isNoted()
|| ItemDefinition.forId(itemId).isStackable()) {
amount = p.getInventory().lookup(itemId).getAmount();
} else {
amount = p.getInventory().getContainer().getNumberOff(itemId);
}
price = GameEngine.prices.getMinimumPrice(itemId) * amount;
p.sm("Your inventory does not contain that many.");
}
if (itemsInShop.freeSlots() <= 0) {
p.sm("The shop is full");
}
for (int i = 0; i < unsellableItems.length; i++) {
if (unsellableItems[i] == itemId) {
p.sm("You cannot sell that item to this shop");
return;
}
}
if (!itemsInShop.contains(new Item(itemId, 1)) && !generalStore) {
p.sm("You cannot sell that item to this shop");
return;
}
itemsInShop.add(new Item(itemId, amount));
p.getInventory().deleteItem(itemId, amount);
p.getInventory().addItem(995, price);
update();

}

/**
* Update the items in the shop for every player viewing this shop
*/
private void update() {
for (Player p : playersViewing) {
openForPlayer(p); // Send items wouldn't work alone lol.
}
}

/**
* Buys an item from the store
*
* @param p
* The player trying to buy
* @param id
* The id of the item they're trying to buy
* @param amount
* The amount of the item they're trying to buy
*/
private void buyItem(Player p, int id, int amount) {
Item item = new Item(id, 1);
int price = GameEngine.prices.getMaximumPrice(id) * amount;
if (p.getInventory().getFreeSlots() < amount
&& !(item.getDefinition().isNoted() || item.getDefinition()
.isStackable())) {
p.sm("Not enough space in your inventory for that many.");
if (p.getInventory().getFreeSlots() == 0) {
return;
}
amount = p.getInventory().getFreeSlots();
price = GameEngine.prices.getMaximumPrice(id) * amount;
}
if (itemsInShop.getNumberOff(id) < amount) {
p.sm("The shop has run out of stock of that item.");
amount = itemsInShop.getNumberOff(id);
price = GameEngine.prices.getMaximumPrice(id) * amount;
}
if (p.getInventory().getContainer().getNumberOff(995) < price) {
p.sm("You do not have enough coins for that many.");
price = price / p.getInventory().getContainer().getNumberOff(995);
if (price == 0) {
return;
}
}
p.getInventory().deleteItem(995, price);
p.getInventory().addItem(id, amount);
itemsInShop.remove(new Item(id, amount));
if (!generalStore) {
if (itemsInShop.getNumberOff(id) == 0) {
itemsInShop.add(new Item(id, 1));
}
}
update();
}

/**
* Format a number into a string with commas
*
* @param price
* The original number
* @return The formatted string
*/
public String formatPrice(int price) {
return NumberFormat.getInstance().format(price);
}

}[/CODE]
Link to comment
Share on other sites

  • Replies 78
  • Created
  • Last Reply

Top Posters In This Topic

simple fix...

you put the code wrong::

You have 2 "ShopN" in your code and the first ShopN should be the items and not the number

[code]
shops.put(2, new Shop(2, false, GameEngine.shops.ShopN,
GameEngine.shops.ShopN));
[/code]

And just to let you know all of your shops have that error.
Link to comment
Share on other sites

[quote name='Intensive Tony']I Founded a bug. When i try to buy 50 uncut onyx i get full inventory but it doesnt cost anything so when i cut them and sell them it makes about 80m each inventory anyone know fix?[/QUOTE]


I had the same problem, but i looked at the code for a little.
just look at the code... more specifically shop.java
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...