2021-06-20 11:43:02 +00:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.ShipSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ShipSync.Events.Hull
|
|
|
|
|
{
|
2021-07-12 21:02:50 +00:00
|
|
|
|
internal class HullRepairTickEvent : QSBEvent<RepairTickMessage>
|
2021-06-20 11:43:02 +00:00
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.HullRepairTick;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener() => GlobalMessenger<ShipHull, float>.AddListener(EventNames.QSBHullRepairTick, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<ShipHull, float>.RemoveListener(EventNames.QSBHullRepairTick, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(ShipHull hull, float repairFraction) => SendEvent(CreateMessage(hull, repairFraction));
|
|
|
|
|
|
|
|
|
|
private RepairTickMessage CreateMessage(ShipHull hull, float repairFraction)
|
|
|
|
|
{
|
2021-11-01 15:49:00 +00:00
|
|
|
|
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBShipHull>(hull);
|
2021-06-20 11:43:02 +00:00
|
|
|
|
return new RepairTickMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = worldObject.ObjectId,
|
|
|
|
|
RepairNumber = repairFraction
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, RepairTickMessage message)
|
|
|
|
|
{
|
|
|
|
|
var worldObject = QSBWorldSync.GetWorldFromId<QSBShipHull>(message.ObjectId);
|
|
|
|
|
worldObject.RepairTick(message.RepairNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|