Files
lakebane/src/engine/objects/ItemTemplate.java
T

127 lines
5.4 KiB
Java
Raw Normal View History

2024-02-18 11:00:56 -05:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
2024-02-18 14:03:41 -05:00
import engine.Enum;
2024-02-18 11:39:11 -05:00
import engine.math.Vector3fImmutable;
import org.json.simple.JSONArray;
2024-02-18 11:00:56 -05:00
import org.json.simple.JSONObject;
2024-02-18 14:03:41 -05:00
import java.util.EnumSet;
2024-02-18 11:00:56 -05:00
import java.util.HashMap;
public class ItemTemplate {
2024-02-18 11:39:11 -05:00
// Global template lookup
2024-02-18 11:00:56 -05:00
public static HashMap<Integer, ItemTemplate> itemTemplates = new HashMap<>();
2024-02-18 11:39:11 -05:00
// Template Properties
2024-02-18 14:25:28 -05:00
public String obj_name;
public Vector3fImmutable obj_scale;
2024-02-18 11:41:24 -05:00
public int obj_render_object;
2024-02-18 13:29:01 -05:00
public int obj_icon;
2024-02-18 12:35:55 -05:00
public float combat_health_current;
public float combat_health_full;
2024-02-18 12:15:13 -05:00
public HashMap<String, Float> combat_attack_resist = new HashMap<>();
2024-02-18 14:03:41 -05:00
public Enum.ItemType item_type;
public int item_eq_slots_value;
public boolean item_eq_slots_type;
2024-02-18 14:17:11 -05:00
public EnumSet<Enum.ItemEquipSlotType> item_eq_slots_or = EnumSet.noneOf(Enum.ItemEquipSlotType.class);
public EnumSet<Enum.ItemEquipSlotType> item_eq_slots_and = EnumSet.noneOf(Enum.ItemEquipSlotType.class);
2024-02-18 14:25:28 -05:00
public int item_value;
public int item_wt;
public float item_passive_defense_mod;
public String item_base_name;
public String item_dsc;
public int item_render_object_female;
public float item_health_full;
2024-02-18 13:29:01 -05:00
2024-02-18 14:29:56 -05:00
public EnumSet<Enum.CharacterSkills> item_skill_used = EnumSet.noneOf(Enum.CharacterSkills.class);
2024-02-19 02:40:59 -05:00
public EnumSet<Enum.CharacterSkills> item_skill_mastery_used = EnumSet.noneOf(Enum.CharacterSkills.class);
2024-02-18 14:29:56 -05:00
2024-02-18 11:00:56 -05:00
public ItemTemplate(JSONObject jsonObject) {
2024-02-18 12:28:14 -05:00
// Reading a String
2024-02-18 11:39:11 -05:00
obj_name = (String) jsonObject.get("obj_name");
2024-02-18 11:55:45 -05:00
2024-02-18 12:28:14 -05:00
// Reading floats from an array
2024-02-18 12:04:41 -05:00
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());
2024-02-18 11:55:45 -05:00
2024-02-18 12:28:14 -05:00
// Reading an integer value
2024-02-18 11:49:24 -05:00
obj_render_object = ((Long) jsonObject.get("obj_render_object")).intValue();
2024-02-18 13:29:01 -05:00
obj_icon = ((Long) jsonObject.get("obj_icon")).intValue();
2024-02-18 12:15:13 -05:00
2024-02-18 12:35:55 -05:00
// Reading float values
combat_health_current = ((Double) jsonObject.get("combat_health_current")).floatValue();
combat_health_full = ((Double) jsonObject.get("combat_health_full")).floatValue();
2024-02-18 12:28:14 -05:00
// Reading a hashmap of floats
2024-02-18 12:26:11 -05:00
JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist");
for (Object key : resist_json.keySet()) {
2024-02-18 12:30:23 -05:00
float resist = ((Double) resist_json.get(key)).floatValue();
2024-02-18 12:26:11 -05:00
combat_attack_resist.put((String) key, resist);
}
2024-02-18 14:03:41 -05:00
// Parsing an enum
2024-02-18 13:40:16 -05:00
2024-02-19 02:25:25 -05:00
item_type = Enum.ItemType.valueOf((String) jsonObject.get("item_type"));
2024-02-18 14:03:41 -05:00
item_eq_slots_value = ((Long) jsonObject.get("item_eq_slots_value")).intValue();
2024-02-18 14:08:45 -05:00
item_eq_slots_type = (boolean) jsonObject.get("item_eq_slots_type");
2024-02-18 14:03:41 -05:00
// Parsing an enumset
JSONArray eq_slots_or = (JSONArray) jsonObject.get("item_eq_slots_or");
if (eq_slots_or.isEmpty() == false)
for (Object o : eq_slots_or)
item_eq_slots_or.add(Enum.ItemEquipSlotType.valueOf((String) o));
2024-02-18 11:00:56 -05:00
2024-02-18 14:41:34 -05:00
JSONArray eq_slots_and = (JSONArray) jsonObject.get("item_eq_slots_and");
2024-02-18 14:17:11 -05:00
if (eq_slots_and.isEmpty() == false)
for (Object o : eq_slots_or)
item_eq_slots_and.add(Enum.ItemEquipSlotType.valueOf((String) o));
2024-02-18 14:25:28 -05:00
item_value = ((Long) jsonObject.get("item_value")).intValue();
item_wt = ((Long) jsonObject.get("item_wt")).intValue();
item_passive_defense_mod = ((Double) jsonObject.get("item_passive_defense_mod")).floatValue();
item_base_name = (String) jsonObject.get("item_base_name");
item_dsc = (String) jsonObject.get("item_dsc");
item_render_object_female = ((Long) jsonObject.get("item_render_object_female")).intValue();
item_health_full = ((Double) jsonObject.get("item_health_full")).floatValue();
2024-02-18 14:58:50 -05:00
Object skills_used = jsonObject.get("item_skill_used");
2024-02-18 14:29:56 -05:00
2024-02-19 03:04:12 -05:00
if ((int) skills_used != 0)
2024-02-19 02:40:59 -05:00
for (Object o : (JSONArray) skills_used) {
String skilString = ((String) o).replaceAll("\\s", "");
Enum.CharacterSkills characterSkill = Enum.CharacterSkills.valueOf(skilString);
item_skill_used.add(characterSkill);
}
Object mastery_used = jsonObject.get("item_skill_mastery_used");
2024-02-19 03:04:12 -05:00
if ((int) mastery_used != 0)
2024-02-19 02:40:59 -05:00
for (Object o : (JSONArray) mastery_used) {
String masteryString = ((String) o).replaceAll("\\s", "");
Enum.CharacterSkills masterySkill = Enum.CharacterSkills.valueOf(masteryString);
item_skill_mastery_used.add(masterySkill);
}
2024-02-18 13:29:01 -05:00
}
2024-02-18 11:00:56 -05:00
}