using QSB.Events; using QSB.ShipSync.WorldObjects; using QSB.WorldSync; namespace QSB.ShipSync.Events.Hull { internal class HullChangeIntegrityEvent : QSBEvent { public override EventType Type => EventType.HullChangeIntegrity; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBHullChangeIntegrity, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBHullChangeIntegrity, Handler); private void Handler(ShipHull hull, float integrity) => SendEvent(CreateMessage(hull, integrity)); private HullChangeIntegrityMessage CreateMessage(ShipHull hull, float integrity) { var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new HullChangeIntegrityMessage { AboutId = LocalPlayerId, ObjectId = worldObject.ObjectId, Integrity = integrity }; } public override void OnReceiveRemote(bool server, HullChangeIntegrityMessage message) { var worldObject = QSBWorldSync.GetWorldFromId(message.ObjectId); worldObject.ChangeIntegrity(message.Integrity); } } }