mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-12 04:14:08 +00:00
totems: sync visible for list
This commit is contained in:
parent
31d4669773
commit
3829211711
@ -0,0 +1,11 @@
|
||||
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
|
||||
|
||||
public class LocallyVisibleMessage : QSBWorldObjectMessage<QSBAlarmTotem, bool>
|
||||
{
|
||||
public LocallyVisibleMessage(bool visible) : base(visible) { }
|
||||
public override void OnReceiveLocal() => OnReceiveRemote();
|
||||
public override void OnReceiveRemote() => WorldObject.SetLocallyVisible(From, Data);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
|
||||
|
||||
/// <summary>
|
||||
/// sent by host on initial state
|
||||
/// </summary>
|
||||
public class VisibleForMessage : QSBWorldObjectMessage<QSBAlarmTotem, List<uint>>
|
||||
{
|
||||
public VisibleForMessage(List<uint> visibleFor) : base(visibleFor) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
{
|
||||
WorldObject.VisibleFor.Clear();
|
||||
WorldObject.VisibleFor.AddRange(Data);
|
||||
}
|
||||
}
|
@ -72,6 +72,11 @@ public class AlarmTotemPatches : QSBPatch
|
||||
{
|
||||
GlobalMessenger.FireEvent("TutorialAlarmTotemTriggered");
|
||||
}
|
||||
|
||||
if (QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
__instance.GetWorldObject<QSBAlarmTotem>().SendMessage(new LocallyVisibleMessage(true));
|
||||
}
|
||||
}
|
||||
else if (isPlayerVisible && !__instance._isPlayerVisible)
|
||||
{
|
||||
@ -80,6 +85,11 @@ public class AlarmTotemPatches : QSBPatch
|
||||
__instance._simTotemRenderer.sharedMaterials = __instance._simTotemMaterials;
|
||||
__instance._simVisionConeRenderer.SetColor(__instance._simVisionConeRenderer.GetOriginalColor());
|
||||
__instance._pulseLightController.FadeTo(0f, 0.5f);
|
||||
|
||||
if (QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
__instance.GetWorldObject<QSBAlarmTotem>().SendMessage(new LocallyVisibleMessage(false));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1,19 +1,54 @@
|
||||
using QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
|
||||
|
||||
public class QSBAlarmTotem : WorldObject<AlarmTotem>
|
||||
{
|
||||
public readonly List<PlayerInfo> VisibleFor = new();
|
||||
public readonly List<uint> VisibleFor = new();
|
||||
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
this.SendMessage(new SetFaceOpenMessage(AttachedObject._isFaceOpen) { To = to });
|
||||
this.SendMessage(new SetEnabledMessage(AttachedObject.enabled) { To = to });
|
||||
this.SendMessage(new VisibleForMessage(VisibleFor) { To = to });
|
||||
}
|
||||
|
||||
public override async UniTask Init(CancellationToken ct)
|
||||
{
|
||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||
|
||||
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, () =>
|
||||
{
|
||||
if (AttachedObject._isPlayerVisible)
|
||||
{
|
||||
this.SendMessage(new LocallyVisibleMessage(true));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnRemoval() =>
|
||||
QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
|
||||
|
||||
private void OnPlayerLeave(PlayerInfo player) =>
|
||||
VisibleFor.QuickRemove(player.PlayerId);
|
||||
|
||||
public void SetLocallyVisible(uint playerId, bool visible)
|
||||
{
|
||||
if (visible)
|
||||
{
|
||||
VisibleFor.SafeAdd(playerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisibleFor.QuickRemove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnabled(bool enabled)
|
||||
|
Loading…
x
Reference in New Issue
Block a user