Ejemplo n.º 1
0
 public void UpdateVehicle(VehicleMovementData vehicleMovement)
 {
     lock (vehiclesByGuid)
     {
         if (vehiclesByGuid.ContainsKey(vehicleMovement.Guid))
         {
             vehiclesByGuid[vehicleMovement.Guid].Position = vehicleMovement.Position;
             vehiclesByGuid[vehicleMovement.Guid].Rotation = vehicleMovement.Rotation;
         }
     }
 }
Ejemplo n.º 2
0
 public void UpdateVehicle(VehicleMovementData vehicleMovement)
 {
     lock (vehiclesById)
     {
         if (vehiclesById.ContainsKey(vehicleMovement.Id))
         {
             VehicleModel vehicleModel = vehiclesById[vehicleMovement.Id];
             vehicleModel.Position = vehicleMovement.Position;
             vehicleModel.Rotation = vehicleMovement.Rotation;
             vehicleModel.Health   = vehicleMovement.Health;
         }
     }
 }
Ejemplo n.º 3
0
        public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player)
        {
            Vector3    remotePosition  = vehicleModel.Position;
            Vector3    remoteVelocity  = vehicleModel.Velocity;
            Quaternion remoteRotation  = vehicleModel.Rotation;
            Vector3    angularVelocity = vehicleModel.AngularVelocity;

            Vehicle vehicle = null;
            SubRoot subRoot = null;

            Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id);

            if (opGameObject.HasValue)
            {
                GameObject gameObject = opGameObject.Value;

                vehicle = gameObject.GetComponent <Vehicle>();
                subRoot = gameObject.GetComponent <SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot != null)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                    subRoot.GetComponent <LiveMixin>().health = vehicleModel.Health;
                }
                else if (vehicle != null)
                {
                    SeaMoth seamoth = vehicle as SeaMoth;
                    Exosuit exosuit = vehicle as Exosuit;

                    if (seamoth)
                    {
                        mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>();
                    }
                    else if (exosuit)
                    {
                        mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>();
                        if (vehicleModel.GetType() == typeof(ExosuitMovementData))
                        {
                            ExosuitMovementData exoSuitMovement = (ExosuitMovementData)vehicleModel;
                            mvc.SetArmPositions(exoSuitMovement.LeftAimTarget, exoSuitMovement.RightAimTarget);
                        }
                        else
                        {
                            Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData");
                        }
                    }

                    vehicle.GetComponent <LiveMixin>().health = vehicleModel.Health;
                }

                if (mvc != null)
                {
                    mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity);
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }

            if (player.HasValue)
            {
                RemotePlayer playerInstance = player.Value;
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }
Ejemplo n.º 4
0
        private Optional<VehicleMovementData> GetVehicleMovement()
        {
            Vehicle vehicle = Player.main.GetVehicle();
            SubRoot sub = Player.main.GetCurrentSub();

            NitroxId id;
            Vector3 position;
            Quaternion rotation;
            Vector3 velocity;
            Vector3 angularVelocity;
            TechType techType;
            float steeringWheelYaw = 0f, steeringWheelPitch = 0f;
            bool appliedThrottle = false;
            Vector3 leftArmPosition = new Vector3(0, 0, 0);
            Vector3 rightArmPosition = new Vector3(0, 0, 0);

            if (vehicle != null)
            {
                id = NitroxEntity.GetId(vehicle.gameObject);
                position = vehicle.gameObject.transform.position;
                rotation = vehicle.gameObject.transform.rotation;
                techType = CraftData.GetTechType(vehicle.gameObject);

                Rigidbody rigidbody = vehicle.gameObject.GetComponent<Rigidbody>();

                velocity = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;

                // Required because vehicle is either a SeaMoth or an Exosuit, both types which can't see the fields either.
                steeringWheelYaw = (float)vehicle.ReflectionGet<Vehicle, Vehicle>("steeringWheelYaw");
                steeringWheelPitch = (float)vehicle.ReflectionGet<Vehicle, Vehicle>("steeringWheelPitch");

                // Vehicles (or the SeaMoth at least) do not have special throttle animations. Instead, these animations are always playing because the player can't even see them (unlike the cyclops which has cameras).
                // So, we need to hack in and try to figure out when thrust needs to be applied.
                if (vehicle && AvatarInputHandler.main.IsEnabled())
                {
                    if (techType == TechType.Seamoth)
                    {
                        bool flag = vehicle.transform.position.y < Ocean.main.GetOceanLevel() && vehicle.transform.position.y < vehicle.worldForces.waterDepth && !vehicle.precursorOutOfWater;
                        appliedThrottle = flag && GameInput.GetMoveDirection().sqrMagnitude > .1f;
                    }
                    else if (techType == TechType.Exosuit)
                    {
                        Exosuit exosuit = vehicle as Exosuit;
                        if (exosuit)
                        {
                            appliedThrottle = (bool)exosuit.ReflectionGet("_jetsActive") && (float)exosuit.ReflectionGet("thrustPower") > 0f;

                            Transform leftAim = (Transform)exosuit.ReflectionGet("aimTargetLeft", true);
                            Transform rightAim = (Transform)exosuit.ReflectionGet("aimTargetRight", true);

                            Vector3 eulerAngles = exosuit.transform.eulerAngles;
                            eulerAngles.x = MainCamera.camera.transform.eulerAngles.x;
                            Quaternion quaternion = Quaternion.Euler(eulerAngles.x, eulerAngles.y, eulerAngles.z);

                            leftArmPosition = leftAim.transform.position = MainCamera.camera.transform.position + quaternion * Vector3.forward * 100f;
                            rightArmPosition = rightAim.transform.position = MainCamera.camera.transform.position + quaternion * Vector3.forward * 100f;
                        }
                    }
                }
            }
            else if (sub != null && Player.main.isPiloting)
            {
                id = NitroxEntity.GetId(sub.gameObject);
                position = sub.gameObject.transform.position;
                rotation = sub.gameObject.transform.rotation;
                Rigidbody rigidbody = sub.GetComponent<Rigidbody>();
                velocity = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                techType = TechType.Cyclops;

                SubControl subControl = sub.GetComponent<SubControl>();
                steeringWheelYaw = (float)subControl.ReflectionGet("steeringWheelYaw");
                steeringWheelPitch = (float)subControl.ReflectionGet("steeringWheelPitch");
                appliedThrottle = subControl.appliedThrottle && (bool)subControl.ReflectionGet("canAccel");
            }
            else
            {
                return Optional.Empty;
            }

            VehicleMovementData model = VehicleMovementFactory.GetVehicleMovementData(techType,
                                                                                        id,
                                                                                        position,
                                                                                        rotation,
                                                                                        velocity,
                                                                                        angularVelocity,
                                                                                        steeringWheelYaw,
                                                                                        steeringWheelPitch,
                                                                                        appliedThrottle,
                                                                                        leftArmPosition,
                                                                                        rightArmPosition);
            return Optional.Of(model);
        }
