2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.GeyserSync.WorldObjects;
|
2020-08-13 13:32:58 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-03 22:18:22 +00:00
|
|
|
|
using QSB.WorldSync.Events;
|
2020-08-13 13:32:58 +00:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.GeyserSync.Events
|
2020-08-13 13:32:58 +00:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.Geyser;
|
2020-08-13 13:32:58 +00:00
|
|
|
|
|
2020-12-11 13:14:58 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
2020-08-15 19:52:43 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = id,
|
|
|
|
|
State = state
|
|
|
|
|
};
|
2020-08-13 13:32:58 +00:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-02-26 12:47:05 +00:00
|
|
|
|
if (!QSBCore.HasWokenUp)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-24 10:45:25 +00:00
|
|
|
|
var geyser = QSBWorldSync.GetWorldFromId<QSBGeyser>(message.ObjectId);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
geyser?.SetState(message.State);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|