Пример #1
0
        public void HandleMessage(IServerMessageBase msg)
        {
            if (!(msg.Data is VesselUpdateMsgData msgData) || !System.UpdateSystemReady)
            {
                return;
            }

            //We received a msg for our own controlled/updated vessel so ignore it
            if (!VesselCommon.DoVesselChecks(msgData.VesselId))
            {
                return;
            }

            //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example)
            VesselsProtoStore.UpdateVesselProtoValues(msgData);

            var vessel = FlightGlobals.FindVessel(msgData.VesselId);

            if (vessel == null)
            {
                return;
            }

            UpdateVesselFields(vessel, msgData);
            UpdateActionGroups(vessel, msgData);
            UpdateProtoVesselValues(vessel.protoVessel, msgData);
        }
Пример #2
0
        public void SendVesselUpdate(Vessel vessel)
        {
            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselUpdateMsgData>();

            msgData.VesselId        = vessel.id;
            msgData.Name            = vessel.vesselName;
            msgData.Type            = vessel.vesselType.ToString();
            msgData.Situation       = vessel.situation.ToString();
            msgData.Landed          = vessel.Landed;
            msgData.LandedAt        = vessel.landedAtLast;
            msgData.DisplayLandedAt = vessel.displaylandedAt;
            msgData.Splashed        = vessel.Splashed;
            msgData.MissionTime     = vessel.missionTime;
            msgData.LaunchTime      = vessel.launchTime;
            msgData.LastUt          = vessel.lastUT;
            msgData.Persistent      = vessel.isPersistent;
            msgData.RefTransformId  = vessel.referenceTransformId;

            for (var i = 0; i < 17; i++)
            {
                if (msgData.ActionGroups[i] == null)
                {
                    msgData.ActionGroups[i] = new ActionGroup();
                }

                msgData.ActionGroups[i].ActionGroupName = ((KSPActionGroup)(1 << (i & 31))).ToString();
                msgData.ActionGroups[i].State           = vessel.ActionGroups.groups[i];
                msgData.ActionGroups[i].Time            = vessel.ActionGroups.cooldownTimes[i];
            }

            //Update our own values in the store aswell as otherwise if we leave the vessel it can still be in the safety bubble
            VesselsProtoStore.UpdateVesselProtoValues(msgData);

            SendMessage(msgData);
        }
        public void SendVesselUpdate(Vessel vessel)
        {
            if (vessel == null)
            {
                return;
            }

            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselUpdateMsgData>();

            msgData.GameTime         = TimeSyncerSystem.UniversalTime;
            msgData.VesselId         = vessel.id;
            msgData.Name             = vessel.vesselName;
            msgData.Type             = vessel.vesselType.ToString();
            msgData.DistanceTraveled = vessel.distanceTraveled;

            msgData.Situation       = vessel.situation.ToString();
            msgData.Landed          = vessel.Landed;
            msgData.LandedAt        = vessel.landedAt;
            msgData.DisplayLandedAt = vessel.displaylandedAt;
            msgData.Splashed        = vessel.Splashed;
            msgData.MissionTime     = vessel.missionTime;
            msgData.LaunchTime      = vessel.launchTime;
            msgData.LastUt          = vessel.lastUT;
            msgData.Persistent      = vessel.isPersistent;
            msgData.RefTransformId  = vessel.referenceTransformId;

            msgData.AutoClean       = vessel.AutoClean;
            msgData.AutoCleanReason = vessel.AutoCleanReason;
            msgData.WasControllable = vessel.IsControllable;
            msgData.Stage           = vessel.currentStage;
            msgData.Com[0]          = vessel.localCoM.x;
            msgData.Com[1]          = vessel.localCoM.y;
            msgData.Com[2]          = vessel.localCoM.z;

            vessel.protoVessel.autoClean       = vessel.AutoClean;
            vessel.protoVessel.autoCleanReason = vessel.AutoCleanReason;
            vessel.protoVessel.wasControllable = vessel.IsControllable;
            vessel.protoVessel.CoM             = vessel.localCoM;
            vessel.protoVessel.stage           = vessel.currentStage;

            for (var i = 0; i < 17; i++)
            {
                if (msgData.ActionGroups[i] == null)
                {
                    msgData.ActionGroups[i] = new ActionGroup();
                }

                msgData.ActionGroups[i].ActionGroupName = ((KSPActionGroup)(1 << (i & 31))).ToString();
                msgData.ActionGroups[i].State           = vessel.ActionGroups.groups[i];
                msgData.ActionGroups[i].Time            = vessel.ActionGroups.cooldownTimes[i];
            }

            //Update our own values in the store aswell as otherwise if we leave the vessel it can still be in the safety bubble
            VesselsProtoStore.UpdateVesselProtoValues(msgData);
            UpdateOwnProtoVesselValues(vessel);

            SendMessage(msgData);
        }