public void BroadcastDestroyedVehicle(Vehicle vehicle) { using (packetSender.Suppress <VehicleOnPilotModeChanged>()) { string guid = GuidHelper.GetGuid(vehicle.gameObject); LocalPlayer localPlayer = NitroxServiceLocator.LocateService <LocalPlayer>(); VehicleDestroyed vehicleDestroyed = new VehicleDestroyed(guid, localPlayer.PlayerName, vehicle.GetPilotingMode()); packetSender.Send(vehicleDestroyed); // Remove vehicle guid (Detach Player From Vehicle Call OnPilotMode Event if Guid is Empty Dont Send That Event) GuidHelper.SetNewGuid(vehicle.gameObject, string.Empty); // If there is a pilotId then there is a remote player. We must // detach the remote player before destroying the game object. if (!string.IsNullOrEmpty(vehicle.pilotId)) { ushort pilot = ushort.Parse(vehicle.pilotId); Optional <RemotePlayer> remotePilot = playerManager.Find(pilot); if (remotePilot.IsPresent()) { RemotePlayer remotePlayer = remotePilot.Get(); remotePlayer.SetVehicle(null); remotePlayer.SetSubRoot(null); remotePlayer.SetPilotingChair(null); remotePlayer.AnimationController.UpdatePlayerAnimations = true; } } } }
public void BroadcastDestroyedVehicle(Vehicle vehicle) { using (packetSender.Suppress <VehicleOnPilotModeChanged>()) { NitroxId id = NitroxEntity.GetId(vehicle.gameObject); LocalPlayer localPlayer = NitroxServiceLocator.LocateService <LocalPlayer>(); VehicleDestroyed vehicleDestroyed = new VehicleDestroyed(id, localPlayer.PlayerName, vehicle.GetPilotingMode()); packetSender.Send(vehicleDestroyed); // If there is a pilotId then there is a remote player. We must // detach the remote player before destroying the game object. if (!string.IsNullOrEmpty(vehicle.pilotId)) { ushort pilot = ushort.Parse(vehicle.pilotId); Optional <RemotePlayer> remotePilot = playerManager.Find(pilot); if (remotePilot.HasValue) { RemotePlayer remotePlayer = remotePilot.Value; remotePlayer.SetVehicle(null); remotePlayer.SetSubRoot(null); remotePlayer.SetPilotingChair(null); remotePlayer.AnimationController.UpdatePlayerAnimations = true; } } } }
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 = 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); } } if (player.IsPresent()) { RemotePlayer playerInstance = player.Get(); playerInstance.SetVehicle(vehicle); playerInstance.SetSubRoot(subRoot); playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>()); playerInstance.AnimationController.UpdatePlayerAnimations = false; } }
public void DestroyVehicle(NitroxId id, bool isPiloting) { Optional <GameObject> Object = NitroxEntity.GetObjectFrom(id); if (Object.HasValue) { GameObject go = Object.Value; Vehicle vehicle = go.RequireComponent <Vehicle>(); if (isPiloting) //Check Remote Object Have Player inside { ushort pilot = ushort.Parse(vehicle.pilotId); Optional <RemotePlayer> remotePilot = playerManager.Find(pilot); if (remotePilot.HasValue) // Get Remote Player Inside == vehicle.pilotId Remove From Vehicle Before Destroy { RemotePlayer remotePlayer = remotePilot.Value; 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; } } //Destroy vehicle if (vehicle.gameObject != null) { 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); } } }
public void DestroyVehicle(string guid, bool isPiloting) //Destroy Vehicle From network { Optional <GameObject> Object = GuidHelper.GetObjectFrom(guid); if (Object.IsPresent()) { GameObject T = Object.Get(); Vehicle vehicle = T.RequireComponent <Vehicle>(); if (isPiloting) //Check Remote Object Have Player inside { ulong pilot = ulong.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); } } }
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 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; } }