2021-06-20 09:48:37 +01:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.ShipSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
2021-07-04 22:34:38 +01:00
|
|
|
|
using QSB.WorldSync.Events;
|
2021-06-20 09:48:37 +01:00
|
|
|
|
|
|
|
|
|
namespace QSB.ShipSync.Events.Component
|
|
|
|
|
{
|
2021-07-12 22:02:50 +01:00
|
|
|
|
internal class ComponentDamagedEvent : QSBEvent<WorldObjectMessage>
|
2021-06-20 09:48:37 +01:00
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.ComponentDamaged;
|
|
|
|
|
|
|
|
|
|
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, ShipComponent>(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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|