Exemple #1
0
        public void SendVesselMessage(Vessel vessel, bool forceSend, bool forceReloadOnReceive)
        {
            if (vessel == null || (!forceSend && VesselCommon.IsSpectating) || vessel.state == Vessel.State.DEAD || VesselRemoveSystem.Singleton.VesselWillBeKilled(vessel.id))
            {
                return;
            }

            if (!forceSend && !LockSystem.LockQuery.UnloadedUpdateLockBelongsToPlayer(vessel.id, SettingsSystem.CurrentSettings.PlayerName))
            {
                return;
            }
            if (!forceSend && !LockSystem.LockQuery.UpdateLockBelongsToPlayer(vessel.id, SettingsSystem.CurrentSettings.PlayerName))
            {
                return;
            }

            var vesselHasChanges = VesselToProtoRefresh.RefreshVesselProto(vessel);

            if (forceSend || vesselHasChanges || !VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                SendVesselMessage(vessel.BackupVessel(), forceReloadOnReceive);
            }

            if (!VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                VesselsProtoStore.AddOrUpdateVesselToDictionary(vessel);
            }
        }
        /// <summary>
        /// Event triggered when a vessel undocks
        /// </summary>
        /// <param name="part"></param>
        public void OnPartUndock(Part part)
        {
            var vessel = part.vessel;

            if (vessel == null)
            {
                return;
            }

            var isEvaPart = part.FindModuleImplementing <KerbalEVA>() != null;

            if (isEvaPart) //This is the case when a kerbal gets out of a external command seat
            {
                vessel.parts.Remove(part);
                VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(vessel, true);
            }

            //Update the vessel in the proto store as it will have now less parts.
            //If we don't do this it may be reloaded.
            VesselsProtoStore.AddOrUpdateVesselToDictionary(vessel);

            if (VesselCommon.IsSpectating)
            {
                FlightCamera.SetTarget(part.vessel);
                part.vessel.MakeActive();
            }
        }
        public void SendVesselMessage(Vessel vessel, bool force)
        {
            if (vessel == null || VesselCommon.IsSpectating || vessel.state == Vessel.State.DEAD || VesselRemoveSystem.Singleton.VesselWillBeKilled(vessel.id))
            {
                return;
            }

            var vesselHasChanges = VesselToProtoRefresh.RefreshVesselProto(vessel);

            if (force || vesselHasChanges || !VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                SendVesselMessage(vessel.BackupVessel());
            }

            if (!VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                VesselsProtoStore.AddOrUpdateVesselToDictionary(vessel);
            }
        }
        /// <summary>
        /// Event called after the undocking is completed and we have the 2 final vessels
        /// </summary>
        public void UndockingComplete(Vessel vessel1, Vessel vessel2)
        {
            if (VesselCommon.IsSpectating)
            {
                return;
            }

            LunaLog.Log("Undock detected!");

            VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(vessel1, true, true);
            VesselsProtoStore.AddOrUpdateVesselToDictionary(vessel1);
            VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(vessel2, true, true);
            VesselsProtoStore.AddOrUpdateVesselToDictionary(vessel2);

            //Release the locks of the vessel we are not in
            var crewToReleaseLocks = FlightGlobals.ActiveVessel?.id == vessel1.id
                ? vessel2.GetVesselCrew().Select(c => c.name)
                : vessel1.GetVesselCrew().Select(c => c.name);

            LockSystem.Singleton.ReleaseAllVesselLocks(crewToReleaseLocks, FlightGlobals.ActiveVessel?.id == vessel1.id ? vessel2.id : vessel1.id);

            LunaLog.Log($"Undocking finished. Vessels: {vessel1.id} and {vessel2.id}");
        }