Exemplo n.º 1
0
        public void DestroyVehicle(NitroxId id, bool isPiloting) //Destroy Vehicle From network
        {
            Optional <GameObject> Object = NitroxEntity.GetObjectFrom(id);

            if (Object.IsPresent())
            {
                GameObject T       = Object.Get();
                Vehicle    vehicle = T.RequireComponent <Vehicle>();

                if (isPiloting) //Check Remote Object Have Player inside
                {
                    ushort pilot = ushort.Parse(vehicle.pilotId);
                    Optional <RemotePlayer> remotePilot = playerManager.Find(pilot);

                    if (remotePilot.IsPresent()) // Get Remote Player Inside == vehicle.pilotId  Remove From Vehicle Before Destroy
                    {
                        RemotePlayer remotePlayer = remotePilot.Get();
                        remotePlayer.SetVehicle(null);
                        remotePlayer.SetSubRoot(null);
                        remotePlayer.SetPilotingChair(null);
                        remotePlayer.AnimationController.UpdatePlayerAnimations = true;
                    }
                }

                if (vehicle.GetPilotingMode()) //Check Local Object Have Player inside
                {
                    vehicle.ReflectionCall("OnPilotModeEnd", false, false, null);

                    if (!Player.main.ToNormalMode(true))
                    {
                        Player.main.ToNormalMode(false);
                        Player.main.transform.parent = null;
                    }
                }

                if (vehicle.gameObject != null) // Destroy Vehicle
                {
                    if (vehicle.destructionEffect)
                    {
                        GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(vehicle.destructionEffect);
                        gameObject.transform.position = vehicle.transform.position;
                        gameObject.transform.rotation = vehicle.transform.rotation;
                    }

                    UnityEngine.Object.Destroy(vehicle.gameObject);
                    RemoveVehicle(id);
                }
            }
        }
Exemplo n.º 2
0
        public RemotePlayer Create(PlayerContext playerContext, List <TechType> equippedTechTypes)
        {
            Validate.NotNull(playerContext);

            if (playersById.ContainsKey(playerContext.PlayerId))
            {
                throw new Exception("The playerId has already been used.");
            }

            GameObject   remotePlayerBody = CloneLocalPlayerBodyPrototype();
            RemotePlayer remotePlayer     = new RemotePlayer(remotePlayerBody, playerContext, equippedTechTypes, playerModelManager);

            DiscordRPController.Main.UpdatePlayerCount(GetTotalPlayerCount());

            playersById.Add(remotePlayer.PlayerId, remotePlayer);

            return(remotePlayer);
        }
Exemplo n.º 3
0
        public void Create(string playerId, string playerName, PlayerSettings playerSettings)
        {
            if (playersById.ContainsKey(playerId))
            {
                throw new Exception("The playerId has already been used.");
            }

            RemotePlayer player = new RemotePlayer(playerId, playerName, playerSettings);

            PlayerModelDirector playerModelDirector = new PlayerModelDirector(player);

            playerModelDirector
            .AddPing()
            .AddDiveSuit();

            playerModelDirector.Construct();

            playersById.Add(playerId, player);
        }
Exemplo n.º 4
0
        public RemotePlayer Create(PlayerContext playerContext, Optional <NitroxId> subRootId, List <TechType> equippedTechTypes, List <Pickupable> inventoryItems)
        {
            Validate.NotNull(playerContext);

            if (playersById.ContainsKey(playerContext.PlayerId))
            {
                throw new Exception("The playerId has already been used.");
            }

            GameObject   remotePlayerBody = CloneLocalPlayerBodyPrototype();
            RemotePlayer remotePlayer;

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                remotePlayer = new RemotePlayer(remotePlayerBody, playerContext, equippedTechTypes, inventoryItems, playerModelManager);
            }

            if (subRootId.HasValue)
            {
                Optional <GameObject> sub = NitroxEntity.GetObjectFrom(subRootId.Value);
                if (sub.HasValue && sub.Value.TryGetComponent(out SubRoot subRoot))
                {
                    Log.Debug($"Found sub root for {playerContext.PlayerName}. Will add him and update animation.");
                    remotePlayer.SetSubRoot(subRoot);
                }
                else if (sub.HasValue && sub.Value.TryGetComponent(out EscapePod escapePod))
                {
                    Log.Debug($"Found EscapePod for {playerContext.PlayerName}.");
                    remotePlayer.SetEscapePod(escapePod);
                }
                else
                {
                    Log.Error($"Found neither SubRoot component nor EscapePod on {subRootId.Value} for {playerContext.PlayerName}.");
                }
            }

            playersById.Add(remotePlayer.PlayerId, remotePlayer);

            DiscordRPController.Main.UpdatePlayerCount(GetTotalPlayerCount());

            return(remotePlayer);
        }
Exemplo n.º 5
0
        public void Create(PlayerContext playerContext)
        {
            Validate.NotNull(playerContext);

            if (playersById.ContainsKey(playerContext.PlayerId))
            {
                throw new Exception("The playerId has already been used.");
            }

            GameObject   remotePlayerBody = CloneLocalPlayerBodyPrototype();
            RemotePlayer player           = new RemotePlayer(remotePlayerBody, playerContext);

            PlayerModelDirector playerModelDirector = new PlayerModelDirector(player);

            playerModelDirector
            .AddPing()
            .AddDiveSuit();

            playerModelDirector.Construct();

            playersById.Add(player.PlayerId, player);
        }
Exemplo n.º 6
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;
            }
        }
        public static bool TryFind(this PlayerManager playerManager, ushort playerId, out RemotePlayer remotePlayer)
        {
            Optional <RemotePlayer> optional = playerManager.Find(playerId);

            remotePlayer = optional.IsPresent() ? optional.Get() : null;

            return(optional.IsPresent());
        }
        public static bool TryFindByName(this PlayerManager playerManager, string playerName, out RemotePlayer remotePlayer)
        {
            Optional <RemotePlayer> optional = playerManager.FindByName(playerName);

            remotePlayer = optional.IsPresent() ? optional.Get() : null;

            return(optional.IsPresent());
        }
Exemplo n.º 9
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;
            }
        }
Exemplo n.º 10
0
        public void UpdateVehiclePosition(VehicleModel 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 = GuidHelper.GetObjectFrom(vehicleModel.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject gameObject = opGameObject.Get();

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

                MultiplayerVehicleControl mvc = null;

                if (subRoot != null)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                }
                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 (mvc != null)
                {
                    mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity);
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }
            else
            {
                CreateVehicleAt(vehicleModel.TechType, vehicleModel.Guid, remotePosition, remoteRotation);
            }

            if (player.IsPresent())
            {
                RemotePlayer playerInstance = player.Get();
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }
Exemplo n.º 11
0
        public static bool TryFind(this PlayerManager playerManager, ushort playerId, out RemotePlayer remotePlayer)
        {
            Optional <RemotePlayer> optional = playerManager.Find(playerId);

            remotePlayer = optional.HasValue ? optional.Value : null;

            return(optional.HasValue);
        }