ValensHasThePower/PowerOn.cs

102 lines
3.8 KiB
C#
Raw Permalink Normal View History

2022-04-12 23:49:45 +01:00
using BepInEx;
using BepInEx.Configuration;
using EFT.Interactive;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace ValensHasThePower
{
[BepInPlugin("com.Valens.HasThePower", "ValensHasThePower", "1.3.0")]
2022-04-12 23:49:45 +01:00
public class Plugin : BaseUnityPlugin
{
public static ConfigEntry<int> configCustoms;
public static ConfigEntry<int> configInterchange;
public static ConfigEntry<int> configReserve;
private void Awake()
{
/* Example Config
configGreeting = Config.Bind("General", // The section under which the option is shown
"GreetingText", // The key of the configuration option in the configuration file
"Hello, world!", // The default value
"A greeting text to show when the game is launched"); // Description of the option to show in the config file*/
configCustoms = Config.Bind("General.Maps",
"Customs",
2022-04-12 23:49:45 +01:00
100,
"Percentage Chance that Power will be On at Raid Start for the Customs Map." +
"Default is 100.");
2022-04-12 23:49:45 +01:00
configInterchange = Config.Bind("General.Maps",
"Interchange",
2022-04-12 23:49:45 +01:00
100,
"Percentage Chance that Power will be On at Raid Start for the Interchange Map." +
"Default is 100.");
2022-04-12 23:49:45 +01:00
configReserve = Config.Bind("General.Maps",
"Reserve",
2022-04-12 23:49:45 +01:00
100,
"Percentage Chance that Power will be On at Raid Start for the Reserve Map." +
"Default is 100.");
2022-04-12 23:49:45 +01:00
Logger.LogInfo($"Valens...has the POWER!!!");
new PatchThePower().Enable();
}
}
public class PowerOn : MonoBehaviour
2022-04-12 23:49:45 +01:00
{
public void Start()
2022-04-12 23:49:45 +01:00
{
List<Switch> PowerSwitches = FindObjectsOfType<Switch>().ToList();
2022-04-12 23:49:45 +01:00
foreach (var switcher in PowerSwitches)
{
// Customs Power Switch
if (switcher.Id == "custom_DesignStuff_00034" && switcher.name == "reserve_electric_switcher_lever")
{
2022-04-13 00:25:51 +01:00
int percent = RandomGen();
2022-04-12 23:49:45 +01:00
if (percent <= Plugin.configCustoms.Value)
{
PowerSwitch(switcher);
}
}
// Interchange Power Station
2022-04-12 23:49:45 +01:00
if (switcher.Id == "Shopping_Mall_DesignStuff_00055" && switcher.name == "reserve_electric_switcher_lever")
{
2022-04-13 00:25:51 +01:00
int percent = RandomGen();
2022-04-12 23:49:45 +01:00
2022-04-13 00:25:51 +01:00
if (percent <= Plugin.configInterchange.Value)
2022-04-12 23:49:45 +01:00
{
PowerSwitch(switcher);
}
}
// Reserve D2 Switch
if (switcher.Id == "autoId_00000_D2_LEVER" && switcher.name == "reserve_electric_switcher_lever")
{
2022-04-13 00:25:51 +01:00
int percent = RandomGen();
if (percent <= Plugin.configReserve.Value)
2022-04-12 23:49:45 +01:00
{
PowerSwitch(switcher);
}
}
}
}
2022-04-13 00:25:51 +01:00
private static int RandomGen()
{
System.Random chance = new System.Random();
int percent = chance.Next(1, 99);
return percent;
}
2022-04-12 23:49:45 +01:00
private static void PowerSwitch(Switch switcher)
{
switcher.Open();
2022-04-12 23:49:45 +01:00
}
}
}