Browse Source

Migration to org.json

combat-2
MagicBot 7 months ago
parent
commit
8818282341
  1. 53
      src/engine/objects/ItemTemplate.java

53
src/engine/objects/ItemTemplate.java

@ -140,69 +140,68 @@ public class ItemTemplate { @@ -140,69 +140,68 @@ public class ItemTemplate {
try {
// Reading a String
obj_name = (String) jsonObject.get("obj_name");
obj_name = jsonObject.getString("obj_name");
// Reading a boolean
obj_pickable = (boolean) jsonObject.get("obj_pickable");
obj_pickable = jsonObject.getBoolean("obj_pickable");
// Reading floats from an array (note always check for empty arrays)
JSONArray scaleData = (JSONArray) jsonObject.get("obj_scale");
JSONArray scaleData = jsonObject.getJSONArray("obj_scale");
if (scaleData.isEmpty() == false)
obj_scale = new Vector3fImmutable(((Double) scaleData.get(0)).floatValue(), ((Double) scaleData.get(1)).floatValue(),
((Double) scaleData.get(2)).floatValue());
obj_scale = new Vector3fImmutable(scaleData.getFloat(0), scaleData.getFloat(1),
scaleData.getFloat(2));
JSONArray forwardVector = (JSONArray) jsonObject.get("obj_forward_vector");
JSONArray forwardVector = jsonObject.getJSONArray("obj_forward_vector");
if (forwardVector.isEmpty() == false)
obj_forward_vector = new Vector3fImmutable(((Double) forwardVector.get(0)).floatValue(), ((Double) forwardVector.get(1)).floatValue(),
((Double) forwardVector.get(2)).floatValue());
obj_forward_vector = new Vector3fImmutable(forwardVector.getFloat(0), forwardVector.getFloat(1),
forwardVector.getFloat(2));
JSONArray defaultAlighment = (JSONArray) jsonObject.get("obj_default_alignment");
JSONArray defaultAlignment = jsonObject.getJSONArray("obj_default_alignment");
if (defaultAlighment.isEmpty() == false)
obj_default_alignment = new Vector3fImmutable(((Double) defaultAlighment.get(0)).floatValue(), ((Double) defaultAlighment.get(1)).floatValue(),
((Double) defaultAlighment.get(2)).floatValue());
if (defaultAlignment.isEmpty() == false)
obj_default_alignment = new Vector3fImmutable(defaultAlignment.getFloat(0), defaultAlignment.getFloat(1),
defaultAlignment.getFloat(2));
// Reading an integer value
obj_render_object = ((Long) jsonObject.get("obj_render_object")).intValue();
obj_icon = ((Long) jsonObject.get("obj_icon")).intValue();
obj_render_object = jsonObject.getInt("obj_render_object");
obj_icon = jsonObject.getInt("obj_icon");
JSONObject obj_sparse_json = (JSONObject) jsonObject.get("obj_sparse_data");
JSONObject obj_sparse_json = jsonObject.getJSONObject("obj_sparse_data");
for (Object key : obj_sparse_json.keySet()) {
String sparseType = (String) key;
Object sparseValue = obj_sparse_json.get(sparseType);
obj_sparse_data.put(sparseType, sparseValue.toString());
for (String key : obj_sparse_json.keySet()) {
String sparseValue = obj_sparse_json.getString(key);
obj_sparse_data.put(key, sparseValue);
}
// Banes are defined by their sparse data field
if (obj_sparse_data.get("ACTIONRESPONSE") != null)
if (obj_sparse_data.get("ACTIONRESPONSE").equals("4250517122"))
item_bane_rank = ((Long) jsonObject.get("item_bane_rank")).intValue();
item_bane_rank = jsonObject.getInt("item_bane_rank");
// Reading float values
combat_health_current = ((Double) jsonObject.get("combat_health_current")).floatValue();
combat_health_full = ((Double) jsonObject.get("combat_health_full")).floatValue();
combat_health_current = jsonObject.getFloat("combat_health_current");
combat_health_full = jsonObject.getFloat("combat_health_full");
// Reading a hashmap of floats
JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist");
JSONObject resist_json = jsonObject.getJSONObject("combat_attack_resist");
for (String key : resist_json.keySet()) {
float resist = ((Double) resist_json.get(key)).floatValue();
combat_attack_resist.put((String) key, resist);
float resist = resist_json.getFloat(key);
combat_attack_resist.put(key, resist);
}
// Parsing an enum
item_type = mbEnums.ItemType.valueOf((String) jsonObject.get("item_type"));
item_eq_slots_value = ((Long) jsonObject.get("item_eq_slots_value")).intValue();
item_type = mbEnums.ItemType.valueOf(jsonObject.getString("item_type"));
item_eq_slots_value = jsonObject.getInt("item_eq_slots_value");
item_eq_slots_type = (boolean) jsonObject.get("item_eq_slots_type");
// Parsing an enumset

Loading…
Cancel
Save