2021-07-24 21:25:29 +01:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Tools.ProbeLauncherTool.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using QSB.WorldSync.Events;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Tools.ProbeLauncherTool.Events
|
|
|
|
|
{
|
2021-08-09 11:49:58 +01:00
|
|
|
|
internal class RetrieveProbeEvent : QSBEvent<BoolWorldObjectMessage>
|
2021-07-24 21:25:29 +01:00
|
|
|
|
{
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => true;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
2021-08-22 16:54:48 +01:00
|
|
|
|
public override void SetupListener()
|
2021-07-24 21:25:29 +01:00
|
|
|
|
=> GlobalMessenger<QSBProbeLauncher, bool>.AddListener(EventNames.QSBRetrieveProbe, Handler);
|
|
|
|
|
|
2021-08-22 16:54:48 +01:00
|
|
|
|
public override void CloseListener()
|
2021-07-24 21:25:29 +01:00
|
|
|
|
=> GlobalMessenger<QSBProbeLauncher, bool>.RemoveListener(EventNames.QSBRetrieveProbe, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(QSBProbeLauncher launcher, bool playEffects) => SendEvent(CreateMessage(launcher, playEffects));
|
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher, bool playEffects) => new()
|
2021-07-24 21:25:29 +01:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = launcher.ObjectId,
|
|
|
|
|
State = playEffects
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
|
|
|
|
|
{
|
|
|
|
|
var worldObject = QSBWorldSync.GetWorldFromId<QSBProbeLauncher>(message.ObjectId);
|
|
|
|
|
worldObject.RetrieveProbe(message.State);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|