/// <summary> /// Triggered when a part that is in our vessel is about to die /// </summary> /// <param name="data"></param> public void OnPartDie(Part data) { if (!VesselCommon.IsSpectating && !VesselCommon.ActiveVesselIsInSafetyBubble() && data.vessel.id == FlightGlobals.ActiveVessel.id) { var msgData = new VesselChangeMsgData { ChangeType = (int)VesselChangeType.EXPLODE, PartCraftId = data.craftID, PartFlightId = data.flightID, VesselId = data.vessel.id }; System.MessageSender.SendMessage(msgData); } }
private static void HandleVesselChange(VesselChangeMsgData messageData) { var vessel = FlightGlobals.VesselsLoaded.FirstOrDefault(v => v.id == messageData.VesselId); if (vessel != null && !vessel.packed && (VesselCommon.IsSpectating || vessel.id != FlightGlobals.ActiveVessel.id)) { switch ((VesselChangeType)messageData.ChangeType) { case VesselChangeType.Explode: var part = vessel.Parts.FirstOrDefault(p => p.flightID == messageData.PartFlightId) ?? vessel.Parts.FirstOrDefault(p => p.craftID == messageData.PartCraftId); part?.explode(); break; default: throw new ArgumentOutOfRangeException(); } } }