Implement echoing tower selection to all towers
This commit is contained in:
@@ -16,6 +16,7 @@ using Gameplay.GameResources;
|
|||||||
using Gameplay.InGameResources;
|
using Gameplay.InGameResources;
|
||||||
using Gameplay.Production;
|
using Gameplay.Production;
|
||||||
using Gameplay.Rebuilding;
|
using Gameplay.Rebuilding;
|
||||||
|
using Gameplay.Rebuilding.Towers;
|
||||||
using Gameplay.Rebuilding.Walls;
|
using Gameplay.Rebuilding.Walls;
|
||||||
using Gameplay.Scavenge;
|
using Gameplay.Scavenge;
|
||||||
using Gameplay.Units.Characters;
|
using Gameplay.Units.Characters;
|
||||||
@@ -26,6 +27,7 @@ using Gameplay.Vehicles;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using HarmonyLib.Tools;
|
using HarmonyLib.Tools;
|
||||||
using MapEssentials.Temp;
|
using MapEssentials.Temp;
|
||||||
|
using UI.InfoPanels.NestedUIElements;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Zenject;
|
using Zenject;
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ namespace InfectionFreeZone {
|
|||||||
public static ConfigEntry<float> childToAdultRatioInfluenceFloorParam;
|
public static ConfigEntry<float> childToAdultRatioInfluenceFloorParam;
|
||||||
public static ConfigEntry<float> childToAdultRatioInfluenceCeilingParam;
|
public static ConfigEntry<float> childToAdultRatioInfluenceCeilingParam;
|
||||||
|
|
||||||
public static ConfigEntry<float> rotationTimestepMultiplier;
|
public static ConfigEntry<float> rotationTimestepMultiplier; // This is NOT unused!
|
||||||
public static ConfigEntry<float> sunsetHourOffset;
|
public static ConfigEntry<float> sunsetHourOffset;
|
||||||
public static ConfigEntry<float> sunriseHourOffset;
|
public static ConfigEntry<float> sunriseHourOffset;
|
||||||
|
|
||||||
@@ -103,6 +105,12 @@ namespace InfectionFreeZone {
|
|||||||
public static ConfigEntry<string> productionProfitMultiplier;
|
public static ConfigEntry<string> productionProfitMultiplier;
|
||||||
public static Dictionary<ResourceID, float> productionProfitMultiplierDict;
|
public static Dictionary<ResourceID, float> productionProfitMultiplierDict;
|
||||||
|
|
||||||
|
public static ConfigEntry<bool> towerEchoSelectionDebug;
|
||||||
|
public static ConfigEntry<bool> towerEchoSelection;
|
||||||
|
public static List<WeakReference<StructureDefenceModule>> towerEchoSelectionList;
|
||||||
|
|
||||||
|
// See System.Void UI.InfoPanels.NestedUIElements.SelectWeaponPanel::OnWeaponItemClicked(UI.InfoPanels.NestedUIElements.WeaponItem)
|
||||||
|
|
||||||
public void Awake() {
|
public void Awake() {
|
||||||
resourceMultiplierDebug = Config.Bind("General", "Resource Multiplier Debug", false);
|
resourceMultiplierDebug = Config.Bind("General", "Resource Multiplier Debug", false);
|
||||||
resourceMultiplier = Config.Bind("General", "Resource Multiplier", 1f);
|
resourceMultiplier = Config.Bind("General", "Resource Multiplier", 1f);
|
||||||
@@ -196,6 +204,10 @@ namespace InfectionFreeZone {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
towerEchoSelectionDebug = Config.Bind("General", "Tower Echo Selection Debug", false);
|
||||||
|
towerEchoSelection = Config.Bind("General", "Tower Echo Selection", false);
|
||||||
|
towerEchoSelectionList = new List<WeakReference<StructureDefenceModule>>();
|
||||||
|
|
||||||
Logger.LogInfo("Cyka mod loaded");
|
Logger.LogInfo("Cyka mod loaded");
|
||||||
HarmonyFileLog.Enabled = true;
|
HarmonyFileLog.Enabled = true;
|
||||||
Harmony harmony = new Harmony(pluginGuid);
|
Harmony harmony = new Harmony(pluginGuid);
|
||||||
@@ -543,7 +555,7 @@ namespace InfectionFreeZone {
|
|||||||
__result += Main.sunsetHourOffset.Value;
|
__result += Main.sunsetHourOffset.Value;
|
||||||
__result = Mathf.Clamp(__result, 0f, 24f);
|
__result = Mathf.Clamp(__result, 0f, 24f);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(TimeController), "GetSunriseHour")]
|
[HarmonyPatch(typeof(TimeController), "GetSunriseHour")]
|
||||||
public static void PostfixGetSunriseHour(ref float __result) {
|
public static void PostfixGetSunriseHour(ref float __result) {
|
||||||
@@ -574,5 +586,64 @@ namespace InfectionFreeZone {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(StructureDefenceModule), "Awake")]
|
||||||
|
public static void PostfixStructureDefenceModule(StructureDefenceModule __instance) {
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine($"Structure defence module created");
|
||||||
|
Main.towerEchoSelectionList.Add(new WeakReference<StructureDefenceModule>(__instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(SelectWeaponPanel), "OnWeaponItemClicked")]
|
||||||
|
public static void PostfixSelectWeaponPanel(WeaponItem selectedItem) {
|
||||||
|
if (!Main.towerEchoSelection.Value)
|
||||||
|
return;
|
||||||
|
if (selectedItem == null) {
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine("Selected weapon item is null !?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedItem.WeaponData == null) {
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine("Selected weapon data is null !?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Main.towerEchoSelectionDebug.Value) {
|
||||||
|
Console.WriteLine($"Selected weapon item is {selectedItem.name}");
|
||||||
|
Console.WriteLine($"Echoing weapon to {Main.towerEchoSelectionList.Count} towers");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < Main.towerEchoSelectionList.Count; i++) {
|
||||||
|
try {
|
||||||
|
var towerEchoSelection = Main.towerEchoSelectionList[i];
|
||||||
|
if (towerEchoSelection.TryGetTarget(out var towerEchoSelectionT)) {
|
||||||
|
if (towerEchoSelectionT == null) {
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine("Tower defence module is null !?");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine(
|
||||||
|
$"Tower defence weapon is {towerEchoSelectionT.SelectedWeapon.ToString()}");
|
||||||
|
|
||||||
|
towerEchoSelectionT.SetFieldOfView(selectedItem.WeaponData);
|
||||||
|
towerEchoSelectionT.SetupWeapon(selectedItem.WeaponData);
|
||||||
|
|
||||||
|
var selectedWeapon = towerEchoSelectionT.SelectedWeapon == null
|
||||||
|
? "null"
|
||||||
|
: towerEchoSelectionT.SelectedWeapon.ToString();
|
||||||
|
if (Main.towerEchoSelectionDebug.Value)
|
||||||
|
Console.WriteLine($"Tower defence weapon modified to {selectedWeapon}");
|
||||||
|
}
|
||||||
|
} catch (NullReferenceException e) {
|
||||||
|
Console.WriteLine($"Failed to set tower defence weapon: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -63,6 +63,9 @@
|
|||||||
<Reference Include="Zenject">
|
<Reference Include="Zenject">
|
||||||
<HintPath>$(GAME_MANAGED)/Zenject.dll</HintPath>
|
<HintPath>$(GAME_MANAGED)/Zenject.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Sirenix.Serialization">
|
||||||
|
<HintPath>$(GAME_MANAGED)/Sirenix.Serialization.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||||
</Project>
|
</Project>
|
||||||
|
Reference in New Issue
Block a user