Implement magnet radius/strength
This commit is contained in:
@@ -7,11 +7,10 @@ using HarmonyLib;
|
||||
using HarmonyLib.Tools;
|
||||
using UnityEngine;
|
||||
|
||||
// TODO: Make magnet better
|
||||
// TODO: Make more energy generate
|
||||
// TODO: Make attractor more range
|
||||
// TODO: Make battery bigger
|
||||
// TODO: Make shield and repair bigger
|
||||
// TODO: Make turbo more turbo
|
||||
|
||||
namespace TerraTech {
|
||||
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
|
||||
@@ -23,20 +22,35 @@ namespace TerraTech {
|
||||
public static ConfigEntry<int> xpMultiplier;
|
||||
public static ConfigEntry<int> moneyMultiplier;
|
||||
public static ConfigEntry<float> energyGenMultiplier;
|
||||
public static ConfigEntry<float> magnetStrenghtMultiplier;
|
||||
public static ConfigEntry<float> magnetRadiusMultiplier;
|
||||
public static ConfigEntry<bool> allProjectilesHoming;
|
||||
public static ConfigEntry<float> shootingSpeedMultiplier;
|
||||
public static ConfigEntry<float> muzzleVelocityMultiplier;
|
||||
public static ConfigEntry<float> heartbeatIntervalMultiplier;
|
||||
|
||||
public void Awake() {
|
||||
xpMultiplier = Config.Bind("General", "XP Multiplier", 1);
|
||||
moneyMultiplier = Config.Bind("General", "Money Multiplier", 1);
|
||||
energyGenMultiplier = Config.Bind("General", "Energy Generation Multiplier", 1f);
|
||||
shootingSpeedMultiplier = Config.Bind("General", "Shooting Speed Multiplier", 1f);
|
||||
muzzleVelocityMultiplier = Config.Bind("General", "Muzzle Velocity Multiplier", 1f);
|
||||
xpMultiplier = Config.Bind("General", "XP Multiplier", 1, new ConfigDescription("XP Multiplier", new AcceptableValueRange<int>(1, 32)));
|
||||
moneyMultiplier = Config.Bind("General", "Money Multiplier", 1, new ConfigDescription("Money Multiplier", new AcceptableValueRange<int>(1, 32)));
|
||||
energyGenMultiplier = Config.Bind("General", "Energy Generation Multiplier", 1f,
|
||||
new ConfigDescription("Energy Generation Multiplier", new AcceptableValueRange<float>(1f, 64f)));
|
||||
shootingSpeedMultiplier = Config.Bind("General", "Shooting Speed Multiplier", 1f,
|
||||
new ConfigDescription("Shooting Speed Multiplier", new AcceptableValueRange<float>(0.5f, 8f)));
|
||||
magnetStrenghtMultiplier = Config.Bind("General", "Magnet Strength Multiplier", 1f,
|
||||
new ConfigDescription("Magnet Strength Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
||||
magnetRadiusMultiplier = Config.Bind("General", "Magnet Radius Multiplier", 1f,
|
||||
new ConfigDescription("Magnet Radius Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
||||
muzzleVelocityMultiplier = Config.Bind("General", "Muzzle Velocity Multiplier", 1f,
|
||||
new ConfigDescription("Muzzle Velocity Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
||||
heartbeatIntervalMultiplier = Config.Bind("General", "Heartbeat Interval Multiplier", 1f,
|
||||
new ConfigDescription("Heartbeat Interval Multiplier", new AcceptableValueRange<float>(0.1f, 2f)));
|
||||
|
||||
allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false);
|
||||
|
||||
shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
|
||||
energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch();
|
||||
magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
|
||||
magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
|
||||
|
||||
Logger.LogInfo("Cyka mod loaded");
|
||||
HarmonyFileLog.Enabled = true;
|
||||
@@ -58,6 +72,11 @@ namespace TerraTech {
|
||||
static void MoneyMulti(ref int amount) {
|
||||
amount *= Main.moneyMultiplier.Value;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(TechHolders), "SetHeartbeatInterval")]
|
||||
static void MoneyMulti(ref float interval) {
|
||||
interval *= Main.heartbeatIntervalMultiplier.Value;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Projectile), "Fire")]
|
||||
@@ -96,7 +115,7 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
Console.WriteLine("Modifying " + weapons.Count + " weapons");
|
||||
// Console.WriteLine("Modifying " + weapons.Count + " weapons");
|
||||
foreach (KeyValuePair<ModuleWeaponGun, float> keyValuePair in weapons) {
|
||||
DoRestoreSingle(keyValuePair.Key);
|
||||
DoPatchSingle(keyValuePair.Key);
|
||||
@@ -104,10 +123,10 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
static void DoPatchSingle(ModuleWeaponGun weapon) {
|
||||
Console.WriteLine("Patching " + weapon.name);
|
||||
Console.WriteLine("Old value " + weapon.m_ShotCooldown);
|
||||
// Console.WriteLine("Patching " + weapon.name);
|
||||
// Console.WriteLine("Old value " + weapon.m_ShotCooldown);
|
||||
weapon.m_ShotCooldown /= Main.shootingSpeedMultiplier.Value;
|
||||
Console.WriteLine("New value " + weapon.m_ShotCooldown);
|
||||
// Console.WriteLine("New value " + weapon.m_ShotCooldown);
|
||||
}
|
||||
|
||||
static void DoRestoreSingle(ModuleWeaponGun weapon) {
|
||||
@@ -126,9 +145,7 @@ namespace TerraTech {
|
||||
static void PostfixCreate(ModuleEnergy __instance) {
|
||||
if (!generators.ContainsKey(__instance)) {
|
||||
generators.Add(__instance, GetValue(__instance));
|
||||
if (ShouldPatch()) {
|
||||
DoPatchSingle(__instance);
|
||||
}
|
||||
DoPatchSingle(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,8 +157,8 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
Console.WriteLine("Modifying " + generators.Count + " generators");
|
||||
Console.WriteLine("Should patch: " + ShouldPatch());
|
||||
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
||||
// Console.WriteLine("Should patch: " + ShouldPatch());
|
||||
foreach (KeyValuePair<ModuleEnergy, float> keyValuePair in generators) {
|
||||
DoRestoreSingle(keyValuePair.Key);
|
||||
DoPatchSingle(keyValuePair.Key);
|
||||
@@ -149,10 +166,10 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
static void DoPatchSingle(ModuleEnergy moduleEnergy) {
|
||||
Console.WriteLine("Patching " + moduleEnergy.name);
|
||||
Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
||||
// Console.WriteLine("Patching " + moduleEnergy.name);
|
||||
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
||||
SetValue(moduleEnergy, GetValue(moduleEnergy) * Main.energyGenMultiplier.Value);
|
||||
Console.WriteLine("New value " + GetValue(moduleEnergy));
|
||||
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
||||
}
|
||||
|
||||
static void DoRestoreSingle(ModuleEnergy moduleEnergy) {
|
||||
@@ -161,10 +178,6 @@ namespace TerraTech {
|
||||
}
|
||||
}
|
||||
|
||||
static bool ShouldPatch() {
|
||||
return Math.Abs(Main.energyGenMultiplier.Value - 1f) > 0.0001f;
|
||||
}
|
||||
|
||||
private static float GetValue(ModuleEnergy moduleEnergy) {
|
||||
return Traverse.Create(moduleEnergy).Field("m_OutputPerSecond").GetValue() as float? ?? 0f;
|
||||
}
|
||||
@@ -173,4 +186,78 @@ namespace TerraTech {
|
||||
Traverse.Create(moduleEnergy).Field("m_OutputPerSecond").SetValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class MagnetPropertiesManager {
|
||||
private static Dictionary<ModuleItemHolderMagnet, float> strenghts = new Dictionary<ModuleItemHolderMagnet, float>();
|
||||
private static Dictionary<ModuleItemHolderMagnet, float> radii = new Dictionary<ModuleItemHolderMagnet, float>();
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnAttached")]
|
||||
static void PostfixCreate(ModuleItemHolderMagnet __instance) {
|
||||
if (!strenghts.ContainsKey(__instance)) {
|
||||
strenghts.Add(__instance, GetStrength(__instance));
|
||||
radii.Add(__instance, GetRadius(__instance));
|
||||
DoPatchSingle(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnDetaching")]
|
||||
static void PostfixDestroy(ModuleItemHolderMagnet __instance) {
|
||||
DoRestoreSingle(__instance);
|
||||
strenghts.Remove(__instance);
|
||||
radii.Remove(__instance);
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
||||
// Console.WriteLine("Should patch: " + ShouldPatch());
|
||||
foreach (KeyValuePair<ModuleItemHolderMagnet, float> keyValuePair in strenghts) {
|
||||
DoRestoreSingle(keyValuePair.Key);
|
||||
DoPatchSingle(keyValuePair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
static void DoPatchSingle(ModuleItemHolderMagnet moduleEnergy) {
|
||||
// Console.WriteLine("Patching " + moduleEnergy.name);
|
||||
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
||||
SetStrength(moduleEnergy, GetStrength(moduleEnergy) * Main.magnetStrenghtMultiplier.Value);
|
||||
SetRadius(moduleEnergy, GetRadius(moduleEnergy) * Main.magnetRadiusMultiplier.Value);
|
||||
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
||||
}
|
||||
|
||||
static void DoRestoreSingle(ModuleItemHolderMagnet moduleEnergy) {
|
||||
if (strenghts.ContainsKey(moduleEnergy)) {
|
||||
SetStrength(moduleEnergy, strenghts[moduleEnergy]);
|
||||
}
|
||||
if (radii.ContainsKey(moduleEnergy)) {
|
||||
SetRadius(moduleEnergy, radii[moduleEnergy]);
|
||||
}
|
||||
}
|
||||
|
||||
private static float GetStrength(ModuleItemHolderMagnet moduleEnergy) {
|
||||
return Traverse.Create(moduleEnergy).Field("m_Strength").GetValue() as float? ?? 0f;
|
||||
}
|
||||
|
||||
private static void SetStrength(ModuleItemHolderMagnet moduleEnergy, float value) {
|
||||
Traverse.Create(moduleEnergy).Field("m_Strength").SetValue(value);
|
||||
}
|
||||
|
||||
private static float GetRadius(ModuleItemHolderMagnet moduleEnergy) {
|
||||
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleEnergy).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
||||
if (moduleItemPickup) {
|
||||
float radius = Traverse.Create(moduleItemPickup).Field("m_PickupRange").GetValue() as float? ?? 0f;
|
||||
return radius;
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
|
||||
private static void SetRadius(ModuleItemHolderMagnet moduleEnergy, float value) {
|
||||
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleEnergy).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
||||
if (moduleItemPickup) {
|
||||
Traverse.Create(moduleItemPickup).Field("m_PickupRange").SetValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user