From 6ea0fd6b185966fdff86235ebeadd90a13933f36 Mon Sep 17 00:00:00 2001 From: Gerrit Kitts Date: Sun, 2 Feb 2020 10:09:17 -0500 Subject: [PATCH] - Enables MultiTarget via equipment --- IRTweaks/IRTweaks/IRTweaks.csproj | 3 +- IRTweaks/IRTweaks/ModConfig.cs | 12 +++- .../IRTweaks/Modules/Combat/CombatModule.cs | 2 +- .../IRTweaks/Modules/Misc/PilotEffects.cs | 72 +++++++++++++++++++ .../Modules/UI/StreamlinedMainMenu.cs | 1 - IRTweaks/IRTweaks/Properties/AssemblyInfo.cs | 4 +- mod.json | 31 ++++---- .../data/weapon/Weapon_PPC_PPC_0-STOCK.json | 41 +++++++++++ 8 files changed, 147 insertions(+), 19 deletions(-) create mode 100644 IRTweaks/IRTweaks/Modules/Misc/PilotEffects.cs create mode 100644 testingDefs/StreamingAssets/data/weapon/Weapon_PPC_PPC_0-STOCK.json diff --git a/IRTweaks/IRTweaks/IRTweaks.csproj b/IRTweaks/IRTweaks/IRTweaks.csproj index 297d39c..6e91bd2 100644 --- a/IRTweaks/IRTweaks/IRTweaks.csproj +++ b/IRTweaks/IRTweaks/IRTweaks.csproj @@ -1,4 +1,4 @@ - + @@ -93,6 +93,7 @@ + diff --git a/IRTweaks/IRTweaks/ModConfig.cs b/IRTweaks/IRTweaks/ModConfig.cs index b3b7b9d..e13278e 100644 --- a/IRTweaks/IRTweaks/ModConfig.cs +++ b/IRTweaks/IRTweaks/ModConfig.cs @@ -6,17 +6,23 @@ public static class ModStats { public const string CalledShowAlwaysAllow = "IRTCalledShotAlwaysAllow"; public const string CalledShotMod = "IRTCalledShotMod"; + public const string EnableMultiTarget = "IRAllowMultiTarget"; + public const string RandomMechs = "StartingRandomMechLists"; public const string FactionRep = "FactionReputation"; public const string StrayShotValidTargets = "StrayShotValidTargets"; } + public class AbilityOpts { + public string MultiTargetId = "AbilityDefG5"; + } + public class StoreOpts { public int QuantityOnShift = 5; public int QuantityOnControl = 20; } - public class Combat { + public class CombatOpts { public int PilotAttributesMax = 13; public CalledShotOpts CalledShot = new CalledShotOpts(); @@ -46,6 +52,7 @@ public class FixesFlags { public bool DisableCombatSaves = true; public bool ExtendedStats = true; public bool FlexibleSensorLock = true; + public bool MultiTargetStat = true; public bool PreventHeadShots = true; public bool RandomStartByDifficulty = true; public bool SkirmishReset = true; @@ -65,7 +72,8 @@ public class ModConfig { public FixesFlags Fixes = new FixesFlags(); - public Combat Combat = new Combat(); + public AbilityOpts Abilities = new AbilityOpts(); + public CombatOpts Combat = new CombatOpts(); public StoreOpts Store = new StoreOpts(); public void LogConfig() { diff --git a/IRTweaks/IRTweaks/Modules/Combat/CombatModule.cs b/IRTweaks/IRTweaks/Modules/Combat/CombatModule.cs index 67fe95d..18ec24d 100644 --- a/IRTweaks/IRTweaks/Modules/Combat/CombatModule.cs +++ b/IRTweaks/IRTweaks/Modules/Combat/CombatModule.cs @@ -3,7 +3,7 @@ using Harmony; using System; using System.Reflection; -using static IRTweaks.Combat; +using static IRTweaks.CombatOpts; namespace IRTweaks.Modules.Combat { diff --git a/IRTweaks/IRTweaks/Modules/Misc/PilotEffects.cs b/IRTweaks/IRTweaks/Modules/Misc/PilotEffects.cs new file mode 100644 index 0000000..6958d80 --- /dev/null +++ b/IRTweaks/IRTweaks/Modules/Misc/PilotEffects.cs @@ -0,0 +1,72 @@ +using BattleTech; +using Harmony; +using System.Collections.Generic; +using us.frostraptor.modUtils; + +namespace IRTweaks.Modules.Misc { + + [HarmonyPatch(typeof(AbstractActor), "MaxTargets", MethodType.Getter)] + public static class AbstractActor_MaxTargets_Getter { + static bool Prepare() { return Mod.Config.Fixes.MultiTargetStat; } + + static void Postfix(AbstractActor __instance, ref int __result) { + Mod.Log.Trace($"AA:MT:G - entered."); + + if (__instance != null && __instance.StatCollection.ContainsStatistic(ModStats.EnableMultiTarget)) { + Mod.Log.Debug($"Multi-Target stat exists"); + if (__instance.StatCollection.GetStatistic(ModStats.EnableMultiTarget).Value()) { + Mod.Log.Debug($"Enabling multi-target for actor: {CombatantUtils.Label(__instance)}"); + __result = 3; + } else { + Mod.Log.Debug($"Actor: {CombatantUtils.Label(__instance)} has enableMultiTarget: false"); + } + } + } + } + + [HarmonyPatch(typeof(Pilot), "ActiveAbilities", MethodType.Getter)] + public static class Pilot_ActiveAbilities_Getter { + static bool Prepare() { return Mod.Config.Fixes.MultiTargetStat; } + + static void Postfix(Pilot __instance, ref List __result) { + Mod.Log.Trace($"AA:AA:G - entered."); + + if (__instance == null || __instance.ParentActor == null) { return; } + + if (__instance.ParentActor.StatCollection.GetStatistic(ModStats.EnableMultiTarget).Value()) { + Mod.Log.Debug($"Pilot: {__instance} needs multi-target ability"); + + bool hasMultiTarget = false; + foreach (Ability ability in __result) { + if (ability.Def.Targeting == AbilityDef.TargetingType.MultiFire) { + hasMultiTarget = true; + } + } + + if (!hasMultiTarget) { + Traverse combatT = Traverse.Create(__instance).Property("Combat"); + CombatGameState combat = combatT.GetValue(); + + if (combat == null) { return; } + + Mod.Log.Debug(" -- Adding multi-target ability to pilot."); + AbilityDef abilityDef = combat.DataManager.AbilityDefs.Get(Mod.Config.Abilities.MultiTargetId); + Ability ability = new Ability(abilityDef); + ability.Init(combat); + __result.Add(ability); + } + + } + } + } + + [HarmonyPatch(typeof(AbstractActor), "InitEffectStats")] + public static class AbstractActor_InitEffectStats { + static bool Prepare() { return Mod.Config.Fixes.MultiTargetStat; } + + static void Postfix(AbstractActor __instance) { + Mod.Log.Trace($"AA:MT:G - entered."); + __instance.StatCollection.AddStatistic(ModStats.EnableMultiTarget, false); + } + } +} diff --git a/IRTweaks/IRTweaks/Modules/UI/StreamlinedMainMenu.cs b/IRTweaks/IRTweaks/Modules/UI/StreamlinedMainMenu.cs index f3659f1..5319470 100644 --- a/IRTweaks/IRTweaks/Modules/UI/StreamlinedMainMenu.cs +++ b/IRTweaks/IRTweaks/Modules/UI/StreamlinedMainMenu.cs @@ -11,7 +11,6 @@ namespace IRTweaks.Modules.UI { public static class StreamlinedMainMenu { - [HarmonyPatch(typeof(SGContractsWidget), "Init")] [HarmonyPatch(new Type[] { typeof(SimGameState), typeof(Action) })] public static class SGContractsWidget_Init { diff --git a/IRTweaks/IRTweaks/Properties/AssemblyInfo.cs b/IRTweaks/IRTweaks/Properties/AssemblyInfo.cs index 3c02aee..72f376c 100644 --- a/IRTweaks/IRTweaks/Properties/AssemblyInfo.cs +++ b/IRTweaks/IRTweaks/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.3.0")] -[assembly: AssemblyFileVersion("0.5.3.0")] +[assembly: AssemblyVersion("0.5.4.0")] +[assembly: AssemblyFileVersion("0.5.4.0")] diff --git a/mod.json b/mod.json index b33c545..ec687bb 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,7 @@ { "Name": "IRTweaks", "Enabled": true, - "Version": "0.5.1", + "Version": "0.5.4", "Description": "Miscellaneous Tweaks and Fixes", "Author": "IceRaptor", "Website": "https://github.com/IceRaptor/IRTweaks", @@ -12,17 +12,24 @@ "Debug" : false, "Trace" : false, "Fixes" : { - "BulkPurchasing" : true, - "CombatLog" : false, - "DisableCombatSaves" : false, - "ExtendedStats" : false, - "FlexibleSensorLock" : false, - "PreventHeadShots" : false, - "RandomStartByDifficulty" : false, - "SkirmishReset" : false, - "SpawnProtection" : false, - "StreamlinedMainMenu" : true, - "WeaponTooltip" : true + "BulkPurchasing" : "true", + "CombatLog" : "true", + "DisableCampaign" : "true", + "DisableCombatSaves" : "true", + "ExtendedStats" : "true", + "FlexibleSensorLock" : "true", + "MultiTargetStat" : "true", + "PreventHeadShots" : "true", + "RandomStartByDifficulty" : "true", + "ReduceSaveCompression" : "true", + "SkipDeleteSavePopup" : "true", + "SkirmishReset" : "false", + "SpawnProtection" : "true", + "StreamlinedMainMenu" : "true", + "WeaponTooltip" : "true", + }, + "Abilities" : { + "MultiTargetId" : "AbilityDefG5" }, "Combat" : { "PilotAttributesMax" : 14, diff --git a/testingDefs/StreamingAssets/data/weapon/Weapon_PPC_PPC_0-STOCK.json b/testingDefs/StreamingAssets/data/weapon/Weapon_PPC_PPC_0-STOCK.json new file mode 100644 index 0000000..cd97e4b --- /dev/null +++ b/testingDefs/StreamingAssets/data/weapon/Weapon_PPC_PPC_0-STOCK.json @@ -0,0 +1,41 @@ +{ + "statusEffects" : [ + { + "durationData" : { + "duration" : -1, + "ticksOnActivations" : false, + "useActivationsOfTarget" : false, + "ticksOnEndOfRound" : false, + "ticksOnMovements" : false, + "stackLimit" : 1, + "clearedWhenAttacked" : false + }, + "targetingData" : { + "effectTriggerType" : "Passive", + "triggerLimit" : 0, + "extendDurationOnTrigger" : 0, + "specialRules" : "NotSet", + "effectTargetType" : "Creator", + "range" : 0, + "forcePathRebuild" : false, + "forceVisRebuild" : false, + "showInTargetPreview" : false, + "showInStatusPanel" : true + }, + "effectType" : "StatisticEffect", + "Description" : { + "Id" : "IRAllowMultiTargetEffect", + "Name" : "IRMULTITARGET", + "Details" : "Enables multi-target.", + "Icon" : "uixSvgIcon_equipment_ActuatorArm" + }, + "nature" : "Buff", + "statisticData" : { + "statName" : "IRAllowMultiTarget", + "operation" : "Set", + "modValue" : "true", + "modType" : "System.Boolean" + } + } + ], +}