-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFixAssaultWalls.cs
More file actions
56 lines (53 loc) · 1.84 KB
/
FixAssaultWalls.cs
File metadata and controls
56 lines (53 loc) · 1.84 KB
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
using HarmonyLib;
using TaleWorlds.MountAndBlade;
namespace FixSiegeAI
{
// Get units to attack inner gate when outer gate's down
[HarmonyPatch(typeof(CastleGate), "OnDestroyed")]
public static class Patch_OnDestroyed
{
public static void Postfix(CastleGate __instance)
{
TeamAISiegeComponent aic = Mission.Current.AttackerTeam.TeamAI as TeamAISiegeComponent;
if (__instance.GameEntity.HasTag("inner_gate"))
{
Main.Log("Inner gate destroyed!", true);
foreach (Formation f in Mission.Current.PlayerTeam.FormationsIncludingSpecial)
{
if (Main.IsPIC(f) && !f.IsAIControlled)
{
Traverse.Create(f).Method("DisbandAttackEntityDetachment").GetValue();
}
}
}
if (__instance.GameEntity.HasTag("outer_gate"))
{
Main.Log("Outer gate destroyed!", true);
foreach (MissionObject mo in Mission.Current.ActiveMissionObjects)
{
foreach (Formation f in Mission.Current.PlayerTeam.Formations)
{
if (f.IsUsingMachine(mo as BatteringRam) && !aic.InnerGate.IsDestroyed && Main.IsPIC(f) && !f.IsAIControlled)
{
if (Mission.Current.PlayerTeam.IsAttacker) { Main.Log("Sending detachment to attack inner gate!", true); }
Traverse.Create(f).Method("FormAttackEntityDetachment", aic.InnerGate.GameEntity).GetValue();
}
}
}
}
if (Mission.Current.PlayerTeam.IsAttacker && aic.InnerGate.IsDestroyed && aic.OuterGate.IsDestroyed)
{ Main.Log("Charge when ready!", true); }
}
}
// Still trying to debug charging
[HarmonyPatch(typeof(OrderController), "GetChargeOrderSubstituteForSiege")]
public static class Patch_GetChargeOrderSubstituteForSiege
{
public static bool Prefix(OrderController __instance, ref MovementOrder __result, Formation formation)
{
Main.Log("Charge command given.");
__result = MovementOrder.MovementOrderCharge;
return true;
}
}
}