Skip to content

Commit

Permalink
Another attempt to fix corrupt injury string
Browse files Browse the repository at this point in the history
  • Loading branch information
IceRaptor committed Sep 13, 2020
1 parent 1c1d6e2 commit d5038fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
44 changes: 23 additions & 21 deletions IRTweaks/IRTweaks/Modules/Combat/PainTolerance.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using BattleTech;
using BattleTech.UI.TMProWrapper;
using Harmony;
using IRBTModUtils;
using IRBTModUtils.Extension;
using Localize;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;

Expand Down Expand Up @@ -92,43 +91,45 @@ static class Pilot_InjurePilot

static bool Prepare() => Mod.Config.Fixes.PainTolerance;

static bool Prefix(Pilot __instance, ref int dmg, DamageType damageType, ref bool ___needsInjury, ref InjuryReason ___injuryReason )
static bool Prefix(Pilot __instance, DamageType damageType, ref bool ___needsInjury, ref InjuryReason ___injuryReason )
{
Mod.Log.Trace?.Write("P:SNI - entered");

if (__instance.ParentActor == null) return true;

Mod.Log.Info?.Write($"Checking pilot: {__instance.ParentActor.DistinctId()} to resist injury of type: {___injuryReason}");

// Compute the resist penalty for each damage type that we support
if (damageType == DamageType.HeadShot)
{
Mod.Log.Info?.Write($"Actor suffered a headshot, injury resist was set to: {ModState.InjuryResistPenalty}");
Mod.Log.Info?.Write($" Actor suffered a headshot, injury resist was set to: {ModState.InjuryResistPenalty}");
}
else if (damageType == DamageType.AmmoExplosion)
{
Mod.Log.Info?.Write($"Actor suffered an ammo explosion, injury resist was set to: {ModState.InjuryResistPenalty}");
Mod.Log.Info?.Write($" Actor suffered an ammo explosion, injury resist was set to: {ModState.InjuryResistPenalty}");
}
else if (damageType == DamageType.Knockdown)
else if (damageType == DamageType.Knockdown || damageType == DamageType.KnockdownSelf)
{
ModState.InjuryResistPenalty = Mod.Config.Combat.PainTolerance.KnockdownResistPenalty;
Mod.Log.Info?.Write($"Actor was knocked down, setting injury resist to: {ModState.InjuryResistPenalty}");
Mod.Log.Info?.Write($" Actor was knocked down, setting injury resist to: {ModState.InjuryResistPenalty}");
}
else if (damageType == DamageType.SideTorso)
{
ModState.InjuryResistPenalty = Mod.Config.Combat.PainTolerance.SideLocationDestroyedResistPenalty;
Mod.Log.Info?.Write($"Actor torso/side destroyed, setting injury resist to: {ModState.InjuryResistPenalty}");
Mod.Log.Info?.Write($" Actor torso/side destroyed, setting injury resist to: {ModState.InjuryResistPenalty}");
}
else if (damageType == DamageType.Overheat || damageType == DamageType.OverheatSelf ||
"OVERHEATED".Equals(__instance.InjuryReasonDescription, StringComparison.InvariantCultureIgnoreCase))
{
// comparison string must match label in https://github.com/BattletechModders/MechEngineer/blob/master/source/Features/ShutdownInjuryProtection/Patches/Pilot_InjuryReasonDescription_Patch.cs
Mod.Log.Debug?.Write($"Actor damage from overheating or ME heatDamage injury, computing overheat ratio.");
Mod.Log.Debug?.Write($" Actor damage from overheating or ME heatDamage injury, computing overheat ratio.");
float overheatRatio = PainHelper.CalculateOverheatRatio(__instance.ParentActor as Mech);
int overheatPenalty = (int)Math.Floor(overheatRatio * Mod.Config.Combat.PainTolerance.OverheatResistPenaltyPerHeatPercentile);
Mod.Log.Debug?.Write($"overheatPenalty:{overheatPenalty} = " +
Mod.Log.Debug?.Write($" overheatPenalty:{overheatPenalty} = " +
$"Floor( overheatRatio:{overheatRatio} * penaltyPerOverheatDamage{Mod.Config.Combat.PainTolerance.OverheatResistPenaltyPerHeatPercentile} )");

ModState.InjuryResistPenalty = overheatPenalty;
Mod.Log.Info?.Write($"Actor overheated, setting injury resist to: {ModState.InjuryResistPenalty}");
Mod.Log.Info?.Write($" Actor overheated, setting injury resist to: {ModState.InjuryResistPenalty}");
}

// Need default resistance?
Expand All @@ -138,20 +139,21 @@ static bool Prefix(Pilot __instance, ref int dmg, DamageType damageType, ref boo
bool success = PainHelper.MakeResistCheck(__instance);
if (success)
{
Mod.Log.Info?.Write($"Ignoring {__instance.InjuryReason} injury on pilot: {__instance.Name}");
___needsInjury = false;
___injuryReason = InjuryReason.NotSet;

// Reset our mod state
ModState.InjuryResistPenalty = -1;
Mod.Log.Info?.Write($"Ignoring {___injuryReason} injury on pilot.");

// Publish a floatie
string localText = new Text(Mod.LocalizedText.Floaties[ModText.FT_InjuryResist], new object[] {}).ToString();
string localText = new Text(Mod.LocalizedText.Floaties[ModText.FT_InjuryResist], new object[] { }).ToString();
IStackSequence stackSequence = new ShowActorInfoSequence(__instance.ParentActor, localText, FloatieMessage.MessageNature.PilotInjury, useCamera: false);
SharedState.Combat.MessageCenter.PublishMessage(new AddSequenceToStackMessage(stackSequence));

return false;
}
else
{
Mod.Log.Info?.Write($"Pilot will suffer injury type: {___injuryReason}.");
}

ModState.InjuryResistPenalty = -1;

}

Expand Down Expand Up @@ -197,12 +199,12 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
if (instruction.opcode == OpCodes.Ldstr && "{0}: INJURY IGNORED".Equals((string)instruction.operand, StringComparison.InvariantCultureIgnoreCase))
{
injuryStrIdx = i;
Mod.Log.Debug?.Write($"AA:CPSFA Found INJURY IGNORED instruction at idx: {i}");
Mod.Log.Info?.Write($"AA:CPSFA Found INJURY IGNORED instruction at idx: {i}");
}
else if (instruction.opcode == OpCodes.Callvirt && (MethodInfo)instruction.operand == clearNeedsInjuryMI)
{
clearInjuryIdx = i;
Mod.Log.Debug?.Write($"AA:CPSFA Found Pilot.ClearNeedsInjury instruction at idx: {i}");
Mod.Log.Info?.Write($"AA:CPSFA Found Pilot.ClearNeedsInjury instruction at idx: {i}");
}
}

Expand Down Expand Up @@ -233,7 +235,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
if (instruction.opcode == OpCodes.Ldstr && "KNOCKDOWN: INJURY IGNORED".Equals((string)instruction.operand, StringComparison.InvariantCultureIgnoreCase))
{
targetIdx = i;
Mod.Log.Debug?.Write($"M:CK Found INJURY IGNORED instruction at idx: {i}");
Mod.Log.Info?.Write($"M:CK Found INJURY IGNORED instruction at idx: {i}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions IRTweaks/IRTweaks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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.7.5.0")]
[assembly: AssemblyFileVersion("0.7.5.0")]
[assembly: AssemblyVersion("0.7.6.0")]
[assembly: AssemblyFileVersion("0.7.6.0")]

0 comments on commit d5038fc

Please sign in to comment.