34 lines
1.1 KiB
C#
Raw Normal View History

2021-06-20 09:59:02 +01:00
using QSB.Events;
using QSB.ShipSync.WorldObjects;
using QSB.WorldSync;
2021-07-04 22:34:38 +01:00
using QSB.WorldSync.Events;
namespace QSB.ShipSync.Messages.Component
{
2021-07-12 22:02:50 +01:00
internal class ComponentRepairedEvent : QSBEvent<WorldObjectMessage>
{
public override bool RequireWorldObjectsReady => true;
2021-06-20 09:59:02 +01:00
public override void SetupListener() => GlobalMessenger<ShipComponent>.AddListener(EventNames.QSBComponentRepaired, Handler);
public override void CloseListener() => GlobalMessenger<ShipComponent>.RemoveListener(EventNames.QSBComponentRepaired, Handler);
private void Handler(ShipComponent hull) => SendEvent(CreateMessage(hull));
private WorldObjectMessage CreateMessage(ShipComponent hull)
{
2021-11-01 15:49:00 +00:00
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBShipComponent>(hull);
2021-06-20 09:59:02 +01:00
return new WorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = worldObject.ObjectId
};
}
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
{
var worldObject = QSBWorldSync.GetWorldFromId<QSBShipComponent>(message.ObjectId);
worldObject.SetRepaired();
}
}
}