-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJetpackHelper.cs
More file actions
94 lines (80 loc) · 2.99 KB
/
Copy pathJetpackHelper.cs
File metadata and controls
94 lines (80 loc) · 2.99 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
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
using GameNetcodeStuff;
using JetpackPocket.Patches;
namespace JetpackPocket
{
internal static class JetpackHelper
{
public struct JetpackState
{
public bool HasJetpack;
public int HasTwoHandedItem;
}
private static readonly System.Collections.Generic.Dictionary<ulong, JetpackState> PlayerDictionary = new System.Collections.Generic.Dictionary<ulong, JetpackState>();
public static bool HasJetpack(PlayerControllerB player)
{
if (player == null) return false;
return PlayerDictionary.TryGetValue(player.playerClientId, out JetpackState val) && val.HasJetpack;
}
public static bool HasTwoHandedAndJetpack(PlayerControllerB player)
{
return PlayerDictionary.TryGetValue(player.playerClientId, out JetpackState val) && val.HasJetpack && val.HasTwoHandedItem > 0;
}
public static bool HasTwoHanded(PlayerControllerB player)
{
return PlayerDictionary.TryGetValue(player.playerClientId, out JetpackState val) && val.HasTwoHandedItem > 0;
}
private static void SaveState(ulong player, JetpackState value)
{
PlayerDictionary[player] = value;
}
public static void Rescan(PlayerControllerB player)
{
if (player == null) return;
JetpackState newState = new JetpackState();
foreach (var slot in player.ItemSlots)
{
if (IsJetpack(slot))
{
newState.HasJetpack = true;
}
if (IsTwoHanded(slot))
{
newState.HasTwoHandedItem++;
}
}
//utility slot check
if (IsJetpack(player.ItemOnlySlot))
{
newState.HasJetpack = true;
}
SaveState(player.playerClientId, newState);
}
private static bool IsJetpack(GrabbableObject item)
{
if (item == null) return false;
return item.GetType().Name == "JetpackItem";
}
private static bool IsTwoHanded(GrabbableObject item)
{
if (item == null) return false;
return item.itemProperties.twoHanded;
}
public static void UpdateHUD(PlayerControllerB __instance)
{
if (__instance != null && __instance.IsOwner)
{
bool twoHanded = JetpackHelper.HasTwoHanded(__instance);
bool hasJetpack = JetpackHelper.HasJetpack(__instance);
HUDManager.Instance.holdingTwoHandedItem.enabled = (twoHanded && !hasJetpack) || (twoHanded && hasJetpack && !ConfigSync.SyncedCarryMultipleTwoHanded);
}
}
public static void UpdateHUD()
{
var player = GameNetworkManager.Instance.localPlayerController;
if (player != null)
{
UpdateHUD(player);
}
}
}
}