using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;

namespace Ereshor {
    [BepInPlugin(PluginGuid, PluginName, PluginVersion)]
    public class Main : BaseUnityPlugin {
        private const string PluginGuid = "CykaMod";
        private const string PluginName = "CykaMod";
        private const string PluginVersion = "1.0.0";

        public static ConfigEntry<bool> debug;

        public static ConfigEntry<float> xpMultiplier;

        public void Awake() {
            debug = Config.Bind("General", "Debug", false);

            xpMultiplier =
                Config.Bind("General", "XP Multiplier", 1f,
                            new ConfigDescription("XP Multiplier", new AcceptableValueRange<float>(0.01f, 1024f)));

            Logger.LogInfo("Cyka mod loaded");
            HarmonyFileLog.Enabled = true;
            Harmony harmony = new Harmony(PluginGuid);
            harmony.PatchAll();
            var originalMethods = harmony.GetPatchedMethods();
            Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
        }
    }

    [HarmonyPatch(typeof(GameData), "AddExperience")]
    public class GameData_AddExperience {
        public static void Prefix(ref int xp) {
            xp = (int) ((float)xp * Main.xpMultiplier.Value);
        }
    }
}
