Public Repository for the Magicbane Shadowbane Emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.8 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.math.Vector3fImmutable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class ItemTemplate {
// Global template lookup
public static HashMap<Integer, ItemTemplate> itemTemplates = new HashMap<>();
// Template Properties
public String obj_name = "";
public Vector3fImmutable obj_scale = new Vector3fImmutable();
public int obj_render_object;
public int obj_icon;
public float combat_health_current;
public float combat_health_full;
public HashMap<String, Float> combat_attack_resist = new HashMap<>();
public ArrayList combatPowers;
public ItemTemplate(JSONObject jsonObject) {
// Reading a String
obj_name = (String) jsonObject.get("obj_name");
// Reading floats from an array
JSONArray scaleData = (JSONArray) jsonObject.get("obj_scale");
obj_scale = new Vector3fImmutable(((Double) scaleData.get(0)).floatValue(), ((Double) scaleData.get(1)).floatValue(),
((Double) scaleData.get(2)).floatValue());
// Reading an integer value
obj_render_object = ((Long) jsonObject.get("obj_render_object")).intValue();
obj_icon = ((Long) jsonObject.get("obj_icon")).intValue();
// Reading float values
combat_health_current = ((Double) jsonObject.get("combat_health_current")).floatValue();
combat_health_full = ((Double) jsonObject.get("combat_health_full")).floatValue();
// Reading a hashmap of floats
JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist");
for (Object key : resist_json.keySet()) {
float resist = ((Double) resist_json.get(key)).floatValue();
combat_attack_resist.put((String) key, resist);
}
// Reading arraylist of ints
JSONArray combat_json = (JSONArray) jsonObject.get("combat_powers");
if (combat_json.isEmpty() == false)
for (Object o : combat_json)
combatPowers.add(o);
}
}