forked from phasic22/FixSiegeAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FixBlueGear.cs
103 lines (98 loc) · 3.06 KB
/
FixBlueGear.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
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
namespace FixSiegeAI
{
[HarmonyPatch(typeof(OrderController), "ToggleSideOrderUse")]
public static class Patch_ToggleSideOrderUse
{
public static bool Prefix(IEnumerable<Formation> formations, UsableMachine usable)
{
// if every formation is not using, have every formation start
if (formations.All(i => i.IsUsingMachine(usable) == false))
{
foreach (Formation f in formations) { f.StartUsingMachine(usable, true); };
return false;
}
// if not every formation is using, have every formation start
if (formations.Any(i => i.IsUsingMachine(usable) == true) && formations.Any(i => i.IsUsingMachine(usable) == false))
{
foreach (Formation f in formations) { f.StartUsingMachine(usable, true); };
return false;
}
if (usable is SiegeTower || usable is BatteringRam)
{
// if every formation is following, have every formation stop
if (formations.All(i => i.MovementOrder.TargetEntity == usable.WaitEntity))
{
foreach (Formation f in formations)
{
f.StopUsingMachine(usable, true);
f.MovementOrder = MovementOrder.MovementOrderMove(f.OrderPosition);
};
return false;
}
// if every formation is using, have every formation follow
if (formations.All(i => i.IsUsingMachine(usable) == true))
{
foreach (Formation f in formations)
{
var mo = Traverse.Create<MovementOrder>().Method("MovementOrderFollowEntity", usable.WaitEntity).GetValue<MovementOrder>();
Main.Log("Formation following: " + (usable as SiegeWeapon).GetSiegeEngineType(), true);
f.MovementOrder = mo;
}
return false;
}
}
else
{
// if every formation is using, have every formation stop
if (formations.All(i => i.IsUsingMachine(usable) == true))
{
foreach (Formation f in formations)
{
f.StopUsingMachine(usable, true);
};
return false;
}
}
return false;
}
}
// Fix ram blue gear
[HarmonyPatch(typeof(BatteringRam), "GetOrder")]
public static class Patch_BatteringRam_GetOrder
{
public static bool Prefix(ref OrderType __result, BatteringRam __instance, BattleSideEnum side)
{
if (side == BattleSideEnum.Defender)
{
__result = OrderType.AttackEntity;
return false;
}
if (__instance.HasCompletedAction() | __instance.IsDestroyed | __instance.IsDeactivated | __instance.IsDisabled)
{ __result = OrderType.None; return false; }
__result = OrderType.Use;
return false;
}
}
// Fix siege tower blue gear
[HarmonyPatch(typeof(SiegeTower), "GetOrder")]
public static class Patch_SiegeTower_GetOrder
{
public static bool Prefix(ref OrderType __result, SiegeTower __instance, BattleSideEnum side)
{
if (side == BattleSideEnum.Defender)
{
__result = OrderType.AttackEntity;
return false;
}
if (__instance.IsDestroyed | __instance.IsDeactivated | __instance.IsDisabled)
{ __result = OrderType.None; return false; }
__result = OrderType.Use;
return false;
}
}
}