-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathPrecursorActivatedPillar_OnTriggerExit_Patch.cs
More file actions
70 lines (60 loc) · 2.36 KB
/
PrecursorActivatedPillar_OnTriggerExit_Patch.cs
File metadata and controls
70 lines (60 loc) · 2.36 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
using System.Collections.Generic;
using System.Reflection;
using FMOD.Studio;
using NitroxClient.GameLogic.PlayerLogic;
using UnityEngine;
namespace NitroxPatcher.Patches.Dynamic;
/// <summary>
/// Prevents ion cube pedestals from retracting when a player leaves if other players are still nearby.
/// </summary>
public sealed partial class PrecursorActivatedPillar_OnTriggerExit_Patch : NitroxPatch, IDynamicPatch
{
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorActivatedPillar t) => t.OnTriggerExit(default));
/// <summary>
/// Tracks the number of players currently in each pillar's trigger zone.
/// </summary>
private static readonly Dictionary<int, int> playerCountByPillar = [];
public static void IncrementPlayerCount(PrecursorActivatedPillar pillar)
{
int id = pillar.GetInstanceID();
playerCountByPillar.TryGetValue(id, out int count);
playerCountByPillar[id] = count + 1;
}
public static bool Prefix(PrecursorActivatedPillar __instance, Collider col, ref bool ___extended, ref bool ___isFullyExtended, FMODAsset ___closeSound, FMOD_CustomLoopingEmitter ___openedLoopingSound)
{
GameObject entityRoot = UWE.Utils.GetEntityRoot(col.gameObject);
if (!entityRoot)
{
entityRoot = col.gameObject;
}
bool isLocalPlayer = entityRoot.GetComponentInChildren<Player>() != null;
bool isRemotePlayer = entityRoot.GetComponentInChildren<RemotePlayerIdentifier>() != null;
if (!isLocalPlayer && !isRemotePlayer)
{
return false;
}
// Decrement player count (only if we have a count for this pillar)
int id = __instance.GetInstanceID();
int newCount = 0;
if (playerCountByPillar.TryGetValue(id, out int count) && count > 0)
{
newCount = count - 1;
playerCountByPillar[id] = newCount;
}
// Only retract if no players remain
if (newCount <= 0)
{
if (___closeSound)
{
Utils.PlayFMODAsset(___closeSound, __instance.transform, 20f);
}
if (___openedLoopingSound)
{
___openedLoopingSound.Stop(STOP_MODE.ALLOWFADEOUT);
}
___extended = false;
___isFullyExtended = true;
}
return false;
}
}