Remove items from players store/bank

This commit is contained in:
RedSparr0w
2019-11-23 02:20:06 +13:00
parent ca12809861
commit e0925538c7
8 changed files with 55 additions and 16 deletions
@@ -66,8 +66,8 @@ public class Bot {
} }
int item_id = Misc.randomArrayListItem(items); int item_id = Misc.randomArrayListItem(items);
String item_name = ItemAssistant.getItemName(item_id); String item_name = ItemAssistant.getItemName(item_id);
int value = botClient.getShopAssistant().getItemShopValue(item_id); int value = Math.max(1, botClient.getShopAssistant().getItemShopValue(item_id, 0, false));
botClient.forcedChat("Selling " + item_name + " " + GameLogger.formatCurrency(value) + "ea"); botClient.forcedChat("Selling " + item_name + " " + formatSellPrice(value) + " ea");
/* /*
Real chat - Disabled for now, can't get it to function correctly Real chat - Disabled for now, can't get it to function correctly
@@ -80,4 +80,16 @@ public class Bot {
botClient.setChatTextUpdateRequired(true); botClient.setChatTextUpdateRequired(true);
*/ */
} }
private String formatSellPrice(int price) {
if (price > 1e9) {
return (Math.floor(price / 1e8) / 10) + "B";
} else if (price > 1e6) {
return (Math.floor(price / 1e8) / 10) + "M";
} else if (price > 1e3) {
return (Math.floor(price / 100) / 10) + "K";
} else {
return "" + price;
}
}
} }
@@ -66,12 +66,24 @@ public class BotHandler
return null; return null;
} }
public static void addTobank(int shop, int item, int itemN){ public static void addTobank(int shop_id, int item_id, int amount){
for(Bot bot : botList) { for(Bot bot : botList) {
if(bot != null && bot.getBotClient() != null) { if(bot != null && bot.getBotClient() != null) {
Client botClient = bot.getBotClient(); Client botClient = bot.getBotClient();
if(botClient.myShopId == shop) { if(botClient.myShopId == shop_id) {
botClient.getItemAssistant().addItemToBank(item, itemN); botClient.getItemAssistant().addItemToBank(item_id, amount);
return;
}
}
}
}
public static void removeFrombank(int shop_id, int item_id, int amount){
for(Bot bot : botList) {
if(bot != null && bot.getBotClient() != null) {
Client botClient = bot.getBotClient();
if(botClient.myShopId == shop_id) {
botClient.getItemAssistant().removeitemFromBank(item_id, amount);
return; return;
} }
} }
@@ -227,9 +227,10 @@ public class ItemAssistant {
} }
public void addItemToBank(int itemId, int amount) { public void addItemToBank(int itemId, int amount) {
itemId++;
for (int i = 0; i < Constants.BANK_SIZE; i++) { for (int i = 0; i < Constants.BANK_SIZE; i++) {
if (c.bankItems[i] <= 0 || c.bankItems[i] == itemId + 1 && c.bankItemsN[i] + amount < Integer.MAX_VALUE) { if (c.bankItems[i] <= 0 || c.bankItems[i] == itemId && c.bankItemsN[i] + amount < Integer.MAX_VALUE) {
c.bankItems[i] = itemId + 1; c.bankItems[i] = itemId;
c.bankItemsN[i] += amount; c.bankItemsN[i] += amount;
resetBank(); resetBank();
return; return;
@@ -237,6 +238,22 @@ public class ItemAssistant {
} }
} }
public void removeitemFromBank(int itemId, int amount) {
itemId++;
for (int i = 0; i < Constants.BANK_SIZE; i++) {
if (c.bankItems[i] == itemId) {
c.bankItemsN[i] -= amount;
if (c.bankItemsN[i] <= 0) {
c.bankItems[i] = 0;
c.bankItemsN[i] = 0;
}
resetBank();
rearrangeBank();
return;
}
}
}
public void resetItems(int WriteFrame) { public void resetItems(int WriteFrame) {
// synchronized(c) { // synchronized(c) {
if (c.getOutStream() != null && c != null) { if (c.getOutStream() != null && c != null) {
@@ -103,26 +103,22 @@ public class ShopAssistant {
double ShopValue = 1; double ShopValue = 1;
double TotPrice = 0; double TotPrice = 0;
double sellingRatio = isSelling ? 0.85 : 1; double sellingRatio = isSelling ? 0.85 : 1;
for (int i = 0; i < Constants.ITEM_LIMIT; i++) { if (ItemDefinitions.getDef()[ItemID] != null) {
if (ItemDefinitions.getDef()[i] != null) { ShopValue = ItemDefinitions.getDef()[ItemID].highAlch / 3.0 * 5.0 * sellingRatio;
ShopValue = ItemDefinitions.getDef()[ItemID].highAlch/3.0 *5.0 * sellingRatio;
}
} }
TotPrice = ShopValue; TotPrice = ShopValue;
// General store // General store pays less for items
if (isSelling && ShopHandler.ShopBModifier[player.myShopId] == 1) { if (isSelling && ShopHandler.ShopBModifier[player.myShopId] == 1) {
TotPrice *= 0.90; TotPrice *= 0.90;
} else if (Type == 1) {
TotPrice *= 1;
} }
// Minimum value of 1 // Minimum value of 1
return (int) Math.max(1, Math.floor(TotPrice)); return (int) Math.max(1, Math.floor(TotPrice));
} }
public int getItemShopValue(int itemId) { public int getItemShopValue(int itemId) {
return (int) ItemDefinitions.getDef()[itemId].highAlch/3 *5; return getItemShopValue(itemId, 0, false);
} }
@@ -533,7 +529,9 @@ public class ShopAssistant {
player.getItemAssistant().deleteItem2(currency, totalValue); player.getItemAssistant().deleteItem2(currency, totalValue);
player.getItemAssistant().addItem(itemID, amount); player.getItemAssistant().addItem(itemID, amount);
ShopHandler.buyItem(shopID, itemID, amount); ShopHandler.buyItem(shopID, itemID, amount);
ShopHandler.refreshShop(shopID); if (ShopHandler.ShopBModifier[shopID] == 0){
BotHandler.removeFrombank(shopID, itemID, amount);
}
player.getActionSender().sendMessage("You bought " + amount + " " + ItemAssistant.getItemName(itemID).toLowerCase() + " for " + totalValue + " " + ItemAssistant.getItemName(currency).toLowerCase() + "." ); player.getActionSender().sendMessage("You bought " + amount + " " + ItemAssistant.getItemName(itemID).toLowerCase() + " for " + totalValue + " " + ItemAssistant.getItemName(currency).toLowerCase() + "." );
String itemName = ItemAssistant.getItemName(itemID).toLowerCase(); String itemName = ItemAssistant.getItemName(itemID).toLowerCase();