forked from phasic22/FixSiegeAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FixDeployment.cs
76 lines (71 loc) · 2.34 KB
/
FixDeployment.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
using System;
using HarmonyLib;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.ViewModelCollection;
namespace FixSiegeAI
{
// Prevent AI splitting formations at onset of deployment
[HarmonyPatch(typeof(MissionOrderVM), "DeployFormationsOfPlayer")]
public static class Patch_DeployFormationsOfPlayer
{
private static bool Prefix()
{
Main.Log(Environment.NewLine + "Deployment started. ");
foreach (Formation formation in Mission.Current.PlayerTeam.Formations)
{
if (Main.IsPIC(formation))
{
formation.IsAIControlled = false;
Main.Log("AI control disabled.");
}
}
Mission.Current.AllowAiTicking = true;
Mission.Current.ForceTickOccasionally = true;
Mission.Current.PlayerTeam.ResetTactic();
bool isTeleportingAgents = Mission.Current.IsTeleportingAgents;
Mission.Current.IsTeleportingAgents = true;
Mission.Current.PlayerTeam.Tick(0f);
Mission.Current.IsTeleportingAgents = isTeleportingAgents;
Mission.Current.AllowAiTicking = false;
Mission.Current.ForceTickOccasionally = false;
Main.Log("AI reassigning formation locations blocked.");
return false;
}
}
// Remove auto take-over of team by AI after "Begin Assault" button is pressed
[HarmonyPatch(typeof(SiegeMissionController), "OnPlayerDeploymentFinish")]
public static class Patch_OnPlayerDeploymentFinish
{
public static void Postfix()
{
Main.Log(Environment.NewLine + "Begin assault button pressed. ");
if (!Mission.Current.IsFieldBattle)
{
foreach (Formation formation in Mission.Current.PlayerTeam.FormationsIncludingSpecial)
{
if (Main.IsPIC(formation))
{
formation.IsAIControlled = false;
Main.Log("AI control disabled again.");
}
}
Main.Log("Post deployment patch finished. ");
}
}
}
// Stops troops from getting stuck using ladders if within a certain range
[HarmonyPatch(typeof(SiegeLadder), "OnTick")]
public static class Patch_SiegeLadder_OnTick
{
public static void Postfix(SiegeLadder __instance)
{
try
{
//if (Mission.Current != null)
//if (Mission.Current.PlayerTeam.Side is TaleWorlds.Core.BattleSideEnum.Defender) { return; }
if (!__instance.IsUsed) { (__instance as SiegeWeapon).ForcedUse = false; }
else { (__instance as SiegeWeapon).ForcedUse = true; }
} catch { Main.Log("Siege ladder tick skipped"); return; }
}
}
}