2022-04-01 17:41:51 -07:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
|
2022-04-01 02:23:59 -07:00
|
|
|
|
using QSB.Messaging;
|
2022-04-01 17:26:58 -07:00
|
|
|
|
using QSB.Player;
|
2022-04-01 02:23:59 -07:00
|
|
|
|
using QSB.WorldSync;
|
2022-04-01 17:26:58 -07:00
|
|
|
|
using System.Collections.Generic;
|
2022-04-01 17:41:51 -07:00
|
|
|
|
using System.Threading;
|
2022-04-01 02:23:59 -07:00
|
|
|
|
|
|
|
|
|
namespace QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBAlarmTotem : WorldObject<AlarmTotem>
|
|
|
|
|
{
|
2022-04-01 21:56:40 -07:00
|
|
|
|
public readonly List<uint> VisibleFor = new();
|
2022-04-02 02:26:44 -07:00
|
|
|
|
public bool IsLocallyVisible;
|
2022-04-01 17:26:58 -07:00
|
|
|
|
|
2022-04-01 02:23:59 -07:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
2022-04-02 14:08:44 -07:00
|
|
|
|
this.SendMessage(new TotemEnabledMessage(AttachedObject.enabled) { To = to });
|
|
|
|
|
this.SendMessage(new TotemVisibleForMessage(VisibleFor) { To = to });
|
2022-04-01 17:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-02 02:26:44 -07:00
|
|
|
|
public override async UniTask Init(CancellationToken ct) =>
|
2022-04-01 17:41:51 -07:00
|
|
|
|
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval() =>
|
|
|
|
|
QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
|
|
|
|
|
|
|
|
|
|
private void OnPlayerLeave(PlayerInfo player) =>
|
2022-04-01 21:56:40 -07:00
|
|
|
|
VisibleFor.QuickRemove(player.PlayerId);
|
2022-04-01 17:41:51 -07:00
|
|
|
|
|
2022-04-01 21:34:22 -07:00
|
|
|
|
public void SetVisible(uint playerId, bool visible)
|
2022-04-01 17:41:51 -07:00
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
{
|
2022-04-01 21:56:40 -07:00
|
|
|
|
VisibleFor.SafeAdd(playerId);
|
2022-04-01 17:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-04-01 21:56:40 -07:00
|
|
|
|
VisibleFor.QuickRemove(playerId);
|
2022-04-01 17:41:51 -07:00
|
|
|
|
}
|
2022-04-01 02:32:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject.enabled == enabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!enabled &&
|
|
|
|
|
AttachedObject._sector &&
|
|
|
|
|
AttachedObject._sector.ContainsOccupant(DynamicOccupant.Player))
|
|
|
|
|
{
|
|
|
|
|
// local player is in sector, do not disable
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AttachedObject.enabled = enabled;
|
|
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._simTotemMaterials[0] = AttachedObject._origSimEyeMaterial;
|
|
|
|
|
AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials;
|
|
|
|
|
AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simVisionConeRenderer.GetOriginalColor());
|
2022-04-02 14:28:35 -07:00
|
|
|
|
AttachedObject._pulseLightController.SetIntensity(0f);
|
|
|
|
|
/*
|
2022-04-01 02:32:40 -07:00
|
|
|
|
if (AttachedObject._isPlayerVisible)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._isPlayerVisible = false;
|
|
|
|
|
Locator.GetAlarmSequenceController().DecreaseAlarmCounter();
|
|
|
|
|
}
|
2022-04-02 14:28:35 -07:00
|
|
|
|
*/
|
2022-06-12 19:32:06 -07:00
|
|
|
|
if (IsLocallyVisible)
|
|
|
|
|
{
|
|
|
|
|
IsLocallyVisible = false;
|
|
|
|
|
this.SendMessage(new TotemVisibleMessage(false));
|
|
|
|
|
}
|
2022-04-01 02:32:40 -07:00
|
|
|
|
}
|
2022-04-01 02:23:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|