Cleanup part 1 (#213)

* Clean up part 1

- Removed lots of dead code
- Removed unncessary files not in use
- Cleaned up small bits of code
- Removed a few warnings
- Server.java ---> GameEngine.java
- Constants.java ---> GameConstants.java

* Cape Dye

Rewrote cape dying

* Packaging

- redone ----> com.rebotted

* PacketSender/clean up

- ActionSender ---> PacketSender
- Moved many more packets to packetsender
- Cleaned up more dead code

* Merge Client/Player

- Merged Client.java with Player.java (both were doing same thing so redundant to have both)
- Removed some more dead code
- Tidy a few small things up

* Quests/more clean up

- Removed more dead code
- Made quests static in order to clean them up a bit

* More cleanup

- Removed some more of the dead quest code
- Correcting naming of some of the shop variables
This commit is contained in:
Mr Extremez
2019-11-25 11:08:56 -06:00
committed by Daniel Ginovker
parent 3d1ae1b288
commit d876a923b9
379 changed files with 80684 additions and 83170 deletions
@@ -0,0 +1,601 @@
package com.rebotted.game.shops;
import com.rebotted.GameConstants;
import com.rebotted.game.bots.BotHandler;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.ItemDefinitions;
import com.rebotted.game.players.Player;
import com.rebotted.game.players.PlayerHandler;
import com.rebotted.util.GameLogger;
/**
* Many Fixes/Things Added
* @author Andrew (Mr Extremez)
*/
public class ShopAssistant {
private final Player player;
public ShopAssistant(Player player2) {
player = player2;
}
public static final int RANGE_SHOP = 111, PEST_SHOP = 175, CASTLE_SHOP = 112;
/**
* Shops
**/
public void openShop(int ShopID) {
player.getPacketSender().sendSound(1465, 100, 0);
player.getItemAssistant().resetItems(3823);
resetShop(ShopID);
player.isShopping = true;
player.shopId = ShopID;
player.getPacketSender().sendFrame248(3824, 3822);
player.getPacketSender().sendFrame126(ShopHandler.shopName[ShopID], 3901);
}
public void updatePlayerShop() {
for (int i = 0; i < PlayerHandler.players.length; i++) {
if (PlayerHandler.players[i] != null) {
if (PlayerHandler.players[i].isShopping == true
&& PlayerHandler.players[i].shopId == player.shopId
&& i != player.playerId) {
PlayerHandler.players[i].updateShop = true;
}
}
}
}
public void updateshop(int i) {
resetShop(i);
}
public void resetShop(int ShopID) {
synchronized (player) {
player.totalShopItems = 0;
for (int i = 0; i < ShopHandler.MAX_SHOP_ITEMS; i++) { //adds items in store when items are sold until max value.
if (ShopHandler.shopItems[ShopID][i] > 0) {
player.totalShopItems++;
}
}
player.getOutStream().createFrameVarSizeWord(53);
player.getOutStream().writeWord(3900);
player.getOutStream().writeWord(player.totalShopItems);
int TotalCount = 0;
for (int i = 0; i < ShopHandler.shopItems[player.shopId].length; i++)
{
if (ShopHandler.shopItems[ShopID][i] > 0
|| i <= ShopHandler.shopItemsStandard[ShopID])
{
if (ShopHandler.shopItemsN[ShopID][i] > 254) {
player.getOutStream().writeByte(255);
player.getOutStream().writeDWord_v2(ShopHandler.shopItemsN[ShopID][i]);
}
else
{
player.getOutStream().writeByte(ShopHandler.shopItemsN[ShopID][i]);
}
if (ShopHandler.shopItems[ShopID][i] > GameConstants.ITEM_LIMIT
|| ShopHandler.shopItems[ShopID][i] < 0) {
ShopHandler.shopItems[ShopID][i] = GameConstants.ITEM_LIMIT;
}
player.getOutStream().writeWordBigEndianA(
ShopHandler.shopItems[ShopID][i]);
TotalCount++;
}
if (TotalCount > player.totalShopItems) {
break;
}
}
player.getOutStream().endFrameVarSizeWord();
player.flushOutStream();
}
}
public int getItemShopValue(int ItemID, int Type, boolean isSelling) {
double ShopValue = 1;
double TotPrice = 0;
double sellingRatio = isSelling ? 0.85 : 1;
if (ItemDefinitions.getDef()[ItemID] != null) {
ShopValue = ItemDefinitions.getDef()[ItemID].highAlch / 3.0 * 5.0 * sellingRatio;
}
TotPrice = ShopValue;
// General store pays less for items
if (isSelling && ShopHandler.shopBModifier[player.shopId] == 1) {
TotPrice *= 0.90;
}
// Minimum value of 1
return (int) Math.max(1, Math.floor(TotPrice));
}
public int getItemShopValue(int itemId) {
return getItemShopValue(itemId, 0, false);
}
/**
* buy item from shop (Shop Price)
**/
public void buyFromShopPrice(int itemID) {
int ShopValue = (int) Math.floor(getItemShopValue(itemID, 0, false));
int SpecialValue = getTokkulValue(itemID);
String ShopAdd = "";
// player owned shop
if (ShopHandler.shopBModifier[player.shopId] == 0) {
ShopValue = BotHandler.getItemPrice(player.shopId, itemID);
}
if (player.shopId == 138 || player.shopId == 139 || player.shopId == 58) {
player.getPacketSender().sendMessage(ItemAssistant.getItemName(itemID) + ": currently costs " + SpecialValue + " tokkul.");
return;
}
if (player.shopId == PEST_SHOP) {
player.getPacketSender().sendMessage(ItemAssistant.getItemName(itemID)+": currently costs " + getPestItemValue(itemID) + " pest control points.");
return;
}
if (player.shopId == CASTLE_SHOP) {
player.getPacketSender().sendMessage(ItemAssistant.getItemName(itemID)+": currently costs " + getCastleItemValue(itemID) + " castle wars tickets.");
return;
}
if (player.shopId == RANGE_SHOP) {
player.getPacketSender().sendMessage(ItemAssistant.getItemName(itemID)+": currently costs " + getRGItemValue(itemID) + " archery tickets.");
return;
}
if (ShopValue >= 1000 && ShopValue < 1000000) {
ShopAdd = " (" + ShopValue / 1000 + "K)";
} else if (ShopValue >= 1000000) {
ShopAdd = " (" + ShopValue / 1000000 + " million)";
}
player.getPacketSender().sendMessage(ItemAssistant.getItemName(itemID) + ": currently costs " + ShopValue + " coins" + ShopAdd);
}
public int getCastleItemValue(int id) {
switch (id) {
/*Red Items*/
case 4071:
return 4;
case 4069:
return 8;
case 4070:
case 4072:
return 6;
case 4068:
return 5;
/*Silver/Blue Items*/
case 4506:
return 40;
case 4504:
return 80;
case 4505:
case 4507:
return 60;
case 4503:
return 50;
/*Gold/Blue Items*/
case 4511:
return 400;
case 4509:
return 800;
case 4510:
case 4512:
return 600;
case 4508:
return 500;
/*Capes & Hoods*/
case 4513:
case 4514:
case 4515:
case 4516:
return 10;
}
return 0;
}
public int getPestItemValue(int id) {
switch (id) {
}
return 0;
}
public int getRGItemValue(int id) {
switch (id) {
case 47:
return 4;
case 1133:
return 51;
case 1135:
return 2400;
case 829:
return 15;
case 1169:
return 100;
case 892:
return 40;
}
return 0;
}
public int getTokkulValue(int id) {
switch (id) {
case 438:
case 436:
return 4;
case 453:
return 25;
case 1623:
return 37;
case 1621:
return 75;
case 6571:
return 300000;
case 554:
case 555:
case 556:
case 557:
return 6;
case 558:
case 559:
return 4;
case 562:
return 135;
case 560:
return 270;
case 6522:
return 375;
case 6523:
return 60000;
case 6524:
return 67500;
case 6525:
return 37500;
case 6526:
return 52500;
case 6527:
return 45000;
case 6528:
return 75000;
case 6568:
return 90000;
}
return 0;
}
/**
* Sell item to shop (Shop Price)
**/
public void sellToShopPrice(int removeId, int removeSlot) {
int unNotedItemID = getUnNoted(removeId);
String itemName = ItemAssistant.getItemName(unNotedItemID);
for (int i : GameConstants.ITEM_SELLABLE) {
if (unNotedItemID == i) {
player.getPacketSender().sendMessage("You can't sell " + ItemAssistant.getItemName(removeId).toLowerCase() + ".");
return;
}
}
boolean IsIn = false;
switch (ShopHandler.shopSModifier[player.shopId]) {
// Only buys what is in stock
case 2:
for (int j = 0; j <= ShopHandler.shopItemsStandard[player.shopId]; j++) {
if (unNotedItemID == (ShopHandler.shopItems[player.shopId][j] - 1)) {
IsIn = true;
break;
}
}
break;
// General store
case 1:
IsIn = true;
break;
// Player owns this store
case 0:
IsIn = ShopHandler.playerOwnsStore(player.shopId, player);
break;
}
if (IsIn == false) {
player.getPacketSender().sendMessage("You can't sell " + ItemAssistant.getItemName(removeId).toLowerCase() + " to this store.");
} else {
int ShopValue = (int) Math.floor(getItemShopValue(unNotedItemID, 1, true));
int tokkulValue = (int) Math.floor(getTokkulValue(unNotedItemID) *.85);
String ShopAdd = "";
if (ShopValue >= 1000 && ShopValue < 1000000) {
ShopAdd = " (" + (ShopValue / 1000) + "K)";
} else if (ShopValue >= 1000000) {
ShopAdd = " (" + (ShopValue / 1000000) + " million)";
}
if (ShopHandler.playerOwnsStore(player.shopId, player)) {
if (ShopHandler.getStock(player.shopId, unNotedItemID) > 0)
player.getPacketSender().sendMessage(itemName + ": you are selling this item for " + BotHandler.getItemPrice(player.shopId, unNotedItemID) + " coins.");
else
player.getPacketSender().sendMessage(itemName + ": you haven't set your sell price.");
} else if (player.shopId != RANGE_SHOP && player.shopId != PEST_SHOP && player.shopId != CASTLE_SHOP && player.shopId != 138 && player.shopId != 58 && player.shopId != 139) {
player.getPacketSender().sendMessage(itemName + ": shop will buy for " + ShopValue + " coins." + ShopAdd);
} else if (player.shopId == 138 || player.shopId == 139 || player.shopId == 58) {
player.getPacketSender().sendMessage(itemName + ": shop will buy for " + tokkulValue + " tokkul.");
} else if (player.shopId == RANGE_SHOP) {
player.getPacketSender().sendMessage(itemName + ": shop will buy for " + getRGItemValue(unNotedItemID) + " archery tickets." + ShopAdd);
} else if (player.shopId == PEST_SHOP) {
player.getPacketSender().sendMessage(itemName + ": shop will buy for " + getPestItemValue(unNotedItemID) + " pest control points." + ShopAdd);
} else if (player.shopId == CASTLE_SHOP) {
player.getPacketSender().sendMessage(itemName + ": shop will buy for " + getCastleItemValue(unNotedItemID) + " castle war tickets." + ShopAdd);
}
}
}
public boolean sellItem(int itemID, int fromSlot, int amount) {
int unNotedItemID = getUnNoted(itemID);
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
for (int i : GameConstants.ITEM_SELLABLE) {
if (i == unNotedItemID) {
player.getPacketSender().sendMessage("You can't sell " + itemName + ".");
return false;
}
}
if (player.playerRights == 2 && !GameConstants.ADMIN_CAN_SELL_ITEMS) {
player.getPacketSender().sendMessage("Selling items as an admin has been disabled.");
return false;
}
if(!player.isShopping) {
return false;
}
// We can only store 40 items per shop
if (player.totalShopItems >= 40) {
player.getPacketSender().sendMessage("This shop is out of space!");
return false;
}
// Check we have the item in our inventory
int inventoryAmount = player.getItemAssistant().getItemAmount(itemID);
if (amount > 0 && inventoryAmount > 0) {
boolean canSellToStore = false;
// Type of store
switch (ShopHandler.shopSModifier[player.shopId]) {
// Only buys what they sell
case 2:
for (int j = 0; j <= ShopHandler.shopItemsStandard[player.shopId]; j++) {
if (unNotedItemID == (ShopHandler.shopItems[player.shopId][j] - 1)) {
canSellToStore = true;
break;
}
}
break;
// General store - buys anything
case 1:
canSellToStore = true;
break;
// Player owned store - only "buys" from the player whos store it is
case 0:
canSellToStore = ShopHandler.playerOwnsStore(player.shopId, player);
break;
}
if (canSellToStore == false) {
player.getItemAssistant();
player.getPacketSender().sendMessage("You can't sell " + itemName + " to this store.");
return false;
}
// player owned store, setting item price
if (ShopHandler.playerOwnsStore(player.shopId, player)) {
// No items in stock, we are adding 1 and setting the price
if (ShopHandler.getStock(player.shopId, unNotedItemID) <= 0){
player.getItemAssistant().deleteItem(itemID, 1);
BotHandler.addTobank(player.shopId, unNotedItemID, 1);
BotHandler.setPrice(player.shopId, unNotedItemID, amount);
addShopItem(unNotedItemID, 1);
player.getItemAssistant().resetItems(3823);
resetShop(player.shopId);
updatePlayerShop();
return true;
}
}
if (amount > inventoryAmount) {
amount = inventoryAmount;
}
int value = 1;
int currency = 995;
if (player.shopId == 138 || player.shopId == 58 || player.shopId == 139) {
value = (int) Math.floor(getTokkulValue(unNotedItemID) * .85);
currency = 6529;
} else {
value = (int) Math.floor(getItemShopValue(unNotedItemID, amount, true));
currency = 995;
}
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable;
if (!player.getItemAssistant().playerHasItem(currency) && isStackable && amount < inventoryAmount && player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("You don't have enough space in your inventory.");
}
player.getItemAssistant().deleteItem(itemID, amount);
if (ShopHandler.playerOwnsStore(player.shopId, player)) {
// Add items to players store
player.getPacketSender().sendMessage("You sent " + amount + " " + itemName + " to your store.");
BotHandler.addTobank(player.shopId, unNotedItemID, amount);
} else {
// Add currency to players inventory
int totalValue = value * amount;
player.getItemAssistant().addItem(currency, totalValue);
player.getPacketSender().sendMessage("You sold " + amount + " " + itemName + " for " + totalValue + " " + ItemAssistant.getItemName(currency).toLowerCase() + ".");
}
// Add item to the shop
addShopItem(unNotedItemID, amount);
player.getItemAssistant().resetItems(3823);
resetShop(player.shopId);
updatePlayerShop();
return true;
}
return true;
}
public boolean addShopItem(int itemID, int amount) {
boolean Added = false;
if (amount <= 0) {
return false;
}
if (Item.itemIsNote[itemID]) {
itemID = player.getItemAssistant().getUnnotedItem(itemID);
}
for (int i = 0; i < ShopHandler.shopItems[player.shopId].length; i++) {
if (ShopHandler.shopItems[player.shopId][i] - 1 == itemID) {
ShopHandler.shopItemsN[player.shopId][i] += amount;
Added = true;
}
}
if (Added == false) {
for (int i = 0; i < ShopHandler.shopItems[player.shopId].length; i++) {
if (ShopHandler.shopItems[player.shopId][i] == 0) {
ShopHandler.shopItems[player.shopId][i] = itemID + 1;
ShopHandler.shopItemsN[player.shopId][i] = amount;
ShopHandler.shopItemsDelay[player.shopId][i] = 0;
break;
}
}
}
return true;
}
private static int getUnNoted(int itemID){
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
String ItemNameUnNotedItem = ItemAssistant.getItemName(itemID - 1).toLowerCase();
if (itemName.contains(ItemNameUnNotedItem)) {
itemID--; //Replace the noted item by it's un-noted version.
}
return itemID;
}
private static int getNoted(int itemID){
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
String ItemNameUnNotedItem = ItemAssistant.getItemName(itemID + 1).toLowerCase();
if (itemName.contains(ItemNameUnNotedItem)) {
itemID++; //Replace the item by it's noted version.
}
return itemID;
}
private static final int FISHING_ITEMS[] = {383, 371, 377, 359, 321, 341, 353, 345, 327, 317};
public boolean buyItem(int itemID, int fromSlot, int amount) {
int shopID = player.shopId;
int notedItemID = getNoted(itemID);
boolean isPlayerShop = ShopHandler.shopBModifier[player.shopId] == 0;
// Items are stackable if from a player owned shop and notable
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable || (isPlayerShop && getNoted(itemID) != itemID);
int freeSlots = player.getItemAssistant().freeSlots();
int storeQty = ShopHandler.getStock(shopID, itemID);
if (amount > 0) {
if (storeQty <= 0) {
// none in stock, or not sold here
player.getPacketSender().sendMessage("You can't buy that right now!");
return false;
}
if (amount > storeQty) {
// buy all that the store has
amount = storeQty;
}
if (freeSlots <= 0){
if (!isStackable || isStackable && !player.getItemAssistant().playerHasItem(isPlayerShop ? notedItemID : itemID)) {
player.getPacketSender().sendMessage("You don't have enough space in your inventory.");
return false;
}
}
if (!isStackable && amount > freeSlots) {
// player will fill their inventory
amount = freeSlots;
}
if(!player.isShopping) {
return false;
}
for (int i = 0; i < FISHING_ITEMS.length; i++) {
if (player.shopId == 32 && itemID == FISHING_ITEMS[i]) {
player.getPacketSender().sendMessage("You can't buy that item from this store!");
return false;
}
}
int value = 0;
int currency = 995;
// player owned shop
boolean showIsOwnedByThisPlayer = ShopHandler.playerOwnsStore(player.shopId, player);
if (showIsOwnedByThisPlayer) { // PLayers own shop, no cost
value = 0;
currency = -1;
} else if (isPlayerShop) { // Shop owned by another player
value = BotHandler.getItemPrice(player.shopId, itemID);
currency = 995; // gp
} else if (player.shopId == 138 || player.shopId == 58 || player.shopId == 139) {
value = getTokkulValue(itemID);
currency = 6529; // Tokkul
} else if (player.shopId == RANGE_SHOP) {
value = getRGItemValue(itemID);
currency = 1464; // Archery tickets
} else if (player.shopId == PEST_SHOP) {
value = getPestItemValue(itemID);
currency = 995; // gp
} else if (player.shopId == CASTLE_SHOP) {
value = getCastleItemValue(itemID);
currency = 4067; // castle wars tickets
} else {
value = getItemShopValue(itemID, 0, false);
currency = 995; //gp
}
int currencySlot = player.getItemAssistant().getItemSlot(currency);
String currencyName = ItemAssistant.getItemName(currency).toLowerCase();
// player has none of the required currency
if (currencySlot == -1) {
player.getPacketSender().sendMessage("You don't have enough " + currencyName + " to buy that.");
return false;
}
// amount of currency the player has
int currencyAmount = player.playerItemsN[currencySlot];
int totalValue = value * amount;
if (currencyAmount < totalValue) {
amount = (int) Math.floor(player.playerItemsN[currencySlot] / value);
// buy as many as we can afford
totalValue = value * amount;
if (currencyAmount < totalValue || amount <= 0) {
player.getPacketSender().sendMessage("You don't have enough " + currencyName + " to buy that.");
return false;
}
}
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
if (!showIsOwnedByThisPlayer) {
player.getItemAssistant().deleteItem(currency, totalValue);
player.getPacketSender().sendMessage("You bought " + amount + " " + itemName + " for " + totalValue + " " + currencyName + "." );
// If it is a player owned shop, we need to give them the coins
if (ShopHandler.shopSModifier[player.shopId] == 0)
BotHandler.addCoins(shopID, totalValue);
} else {
player.getPacketSender().sendMessage("You withdrew " + amount + " " + itemName + " from your store." );
}
// If it is a player owned store, give the player the noted item
player.getItemAssistant().addItem(isPlayerShop ? notedItemID : itemID, amount);
ShopHandler.buyItem(shopID, itemID, amount);
if (ShopHandler.shopBModifier[shopID] == 0){
BotHandler.removeFrombank(shopID, itemID, amount);
}
if (player.getPlayerAssistant().isPlayer()) {
GameLogger.writeLog(player.playerName, "shopbuying", player.playerName + " bought " + amount + " " + itemName + " for " + totalValue + " " + currencyName + " from store " + shopID + ".");
}
player.getItemAssistant().resetItems(3823);
resetShop(player.shopId);
updatePlayerShop();
return true; //return TRUE / FALSE Update = shop&Inventory / Doesnt Update
}
return false;
}
}
@@ -0,0 +1,248 @@
package com.rebotted.game.shops;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import com.rebotted.game.players.Client;
import com.rebotted.game.players.Player;
import com.rebotted.game.players.PlayerHandler;
import com.rebotted.util.Misc;
public class ShopHandler {
public static int MAX_SHOPS = 400;
public static int MAX_SHOP_ITEMS = 40;
public static int SHOW_DELAY = 2;
public static int SPECIAL_DELAY = 60;
public static int totalshops = 0;
public static int[][] shopItems = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsDelay = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsSN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[] shopItemsStandard = new int[MAX_SHOPS];
public static String[] shopName = new String[MAX_SHOPS];
public static int[] shopSModifier = new int[MAX_SHOPS];
public static int[] shopBModifier = new int[MAX_SHOPS];
public static long[][] shopItemsRestock = new long[MAX_SHOPS][MAX_SHOP_ITEMS];
public ShopHandler() {
for (int i = 0; i < MAX_SHOPS; i++) {
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
ResetItem(i, j);
shopItemsSN[i][j] = 0;
}
shopItemsStandard[i] = 0;
shopSModifier[i] = 0;
shopBModifier[i] = 0;
shopName[i] = "";
}
totalshops = 0;
loadshops("shops.cfg");
}
public static int restockTimeItem(int itemId) {
switch(itemId) {
default:
return 1000;
}
}
public void process() {
boolean DidUpdate = false;
for (int i = 1; i <= totalshops; i++) {
if (shopBModifier[i] == 0 || shopSModifier[i] == 0) continue;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[i][j] > 0) {
if (shopItemsDelay[i][j] >= SHOW_DELAY) {
if (j <= shopItemsStandard[i] && shopItemsN[i][j] <= shopItemsSN[i][j]) {
if (shopItemsN[i][j] < shopItemsSN[i][j] && System.currentTimeMillis() - shopItemsRestock[i][j] > restockTimeItem(shopItems[i][j])) {
shopItemsN[i][j] += 1;
shopItemsDelay[i][j] = 1;
shopItemsDelay[i][j] = 0;
DidUpdate = true;
shopItemsRestock[i][j] = System.currentTimeMillis();
}
} else if (shopItemsDelay[i][j] >= SPECIAL_DELAY) {
DiscountItem(i, j);
shopItemsDelay[i][j] = 0;
DidUpdate = true;
}
refreshshop(i);
}
shopItemsDelay[i][j]++;
}
}
if (DidUpdate) {
for (int k = 1; k < PlayerHandler.players.length; k++) {
if (PlayerHandler.players[k] != null) {
if (PlayerHandler.players[k].isShopping && PlayerHandler.players[k].shopId == i) {
PlayerHandler.players[k].updateShop = true;
PlayerHandler.players[k].updateshop(i);
}
}
}
DidUpdate = false;
}
}
}
private void DiscountItem(int shopID, int ArrayID) {
shopItemsN[shopID][ArrayID] -= 1;
if (shopItemsN[shopID][ArrayID] <= 0) {
shopItemsN[shopID][ArrayID] = 0;
ResetItem(shopID, ArrayID);
}
}
private static void ResetItem(int shopID, int ArrayID) {
shopItems[shopID][ArrayID] = 0;
shopItemsN[shopID][ArrayID] = 0;
shopItemsDelay[shopID][ArrayID] = 0;
}
public boolean loadshops(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[(MAX_SHOP_ITEMS * 2)];
boolean EndOfFile = false;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./data/cfg/" + FileName));
} catch (FileNotFoundException fileex) {
Misc.println(FileName + ": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
Misc.println(FileName + ": error loading file.");
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t+", "\t");
token3 = token2_2.split("\t");
if (token.equals("shop")) {
int shopID = Integer.parseInt(token3[0]);
shopName[shopID] = token3[1].replaceAll("_", " ");
shopSModifier[shopID] = Integer.parseInt(token3[2]);
shopBModifier[shopID] = Integer.parseInt(token3[3]);
for (int i = 0; i < ((token3.length - 4) / 2); i++) {
if (token3[(4 + (i * 2))] != null) {
shopItems[shopID][i] = (Integer.parseInt(token3[(4 + (i * 2))]) + 1);
shopItemsN[shopID][i] = Integer.parseInt(token3[(5 + (i * 2))]);
shopItemsSN[shopID][i] = Integer.parseInt(token3[(5 + (i * 2))]);
shopItemsStandard[shopID]++;
} else {
break;
}
}
totalshops++;
}
} else {
if (line.equals("[ENDOFshopLIST]")) {
try {
characterfile.close();
} catch (IOException ioexception) {
}
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
characterfile.close();
} catch (IOException ioexception) {
}
return false;
}
public static void createPlayerShop(Client player){
int id = getEmptyshop();
player.shopId = id;
shopSModifier[id] = 0;
shopBModifier[id] = 0;
shopName[id] = player.properName + "'s Store";
for (int i = 0; i < MAX_SHOP_ITEMS; i++){
shopItems[id][i] = player.bankItems[i];
shopItemsN[id][i] = player.bankItemsN[i];
shopItemsSN[id][i] = 0;
shopItemsDelay[id][i] = 0;
}
totalshops++;
}
private static int getEmptyshop(){
for (int i = 0; i < MAX_SHOPS; i++) {
if (shopName[i] == "") return i;
}
return -1;
}
public static void refreshshop(int shop_id){
// We don't want to remove items that should be kept in stock
for (int j = shopItemsStandard[shop_id]; j < MAX_SHOP_ITEMS; j++) {
if (shopItemsN[shop_id][j] <= 0) {
ResetItem(shop_id, j);
int next = j + 1;
if (next < MAX_SHOP_ITEMS && shopItemsN[shop_id][next] > 0) {
shopItems[shop_id][j] = shopItems[shop_id][next];
shopItemsN[shop_id][j] = shopItemsN[shop_id][next];
shopItemsDelay[shop_id][j] = shopItemsDelay[shop_id][next];
ResetItem(shop_id, next);
}
}
}
}
public static int getStock(int shop_id, int item_id){
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
return shopItemsN[shop_id][j];
}
}
return -1;
}
public static void buyItem(int shop_id, int item_id, int amount){
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
shopItemsN[shop_id][j] -= amount;
}
}
refreshshop(shop_id);
}
public static boolean playerOwnsStore(int shop_id, Player player){
return shopSModifier[shop_id] == 0 && shopBModifier[shop_id] == 0 && shopName[shop_id].equalsIgnoreCase(player.properName + "'s Store");
}
}
@@ -0,0 +1,103 @@
package com.rebotted.game.shops;
import java.util.HashMap;
import com.rebotted.game.content.randomevents.RandomEventHandler;
import com.rebotted.game.players.Player;
/**
* Shops
* @author Andrew (I'm A Boss on Rune-Server, Mr Extremez on Moparscape & Runelocus)
*/
public class Shops {
public enum Shop {
SHOP1(588, 2), SHOP2(550, 3), SHOP3(575, 4), SHOP4(2356, 5), SHOP5(
3796, 6), SHOP6(1860, 7), SHOP7(559, 9), SHOP8(562, 10), SHOP9(
581, 11), SHOP10(548, 12), SHOP11(554, 13), SHOP12(601, 14), SHOP13(
1301, 15), SHOP14(1039, 16), SHOP15(2353, 17), SHOP16(3166, 18), SHOP17(
2161, 19), SHOP18(2162, 20), SHOP19(600, 21), SHOP20(603, 22), SHOP21(
593, 23), SHOP22(545, 24), SHOP23(585, 25), SHOP24(2305, 26), SHOP25(
2307, 27), SHOP26(2304, 28), SHOP27(2306, 29), SHOP28(517, 30), SHOP29(
558, 31), SHOP30(576, 32), SHOP31(1369, 33), SHOP32(1038, 35), SHOP33(
1433, 36), SHOP34(584, 37), SHOP35(540, 38), SHOP36(2157, 39), SHOP37(
538, 40), SHOP38(1303, 41), SHOP39(578, 42), SHOP40(587, 43), SHOP41(
1398, 44), SHOP42(556, 45), SHOP43(1865, 46), SHOP44(543, 47), SHOP45(
2198, 48), SHOP46(580, 49), SHOP47(1862, 50), SHOP48(583, 51), SHOP49(
553, 52), SHOP50(461, 53), SHOP51(903, 54), SHOP551(2258, 55), SHOP52(
1435, 56), SHOP53(3800, 57), SHOP54(2623, 58), SHOP55(594, 59), SHOP56(
579, 60), SHOP57(2160, 61), SHOP58(2191, 61), SHOP59(589, 62), SHOP60(
549, 63), SHOP61(542, 64), SHOP62(3038, 65), SHOP63(544, 66), SHOP64(
541, 67), SHOP65(1434, 68), SHOP66(577, 69), SHOP67(539, 70), SHOP68(
1980, 71), SHOP69(546, 72), SHOP70(382, 73), SHOP71(3541, 74), SHOP72(
520, 75), SHOP73(1436, 76), SHOP74(590, 77), SHOP75(971, 78), SHOP76(
1917, 79), SHOP77(1040, 80), SHOP78(563, 81), SHOP79(522, 82), SHOP80(
524, 83), SHOP81(526, 84), SHOP82(2154, 85), SHOP83(1334, 86), SHOP84(
2552, 87), SHOP85(528, 88), SHOP86(1254, 89), SHOP87(2086, 90), SHOP88(
3824, 91), SHOP89(1866, 92), SHOP90(1699, 93), SHOP91(1282, 94), SHOP92(
530, 95), SHOP93(516, 96), SHOP94(560, 97), SHOP95(471, 98), //SHOP96(1208, 99),
SHOP97(532, 100), SHOP98(3797, 101), SHOP99(534, 102), SHOP100(
836, 103), SHOP101(551, 104), SHOP102(586, 105), SHOP103(564,
106), SHOP104(747, 107), SHOP105(573, 108), SHOP106(1316, 108), SHOP107(
547, 108), SHOP114(1787, 110), SHOP116(1526, 112), SHOP115(568,
113), SHOP118(1083, 114), SHOP119(735, 115), SHOP120(793, 116), SHOP121(
794, 116), SHOP122(1079, 117), SHOP123(682, 119), SHOP124(683,
120), SHOP125(692, 121), SHOP126(1658, 122), SHOP127(461, 123),
// SHOP128(537, 124),
// SHOP129(536, 125),
SHOP130(904, 126), SHOP131(2152, 127), SHOP132(2153, 128), SHOP133(
2151, 129), SHOP134(2158, 130), SHOP135(2156, 131), SHOP136(
2159, 132), SHOP137(851, 133), SHOP138(602, 134), SHOP139(596,
135), SHOP140(597, 136), SHOP141(1784, 137), SHOP142(2620, 138), SHOP143(
2622, 139), SHOP144(552, 88), SHOP145(1778, 140), SHOP146(1782,
141), SHOP147(849, 142);
private final int npcId, shopId;
public static HashMap<Integer, Shop> npc = new HashMap<Integer, Shop>();
public static Shop forId(int id) {
return npc.get(id);
}
static {
for (Shop f : Shop.values())
npc.put(f.getNpc(), f);
}
private Shop(int npcId, int shopId) {
this.npcId = npcId;
this.shopId = shopId;
}
public int getNpc() {
return npcId;
}
public int getShop() {
return shopId;
}
}
public static void dialogueShop(Player c, int npcClick) {
final Shop shops = Shop.forId(npcClick);
if (shops == null)
return;
if (npcClick == shops.getNpc()) {
c.getDialogueHandler().sendDialogues(1322, shops.getNpc());
}
}
public static void openShop(Player c, int npcClickId) {
final Shop shops = Shop.forId(npcClickId);
if (shops == null)
return;
if (npcClickId == shops.getNpc()) {
c.getShopAssistant().openShop(shops.getShop());
RandomEventHandler.addRandom(c);
}
}
}