Ejemplo n.º 5
0
        private Optional <VehicleMovementData> GetVehicleModel()
        {
            Vehicle vehicle = Player.main.GetVehicle();
            SubRoot sub     = Player.main.GetCurrentSub();

            string     guid;
            Vector3    position;
            Quaternion rotation;
            Vector3    velocity;
            Vector3    angularVelocity;
            TechType   techType;
            float      steeringWheelYaw = 0f, steeringWheelPitch = 0f;
            bool       appliedThrottle = false;

            if (vehicle != null)
            {
                guid     = GuidHelper.GetGuid(vehicle.gameObject);
                position = vehicle.gameObject.transform.position;
                rotation = vehicle.gameObject.transform.rotation;
                techType = CraftData.GetTechType(vehicle.gameObject);

                Rigidbody rigidbody = vehicle.gameObject.GetComponent <Rigidbody>();

                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;

                // Required because vehicle is either a SeaMoth or an Exosuit, both types which can't see the fields either.
                steeringWheelYaw   = (float)vehicle.ReflectionGet <Vehicle, Vehicle>("steeringWheelYaw");
                steeringWheelPitch = (float)vehicle.ReflectionGet <Vehicle, Vehicle>("steeringWheelPitch");

                // Vehicles (or the SeaMoth at least) do not have special throttle animations. Instead, these animations are always playing because the player can't even see them (unlike the cyclops which has cameras).
                // So, we need to hack in and try to figure out when thrust needs to be applied.
                if (vehicle && AvatarInputHandler.main.IsEnabled())
                {
                    if (techType == TechType.Seamoth)
                    {
                        bool flag = vehicle.transform.position.y < Ocean.main.GetOceanLevel() && vehicle.transform.position.y < vehicle.worldForces.waterDepth && !vehicle.precursorOutOfWater;
                        appliedThrottle = flag && GameInput.GetMoveDirection().sqrMagnitude > .1f;
                    }
                    else if (techType == TechType.Exosuit)
                    {
                        Exosuit exosuit = vehicle as Exosuit;
                        if (exosuit)
                        {
                            appliedThrottle = (bool)exosuit.ReflectionGet("_jetsActive") && (float)exosuit.ReflectionGet("thrustPower") > 0f;
                        }
                    }
                }
            }
            else if (sub != null && Player.main.isPiloting)
            {
                guid     = GuidHelper.GetGuid(sub.gameObject);
                position = sub.gameObject.transform.position;
                rotation = sub.gameObject.transform.rotation;
                Rigidbody rigidbody = sub.GetComponent <Rigidbody>();
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                techType        = TechType.Cyclops;

                SubControl subControl = sub.GetComponent <SubControl>();
                steeringWheelYaw   = (float)subControl.ReflectionGet("steeringWheelYaw");
                steeringWheelPitch = (float)subControl.ReflectionGet("steeringWheelPitch");
                appliedThrottle    = subControl.appliedThrottle && (bool)subControl.ReflectionGet("canAccel");
            }
            else
            {
                return(Optional <VehicleMovementData> .Empty());
            }

            VehicleMovementData model = new VehicleMovementData(techType.Model(),
                                                                guid,
                                                                position,
                                                                rotation,
                                                                velocity,
                                                                angularVelocity,
                                                                steeringWheelYaw,
                                                                steeringWheelPitch,
                                                                appliedThrottle);

            return(Optional <VehicleMovementData> .Of(model));
        }
