mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-03 17:38:30 +00:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using QSB.Events;
|
|
using QSB.ShipSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
using QSB.WorldSync.Events;
|
|
|
|
namespace QSB.ShipSync.Messages.Component
|
|
{
|
|
internal class ComponentDamagedEvent : QSBEvent<WorldObjectMessage>
|
|
{
|
|
public override bool RequireWorldObjectsReady => true;
|
|
|
|
public override void SetupListener() => GlobalMessenger<ShipComponent>.AddListener(EventNames.QSBComponentDamaged, Handler);
|
|
public override void CloseListener() => GlobalMessenger<ShipComponent>.RemoveListener(EventNames.QSBComponentDamaged, Handler);
|
|
|
|
private void Handler(ShipComponent hull) => SendEvent(CreateMessage(hull));
|
|
|
|
private WorldObjectMessage CreateMessage(ShipComponent hull)
|
|
{
|
|
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBShipComponent>(hull);
|
|
return new WorldObjectMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
ObjectId = worldObject.ObjectId
|
|
};
|
|
}
|
|
|
|
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
|
|
{
|
|
var worldObject = QSBWorldSync.GetWorldFromId<QSBShipComponent>(message.ObjectId);
|
|
worldObject.SetDamaged();
|
|
}
|
|
}
|
|
}
|