137 lines
4.2 KiB
C#
137 lines
4.2 KiB
C#
using BepInEx.Configuration;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Cult_of_the_Shock
|
|
{
|
|
public class ShockConfig
|
|
{
|
|
private static HashSet<string> ACTIONS = new HashSet<string> { "Shock", "Vibrate", "Sound" };
|
|
|
|
private readonly ConfigFile config;
|
|
|
|
private readonly ConfigEntry<string> url;
|
|
private readonly ConfigEntry<string> token;
|
|
private readonly ConfigEntry<string> shockerIds;
|
|
|
|
private readonly ConfigEntry<string> deathAction;
|
|
private readonly ConfigEntry<string> deathIntensity;
|
|
private readonly ConfigEntry<string> deathDuration;
|
|
|
|
private readonly ConfigEntry<string> damageAction;
|
|
private readonly ConfigEntry<string> damageIntensity;
|
|
private readonly ConfigEntry<string> 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;
|
|
}
|
|
}
|
|
|
|
}
|