More fixes and cleanup
This commit is contained in:
@@ -55,9 +55,10 @@ public class ShopQuestion extends Question {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String buyKey = properties.stringPropertyNames().stream()
|
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()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
buyKey = properties.getProperty(buyKey);
|
||||||
|
|
||||||
if (properties.containsKey("close")) {
|
if (properties.containsKey("close")) {
|
||||||
logger.log(Level.INFO, "ShopQuestion.answer: close requested");
|
logger.log(Level.INFO, "ShopQuestion.answer: close requested");
|
||||||
@@ -144,16 +145,17 @@ public class ShopQuestion extends Question {
|
|||||||
form.endHorizontalFlow();
|
form.endHorizontalFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Items tree (hover shows description)
|
// Items table with header row
|
||||||
int height = 16 + 16 * items.size();
|
form.beginTable(items.size(), new String[] {"Name", "Cost", "Buy"});
|
||||||
String header = "height=\"" + height + "\"col{text=\"Price\";width=\"80\"};col{text=\"Buy\";width=\"50\"};";
|
|
||||||
form.beginTree("shopItems", 2, header);
|
// Item rows
|
||||||
for (ShopItem item : items) {
|
for (ShopItem item : items) {
|
||||||
String priceCell = "text=\"" + escape(item.getPriceDisplay()) + "\"";
|
form.addRaw("label{text=\"" + escape(item.getName()) + "\";hover=\"" + escape(item.getDescription()) + "\"};");
|
||||||
String buyCell = "id=\"buy_" + item.getId() + "\";text=\"+1\";checkbox=\"true\"";
|
form.addLabel(item.getPriceDisplay());
|
||||||
form.addTreeRow("i" + item.getId(), item.getName(), item.getDescription(), priceCell, buyCell);
|
form.addRaw("radio{id=\"buy_" + item.getId() + "\";group=\"selected_item\"}");
|
||||||
}
|
}
|
||||||
form.endTree();
|
|
||||||
|
form.endTable();
|
||||||
|
|
||||||
form.beginHorizontalFlow();
|
form.beginHorizontalFlow();
|
||||||
form.addButton("Close", "close");
|
form.addButton("Close", "close");
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect {
|
|||||||
private float ql;
|
private float ql;
|
||||||
private boolean randomQl;
|
private boolean randomQl;
|
||||||
private byte rarity;
|
private byte rarity;
|
||||||
|
private int weight;
|
||||||
|
|
||||||
|
private int liquidContainerTemplateId;
|
||||||
|
|
||||||
public void setItemTemplateId(int itemTemplateId) {
|
public void setItemTemplateId(int itemTemplateId) {
|
||||||
this.itemTemplateId = itemTemplateId;
|
this.itemTemplateId = itemTemplateId;
|
||||||
@@ -31,6 +34,14 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect {
|
|||||||
this.rarity = rarity;
|
this.rarity = rarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLiquidContainerTemplateId(int liquidContainerTemplateId) {
|
||||||
|
this.liquidContainerTemplateId = liquidContainerTemplateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeight(int weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPurchase(Player player) {
|
public void onPurchase(Player player) {
|
||||||
try {
|
try {
|
||||||
@@ -38,9 +49,23 @@ public class ShopWurmItemPurchaseEffect implements ShopItemPurchaseEffect {
|
|||||||
if(randomQl) {
|
if(randomQl) {
|
||||||
thisPurchaseQl = Server.rand.nextInt(99) + 1;
|
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);
|
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()));
|
player.sendSystemMessage(String.format("You receive a %s.", template.getName()));
|
||||||
} catch (NoSuchTemplateException e) {
|
} catch (NoSuchTemplateException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user