-
Notifications
You must be signed in to change notification settings - Fork 1
/
DamageModifierHelper.cs
188 lines (175 loc) · 5.03 KB
/
DamageModifierHelper.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using HarmonyLib;
using SandBox.Missions.MissionLogics.Arena;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaleWorlds.Engine;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
namespace DamageModifiers
{
internal enum AgentType
{
Player = 0,
Hero = 1,
Other = 2,
}
internal static class DamageModifierHelper
{
internal static void AdjustInflictedDamage(
Agent attackerAgent,
Agent victimAgent,
GameEntity hitObject,
ref AttackInformation attackInformation,
ref AttackCollisionData attackCollisionData)
{
try
{
// apply modifier
attackCollisionData.InflictedDamage = MathF.Round(attackCollisionData.InflictedDamage * GetDamageMultiplier(attackerAgent, victimAgent, hitObject != null, ref attackInformation, ref attackCollisionData));
}
catch (Exception exc)
{
// catch anything going wrong, just in case - we all know how much Bannerlord loves to crash otherwise!
FileLog.Log($"{nameof(DamageModifiers)}.{nameof(AdjustInflictedDamage)}: [{exc.GetType()}] {exc.Message}\n{exc.StackTrace}");
}
}
internal static bool IsArenaFight(this List<MissionBehavior> missionBehaviors)
{
if (missionBehaviors != null)
{
for (int i = 0; i < missionBehaviors.Count; i++)
{
// Arena fights and Tournaments
if (missionBehaviors[i] is ArenaAgentStateDeciderLogic)
return true;
}
}
return false;
}
internal static AgentType GetAgentType(this Agent agent)
{
agent = agent?.IsMount == true ? agent.RiderAgent : agent;
if (agent != null)
{
if (!agent.IsAIControlled)
return AgentType.Player;
if (agent.Character?.IsHero == true)
return AgentType.Hero;
}
return AgentType.Other;
}
internal static float GetDamageMultiplier(
Agent attackerAgent,
Agent victimAgent,
bool isObjectHit,
ref AttackInformation attackInformation,
ref AttackCollisionData attackCollisionData)
{
// fall damage multiplier
if (attackCollisionData.IsFallDamage)
return DamageModifiers.Settings.Fall;
// check if arena fight
var isArenaFight = Mission.Current.MissionBehaviors.IsArenaFight();
// get riders and agent types
var attackerType = attackerAgent.GetAgentType();
var victimType = victimAgent.GetAgentType();
var output = 1f;
// modifier depending on attacker and victim
switch (attackerType)
{
// attacker: player
case AgentType.Player:
switch (victimType)
{
// victim: player
case AgentType.Player:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaPlayerPlayer :
DamageModifiers.Settings.BattlePlayerPlayer;
break;
// victim: hero
case AgentType.Hero:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaPlayerHero :
DamageModifiers.Settings.BattlePlayerHero;
break;
// victim: other
case AgentType.Other:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaPlayerOther :
DamageModifiers.Settings.BattlePlayerOther;
break;
}
break;
// attacker: hero
case AgentType.Hero:
switch (victimType)
{
// victim: player
case AgentType.Player:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaHeroPlayer :
DamageModifiers.Settings.BattleHeroPlayer;
break;
// victim: hero
case AgentType.Hero:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaHeroHero :
DamageModifiers.Settings.BattleHeroHero;
break;
// victim: other
case AgentType.Other:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaHeroOther :
DamageModifiers.Settings.BattleHeroOther;
break;
}
break;
// attacker: other
case AgentType.Other:
switch (victimType)
{
// victim: player
case AgentType.Player:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaOtherPlayer :
DamageModifiers.Settings.BattleOtherPlayer;
break;
// victim: hero
case AgentType.Hero:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaOtherHero :
DamageModifiers.Settings.BattleOtherHero;
break;
// victim: other
case AgentType.Other:
output *= isArenaFight ?
DamageModifiers.Settings.ArenaOtherOther :
DamageModifiers.Settings.BattleOtherOther;
break;
}
break;
}
// object damage modifier
if (isObjectHit)
output *= DamageModifiers.Settings.Objects;
// horse charge damage modifier
if (attackCollisionData.IsHorseCharge)
output *= DamageModifiers.Settings.HorseCharge;
// ranged damage modifier
else if (attackCollisionData.IsMissile)
output *= DamageModifiers.Settings.Ranged;
// melee damage modifier
else
output *= DamageModifiers.Settings.Melee;
// shield damage modifier
if (attackCollisionData.AttackBlockedWithShield)
output *= DamageModifiers.Settings.Shields;
// output
return output;
}
}
}