-
Notifications
You must be signed in to change notification settings - Fork 0
/
InjuriesHurt.cs
67 lines (60 loc) · 2.12 KB
/
InjuriesHurt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using BattleTech;
using Harmony;
using Newtonsoft.Json;
using System;
using System.Reflection;
namespace com.Tyler799.Battletech.InjuriesHurtMod
{
public class InjuriesHurt
{
public static Settings ModSettings;
public static void Init(string _directory, string settingsJSON)
{
try
{
ModSettings = JsonConvert.DeserializeObject<Settings>(settingsJSON);
}
catch (Exception ex)
{
ModSettings = new Settings();
}
// make Harmony call your hooks
var harmony = HarmonyInstance.Create("com.Tyler799.Battletech.InjuriesHurtMod");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
public class Settings
{
public double gutsEffectPercentage = 0.5;
}
// Modifies tactics value
[HarmonyPatch(typeof(Pilot))]
[HarmonyPatch("Tactics", PropertyMethod.Getter)]
public class TacticsHealthModifier
{
public static void Postfix(Pilot __instance, ref int __result)
{
__result = (int)(__result * ((((InjuriesHurt.ModSettings.gutsEffectPercentage / 10) * __instance.Guts - 1) * __instance.Injuries) / (float)__instance.Health + 1));
}
}
// Modifies piloting value
[HarmonyPatch(typeof(Pilot))]
[HarmonyPatch("Piloting", PropertyMethod.Getter)]
public class PilotingHealthModifier
{
public static void Postfix(Pilot __instance, ref int __result)
{
__result = (int)(__result * ((((InjuriesHurt.ModSettings.gutsEffectPercentage / 10) * __instance.Guts - 1) * __instance.Injuries) / (float)__instance.Health + 1));
}
}
// Modifies gunnery value
[HarmonyPatch(typeof(Pilot))]
[HarmonyPatch("Gunnery", PropertyMethod.Getter)]
public class GunneryHealthModifier
{
public static void Postfix(Pilot __instance, ref int __result)
{
__result = (int)(__result * ((((InjuriesHurt.ModSettings.gutsEffectPercentage / 10) * __instance.Guts - 1) * __instance.Injuries) / (float)__instance.Health + 1));
}
}
}