package server; import org.json.JSONArray; import org.json.JSONObject; import java.io.FileReader; import java.util.ArrayList; import java.util.List; public class SpecialWeaponConfig { private static List weapons = new ArrayList<>(); static class WeaponConfig { int itemId; String name; List skinBonuses; boolean defaultCanFire; } static class SkinBonus { String skin; float damageMultiplier; boolean canFire; } public static void loadConfig() { try (FileReader reader = new FileReader("resources/special_weapons.json")) { StringBuilder json = new StringBuilder(); int c; while ((c = reader.read()) != -1) json.append((char) c); JSONArray array = new JSONArray(json.toString()); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); WeaponConfig weapon = new WeaponConfig(); weapon.itemId = obj.getInt("itemId"); weapon.name = obj.getString("name"); weapon.defaultCanFire = obj.getBoolean("defaultCanFire"); weapon.skinBonuses = new ArrayList<>(); JSONArray bonuses = obj.getJSONArray("skinBonuses"); for (int j = 0; j < bonuses.length(); j++) { JSONObject bonus = bonuses.getJSONObject(j); SkinBonus skinBonus = new SkinBonus(); skinBonus.skin = bonus.getString("skin"); skinBonus.damageMultiplier = (float) bonus.getDouble("damageMultiplier"); skinBonus.canFire = bonus.getBoolean("canFire"); weapon.skinBonuses.add(skinBonus); } weapons.add(weapon); } } catch (Exception e) { System.err.println("Error loading special_weapons.json: " + e); } } public static float getDamageMultiplier(int itemId, String skin) { for (WeaponConfig weapon : weapons) { if (weapon.itemId == itemId) { for (SkinBonus bonus : weapon.skinBonuses) { if (bonus.skin.equals(skin)) { return bonus.damageMultiplier; } } break; } } return 1.0f; // No bonus } public static boolean canFire(int itemId, String skin) { for (WeaponConfig weapon : weapons) { if (weapon.itemId == itemId) { for (SkinBonus bonus : weapon.skinBonuses) { if (bonus.skin.equals(skin)) { return bonus.canFire; } } return weapon.defaultCanFire; } } return true; // Default for non-special weapons } }