|
|
@@ -5,34 +5,53 @@ import java.util.Optional;
|
|
|
import org.leumasjaffe.charsheet.model.observable.IntValue;
|
|
|
import org.leumasjaffe.charsheet.model.observable.StringValue;
|
|
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonCreator;
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
+
|
|
|
import lombok.AccessLevel;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
-import lombok.NoArgsConstructor;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.experimental.Delegate;
|
|
|
import lombok.experimental.FieldDefaults;
|
|
|
|
|
|
-@AllArgsConstructor @NoArgsConstructor
|
|
|
-@Data
|
|
|
@FieldDefaults(level=AccessLevel.PRIVATE)
|
|
|
public class DDItem {
|
|
|
- String name = "";
|
|
|
- IntValue count = new IntValue(1);
|
|
|
- IntValue countEquipped = new IntValue(0);
|
|
|
- float weight = 0.f;
|
|
|
- Money value = new Money(0, 0, 0, 0);
|
|
|
- StringValue page = new StringValue();
|
|
|
- EquipmentSlot slot = EquipmentSlot.NONE;
|
|
|
- Optional<DDWeapon> weapon;
|
|
|
- Optional<DDArmor> armor;
|
|
|
+ @Data @FieldDefaults(level=AccessLevel.PRIVATE)
|
|
|
+ public static class Prototype {
|
|
|
+ String name = "";
|
|
|
+ float weight = 0.f;
|
|
|
+ Money value = new Money(0, 0, 0, 0);
|
|
|
+ StringValue page = new StringValue();
|
|
|
+ EquipmentSlot slot = EquipmentSlot.NONE;
|
|
|
+ Optional<DDWeapon> weapon = Optional.empty();
|
|
|
+ Optional<DDArmor> armor = Optional.empty();
|
|
|
+ }
|
|
|
|
|
|
+ @Delegate Prototype name;
|
|
|
+ @Getter IntValue count = new IntValue(1);
|
|
|
+ @Getter IntValue countEquipped = new IntValue(0);
|
|
|
+
|
|
|
+ @JsonCreator
|
|
|
+ public DDItem(@JsonProperty("name") String name,
|
|
|
+ @JsonProperty("count") int count,
|
|
|
+ @JsonProperty("countEquipped") int countEquipped,
|
|
|
+ @JsonProperty("weapon") Optional<DDEnchantedItem> weapon,
|
|
|
+ @JsonProperty("armor") Optional<DDEnchantedItem> armor) {
|
|
|
+ this.name = DDItemFactory.loadItem(name);
|
|
|
+ this.count.value(count);
|
|
|
+ this.countEquipped.value(countEquipped);
|
|
|
+ weapon.ifPresent(e -> getWeapon().get().setEnchant(e));
|
|
|
+ armor.ifPresent(e -> getArmor().get().setEnchant(e));
|
|
|
+ }
|
|
|
+
|
|
|
public String getFullName() {
|
|
|
- return weapon.map(DDWeapon::getNameModifier).orElse(
|
|
|
- armor.map(DDArmor::getNameModifier).orElse("")) + getName();
|
|
|
+ return getWeapon().map(DDWeapon::getNameModifier).orElse(
|
|
|
+ getArmor().map(DDArmor::getNameModifier).orElse("")) + getName();
|
|
|
}
|
|
|
|
|
|
public Money getActualValue() {
|
|
|
- return getValue().sum(weapon.map(DDWeapon::getActualValue).orElse(
|
|
|
- armor.map(DDArmor::getActualValue).orElse(Money.fromCopper(0))));
|
|
|
+ return getValue().sum(getWeapon().map(DDWeapon::getActualValue).orElse(
|
|
|
+ getArmor().map(DDArmor::getActualValue).orElse(Money.fromCopper(0))));
|
|
|
}
|
|
|
|
|
|
public void adjustCount(int amt) {
|
|
|
@@ -46,4 +65,11 @@ public class DDItem {
|
|
|
public int getUnequippedCount() {
|
|
|
return count.value() - countEquipped.value();
|
|
|
}
|
|
|
+
|
|
|
+ @JsonProperty("name")
|
|
|
+ private String json_getName() { return getName(); }
|
|
|
+ @JsonProperty("armor")
|
|
|
+ private Optional<DDEnchantedItem> json_getArmor() { return getWeapon().map(DDWeapon::getEnchant); }
|
|
|
+ @JsonProperty("weapon")
|
|
|
+ private Optional<DDEnchantedItem> json_getWeapon() { return getArmor().map(DDArmor::getEnchant); }
|
|
|
}
|