From ae303482b0d37403b722863aaf02e83be7379b1b Mon Sep 17 00:00:00 2001 From: gamer147 Date: Wed, 26 Nov 2025 10:21:40 -0500 Subject: [PATCH] More fixes and cleanup --- .../server/questions/ShopQuestion.java | 20 +++++++------ .../ShopWurmItemPurchaseEffect.java | 29 +++++++++++++++++-- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/wurmonline/server/questions/ShopQuestion.java b/src/main/java/com/wurmonline/server/questions/ShopQuestion.java index 689ebff..d9d9f37 100644 --- a/src/main/java/com/wurmonline/server/questions/ShopQuestion.java +++ b/src/main/java/com/wurmonline/server/questions/ShopQuestion.java @@ -55,9 +55,10 @@ public class ShopQuestion extends Question { } String buyKey = properties.stringPropertyNames().stream() - .filter(k -> k.startsWith("buy_") && properties.getProperty(k).equals("true")) + .filter(k -> k.equals("selected_item") && properties.getProperty(k).startsWith("buy_")) .findFirst() .orElse(null); + buyKey = properties.getProperty(buyKey); if (properties.containsKey("close")) { logger.log(Level.INFO, "ShopQuestion.answer: close requested"); @@ -144,16 +145,17 @@ public class ShopQuestion extends Question { form.endHorizontalFlow(); } - // Items tree (hover shows description) - int height = 16 + 16 * items.size(); - String header = "height=\"" + height + "\"col{text=\"Price\";width=\"80\"};col{text=\"Buy\";width=\"50\"};"; - form.beginTree("shopItems", 2, header); + // Items table with header row + form.beginTable(items.size(), new String[] {"Name", "Cost", "Buy"}); + + // Item rows for (ShopItem item : items) { - String priceCell = "text=\"" + escape(item.getPriceDisplay()) + "\""; - String buyCell = "id=\"buy_" + item.getId() + "\";text=\"+1\";checkbox=\"true\""; - form.addTreeRow("i" + item.getId(), item.getName(), item.getDescription(), priceCell, buyCell); + form.addRaw("label{text=\"" + escape(item.getName()) + "\";hover=\"" + escape(item.getDescription()) + "\"};"); + form.addLabel(item.getPriceDisplay()); + form.addRaw("radio{id=\"buy_" + item.getId() + "\";group=\"selected_item\"}"); } - form.endTree(); + + form.endTable(); form.beginHorizontalFlow(); form.addButton("Close", "close"); diff --git a/src/main/java/mod/treestar/shopmod/purchasehandlers/ShopWurmItemPurchaseEffect.java b/src/main/java/mod/treestar/shopmod/purchasehandlers/ShopWurmItemPurchaseEffect.java index a00e4d7..fb6ac4c 100644 --- a/src/main/java/mod/treestar/shopmod/purchasehandlers/ShopWurmItemPurchaseEffect.java +++ b/src/main/java/mod/treestar/shopmod/purchasehandlers/ShopWurmItemPurchaseEffect.java @@ -14,6 +14,9 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect { private float ql; private boolean randomQl; private byte rarity; + private int weight; + + private int liquidContainerTemplateId; public void setItemTemplateId(int itemTemplateId) { this.itemTemplateId = itemTemplateId; @@ -31,6 +34,14 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect { this.rarity = rarity; } + public void setLiquidContainerTemplateId(int liquidContainerTemplateId) { + this.liquidContainerTemplateId = liquidContainerTemplateId; + } + + public void setWeight(int weight) { + this.weight = weight; + } + @Override public void onPurchase(Player player) { try { @@ -38,9 +49,23 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect { if(randomQl) { thisPurchaseQl = Server.rand.nextInt(99) + 1; } - Item item = ItemFactory.createItem(itemTemplateId, thisPurchaseQl, (byte) 0, (byte) rarity, null); - player.getInventory().insertItem(item); ItemTemplate template = ItemTemplateFactory.getInstance().getTemplate(itemTemplateId); + Item item = null; + if(template.isLiquid()) { + Item liquid = ItemFactory.createItem(itemTemplateId, thisPurchaseQl, (byte)0, (byte)rarity, null); + item = ItemFactory.createItem(liquidContainerTemplateId > 0 ? liquidContainerTemplateId : ItemList.barrelSmall, 1, (byte)0, (byte)rarity, null); + item.insertItem(liquid); + if(weight != 0) { + liquid.setWeight(weight, false, true); + } + } + else { + item = ItemFactory.createItem(itemTemplateId, thisPurchaseQl, (byte) 0, (byte) rarity, null); + if(weight != 0) { + item.setWeight(weight, false, true); + } + } + player.getInventory().insertItem(item); player.sendSystemMessage(String.format("You receive a %s.", template.getName())); } catch (NoSuchTemplateException e) { throw new RuntimeException(e);