Esempio n. 1
0
  private static Map<String, String> generateAdditionalProperties(
      WorldObject inventoryWorldObject) {
    Map<String, String> additionalProperties = new LinkedHashMap<>();

    List<ManagedProperty<?>> propertyKeys = inventoryWorldObject.getPropertyKeys();
    Collections.sort(propertyKeys, new PropertyComparator());

    for (ManagedProperty<?> propertyKey : propertyKeys) {
      String name = propertyKey.getName().toLowerCase();
      if (propertyKey == Constants.DAMAGE
          || propertyKey == Constants.ARMOR
          || propertyKey == Constants.WEIGHT
          || propertyKey == Constants.QUANTITY
          || Constants.isTool(propertyKey)) {
        String value = inventoryWorldObject.getProperty(propertyKey).toString();
        additionalProperties.put(name, value);
      } else if (propertyKey == Constants.EQUIPMENT_HEALTH) {
        String value = inventoryWorldObject.getProperty(propertyKey).toString();
        int intValue = Integer.parseInt(value);
        int percentage = (100 * intValue) / 1000;
        additionalProperties.put(name, percentage + "%");
      } else if (propertyKey == Constants.SELLABLE) {
        Boolean sellable = (Boolean) inventoryWorldObject.getProperty(propertyKey);
        additionalProperties.put(name, sellable ? "yes" : "no");
      } else if (propertyKey == Constants.TWO_HANDED_WEAPON) {
        Boolean twohHanded = (Boolean) inventoryWorldObject.getProperty(propertyKey);
        additionalProperties.put("two handed", twohHanded ? "yes" : "no");
      }
    }

    return additionalProperties;
  }
Esempio n. 2
0
 public String getToolBonus() {
   for (ManagedProperty<?> property : Constants.getToolProperties()) {
     String value = additionalProperties.get(property.getName().toLowerCase());
     if (value != null) {
       return value;
     }
   }
   throw new IllegalStateException("No tool bonus was found in " + additionalProperties);
 }