Increase resource stack limits and improve makeitem resources

This commit is contained in:
Rob
2026-07-12 04:05:49 +01:00
parent 3cce29dcc8
commit edd2441cda
+51 -16
View File
@@ -32,47 +32,82 @@ public class MakeItemCmd extends AbstractDevCmd {
@Override @Override
protected void _doCmd(PlayerCharacter pc, String[] words, protected void _doCmd(PlayerCharacter pc, String[] words,
AbstractGameObject target) { AbstractGameObject target) {
if (words[0].equals("resources")) { if (words[0].equals("resources")) {
int resourceAmount = 1000;
if (words.length > 1) {
try {
resourceAmount = Integer.parseInt(words[1]);
} catch (NumberFormatException e) {
throwbackError(pc, "Resource amount must be a number.");
return;
}
}
if (resourceAmount < 1)
resourceAmount = 1;
resourceAmount = Math.min(
resourceAmount,
MBServerStatics.RESOURCE_STACK_LIMIT
);
for (int ibID : Warehouse.getMaxResources().keySet()) { for (int ibID : Warehouse.getMaxResources().keySet()) {
if (ibID == 7) if (ibID == 7)
continue; continue;
ItemBase ib = ItemBase.getItemBase(ibID); ItemBase ib = ItemBase.getItemBase(ibID);
short weight = ib.getWeight(); if (ib == null)
if (!pc.getCharItemManager().hasRoomInventory(weight)) { continue;
throwbackError(pc, "Not enough room in inventory for any more of this item");
short weight = ib.getWeight();
if (!pc.getCharItemManager().hasRoomInventory(weight)) {
throwbackError(pc, "Not enough room in inventory for any more resources.");
pc.getCharItemManager().updateInventory(); pc.getCharItemManager().updateInventory();
return; return;
} }
boolean worked = false; Item item = new Item(
Item item = new Item(ib, pc.getObjectUUID(), ib,
OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) ib.getDurability(), (short) ib.getDurability(), pc.getObjectUUID(),
true, false, ItemContainerType.INVENTORY, (byte) 0, OwnerType.PlayerCharacter,
new ArrayList<>(), ""); (byte) 0,
(byte) 0,
(short) ib.getDurability(),
(short) ib.getDurability(),
true,
false,
ItemContainerType.INVENTORY,
(byte) 0,
new ArrayList<>(),
""
);
item.setNumOfItems(Warehouse.getMaxResources().get(ibID)); item.setNumOfItems(resourceAmount);
try { try {
item = DbManager.ItemQueries.ADD_ITEM(item); item = DbManager.ItemQueries.ADD_ITEM(item);
worked = true;
} catch (Exception e) { } catch (Exception e) {
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); throwbackError(
pc,
"Unable to create resource " + ib.getName() + ": " + e.getMessage()
);
return; return;
} }
if (item == null || !worked) { if (item == null) {
throwbackError(pc, "DB error 2: Unable to create item."); throwbackError(pc, "Unable to create resource " + ib.getName() + ".");
return; return;
} }
//add item to inventory
pc.getCharItemManager().addItemToInventory(item); pc.getCharItemManager().addItemToInventory(item);
} }
pc.getCharItemManager().updateInventory();
return; return;
} }
if (words.length < 3 || words.length > 5) { if (words.length < 3 || words.length > 5) {