using BepInEx.Configuration; using System.Collections.Generic; using System.Linq; namespace Cult_of_the_Shock { public class ShockConfig { private static HashSet ACTIONS = new HashSet { "Shock", "Vibrate", "Sound" }; private readonly ConfigFile config; private readonly ConfigEntry url; private readonly ConfigEntry token; private readonly ConfigEntry shockerIds; private readonly ConfigEntry deathAction; private readonly ConfigEntry deathIntensity; private readonly ConfigEntry deathDuration; private readonly ConfigEntry damageAction; private readonly ConfigEntry damageIntensity; private readonly ConfigEntry damageDuration; public ShockConfig(ConfigFile config) { this.config = config; url = config.Bind("Shocker", "url", "https://api.openshock.app", "The base url of your api (without trailing slash)"); token = config.Bind("Shocker", "token", "secrettoken", "Your API token"); shockerIds = config.Bind("Shocker", "shockerIds", "uuid1,uuid2", "Ids of your shockers (separated by commas, to spaces)"); deathAction = config.Bind("Death", "action", "Nothing", "What to do on death (Nothing, Shock, Vibrate, Sound)"); deathIntensity = config.Bind("Death", "intensity", "1", "Intensity on death (1 - 100)"); deathDuration = config.Bind("Death", "duration", "300", "Duration on death in milliseconds (min 300)"); damageAction = config.Bind("Damage", "action", "Nothing", "What to do on damage (Nothing, Shock, Vibrate, Sound)"); damageIntensity = config.Bind("Damage", "intensity", "1", "Intensity on death (1 - 100)"); damageDuration = config.Bind("Damage", "duration", "300", "Duration on damage in milliseconds (min 300)"); config.ConfigReloaded += (_, _) => OnReload(); } private void OnReload() { Plugin.Logger.LogInfo($"Config reloaded"); } public string GetDeathJson() { if (!ACTIONS.Contains(deathAction.Value)) { return null; } var controls = GetIds().Select(id => $@"{{ ""id"": ""{id}"", ""type"": ""{deathAction.Value}"", ""intensity"": {deathIntensity.Value}, ""duration"": {deathDuration.Value}, ""exclusive"": false }}" ); return "[" + string.Join(",\n", controls) + "]"; } public string GetDamageJson() { if (!ACTIONS.Contains(damageAction.Value)) { return null; } var controls = GetIds().Select(id => $@"{{ ""id"": ""{id}"", ""type"": ""{damageAction.Value}"", ""intensity"": {damageIntensity.Value}, ""duration"": {damageDuration.Value}, ""exclusive"": false }}" ); return "[" + string.Join(",\n", controls) + "]"; } public void Reload() { config.Reload(); } private string[] GetIds() { return shockerIds.Value.Split(','); } public string GetToken() { return token.Value; } public string GetURL() { return url.Value; } } }