/
Main.cs
110 lines (104 loc) · 4.35 KB
/
Main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using TaleWorlds.Library;
using HarmonyLib;
using System.Xml;
using System.Collections.Generic;
namespace AnotherArmorDamage
{
public static class Vars
{
public static Dictionary<string, float> dict = new Dictionary<string, float> { };
}
public static class MyPatcher
{
public static void DoPatching()
{
var harmony = new Harmony("com.jj.dmg");
harmony.PatchAll();
}
}
[HarmonyPatch(typeof(Mission))]
[HarmonyPatch("ConvertBaseAttackMagnitude")]
class RemoveDamageFactor
{
static bool Prefix(WeaponComponentData weapon, StrikeType strikeType, float baseMagnitude, ref float __result)
{
__result = baseMagnitude;
return false;
}
}
[HarmonyPatch(typeof(Mission))]
[HarmonyPatch("ComputeBlowMagnitudeMissile")]
class MissileMultiplier
{
static bool Prefix(ref AttackCollisionData acd,
ItemObject weaponItem,
bool isVictimAgentNull,
float momentumRemaining,
float missileTotalDamage,
out float baseMagnitude,
out float specialMagnitude,
Vec3 victimVel)
{
double num1 = (isVictimAgentNull ? (double)acd.MissileVelocity.Length : (double)(victimVel - acd.MissileVelocity).Length) / (double)acd.MissileStartingBaseSpeed;
float num2 = (float)(num1 * num1);
baseMagnitude = num2 * missileTotalDamage * momentumRemaining * Vars.dict["MissileFactor"];
specialMagnitude = baseMagnitude;
return false;
}
}
[HarmonyPatch(typeof(CombatStatCalculator))]
[HarmonyPatch("ComputeRawDamageNew")]
class ArmorDamage
{
static bool Prefix(DamageTypes damageType, float magnitude, float armorEffectiveness, ref float __result)
{
// magnitude is around 20 for one handed sword swing and 40 for two handed axe swing
float bluntReduction = 100f / (100f + armorEffectiveness);
float bluntDmg = magnitude * bluntReduction;
float bleedDmg = 0f;
switch (damageType)
{
case DamageTypes.Cut:
if (armorEffectiveness < Vars.dict["CutLimit"])
{
bleedDmg = Math.Max(0f, magnitude - Vars.dict["CutArmor"] * armorEffectiveness);
bleedDmg *= Vars.dict["CutDmg"];
}
bluntDmg *= Vars.dict["CutBluntDmg"];
break;
case DamageTypes.Pierce:
bleedDmg = Math.Max(0f, magnitude - Vars.dict["PierceArmor"] * armorEffectiveness);
bleedDmg *= Vars.dict["PierceDmg"];
bluntDmg *= Vars.dict["PierceBluntDmg"];
break;
case DamageTypes.Blunt:
bluntDmg *= Vars.dict["BluntBluntDmg"];
break;
}
if (Vars.dict["ShowCalc"] > 0 && magnitude > 5 && armorEffectiveness > 0)
{
InformationManager.DisplayMessage(new InformationMessage("magnitude " + magnitude + " bluntDmg " + bluntDmg + " bleedDmg " + bleedDmg + " armorEffectiveness " + armorEffectiveness));
//System.Diagnostics.Debug.WriteLine("type " + damageType + " magnitude " + magnitude + " bluntDmg " + bluntDmg + " bleedDmg " + bleedDmg + " armorEffectiveness " + armorEffectiveness);
}
__result = bluntDmg + bleedDmg;
return false;
}
}
class Main : MBSubModuleBase
{
protected override void OnSubModuleLoad()
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(BasePath.Name + "Modules/AnotherArmorDamage/config.xml");
foreach (XmlNode childNode in xmlDocument.SelectSingleNode("/config").ChildNodes)
{
if (childNode.NodeType == XmlNodeType.Element)
Vars.dict.Add(childNode.Name, float.Parse(childNode.InnerText));
}
MyPatcher.DoPatching();
}
}
}