mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +00:00
Semi functional player shops
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package redone.game.bots;
|
||||
|
||||
import redone.Server;
|
||||
import redone.game.items.ItemAssistant;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
import redone.util.GameLogger;
|
||||
import redone.util.Misc;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -55,7 +59,15 @@ public class Bot {
|
||||
}
|
||||
|
||||
public void sendTradeChat() {
|
||||
botClient.forcedChat("Selling Rune Platebody 210k ea");
|
||||
ArrayList<Integer> items = new ArrayList<Integer>();
|
||||
for (int slot = 0; slot < 40; slot++){
|
||||
if(botClient.bankItems[slot] > 0)
|
||||
items.add(botClient.bankItems[slot] - 1);
|
||||
}
|
||||
int item_id = Misc.randomArrayListItem(items);
|
||||
String item_name = ItemAssistant.getItemName(item_id);
|
||||
int value = botClient.getShopAssistant().getItemShopValue(item_id);
|
||||
botClient.forcedChat("Selling " + item_name + " " + GameLogger.formatCurrency(value) + "ea");
|
||||
/*
|
||||
Real chat - Disabled for now, can't get it to function correctly
|
||||
|
||||
|
||||
@@ -66,4 +66,16 @@ public class BotHandler
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addTobank(int shop, int item, int itemN){
|
||||
for(Bot bot : botList) {
|
||||
if(bot != null && bot.getBotClient() != null) {
|
||||
Client botClient = bot.getBotClient();
|
||||
if(botClient.myShopId == shop) {
|
||||
botClient.getItemAssistant().addItemToBank(item, itemN);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2426,17 +2426,23 @@ public class ItemAssistant {
|
||||
}
|
||||
|
||||
public void deleteItem(int id, int amount) {
|
||||
if (id <= 0) {
|
||||
if (id <= 0 || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < c.playerItems.length; j++) {
|
||||
id++;
|
||||
for (int slot = 0; slot < c.playerItems.length; slot++) {
|
||||
if (amount <= 0) {
|
||||
break;
|
||||
}
|
||||
if (c.playerItems[j] == id + 1) {
|
||||
c.playerItems[j] = 0;
|
||||
c.playerItemsN[j] = 0;
|
||||
amount--;
|
||||
if (c.playerItems[slot] == id) {
|
||||
if (c.playerItemsN[slot] > amount) {
|
||||
c.playerItemsN[slot] -= amount;
|
||||
break;
|
||||
} else {
|
||||
amount -= c.playerItemsN[slot];
|
||||
c.playerItems[slot] = 0;
|
||||
c.playerItemsN[slot] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
resetItems(3214);
|
||||
@@ -2462,9 +2468,6 @@ public class ItemAssistant {
|
||||
public void deleteItem2(int id, int amount) {
|
||||
int am = amount;
|
||||
for (int i = 0; i < c.playerItems.length; i++) {
|
||||
if (am == 0) {
|
||||
break;
|
||||
}
|
||||
if (c.playerItems[i] == id + 1) {
|
||||
if (c.playerItemsN[i] > amount) {
|
||||
c.playerItemsN[i] -= amount;
|
||||
@@ -2472,7 +2475,6 @@ public class ItemAssistant {
|
||||
} else {
|
||||
c.playerItems[i] = 0;
|
||||
c.playerItemsN[i] = 0;
|
||||
am--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1642,8 +1642,7 @@ public class PlayerAssistant {
|
||||
switch (spellId) {
|
||||
case 1162: // low alch
|
||||
if (player.inTrade) {
|
||||
player.getActionSender().sendMessage(
|
||||
"You can't alch while in trade!");
|
||||
player.getActionSender().sendMessage("You can't alch while in trade!");
|
||||
return;
|
||||
}
|
||||
if (player.isBotting == true) {
|
||||
@@ -1667,7 +1666,7 @@ public class PlayerAssistant {
|
||||
}
|
||||
}
|
||||
if (canAlch) {
|
||||
int value = player.getShopAssistant().getItemShopValue( itemId) / 3;
|
||||
int value = (int) Math.floor(player.getShopAssistant().getItemShopValue(itemId) * 0.4);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "alchemy", player.playerName + " cast Low Alchemy on " + itemName + " for " + GameLogger.formatCurrency(value) + " coins");
|
||||
@@ -1740,7 +1739,7 @@ public class PlayerAssistant {
|
||||
}
|
||||
}
|
||||
if (canAlch) {
|
||||
int value = (int) (player.getShopAssistant().getItemShopValue(itemId) * .75);
|
||||
int value = (int) Math.floor(player.getShopAssistant().getItemShopValue(itemId) * 0.75);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "alchemy", player.playerName + " cast High Alchemy on " + itemName + " for" + GameLogger.formatCurrency(value) + " coins");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package redone.game.shops;
|
||||
|
||||
import redone.Constants;
|
||||
import redone.game.bots.Bot;
|
||||
import redone.game.bots.BotHandler;
|
||||
import redone.game.items.Item;
|
||||
import redone.game.items.ItemAssistant;
|
||||
import redone.game.items.ItemDefinitions;
|
||||
@@ -25,15 +27,6 @@ public class ShopAssistant {
|
||||
|
||||
public static final int RANGE_SHOP = 111, PEST_SHOP = 175, CASTLE_SHOP = 112;
|
||||
|
||||
public boolean shopSellsItem(int itemID) {
|
||||
for (int i = 0; i < ShopHandler.ShopItems[player.myShopId].length; i++) {
|
||||
if (itemID == ShopHandler.ShopItems[player.myShopId][i] - 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shops
|
||||
**/
|
||||
@@ -67,17 +60,11 @@ public class ShopAssistant {
|
||||
public void resetShop(int ShopID) {
|
||||
synchronized (player) {
|
||||
player.TotalShopItems = 0;
|
||||
for (int i = 0; i < ShopHandler.MaxShopItems; i++)
|
||||
{ //adds items in store when items are sold until max value.
|
||||
if (ShopHandler.ShopItems[ShopID][i] > 0)
|
||||
{
|
||||
for (int i = 0; i < ShopHandler.MaxShopItems; i++) { //adds items in store when items are sold until max value.
|
||||
if (ShopHandler.ShopItems[ShopID][i] > 0) {
|
||||
player.TotalShopItems++;
|
||||
}
|
||||
}
|
||||
if (player.TotalShopItems > 40){
|
||||
player.TotalShopItems = 40; //sets the number of stack of item sold to max possible value if the resulting amount is higher than max value.
|
||||
//Items sold when shops are full will dissapears. Much more code would be needed if we want to restrict selling while still permitting selling items already in shops and such.
|
||||
}
|
||||
player.getOutStream().createFrameVarSizeWord(53);
|
||||
player.getOutStream().writeWord(3900);
|
||||
player.getOutStream().writeWord(player.TotalShopItems);
|
||||
@@ -89,13 +76,11 @@ public class ShopAssistant {
|
||||
{
|
||||
if (ShopHandler.ShopItemsN[ShopID][i] > 254) {
|
||||
player.getOutStream().writeByte(255);
|
||||
player.getOutStream().writeDWord_v2(
|
||||
ShopHandler.ShopItemsN[ShopID][i]);
|
||||
player.getOutStream().writeDWord_v2(ShopHandler.ShopItemsN[ShopID][i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getOutStream().writeByte(
|
||||
ShopHandler.ShopItemsN[ShopID][i]);
|
||||
player.getOutStream().writeByte(ShopHandler.ShopItemsN[ShopID][i]);
|
||||
}
|
||||
if (ShopHandler.ShopItems[ShopID][i] > Constants.ITEM_LIMIT
|
||||
|| ShopHandler.ShopItems[ShopID][i] < 0) {
|
||||
@@ -114,29 +99,26 @@ public class ShopAssistant {
|
||||
}
|
||||
}
|
||||
|
||||
public double getItemShopValue(int ItemID, int Type, boolean isSelling) {
|
||||
public int getItemShopValue(int ItemID, int Type, boolean isSelling) {
|
||||
double ShopValue = 1;
|
||||
double TotPrice = 0;
|
||||
double sellingRatio = isSelling ? 0.85 : 1;
|
||||
for (int i = 0; i < Constants.ITEM_LIMIT; i++) {
|
||||
if (ItemDefinitions.getDef()[i] != null) {
|
||||
ShopValue = ItemDefinitions.getDef()[ItemID].highAlch/3.0 *5.0 * sellingRatio;
|
||||
ShopValue = ShopValue <= 0 ? 1 : ShopValue; //Don't let the value be 0
|
||||
}
|
||||
}
|
||||
|
||||
TotPrice = ShopValue;
|
||||
|
||||
if (ShopHandler.ShopBModifier[player.myShopId] == 1) {
|
||||
TotPrice *= 1;
|
||||
TotPrice *= 1;
|
||||
if (Type == 1) {
|
||||
TotPrice *= 1;
|
||||
}
|
||||
// General store
|
||||
if (isSelling && ShopHandler.ShopBModifier[player.myShopId] == 1) {
|
||||
TotPrice *= 0.90;
|
||||
} else if (Type == 1) {
|
||||
TotPrice *= 1;
|
||||
}
|
||||
return (int) Math.round(TotPrice);
|
||||
// Minimum value of 1
|
||||
return (int) Math.max(1, Math.floor(TotPrice));
|
||||
}
|
||||
|
||||
public int getItemShopValue(int itemId) {
|
||||
@@ -334,7 +316,9 @@ public class ShopAssistant {
|
||||
} else if (ShopValue >= 1000000) {
|
||||
ShopAdd = " (" + (ShopValue / 1000000) + " million)";
|
||||
}
|
||||
if (player.myShopId != RANGE_SHOP && player.myShopId != PEST_SHOP && player.myShopId != CASTLE_SHOP && player.myShopId != 138 && player.myShopId != 58 && player.myShopId != 139) {
|
||||
if (ShopHandler.ShopName[player.myShopId].equalsIgnoreCase(player.properName + "'s Store")) {
|
||||
player.getActionSender().sendMessage(ItemAssistant.getItemName(removeId) + ": set your sell price.");
|
||||
} else if (player.myShopId != RANGE_SHOP && player.myShopId != PEST_SHOP && player.myShopId != CASTLE_SHOP && player.myShopId != 138 && player.myShopId != 58 && player.myShopId != 139) {
|
||||
player.getActionSender().sendMessage(ItemAssistant.getItemName(removeId) + ": shop will buy for " + ShopValue + " coins." + ShopAdd);
|
||||
} else if (player.myShopId == 138 || player.myShopId == 139 || player.myShopId == 58) {
|
||||
player.getActionSender().sendMessage(ItemAssistant.getItemName(removeId) + ": shop will buy for " + tokkulValue + " tokkul.");
|
||||
@@ -349,11 +333,8 @@ public class ShopAssistant {
|
||||
}
|
||||
|
||||
public boolean sellItem(int itemID, int fromSlot, int amount) {
|
||||
|
||||
player.getItemAssistant();
|
||||
for (int i : Constants.ITEM_SELLABLE) {
|
||||
if (i == itemID) {
|
||||
player.getItemAssistant();
|
||||
player.getActionSender().sendMessage("You can't sell " + ItemAssistant.getItemName(itemID).toLowerCase() + ".");
|
||||
return false;
|
||||
}
|
||||
@@ -365,76 +346,82 @@ public class ShopAssistant {
|
||||
if(!player.isShopping) {
|
||||
return false;
|
||||
}
|
||||
if (player.TotalShopItems >= 39) {
|
||||
player.getActionSender().sendMessage("If you sell more individuals items in this shop, they won't be displayed.");
|
||||
// We can only store 40 items per shop
|
||||
if (player.TotalShopItems >= 40) {
|
||||
player.getActionSender().sendMessage("This shop is out of space!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (amount > 0 && itemID == (player.playerItems[fromSlot] - 1)) {
|
||||
boolean IsIn = 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.myShopId]) {
|
||||
// Only buys what is in stock
|
||||
// Only buys what they sell
|
||||
case 2:
|
||||
for (int j = 0; j <= ShopHandler.ShopItemsStandard[player.myShopId]; j++) {
|
||||
if (itemID == (ShopHandler.ShopItems[player.myShopId][j] - 1)) {
|
||||
IsIn = true;
|
||||
canSellToStore = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// General store
|
||||
// General store - buys anything
|
||||
case 1:
|
||||
IsIn = true;
|
||||
canSellToStore = true;
|
||||
break;
|
||||
// Player owned store
|
||||
// Player owned store - only "buys" from the player whos store it is
|
||||
case 0:
|
||||
System.out.println("Is players shop: " + (ShopHandler.ShopName[player.myShopId].equalsIgnoreCase(player.properName + "'s Store") ? "true" : "false"));
|
||||
IsIn = ShopHandler.ShopName[player.myShopId].equalsIgnoreCase(player.properName + "'s Store");
|
||||
canSellToStore = ShopHandler.ShopName[player.myShopId].equalsIgnoreCase(player.properName + "'s Store");
|
||||
break;
|
||||
}
|
||||
if (IsIn == false) {
|
||||
if (canSellToStore == false) {
|
||||
player.getItemAssistant();
|
||||
player.getActionSender().sendMessage("You can't sell " + ItemAssistant.getItemName(itemID).toLowerCase() + " to this store.");
|
||||
return false;
|
||||
}
|
||||
if (amount > player.playerItemsN[fromSlot] && (ItemDefinitions.getDef()[player.playerItems[fromSlot] - 1].isNoteable == true || ItemDefinitions.getDef()[player.playerItems[fromSlot] - 1].isStackable == true)) {
|
||||
amount = player.playerItemsN[fromSlot];
|
||||
} else if (amount > player.getItemAssistant().getItemAmount(itemID) && ItemDefinitions.getDef()[player.playerItems[fromSlot] - 1].isNoteable == false && ItemDefinitions.getDef()[player.playerItems[fromSlot] - 1].isStackable == false) {
|
||||
amount = player.getItemAssistant().getItemAmount(itemID);
|
||||
if (amount > inventoryAmount) {
|
||||
amount = inventoryAmount;
|
||||
}
|
||||
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
|
||||
int TotPrice2 = 0;
|
||||
int value = 1;
|
||||
int currency = 995;
|
||||
if (player.myShopId == 138 || player.myShopId == 58 || player.myShopId == 139) {
|
||||
TotPrice2 = (int) Math.floor(getTokkulValue(itemID) * .85) * amount;
|
||||
value = (int) Math.floor(getTokkulValue(itemID) * .85);
|
||||
currency = 6529;
|
||||
} else {
|
||||
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, amount, true) * amount); //Something about total price of item?
|
||||
value = (int) Math.floor(getItemShopValue(itemID, amount, true));
|
||||
currency = 995;
|
||||
}
|
||||
if (player.getItemAssistant().freeSlots() > 0 || player.getItemAssistant().playerHasItem(995) || player.getItemAssistant().playerHasItem(6529)) { //Checks to see if player has room for coins.
|
||||
if (!ItemDefinitions.getDef()[itemID].isNoteable) { //Check to see if its notable.
|
||||
player.getItemAssistant().deleteItem2(itemID, amount);
|
||||
} else {
|
||||
player.getItemAssistant().deleteItem2(itemID, amount);
|
||||
String ItemNameUnNotedItem = ItemAssistant.getItemName(itemID - 1).toLowerCase();
|
||||
if (itemName.contains(ItemNameUnNotedItem)) {
|
||||
itemID = itemID - 1; //Replace the noted item by it's un-noted version.
|
||||
}
|
||||
}
|
||||
if (player.myShopId == 138 || player.myShopId == 139 || player.myShopId == 58) {
|
||||
player.getItemAssistant().addItem(6529, TotPrice2); //Add the tokkul to your inventory.
|
||||
} else {
|
||||
player.getItemAssistant().addItem(995, TotPrice2); //Add the coins to your inventory.
|
||||
}
|
||||
addShopItem(itemID, amount); //Add item to the shop.
|
||||
if (player.getPlayerAssistant().isPlayer()) { //Logger
|
||||
GameLogger.writeLog(player.playerName, "shopselling", player.playerName + " sold " + itemName + " to store id: " + player.myShopId + " for" + GameLogger.formatCurrency(TotPrice2) + " coins");
|
||||
}
|
||||
} else {
|
||||
|
||||
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable;
|
||||
|
||||
if (!player.getItemAssistant().playerHasItem(currency) && isStackable && amount < inventoryAmount && player.getItemAssistant().freeSlots() <= 0) {
|
||||
player.getActionSender().sendMessage("You don't have enough space in your inventory.");
|
||||
}
|
||||
|
||||
player.getItemAssistant().deleteItem(itemID, amount);
|
||||
String ItemNameUnNotedItem = ItemAssistant.getItemName(itemID - 1).toLowerCase();
|
||||
if (itemName.contains(ItemNameUnNotedItem)) {
|
||||
itemID = itemID - 1; //Replace the noted item by it's un-noted version.
|
||||
}
|
||||
|
||||
if (ShopHandler.ShopName[player.myShopId].equalsIgnoreCase(player.properName + "'s Store")) {
|
||||
// Add items to players store
|
||||
player.getActionSender().sendMessage("You sent " + amount + " " + itemName + " to your store.");
|
||||
BotHandler.addTobank(player.myShopId, itemID, amount);
|
||||
} else {
|
||||
// Add currency to players inventory
|
||||
int totalValue = value * amount;
|
||||
player.getItemAssistant().addItem(currency, totalValue);
|
||||
player.getActionSender().sendMessage("You sold " + amount + " " + itemName + " for " + totalValue + " " + ItemAssistant.getItemName(itemID).toLowerCase() + ".");
|
||||
}
|
||||
|
||||
// Add item to the shop
|
||||
addShopItem(itemID, amount);
|
||||
player.getItemAssistant().resetItems(3823);
|
||||
resetShop(player.myShopId);
|
||||
updatePlayerShop();
|
||||
player.getActionSender().sendMessage("You sold " + amount + " " +itemName + " for " + TotPrice2 + " coins." );
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
@@ -470,266 +457,88 @@ public class ShopAssistant {
|
||||
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 iValue = 0;
|
||||
int boughtQty = 0;
|
||||
boolean boughtItem = false;
|
||||
int shopID = player.myShopId;
|
||||
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable;
|
||||
int freeSlots = player.getItemAssistant().freeSlots();
|
||||
int storeQty = ShopHandler.getStock(shopID, itemID);
|
||||
System.out.println("Item " + itemID + " stock = " + storeQty);
|
||||
if (amount > 0) {
|
||||
//S4
|
||||
if (ShopHandler.ShopItemsN[player.myShopId][fromSlot] == 0) {
|
||||
if (storeQty <= 0) {
|
||||
// none in stock, or not sold here
|
||||
player.getActionSender().sendMessage("You can't buy that right now!");
|
||||
return false;
|
||||
}
|
||||
if (amount > ShopHandler.ShopItemsN[player.myShopId][fromSlot] && ShopHandler.ShopItemsN[player.myShopId][fromSlot] > 0) {
|
||||
amount = ShopHandler.ShopItemsN[player.myShopId][fromSlot];
|
||||
if (amount > storeQty) {
|
||||
// buy all that the store has
|
||||
amount = storeQty;
|
||||
}
|
||||
|
||||
if (amount % 23 == 0) {
|
||||
amount = amount / 23;
|
||||
iValue = 23; }
|
||||
else if (amount % 19 == 0) {
|
||||
amount = amount / 19;
|
||||
iValue = 19;
|
||||
} else if (amount % 17 == 0) {
|
||||
amount = amount / 17;
|
||||
iValue = 17;
|
||||
} else if (amount % 13 == 0) {
|
||||
amount = amount / 13;
|
||||
iValue = 13;
|
||||
} else if (amount % 11 == 0) {
|
||||
amount = amount / 11;
|
||||
iValue = 11;
|
||||
} else if (amount % 7 == 0) {
|
||||
amount = amount / 7;
|
||||
iValue = 7;
|
||||
} else if (amount % 5 == 0) {
|
||||
amount = amount / 5;
|
||||
iValue = 5;
|
||||
if (freeSlots <= 0){
|
||||
if (!isStackable || isStackable && !player.getItemAssistant().playerHasItem(itemID)) {
|
||||
player.getActionSender().sendMessage("You don't have enough space in your inventory.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (amount % 3 == 0) {
|
||||
amount = amount / 3;
|
||||
iValue = 3;
|
||||
} else if (amount % 2 == 0) {
|
||||
amount = amount / 2;
|
||||
iValue = 2;
|
||||
} else{
|
||||
iValue = 1;
|
||||
if (!isStackable && amount > freeSlots) {
|
||||
// player will fill their inventory
|
||||
amount = freeSlots;
|
||||
}
|
||||
if(!player.isShopping) {
|
||||
return false;
|
||||
}
|
||||
if (ShopHandler.ShopItems[player.myShopId][fromSlot] - 1 != itemID || ShopHandler.ShopItems[player.myShopId][fromSlot] < 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < FISHING_ITEMS.length; i++) {
|
||||
if (player.myShopId == 32 && itemID == FISHING_ITEMS[i]) {
|
||||
player.getActionSender().sendMessage("You can't buy that item from this store!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!shopSellsItem(itemID)) {
|
||||
int value = 0; // Item Value
|
||||
int currency = 995; // currency this shop uses
|
||||
if (player.myShopId == 138 || player.myShopId == 58 || player.myShopId == 139) {
|
||||
value = getTokkulValue(itemID);
|
||||
currency = 6529; // Tokkul
|
||||
} else if (player.myShopId == RANGE_SHOP) {
|
||||
value = getRGItemValue(itemID);
|
||||
currency = 1464; // Archery tickets
|
||||
} else if (player.myShopId == PEST_SHOP) {
|
||||
value = getPestItemValue(itemID);
|
||||
currency = 995; // gp
|
||||
} else if (player.myShopId == 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);
|
||||
|
||||
// player has none of the required currency
|
||||
if (currencySlot == -1) {
|
||||
player.getActionSender().sendMessage("You don't have enough " + ItemAssistant.getItemName(currency).toLowerCase() + " to buy that.");
|
||||
return false;
|
||||
}
|
||||
int TotPrice2 = 0; //ShopPrice
|
||||
int RemainingToBuy; //Remaining of item to buy to fill the order. It's the remaining that can't fit in the loop. It has to be processed by itself after the loop.
|
||||
int Slot = 0; //gp (995)
|
||||
int tokkulSlot = 0;
|
||||
int rangeSlot = 0;
|
||||
int castleSlot = 0;
|
||||
for (int i = amount; iValue > 0; iValue--) {
|
||||
if (player.myShopId != 138 && player.myShopId != 58 && player.myShopId != 139 && player.myShopId != RANGE_SHOP && player.myShopId != PEST_SHOP && player.myShopId != CASTLE_SHOP) {
|
||||
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, 0, false));
|
||||
} else if (player.myShopId == 138 || player.myShopId == 58 || player.myShopId == 139) {
|
||||
TotPrice2 = getTokkulValue(itemID);
|
||||
} else if (player.myShopId == RANGE_SHOP) {
|
||||
TotPrice2 = getRGItemValue(itemID);
|
||||
} else if (player.myShopId == PEST_SHOP) {
|
||||
TotPrice2 = getPestItemValue(itemID);
|
||||
} else if (player.myShopId == CASTLE_SHOP) {
|
||||
TotPrice2 = getCastleItemValue(itemID);
|
||||
}
|
||||
Slot = player.getItemAssistant().getItemSlot(995);
|
||||
tokkulSlot = player.getItemAssistant().getItemSlot(6529);
|
||||
rangeSlot = player.getItemAssistant().getItemSlot(1464);
|
||||
castleSlot = player.getItemAssistant().getItemSlot(4067);
|
||||
if (Slot == -1) {
|
||||
if (player.myShopId != 138 && player.myShopId != 139 && player.myShopId != 58 && player.myShopId != RANGE_SHOP && player.myShopId != CASTLE_SHOP && player.myShopId != PEST_SHOP) {
|
||||
player.getActionSender().sendMessage("You don't have enough coins.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rangeSlot == -1) {
|
||||
if (player.myShopId == RANGE_SHOP) {
|
||||
player.getActionSender().sendMessage("You don't have enough archery tickets to buy that.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (castleSlot == -1) {
|
||||
if (player.myShopId == CASTLE_SHOP) {
|
||||
player.getActionSender().sendMessage("You don't have enough castle wars tickets to buy that.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tokkulSlot == -1) {
|
||||
if (player.myShopId == 138 || player.myShopId == 58 || player.myShopId == 139) {
|
||||
player.getActionSender().sendMessage("You don't have enough tokkul to buy that.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (TotPrice2 <= 1) {
|
||||
TotPrice2 = (int) Math.floor(getItemShopValue(itemID, 0, false));
|
||||
TotPrice2 *= 1.66;
|
||||
}
|
||||
|
||||
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "shopbuying", player.playerName + " bought " + itemName + " from store id: " + player.myShopId + " for" + GameLogger.formatCurrency(TotPrice2) + " coins");
|
||||
}
|
||||
// amount of currency the player has
|
||||
int currencyAmount = player.playerItemsN[currencySlot];
|
||||
|
||||
// TzHaar Shops
|
||||
if (player.myShopId == 138 || player.myShopId == 139 || player.myShopId == 58) {
|
||||
if (player.playerItemsN[tokkulSlot] >= TotPrice2) {
|
||||
if (player.getItemAssistant().freeSlots() > 0 || (player.getItemAssistant().playerHasItem(itemID) && ItemDefinitions.getDef()[itemID].isStackable)) {
|
||||
player.getItemAssistant().deleteItem(6529, tokkulSlot, TotPrice2);
|
||||
player.getItemAssistant().addItem(itemID, 1);
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= 1;
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0;
|
||||
ShopHandler.ShopItemsRestock[player.myShopId][fromSlot] = System.currentTimeMillis();
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = 0;
|
||||
}
|
||||
} else {
|
||||
player.getActionSender()
|
||||
.sendMessage(
|
||||
"You don't have enough space in your inventory.");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
player.getActionSender().sendMessage(
|
||||
"You don't have enough tokkul.");
|
||||
break;
|
||||
}
|
||||
} else if (player.myShopId == RANGE_SHOP) {
|
||||
if (player.playerItemsN[rangeSlot] >= TotPrice2) {
|
||||
if (player.getItemAssistant().freeSlots() > 0 || (player.getItemAssistant().playerHasItem(itemID) && ItemDefinitions.getDef()[itemID].isStackable)) {
|
||||
player.getItemAssistant().deleteItem(1464, rangeSlot, TotPrice2);
|
||||
player.getItemAssistant().addItem(itemID, 1);
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= 1;
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0;
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = 0;
|
||||
}
|
||||
} else {
|
||||
player.getActionSender()
|
||||
.sendMessage(
|
||||
"You don't have enough space in your inventory.");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
player.getActionSender().sendMessage(
|
||||
"You don't have enough archery tickets.");
|
||||
break;
|
||||
}
|
||||
} else if (player.myShopId == CASTLE_SHOP) {
|
||||
if (player.playerItemsN[castleSlot] >= TotPrice2) {
|
||||
if (player.getItemAssistant().freeSlots() > 0 || (player.getItemAssistant().playerHasItem(itemID) && ItemDefinitions.getDef()[itemID].isStackable)) {
|
||||
player.getItemAssistant().deleteItem(4067, castleSlot, TotPrice2);
|
||||
player.getItemAssistant().addItem(itemID, 1);
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= 1;
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0;
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = 0;
|
||||
}
|
||||
} else {
|
||||
player.getActionSender()
|
||||
.sendMessage(
|
||||
"You don't have enough space in your inventory.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (player.playerItemsN[Slot] >= TotPrice2 * amount) {
|
||||
if (player.getItemAssistant().freeSlots() >= amount || (player.getItemAssistant().playerHasItem(itemID) && ItemDefinitions.getDef()[itemID].isStackable) || player.getItemAssistant().freeSlots() >= 1 && ItemDefinitions.getDef()[itemID].isStackable) {
|
||||
player.getItemAssistant().deleteItem(995,
|
||||
player.getItemAssistant().getItemSlot(995),
|
||||
TotPrice2 * amount);
|
||||
player.getItemAssistant().addItem(itemID, amount); //All of these actions are performed in a loop. We are in the loop right now.
|
||||
boughtQty+=amount;
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= amount; //Delete X item from shop at the slot the item is.
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0; //Shit ass delay
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = itemID + 1;
|
||||
}
|
||||
} else {
|
||||
if (player.getItemAssistant().freeSlots() == 0) {
|
||||
player.getActionSender().sendMessage(
|
||||
"You don't have enough space in your inventory.");
|
||||
} else {
|
||||
//Buys the remaining item to fill the inventory slots.
|
||||
RemainingToBuy = player.getItemAssistant().freeSlots();
|
||||
amount = RemainingToBuy;
|
||||
player.getItemAssistant().deleteItem(995,
|
||||
player.getItemAssistant().getItemSlot(995),
|
||||
TotPrice2 * amount);
|
||||
player.getItemAssistant().addItem(itemID, amount);
|
||||
boughtQty+=amount;
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= amount;
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0;
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = itemID + 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
boughtItem = true;
|
||||
} else {
|
||||
if (player.playerItemsN[Slot] / TotPrice2 > 0) {
|
||||
amount = (int)Math.floor(player.playerItemsN[Slot] / TotPrice2);
|
||||
} else {
|
||||
player.getActionSender().sendMessage("You don't have enough coins.");
|
||||
player.getItemAssistant().resetItems(3823);
|
||||
resetShop(player.myShopId);
|
||||
updatePlayerShop();
|
||||
return false;
|
||||
}
|
||||
if (player.getItemAssistant().freeSlots() >= amount || (player.getItemAssistant().playerHasItem(itemID) && ItemDefinitions.getDef()[itemID].isStackable) || player.getItemAssistant().freeSlots() >= 1 && ItemDefinitions.getDef()[itemID].isStackable) {
|
||||
player.getItemAssistant().deleteItem(995,
|
||||
player.getItemAssistant().getItemSlot(995),
|
||||
TotPrice2 * amount);
|
||||
player.getItemAssistant().addItem(itemID, amount); //All of these actions are performed in a loop. We are in the loop right now.
|
||||
boughtQty+=amount;
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= amount; //Delete X item from shop at the slot the item is.
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0; //Shit ass delay
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = itemID + 1;
|
||||
}
|
||||
} else {
|
||||
if (player.getItemAssistant().freeSlots() == 0) {
|
||||
player.getActionSender().sendMessage(
|
||||
"You don't have enough space in your inventory.");
|
||||
} else {
|
||||
//Buys the remaining item to fill the inventory slots.
|
||||
RemainingToBuy = player.getItemAssistant().freeSlots();
|
||||
amount = RemainingToBuy;
|
||||
player.getItemAssistant().deleteItem(995,
|
||||
player.getItemAssistant().getItemSlot(995),
|
||||
TotPrice2 * amount);
|
||||
player.getItemAssistant().addItem(itemID, amount);
|
||||
boughtQty+=amount;
|
||||
ShopHandler.ShopItemsN[player.myShopId][fromSlot] -= amount;
|
||||
ShopHandler.ShopItemsDelay[player.myShopId][fromSlot] = 0;
|
||||
if (fromSlot + 1 > ShopHandler.ShopItemsStandard[player.myShopId]) {
|
||||
ShopHandler.ShopItems[player.myShopId][fromSlot] = itemID + 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
boughtItem = true;
|
||||
}
|
||||
int totalValue = value * amount;
|
||||
if (currencyAmount < totalValue) {
|
||||
amount = (int) Math.floor(player.playerItemsN[currencySlot] / amount);
|
||||
// buy as many as we can afford
|
||||
totalValue = value * amount;
|
||||
if (currencyAmount < totalValue) {
|
||||
player.getActionSender().sendMessage("You don't have enough " + ItemAssistant.getItemName(currency).toLowerCase() + " to buy that.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (boughtItem) {
|
||||
player.getActionSender().sendMessage("You bought " + boughtQty + " " + ItemAssistant.getItemName(itemID).toLowerCase() + " for " + TotPrice2 * boughtQty + " coins." );
|
||||
player.getItemAssistant().deleteItem2(currency, totalValue);
|
||||
player.getItemAssistant().addItem(itemID, amount);
|
||||
ShopHandler.buyItem(shopID, itemID, amount);
|
||||
ShopHandler.refreshShop(shopID);
|
||||
player.getActionSender().sendMessage("You bought " + amount + " " + ItemAssistant.getItemName(itemID).toLowerCase() + " for " + totalValue + " " + ItemAssistant.getItemName(currency).toLowerCase() + "." );
|
||||
|
||||
String itemName = ItemAssistant.getItemName(itemID).toLowerCase();
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "shopbuying", player.playerName + " bought " + amount + " " + ItemAssistant.getItemName(itemID).toLowerCase() + " for " + totalValue + " " + ItemAssistant.getItemName(currency).toLowerCase() + " from store " + shopID + ".");
|
||||
}
|
||||
player.getItemAssistant().resetItems(3823);
|
||||
resetShop(player.myShopId);
|
||||
|
||||
@@ -48,7 +48,6 @@ public class ShopHandler {
|
||||
|
||||
public static int restockTimeItem(int itemId) {
|
||||
switch(itemId) {
|
||||
|
||||
default:
|
||||
return 1000;
|
||||
}
|
||||
@@ -100,7 +99,7 @@ public class ShopHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetItem(int ShopID, int ArrayID) {
|
||||
private static void ResetItem(int ShopID, int ArrayID) {
|
||||
ShopItems[ShopID][ArrayID] = 0;
|
||||
ShopItemsN[ShopID][ArrayID] = 0;
|
||||
ShopItemsDelay[ShopID][ArrayID] = 0;
|
||||
@@ -179,6 +178,12 @@ public class ShopHandler {
|
||||
player.myShopId = id;
|
||||
ShopSModifier[id] = 0;
|
||||
ShopName[id] = player.properName + "'s Store";
|
||||
for (int i = 0; i < MaxShopItems; i++){
|
||||
ShopItems[id][i] = player.bankItems[i];
|
||||
ShopItemsN[id][i] = player.bankItemsN[i];
|
||||
ShopItemsSN[id][i] = 0;
|
||||
ShopItemsDelay[id][i] = 0;
|
||||
}
|
||||
TotalShops++;
|
||||
}
|
||||
|
||||
@@ -188,4 +193,42 @@ public class ShopHandler {
|
||||
}
|
||||
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 < MaxShopItems; j++) {
|
||||
if (ShopItems[shop_id][j] > 0 && ShopItemsN[shop_id][j] <= 0) {
|
||||
ResetItem(shop_id, j);
|
||||
if (ShopItems[shop_id][j + 1] > 0) {
|
||||
ShopItems[shop_id][j] = ShopItems[shop_id][j + 1];
|
||||
ShopItemsN[shop_id][j] = ShopItemsN[shop_id][j + 1];
|
||||
ShopItemsSN[shop_id][j] = ShopItemsSN[shop_id][j + 1];
|
||||
ShopItemsDelay[shop_id][j] = ShopItemsDelay[shop_id][j + 1];
|
||||
ResetItem(shop_id, j + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getStock(int shop_id, int item_id){
|
||||
item_id++;
|
||||
for (int j = 0; j < MaxShopItems; j++) {
|
||||
if (ShopItems[shop_id][j] > 0)
|
||||
System.out.println("item " + item_id + " = " + ShopItemsN[shop_id][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 < MaxShopItems; j++) {
|
||||
if (ShopItems[shop_id][j] == item_id) {
|
||||
ShopItemsN[shop_id][j] -= amount;
|
||||
}
|
||||
}
|
||||
refreshShop(shop_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ public class GameLogger {
|
||||
s = s.substring(0, k).replace(",", ".") + "," + s.substring(k);
|
||||
}
|
||||
if (s.length() > 8) {
|
||||
|
||||
s = s.substring(0, s.length() - 8).replace(",", ".") + " million (" + s + ")";
|
||||
} else if (s.length() > 4) {
|
||||
s = s.substring(0, s.length() - 4) + "K (" + s + ")";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package redone.util;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Misc {
|
||||
|
||||
@@ -156,6 +157,11 @@ public class Misc {
|
||||
return arr[(int) Math.floor(Math.random() * arr.length)];
|
||||
}
|
||||
|
||||
public static int randomArrayListItem(ArrayList<Integer> arr) {
|
||||
int index = (int) Math.floor(Math.random() * arr.size());
|
||||
return arr.get(index);
|
||||
}
|
||||
|
||||
public static long playerNameToInt64(String s) {
|
||||
long l = 0L;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user