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.

259 lines
12 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.Enum;
import engine.math.Vector3fImmutable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
9 months ago
import org.pmw.tinylog.Logger;
import java.util.EnumSet;
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;
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 Enum.ItemType item_type;
public int item_eq_slots_value;
public boolean item_eq_slots_type;
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);
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;
9 months ago
public int item_parry_anim_id;
public EnumSet<Enum.CharacterSkills> item_skill_used = EnumSet.noneOf(Enum.CharacterSkills.class);
public EnumSet<Enum.CharacterSkills> item_skill_mastery_used = EnumSet.noneOf(Enum.CharacterSkills.class);
// Armor specific fields
9 months ago
public float item_bulk_factor;
public int item_defense_rating;
// Weapon specific fields
public float item_weapon_wepspeed;
public float item_weapon_max_range;
public int item_weapon_projectile_id;
public float item_weapon_projectile_speed;
public int item_weapon_combat_idle_anim;
public Enum.SourceType item_weapon_damage_type;
public int item_weapon_damage_min;
public int item_weapon_damage_max;
9 months ago
public EnumSet<Enum.ItemFlags> item_flags = EnumSet.noneOf(Enum.ItemFlags.class);
9 months ago
public EnumSet<Enum.ItemUseFlags> item_use_flags = EnumSet.noneOf(Enum.ItemUseFlags.class);
public int item_initial_charges;
public HashMap<Enum.CharacterSkills, Integer> item_skill_required = new HashMap<>();
9 months ago
public EnumSet<Enum.MonsterType> item_race_req = EnumSet.noneOf(Enum.MonsterType.class);
public EnumSet<Enum.MonsterType> item_race_res = EnumSet.noneOf(Enum.MonsterType.class);
9 months ago
9 months ago
public EnumSet<Enum.ClassType> item_class_req = EnumSet.noneOf(Enum.ClassType.class);
public EnumSet<Enum.ClassType> item_class_res = EnumSet.noneOf(Enum.ClassType.class);
9 months ago
public EnumSet<Enum.DisciplineType> item_disc_req = EnumSet.noneOf(Enum.DisciplineType.class);
public EnumSet<Enum.DisciplineType> item_disc_res = EnumSet.noneOf(Enum.DisciplineType.class);
public ItemTemplate(JSONObject jsonObject) {
9 months ago
try {
// Reading a String
9 months ago
obj_name = (String) jsonObject.get("obj_name");
9 months ago
// Reading floats from an array
9 months ago
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());
9 months ago
// Reading an integer value
9 months ago
obj_render_object = ((Long) jsonObject.get("obj_render_object")).intValue();
obj_icon = ((Long) jsonObject.get("obj_icon")).intValue();
9 months ago
// Reading float values
9 months ago
combat_health_current = ((Double) jsonObject.get("combat_health_current")).floatValue();
combat_health_full = ((Double) jsonObject.get("combat_health_full")).floatValue();
9 months ago
// Reading a hashmap of floats
9 months ago
JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist");
9 months ago
for (Object key : resist_json.keySet()) {
float resist = ((Double) resist_json.get(key)).floatValue();
combat_attack_resist.put((String) key, resist);
}
9 months ago
// Parsing an enum
9 months ago
item_type = Enum.ItemType.valueOf((String) jsonObject.get("item_type"));
item_eq_slots_value = ((Long) jsonObject.get("item_eq_slots_value")).intValue();
item_eq_slots_type = (boolean) jsonObject.get("item_eq_slots_type");
9 months ago
// Parsing an enumset
9 months ago
JSONArray eq_slots_or = (JSONArray) jsonObject.get("item_eq_slots_or");
9 months ago
if (eq_slots_or.isEmpty() == false)
for (Object o : eq_slots_or)
item_eq_slots_or.add(Enum.ItemEquipSlotType.valueOf((String) o));
9 months ago
JSONArray eq_slots_and = (JSONArray) jsonObject.get("item_eq_slots_and");
9 months ago
if (eq_slots_and.isEmpty() == false)
for (Object o : eq_slots_and)
9 months ago
item_eq_slots_and.add(Enum.ItemEquipSlotType.valueOf((String) o));
9 months ago
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();
9 months ago
Object skills_used = jsonObject.get("item_skill_used");
9 months ago
if (skills_used instanceof String) {
String skilString = (String) skills_used;
skilString = skilString.replaceAll("\\s", "");
skilString = skilString.replaceAll(",", "");
item_skill_used.add(Enum.CharacterSkills.valueOf(skilString));
}
9 months ago
Object mastery_used = jsonObject.get("item_skill_mastery_used");
9 months ago
if (mastery_used instanceof String) {
String masteryString = (String) mastery_used;
masteryString = masteryString.replaceAll("\\s", "");
masteryString = masteryString.replaceAll(",", "");
item_skill_mastery_used.add(Enum.CharacterSkills.valueOf(masteryString));
}
9 months ago
item_parry_anim_id = ((Long) jsonObject.get("item_parry_anim_id")).intValue();
9 months ago
// Fields only present for ARMOR
9 months ago
if (item_type.equals(Enum.ItemType.ARMOR)) {
9 months ago
item_bulk_factor = ((Double) jsonObject.get("item_bulk_factor")).floatValue();
item_defense_rating = ((Long) jsonObject.get("item_defense_rating")).intValue();
}
9 months ago
if (item_type.equals(Enum.ItemType.WEAPON)) {
JSONObject item_weapon = (JSONObject) jsonObject.get("item_weapon");
item_weapon_wepspeed = ((Double) item_weapon.get("weapon_wepspeed")).floatValue();
item_weapon_max_range = ((Double) item_weapon.get("weapon_max_range")).floatValue();
item_weapon_projectile_id = ((Long) item_weapon.get("weapon_projectile_id")).intValue();
item_weapon_projectile_speed = ((Double) item_weapon.get("weapon_projectile_speed")).floatValue();
item_weapon_combat_idle_anim = ((Long) item_weapon.get("weapon_combat_idle_anim")).intValue();
JSONArray weapon_damage = (JSONArray) item_weapon.get("weapon_damage");
for (Object o : weapon_damage) {
JSONObject damage_entry = (JSONObject) o;
item_weapon_damage_type = Enum.SourceType.valueOf((String) damage_entry.get("damage_type"));
item_weapon_damage_min = ((Long) damage_entry.get("damage_min")).intValue();
item_weapon_damage_max = ((Long) damage_entry.get("damage_max")).intValue();
}
}
9 months ago
JSONArray itemflags = (JSONArray) jsonObject.get("item_flags");
9 months ago
9 months ago
if (itemflags.isEmpty() == false)
for (Object o : itemflags) {
String flag = (String) o;
if (flag.equals("None") == false)
item_flags.add(Enum.ItemFlags.valueOf((String) o));
}
9 months ago
9 months ago
JSONArray itemUseflags = (JSONArray) jsonObject.get("item_use_flags");
9 months ago
9 months ago
if (itemUseflags.isEmpty() == false)
for (Object o : itemUseflags)
item_use_flags.add(Enum.ItemUseFlags.valueOf((String) o));
9 months ago
9 months ago
item_initial_charges = ((Long) jsonObject.get("item_initial_charges")).intValue();
9 months ago
9 months ago
JSONArray skill_required = (JSONArray) jsonObject.get("item_skill_req");
9 months ago
for (Object o : skill_required) {
JSONObject skill_req = (JSONObject) o;
String skill_type = (String) skill_req.get("skill_type");
skill_type = skill_type.replaceAll("\\s", "");
skill_type = skill_type.replaceAll(",", "");
int skill_level = ((Long) skill_req.get("skill_level")).intValue();
item_skill_required.put(Enum.CharacterSkills.valueOf(skill_type), skill_level);
}
9 months ago
JSONObject race_required = (JSONObject) jsonObject.get("item_race_req");
boolean restrict = ((Boolean) race_required.get("restrict"));
JSONArray races = (JSONArray) race_required.get("races");
for (Object o : races) {
String race = (String) o;
race = race.replaceAll("\\s", "");
race = race.replaceAll(",", "");
race = race.replaceAll("-", "");
9 months ago
if (restrict)
9 months ago
item_race_res.add(Enum.MonsterType.valueOf(race));
9 months ago
else
9 months ago
item_race_req.add(Enum.MonsterType.valueOf(race));
9 months ago
}
9 months ago
JSONObject class_required = (JSONObject) jsonObject.get("item_class_req");
restrict = ((Boolean) class_required.get("restrict"));
JSONArray classes = (JSONArray) class_required.get("classes");
9 months ago
for (Object o : classes) {
9 months ago
String classEntry = (String) o;
classEntry = classEntry.replaceAll("\\s", "");
classEntry = classEntry.replaceAll(",", "");
if (restrict)
item_class_res.add(Enum.ClassType.valueOf(classEntry));
else
item_class_req.add(Enum.ClassType.valueOf(classEntry));
}
9 months ago
JSONObject disc_required = (JSONObject) jsonObject.get("item_disc_req");
restrict = ((Boolean) disc_required.get("restrict"));
9 months ago
JSONArray discs = (JSONArray) disc_required.get("discs");
9 months ago
for (Object o : discs) {
String disc = (String) o;
disc = disc.replaceAll("\\s", "");
disc = disc.replaceAll(",", "");
if (restrict)
9 months ago
item_disc_res.add(Enum.DisciplineType.valueOf(disc));
9 months ago
else
9 months ago
item_disc_req.add(Enum.DisciplineType.valueOf(disc));
9 months ago
}
9 months ago
} catch (Exception e) {
Logger.error(e);
}
}
9 months ago
}