private static bool ProcessCoupleInternal(Guid vesselId, Guid coupledVesselId, uint partFlightId, uint coupledPartFlightId, CoupleTrigger trigger) { if (!VesselCommon.DoVesselChecks(vesselId)) { return(false); } //If the coupling is against our OWN vessel we must FORCE the loading var forceLoad = FlightGlobals.ActiveVessel && (FlightGlobals.ActiveVessel.id == vesselId || FlightGlobals.ActiveVessel.id == coupledVesselId); _dominantVessel = FlightGlobals.FindVessel(vesselId); if (_dominantVessel == null) { return(false); } if (!_dominantVessel.loaded && forceLoad) { _dominantVessel.Load(); } _weakVessel = FlightGlobals.FindVessel(coupledVesselId); if (_weakVessel == null) { return(false); } if (!_weakVessel.loaded && forceLoad) { _weakVessel.Load(); } var protoPart = _dominantVessel.protoVessel.GetProtoPart(partFlightId); var coupledProtoPart = _weakVessel.protoVessel.GetProtoPart(coupledPartFlightId); if (protoPart != null && coupledProtoPart != null) { if (protoPart.partRef && coupledProtoPart.partRef) { VesselCoupleSystem.Singleton.IgnoreEvents = true; //Remember! The weak vessel must couple with the DOMINANT vessel and not the other way around! switch (trigger) { case CoupleTrigger.DockingNode: var weakDockingNode = coupledProtoPart.partRef.FindModuleImplementing <ModuleDockingNode>(); if (weakDockingNode) { var dominantDockingNode = protoPart.partRef.FindModuleImplementing <ModuleDockingNode>(); if (dominantDockingNode) { weakDockingNode.DockToVessel(dominantDockingNode); } } break; case CoupleTrigger.GrappleNode: var grappleModule = coupledProtoPart.partRef.FindModuleImplementing <ModuleGrappleNode>(); if (grappleModule) { GrappleMethod.Invoke(grappleModule, new object[] { coupledProtoPart, protoPart }); } break; case CoupleTrigger.Kerbal: var kerbalEva = coupledProtoPart.partRef.FindModuleImplementing <KerbalEVA>(); if (kerbalEva) { var seat = KerbalSeatField.GetValue(kerbalEva) as KerbalSeat; if (seat) { kerbalEva.fsm.RunEvent(kerbalEva.On_seatBoard); } } break; case CoupleTrigger.Other: coupledProtoPart.partRef.Couple(protoPart.partRef); break; } VesselCoupleSystem.Singleton.IgnoreEvents = false; return(true); } } return(false); }
public void SendVesselCouple(Vessel vessel, uint partFlightId, Guid coupledVesselId, uint coupledPartFlightId, CoupleTrigger trigger) { if (vessel == null) { return; } var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselCoupleMsgData>(); msgData.GameTime = TimeSyncSystem.UniversalTime; msgData.VesselId = vessel.id; msgData.PartFlightId = partFlightId; msgData.CoupledVesselId = coupledVesselId; msgData.CoupledPartFlightId = coupledPartFlightId; msgData.SubspaceId = WarpSystem.Singleton.CurrentSubspace; msgData.Trigger = (int)trigger; SendMessage(msgData); }