public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem) { int remotePlayersSynced = 0; foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData) { waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count); List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.Enum()).ToList(); RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes); if (playerData.SubRootId.IsPresent()) { Optional <GameObject> sub = NitroxEntity.GetObjectFrom(playerData.SubRootId.Get()); if (sub.IsPresent()) { player.SetSubRoot(sub.Get().GetComponent <SubRoot>()); } else { Log.Error("Could not spawn remote player into subroot with id: " + playerData.SubRootId.Get()); } } remotePlayersSynced++; yield return(null); } }
public override void Process(VehicleMovement vehicleMovement) { Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(vehicleMovement.Guid); RemotePlayer player = remotePlayerManager.FindOrCreate(vehicleMovement.PlayerId); Vector3 remotePosition = vehicleMovement.Position; Vector3 remoteVelocity = vehicleMovement.Velocity; Quaternion remoteRotation = vehicleMovement.BodyRotation; Vector3 angularVelocity = vehicleMovement.AngularVelocity; Vehicle vehicle = null; SubRoot subRoot = null; 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) { var seamoth = vehicle as SeaMoth; var 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(vehicleMovement.AppliedThrottle); mvc.SetSteeringWheel(vehicleMovement.SteeringWheelYaw, vehicleMovement.SteeringWheelPitch); } } else { CreateVehicleAt(player, vehicleMovement.TechType, vehicleMovement.Guid, remotePosition, remoteRotation); } player.SetVehicle(vehicle); player.SetSubRoot(subRoot); player.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>()); player.animationController.UpdatePlayerAnimations = false; }
public override void Process(VehicleMovement vehicleMovement) { Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(vehicleMovement.Guid); RemotePlayer player = remotePlayerManager.FindOrCreate(vehicleMovement.PlayerId); Vector3 remotePosition = ApiHelper.Vector3(vehicleMovement.Position); Vector3 remoteVelocity = ApiHelper.Vector3(vehicleMovement.Velocity); Quaternion remoteRotation = ApiHelper.Quaternion(vehicleMovement.BodyRotation); Vehicle vehicle = null; SubRoot subRoot = null; if (opGameObject.IsPresent()) { GameObject gameObject = opGameObject.Get(); Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>(); if (rigidbody != null) { //todo: maybe toggle kinematic if jumping large distances? /* * For the cyclops, it is too intense for the game to lerp the entire structure every movement * packet update. Instead, we try to match the velocity. Due to floating points not being * precise, this will skew quickly. To counter this, we apply micro adjustments each packet * to get the simulation back in sync. The adjustments will increase in size the larger the * out of sync issue is. * * Besides, this causes the movement of the Cyclops, vehicles and player to be very fluid. */ rigidbody.velocity = MovementHelper.GetCorrectedVelocity(remotePosition, remoteVelocity, gameObject, PlayerMovement.BROADCAST_INTERVAL); rigidbody.angularVelocity = MovementHelper.GetCorrectedAngularVelocity(remoteRotation, gameObject, PlayerMovement.BROADCAST_INTERVAL); } else { Console.WriteLine("Vehicle did not have a rigidbody!"); } vehicle = gameObject.GetComponent <Vehicle>(); subRoot = gameObject.GetComponent <SubRoot>(); } else { CreateVehicleAt(player, vehicleMovement.TechType, vehicleMovement.Guid, remotePosition, remoteRotation); } player.SetVehicle(vehicle); player.SetSubRoot(subRoot); player.SetPilotingChair(subRoot.GetComponentInChildren <PilotingChair>()); player.animationController.UpdatePlayerAnimations = false; }
public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem) { int remotePlayersSynced = 0; foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData) { waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count); List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.ToUnity()).ToList(); RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes); if (playerData.SubRootId.HasValue) { Optional <GameObject> sub = NitroxEntity.GetObjectFrom(playerData.SubRootId.Value); if (sub.HasValue) { Log.Debug($"sub value set to {sub.Value}. Try to find subroot"); SubRoot subroot = null; sub.Value.TryGetComponent <SubRoot>(out subroot); if (subroot != null) { Log.Debug("Found subroot for player. Will add him and update animation."); player.SetSubRoot(subroot); // Set the animation for the remote player to standing instead of swimming if player is not in a flooded subroot if (!subroot.IsUnderwater(player.Body.transform.position)) { player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF); } } Log.Debug("Trying to find escape pod."); EscapePod escapePod = null; sub.Value.TryGetComponent <EscapePod>(out escapePod); if (escapePod != null) { Log.Debug("Found escape pod for player. Will add him and update animation."); player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF); } } else { Log.Error("Could not spawn remote player into subroot/escape pod with id: " + playerData.SubRootId.Value); } } remotePlayersSynced++; yield return(null); } }
private void CreateRemotePlayers(List <InitialRemotePlayerData> remotePlayerData) { foreach (InitialRemotePlayerData playerData in remotePlayerData) { RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext); if (playerData.SubRootGuid.IsPresent()) { //TODO: require and run async after base pieces are loaded (similar to how items are added to inventories) Optional <GameObject> sub = GuidHelper.GetObjectFrom(playerData.SubRootGuid.Get()); if (sub.IsPresent()) { player.SetSubRoot(sub.Get().GetComponent <SubRoot>()); } } } }
public override void Process(InitialPlayerSync packet) { foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData) { RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, playerData.EquippedTechTypes); if (playerData.SubRootGuid.IsPresent()) { Optional <GameObject> sub = GuidHelper.GetObjectFrom(playerData.SubRootGuid.Get()); if (sub.IsPresent()) { player.SetSubRoot(sub.Get().GetComponent <SubRoot>()); } else { Log.Error("Could not spawn remote player into subroot with guid: " + playerData.SubRootGuid.Get()); } } } }
public override void Process(InitialPlayerSync packet) { foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData) { List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.Enum()).ToList(); RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes); if (playerData.SubRootId.IsPresent()) { Optional <GameObject> sub = NitroxIdentifier.GetObjectFrom(playerData.SubRootId.Get()); if (sub.IsPresent()) { player.SetSubRoot(sub.Get().GetComponent <SubRoot>()); } else { Log.Error("Could not spawn remote player into subroot with id: " + playerData.SubRootId.Get()); } } } }
public void CreateRemotePlayers(object sender, EventArgs eventArgs) { ThrottledBuilder.main.QueueDrained -= CreateRemotePlayers; foreach (InitialRemotePlayerData playerData in remotePlayerData) { RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext); if (playerData.SubRootGuid.IsPresent()) { Optional <GameObject> sub = GuidHelper.GetObjectFrom(playerData.SubRootGuid.Get()); if (sub.IsPresent()) { player.SetSubRoot(sub.Get().GetComponent <SubRoot>()); } else { Log.Error("Could not spawn remote player into subroot with guid: " + playerData.SubRootGuid.Get()); } } } }