DDItem.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package org.leumasjaffe.charsheet.model.inventory;
  2. import java.util.Collections;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import org.leumasjaffe.charsheet.model.observable.IntValue;
  6. import org.leumasjaffe.charsheet.model.observable.StringValue;
  7. import com.fasterxml.jackson.annotation.JsonAnyGetter;
  8. import com.fasterxml.jackson.annotation.JsonAnySetter;
  9. import lombok.AccessLevel;
  10. import lombok.AllArgsConstructor;
  11. import lombok.Data;
  12. import lombok.NoArgsConstructor;
  13. import lombok.experimental.FieldDefaults;
  14. @AllArgsConstructor
  15. @Data
  16. @NoArgsConstructor
  17. @FieldDefaults(level=AccessLevel.PRIVATE)
  18. public class DDItem {
  19. String name = "";
  20. IntValue count = new IntValue(1);
  21. int countEquipped = 0;
  22. IntValue weight = new IntValue(0);
  23. Money value = new Money(0, 0, 0, 0);
  24. StringValue page = new StringValue();
  25. EquipmentSlot slot = EquipmentSlot.NONE;
  26. DDWeapon weapon = null;
  27. DDArmor armor = null;
  28. Map<String, Object> properties = new HashMap<>();
  29. public boolean isWeapon() { return weapon != null; }
  30. public boolean isArmor() { return armor != null; }
  31. @SuppressWarnings("unchecked")
  32. public <T> T getProperty(final String key) {
  33. return (T) properties.get(key);
  34. }
  35. @JsonAnySetter
  36. public void setProperty(final String key, final Object prop) {
  37. if ( properties == null ) { properties = new HashMap<>(); }
  38. properties.put(key, prop);
  39. }
  40. @JsonAnyGetter
  41. private Map<String, Object> getProperties() {
  42. return Collections.unmodifiableMap(properties);
  43. }
  44. public int getUnequippedCount() {
  45. return count.value() - countEquipped;
  46. }
  47. }