Ejemplo n.º 6
0
 public VehicleMovement(ushort playerId, VehicleMovementData vehicleMovementData) : base(playerId, vehicleMovementData.Position, vehicleMovementData.Velocity, vehicleMovementData.Rotation, vehicleMovementData.Rotation)
 {
     VehicleMovementData = vehicleMovementData;
     DeliveryMethod      = NitroxDeliveryMethod.DeliveryMethod.UNRELIABLE_SEQUENCED;
     UdpChannel          = UdpChannelId.VEHICLE_MOVEMENT;
 }
Ejemplo n.º 7
0
 public VehicleMovement(ushort playerId, VehicleMovementData vehicle) : base(playerId, vehicle.Position, vehicle.Velocity, vehicle.Rotation, vehicle.Rotation)
 {
     Vehicle        = vehicle;
     DeliveryMethod = NitroxDeliveryMethod.DeliveryMethod.UnreliableSequenced;
     UdpChannel     = UdpChannelId.VEHICLE_MOVEMENT;
 }
Ejemplo n.º 8
0
        public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player)
        {
            Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id);
            Vehicle vehicle = null;
            SubRoot subRoot = null;

            if (opGameObject.HasValue)
            {
                Rocket rocket = opGameObject.Value.GetComponent <Rocket>();
                vehicle = opGameObject.Value.GetComponent <Vehicle>();
                subRoot = opGameObject.Value.GetComponent <SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                }
                else if (vehicle)
                {
                    if (vehicle.docked)
                    {
                        Log.Debug($"For vehicle {vehicleModel.Id} position update while docked, will not execute");
                        return;
                    }

                    switch (vehicle)
                    {
                    case SeaMoth seamoth:
                    {
                        mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>();
                        break;
                    }

                    case Exosuit exosuit:
                    {
                        mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>();

                        if (vehicleModel is ExosuitMovementData exoSuitMovement)
                        {
                            mvc.SetArmPositions(exoSuitMovement.LeftAimTarget.ToUnity(), exoSuitMovement.RightAimTarget.ToUnity());
                        }
                        else
                        {
                            Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData");
                        }
                        break;
                    }
                    }
                }
                else if (rocket)
                {
                    rocket.transform.position = vehicleModel.Position.ToUnity();
                    rocket.transform.rotation = vehicleModel.Rotation.ToUnity();
                }

                if (mvc)
                {
                    mvc.SetPositionVelocityRotation(
                        vehicleModel.Position.ToUnity(),
                        vehicleModel.Velocity.ToUnity(),
                        vehicleModel.Rotation.ToUnity(),
                        vehicleModel.AngularVelocity.ToUnity()
                        );
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }

            if (player.HasValue)
            {
                RemotePlayer playerInstance = player.Value;
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }
Ejemplo n.º 9
0
 public VehicleMovement(string playerId, VehicleMovementData vehicle) : base(playerId, vehicle.Position, vehicle.Velocity, vehicle.Rotation, vehicle.Rotation, Optional <string> .Empty())
 {
     Vehicle        = vehicle;
     DeliveryMethod = NetDeliveryMethod.UnreliableSequenced;
     UdpChannel     = UdpChannelId.VEHICLE_MOVEMENT;
 }