Compare commits

...

1 Commits

Author SHA1 Message Date
gamer147
ae303482b0 More fixes and cleanup 2025-11-26 10:21:40 -05:00
2 changed files with 38 additions and 11 deletions

View File

@@ -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");

View File

@@ -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);