Add shop block multipliers
This commit is contained in:
@@ -40,6 +40,8 @@ namespace TerraTech {
|
||||
public static ConfigEntry<float> wirelessChargingPowerPerArcMultiplier;
|
||||
public static ConfigEntry<float> wirelessChargingArcFiringIntervalMultiplier;
|
||||
public static ConfigEntry<float> weaponRotationSpeedMultiplier;
|
||||
public static ConfigEntry<float> shopBlocksGeneratedTotalMultiplier;
|
||||
public static ConfigEntry<float> shopPerBlockStopMultiplier;
|
||||
|
||||
public void Awake() {
|
||||
debug = Config.Bind("General", "Debug", false);
|
||||
@@ -128,6 +130,13 @@ namespace TerraTech {
|
||||
new ConfigDescription("Miner Mining Speed", new AcceptableValueRange<float>(1f, 32f)));
|
||||
|
||||
allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false);
|
||||
shopBlocksGeneratedTotalMultiplier =
|
||||
Config.Bind("Shop", "Shop Blocks Generated Total Multiplier", 1f,
|
||||
new ConfigDescription("Shop Blocks Generated Total Multiplier",
|
||||
new AcceptableValueRange<float>(1f, 32f)));
|
||||
shopPerBlockStopMultiplier = Config.Bind(
|
||||
"Shop", "Shop Per Block Stop Multiplier", 1f,
|
||||
new ConfigDescription("Shop Per Block Stop Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
||||
|
||||
shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
|
||||
weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
|
||||
@@ -149,6 +158,9 @@ namespace TerraTech {
|
||||
WirelessChargerPropertiesManager.DoPatch();
|
||||
wirelessChargingRadiusMultiplier.SettingChanged += (sender, args) =>
|
||||
WirelessChargerPropertiesManager.DoPatch();
|
||||
shopBlocksGeneratedTotalMultiplier.SettingChanged += (sender, args) =>
|
||||
InventorySupplierPropertiesManager.DoPatch();
|
||||
shopPerBlockStopMultiplier.SettingChanged += (sender, args) => InventorySupplierPropertiesManager.DoPatch();
|
||||
|
||||
Logger.LogInfo("Cyka mod loaded");
|
||||
HarmonyFileLog.Enabled = true;
|
||||
|
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace TerraTech {
|
||||
[HarmonyPatch]
|
||||
public class InventorySupplierPropertiesManager {
|
||||
private static Dictionary<InventorySupplier, int> inventoryNumBlockTypes =
|
||||
new Dictionary<InventorySupplier, int>();
|
||||
private static Dictionary<InventorySupplier, int> inventoryQuantityPerBlockType =
|
||||
new Dictionary<InventorySupplier, int>();
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(InventorySupplier), "CreateRandomInventoryBlockList")]
|
||||
static void PrefixCreateRandomInventoryBlockList(InventorySupplier __instance) {
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("InventorySupplier.CreateRandomInventoryBlockList");
|
||||
try {
|
||||
if (!inventoryNumBlockTypes.ContainsKey(__instance)) {
|
||||
// if (Main.debug.Value)
|
||||
// Console.WriteLine("Patching; m_NumBlockTypes: {0}", __instance.m_NumBlockTypes);
|
||||
DoPatchSingle(__instance);
|
||||
// if (Main.debug.Value)
|
||||
// Console.WriteLine("Patched; m_NumBlockTypes: {0}", __instance.m_NumBlockTypes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine("Error patching InventorySupplier: {0}\nStack trace: {1}", e.Message, e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Modifying {0} InventorySupplier", inventoryNumBlockTypes.Count);
|
||||
foreach (KeyValuePair<InventorySupplier, int> keyValuePair in inventoryNumBlockTypes) {
|
||||
try {
|
||||
DoRestoreSingle(keyValuePair.Key);
|
||||
DoPatchSingle(keyValuePair.Key);
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine("Error patching InventorySupplier: {0}\nStack trace: {1}", e.Message,
|
||||
e.StackTrace);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DoPatchSingle(InventorySupplier inventorySupplier) {
|
||||
var trav = Traverse.Create(inventorySupplier);
|
||||
var rarityRange = trav.Field("m_RarityRangeParams").GetValue();
|
||||
var blockTypesField = trav.Field("m_RarityRangeParams").Field("m_NumBlockTypes");
|
||||
var quantityPerBlockField = trav.Field("m_RarityRangeParams").Field("m_QuantityPerBlockType");
|
||||
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Patching {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}",
|
||||
"InventorySupplier", rarityRange, blockTypesField.GetValue(),
|
||||
quantityPerBlockField.GetValue());
|
||||
|
||||
if (!inventoryNumBlockTypes.ContainsKey(inventorySupplier)) {
|
||||
inventoryNumBlockTypes.Add(inventorySupplier, (int)blockTypesField.GetValue());
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Added {0} to inventoryNumBlockTypes with value: {1}", inventorySupplier,
|
||||
(int)blockTypesField.GetValue());
|
||||
}
|
||||
if (!inventoryQuantityPerBlockType.ContainsKey(inventorySupplier)) {
|
||||
inventoryQuantityPerBlockType.Add(inventorySupplier, (int)quantityPerBlockField.GetValue());
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Added {0} to inventoryQuantityPerBlockType with value: {1}", inventorySupplier,
|
||||
(int)quantityPerBlockField.GetValue());
|
||||
}
|
||||
|
||||
if (inventoryNumBlockTypes.ContainsKey(inventorySupplier)) {
|
||||
int newBlockTypesValue =
|
||||
(int)(inventoryNumBlockTypes[inventorySupplier] * Main.shopBlocksGeneratedTotalMultiplier.Value);
|
||||
blockTypesField.SetValue(newBlockTypesValue);
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Set blockTypesField value to: {0}", newBlockTypesValue);
|
||||
}
|
||||
if (inventoryQuantityPerBlockType.ContainsKey(inventorySupplier)) {
|
||||
int newQuantityPerBlockValue =
|
||||
(int)(inventoryQuantityPerBlockType[inventorySupplier] * Main.shopPerBlockStopMultiplier.Value);
|
||||
quantityPerBlockField.SetValue(newQuantityPerBlockValue);
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Set quantityPerBlockField value to: {0}", newQuantityPerBlockValue);
|
||||
}
|
||||
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Patched {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}",
|
||||
"InventorySupplier", rarityRange, blockTypesField.GetValue(),
|
||||
quantityPerBlockField.GetValue());
|
||||
}
|
||||
|
||||
static void DoRestoreSingle(InventorySupplier inventorySupplier) {
|
||||
var trav = Traverse.Create(inventorySupplier);
|
||||
var rarityRange = trav.Field("m_RarityRangeParams").GetValue();
|
||||
var blockTypesField = trav.Field("m_RarityRangeParams").Field("m_NumBlockTypes");
|
||||
var quantityPerBlockField = trav.Field("m_RarityRangeParams").Field("m_QuantityPerBlockType");
|
||||
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Restoring {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}",
|
||||
"InventorySupplier", rarityRange, blockTypesField.GetValue(),
|
||||
quantityPerBlockField.GetValue());
|
||||
if (inventoryNumBlockTypes.ContainsKey(inventorySupplier)) {
|
||||
blockTypesField.SetValue(inventoryNumBlockTypes[inventorySupplier]);
|
||||
quantityPerBlockField.SetValue(inventoryQuantityPerBlockType[inventorySupplier]);
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine(
|
||||
"Restored {0}; rarityRange: {1}; blockTypesField: {2}; quantityPerBlockField: {3}",
|
||||
"InventorySupplier", rarityRange, blockTypesField.GetValue(), quantityPerBlockField.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -42,6 +42,7 @@
|
||||
<Compile Include="FuelPropertiesManager.cs" />
|
||||
<Compile Include="GeneratorPropertiesManager.cs" />
|
||||
<Compile Include="HomingAndVelocityProjectilePatch.cs" />
|
||||
<Compile Include="InventorySupplierPropertiesManager.cs" />
|
||||
<Compile Include="MagnetPropertiesManager.cs" />
|
||||
<Compile Include="MinerPropertiesManager.cs" />
|
||||
<Compile Include="Patches.cs" />
|
||||
|
Reference in New Issue
Block a user