-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using BattleTech; | ||
|
||
namespace CustomComponents | ||
{ | ||
public interface ICheckIsDead | ||
{ | ||
bool IsMechDestroyed(MechComponentRef item, Mech mech); | ||
bool IsVechicleDestroyed(VehicleComponentRef item, Vehicle mech); | ||
bool IsTurretDestroyed(TurretComponentRef item, Turret mech); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using BattleTech; | ||
using Harmony; | ||
|
||
namespace CustomComponents.Patches | ||
{ | ||
[HarmonyPatch(typeof(Mech), "IsDead")] | ||
[HarmonyPatch(MethodType.Getter)] | ||
public static class Mech_IsDead | ||
{ | ||
[HarmonyPostfix] | ||
public static void IsDestroyedChecks(Mech __instance, ref bool __result) | ||
{ | ||
if (__instance == null) return; | ||
|
||
try | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"Check if dead for mech {__instance.MechDef.Name}{__instance.MechDef.Chassis.Description.Id}"); | ||
|
||
|
||
if (__result) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Vanila destroyed"); | ||
return ; | ||
} | ||
|
||
foreach (var item in __instance.MechDef.Inventory) | ||
{ | ||
if (Control.Settings.CheckCriticalComponent && item.Def.CriticalComponent && | ||
item.DamageLevel == ComponentDamageLevel.Destroyed) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Destroyed by CriticalComponent {item.ComponentDefID}"); | ||
__result = true; | ||
return; | ||
} | ||
|
||
if (item.Is<ICheckIsDead>(out var d) && d.IsMechDestroyed(item, __instance)) | ||
{ | ||
__result = true; | ||
Control.LogDebug(DType.IsDestroyed, | ||
$"- Destroyed by CheckDestroyed {item.ComponentDefID} of {d.GetType()}"); | ||
return; | ||
} | ||
} | ||
|
||
Control.LogDebug(DType.IsDestroyed, $"- not destroyed"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Control.LogError(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using BattleTech; | ||
using Harmony; | ||
|
||
namespace CustomComponents.Patches | ||
{ | ||
[HarmonyPatch(typeof(Turret), "IsDead")] | ||
[HarmonyPatch(MethodType.Getter)] | ||
public static class Turret_IsDead | ||
{ | ||
[HarmonyPostfix] | ||
public static void IsDestroyedChecks(Turret __instance, ref bool __result) | ||
{ | ||
if (__instance == null) return; | ||
|
||
try | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"Check if dead for turret {__instance.TurretDef.Description.Id}"); | ||
|
||
|
||
if (__result) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Vanila destroyed"); | ||
return ; | ||
} | ||
|
||
foreach (var item in __instance.TurretDef.Inventory) | ||
{ | ||
if (Control.Settings.CheckCriticalComponent && item.Def.CriticalComponent && | ||
item.DamageLevel == ComponentDamageLevel.Destroyed) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Destroyed by CriticalComponent {item.ComponentDefID}"); | ||
__result = true; | ||
return; | ||
} | ||
|
||
if (item.Def.Is<ICheckIsDead>(out var d) && d.IsTurretDestroyed(item, __instance)) | ||
{ | ||
__result = true; | ||
Control.LogDebug(DType.IsDestroyed, | ||
$"- Destroyed by CheckDestroyed {item.ComponentDefID} of {d.GetType()}"); | ||
return; | ||
} | ||
} | ||
|
||
Control.LogDebug(DType.IsDestroyed, $"- not destroyed"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Control.LogError(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using BattleTech; | ||
using Harmony; | ||
|
||
namespace CustomComponents.Patches | ||
{ | ||
[HarmonyPatch(typeof(Vehicle), "IsDead")] | ||
[HarmonyPatch(MethodType.Getter)] | ||
public static class Vehicle_IsDead | ||
{ | ||
[HarmonyPostfix] | ||
public static void IsDestroyedChecks(Vehicle __instance, ref bool __result) | ||
{ | ||
if (__instance == null) return; | ||
|
||
try | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"Check if dead for vehicle {__instance.VehicleDef.Description.Id}"); | ||
|
||
|
||
if (__result) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Vanila destroyed"); | ||
return ; | ||
} | ||
|
||
foreach (var item in __instance.VehicleDef.Inventory) | ||
{ | ||
if (Control.Settings.CheckCriticalComponent && item.Def.CriticalComponent && | ||
item.DamageLevel == ComponentDamageLevel.Destroyed) | ||
{ | ||
Control.LogDebug(DType.IsDestroyed, $"- Destroyed by CriticalComponent {item.ComponentDefID}"); | ||
__result = true; | ||
return; | ||
} | ||
|
||
if (item.Def.Is<ICheckIsDead>(out var d) && d.IsVechicleDestroyed(item, __instance)) | ||
{ | ||
__result = true; | ||
Control.LogDebug(DType.IsDestroyed, | ||
$"- Destroyed by CheckDestroyed {item.ComponentDefID} of {d.GetType()}"); | ||
return; | ||
} | ||
} | ||
|
||
Control.LogDebug(DType.IsDestroyed, $"- not destroyed"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Control.LogError(e); | ||
} | ||
} | ||
} | ||
} |