-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMission.cs
83 lines (74 loc) · 3.18 KB
/
Mission.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
using System;
using System.Linq;
using System.Reflection;
using FormationSorter.Utilities;
using HarmonyLib;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.View.MissionViews;
using TaleWorlds.MountAndBlade.ViewModelCollection.Input;
using TaleWorlds.MountAndBlade.ViewModelCollection.Order;
namespace FormationSorter;
public static class Mission
{
public static MissionOrderVM MissionOrderVM;
public static OrderItemVM OrderItemVM;
public static OrderSetVM OrderSetVM;
public static InputKeyItemVM InputKeyItemVM;
public static TaleWorlds.MountAndBlade.Mission Current => TaleWorlds.MountAndBlade.Mission.Current;
public static Agent PlayerAgent => Current?.MainAgent;
private static MissionMainAgentController PlayerAgentController => Current?.GetMissionBehavior<MissionMainAgentController>();
internal static bool IsOrderShoutingAllowed()
{
MethodInfo shoutingAllowed = typeof(TaleWorlds.MountAndBlade.Mission).GetCachedMethod("IsOrderShoutingAllowed")
?? typeof(TaleWorlds.MountAndBlade.Mission).GetCachedMethod("IsOrderGesturesEnabled");
return Current is not null && shoutingAllowed?.Invoke(Current, new object[] { }) is true;
}
internal static bool IsCaptainAssignmentAllowed()
{
Type assignmentLogicType = AccessTools.TypeByName("GeneralsAndCaptainsAssignmentLogic") ?? AccessTools.TypeByName("AutoCaptainAssignmentLogic");
return assignmentLogicType is not null && Current?.MissionBehaviors?.Any(b =>
{
try
{
return Convert.ChangeType(b, assignmentLogicType) is not null;
}
catch
{
return false;
}
}) is true;
}
public static bool CanPlayerInteract()
{
Agent playerAgent = PlayerAgent;
if (playerAgent is null)
return false;
MissionMainAgentController playerAgentController = PlayerAgentController;
MissionMainAgentInteractionComponent interactionComponent = playerAgentController?.InteractionComponent;
if (interactionComponent is null)
return false;
IFocusable currentInteractableObject = (IFocusable)typeof(MissionMainAgentInteractionComponent).GetCachedField("_currentInteractableObject")
.GetValue(interactionComponent);
if (currentInteractableObject is null)
return false;
Agent agent = currentInteractableObject as Agent;
return agent?.IsMount != false;
}
public static bool IsCurrentValid(bool uiFeedback = false)
{
TaleWorlds.MountAndBlade.Mission current = Current;
if (current is null || current.Mode is MissionMode.Deployment || MissionOrderVM is null)
return false;
try
{
if (MissionOrderVM.OrderController is null || MissionOrderVM.TroopController is null)
return false;
}
catch // to catch errors that are entirely out of my control
{
return false;
}
return (bool)typeof(MissionOrderVM).GetCachedMethod("CheckCanBeOpened").Invoke(MissionOrderVM, new object[] { uiFeedback });
}
}