2022-08-16 23:57:17 +00:00
|
|
|
|
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
2024-02-13 13:06:43 +00:00
|
|
|
|
using QSB.WorldSync.Messages;
|
2022-08-16 23:57:17 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* For those who come here,
|
|
|
|
|
* leave while you still can.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace QSB.EchoesOfTheEye.LightSensorSync;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-08-17 00:14:09 +00:00
|
|
|
|
/// only purpose is to handle initial state sync.
|
2022-08-17 00:05:13 +00:00
|
|
|
|
///
|
2022-08-17 00:14:09 +00:00
|
|
|
|
/// we don't have to worry about start illuminated or sectors.
|
2023-05-08 18:38:24 +00:00
|
|
|
|
/// ownership is always given to local player light sensor.
|
2022-08-16 23:57:17 +00:00
|
|
|
|
///
|
|
|
|
|
/// 2 uses:
|
|
|
|
|
/// - AlarmTotem.CheckPlayerVisible
|
2022-08-17 00:05:13 +00:00
|
|
|
|
/// - GhostSensors.FixedUpdate_Sensors
|
2022-08-16 23:57:17 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
[RequireComponent(typeof(SingleLightSensor))]
|
|
|
|
|
public class QSBPlayerLightSensor : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private SingleLightSensor _lightSensor;
|
2022-08-17 00:05:13 +00:00
|
|
|
|
private uint _playerId;
|
2022-08-16 23:57:17 +00:00
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
_lightSensor = GetComponent<SingleLightSensor>();
|
2022-08-17 00:05:13 +00:00
|
|
|
|
_playerId = QSBPlayerManager.PlayerList.First(x => x.LightSensor == _lightSensor).PlayerId;
|
2022-08-16 23:57:17 +00:00
|
|
|
|
|
|
|
|
|
RequestInitialStatesMessage.SendInitialState += SendInitialState;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 00:05:13 +00:00
|
|
|
|
private void OnDestroy() =>
|
2022-08-16 23:57:17 +00:00
|
|
|
|
RequestInitialStatesMessage.SendInitialState -= SendInitialState;
|
|
|
|
|
|
|
|
|
|
private void SendInitialState(uint to)
|
|
|
|
|
{
|
2022-08-17 00:05:13 +00:00
|
|
|
|
new PlayerSetIlluminatedMessage(_playerId, _lightSensor._illuminated) { To = to }.Send();
|
2022-08-16 23:57:17 +00:00
|
|
|
|
if (_lightSensor._illuminatingDreamLanternList != null)
|
|
|
|
|
{
|
2022-08-17 00:05:13 +00:00
|
|
|
|
new PlayerIlluminatingLanternsMessage(_playerId, _lightSensor._illuminatingDreamLanternList) { To = to }.Send();
|
2022-08-16 23:57:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|