import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.FileReader;
import java.io.IOException;

public class JsonDamageHandler {
    private JSONObject config;

    public JsonDamageHandler() {
        JSONParser parser = new JSONParser();
        try {
            config = (JSONObject) parser.parse(new FileReader("game_config.json"));
        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
    public void applyDamage(Player player) {
        JSONObject damageSettings = (JSONObject) config.get("DamageSettings");
        double armorLoss = (double) damageSettings.get("ArmorDurabilityLoss");
        double helmetLoss = (double) damageSettings.get("HelmetDurabilityLoss");
        double bodyDamageMultiplier = (double) damageSettings.get("BodyDamageMultiplier");
        player.setArmorDurability(player.getArmorDurability() - armorLoss);
        player.setHelmetDurability(player.getHelmetDurability() - helmetLoss);
        double bodyDamage = 100 * bodyDamageMultiplier;
        player.setBodyHealth(player.getBodyHealth() - bodyDamage);
    }
    public static void main(String[] args) {
        Player player = new Player(100, 100, 100);
        JsonDamageHandler handler = new JsonDamageHandler();
        handler.applyDamage(player);
        System.out.println("Armor Durability: " + player.getArmorDurability());
        System.out.println("Helmet Durability: " + player.getHelmetDurability());
        System.out.println("Body Health: " + player.getBodyHealth());
    }
}
