public Item transform(RPObject rpobject) {
// We simply ignore corpses...
if (rpobject.get("type").equals("item")) {
final String name = UpdateConverter.updateItemName(rpobject.get("name"));
final Item item = UpdateConverter.updateItem(name);
if (item == null) {
// no such item in the game anymore
return null;
}
item.setID(rpobject.getID());
if (rpobject.has("persistent")
&& (rpobject.getInt("persistent") == 1)) {
/*
* Keep [new] rpclass
*/
final RPClass rpclass = item.getRPClass();
item.fill(rpobject);
item.setRPClass(rpclass);
// If we've updated the item name we don't want persistent reverting it
item.put("name", name);
}
if (item instanceof StackableItem) {
int quantity = 1;
if (rpobject.has("quantity")) {
quantity = rpobject.getInt("quantity");
} else {
logger.warn("Adding quantity=1 to "
+ rpobject
+ ". Most likely cause is that this item was not stackable in the past");
}
((StackableItem) item).setQuantity(quantity);
if (quantity <= 0) {
logger.warn("Ignoring item "
+ name
+ " because this item has an invalid quantity: "
+ quantity);
return null;
}
}
// make sure saved individual information is
// restored
final String[] individualAttributes = { "infostring",
"description", "bound", "undroppableondeath" };
for (final String attribute : individualAttributes) {
if (rpobject.has(attribute)) {
item.put(attribute, rpobject.get(attribute));
}
}
if (rpobject.has("logid")) {
item.put("logid", rpobject.get("logid"));
}
// Contents, if the item has slot(s)
for (RPSlot slot : rpobject.slots()) {
RPSlot itemSlot = item.getSlot(slot.getName());
for (RPObject obj : slot) {
// Transform the contents too
itemSlot.add(transform(obj));
}
}