using QSB.Events; using QSB.ShipSync.WorldObjects; using QSB.WorldSync; namespace QSB.ShipSync.Events.Hull { internal class HullRepairTickEvent : QSBEvent { public override EventType Type => EventType.HullRepairTick; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBHullRepairTick, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBHullRepairTick, Handler); private void Handler(ShipHull hull, float repairFraction) => SendEvent(CreateMessage(hull, repairFraction)); private RepairTickMessage CreateMessage(ShipHull hull, float repairFraction) { var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new RepairTickMessage { AboutId = LocalPlayerId, ObjectId = worldObject.ObjectId, RepairNumber = repairFraction }; } public override void OnReceiveRemote(bool server, RepairTickMessage message) { var worldObject = QSBWorldSync.GetWorldFromId(message.ObjectId); worldObject.RepairTick(message.RepairNumber); } } }