public static bool Prefix(ref SubRoot __instance) { var cyclopsLife = (LiveMixin)__instance.GetInstanceField("live"); if (__instance.upgradeConsole == null || !cyclopsLife.IsAlive()) { return(true); // safety check } __instance.shieldUpgrade = false; __instance.sonarUpgrade = false; __instance.vehicleRepairUpgrade = false; __instance.decoyTubeSizeIncreaseUpgrade = false; bool hasFireSupression = false; HandleToggleableUpgrades(__instance, __instance.upgradeConsole.modules, ref hasFireSupression); foreach (AuxUpgradeConsole auxConsole in UpgradeConsoleCache.AuxUpgradeConsoles) { HandleToggleableUpgrades(__instance, auxConsole.Modules, ref hasFireSupression); } var cyclopsHUD = __instance.GetComponentInChildren <CyclopsHolographicHUD>(); cyclopsHUD.fireSuppressionSystem.SetActive(hasFireSupression); // No need to execute original method anymore return(false); // Completely override the method and do not continue with original execution }
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 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 static void SendCyclopsState(SubRoot cyclops) { if (cyclops == null || Multiplayer.main.blocked) { return; } var res = new ClientCyclopsState(); res.vehicleGuid = GuidHelper.Get(cyclops.gameObject); var shield = cyclops.GetComponentInChildren <CyclopsShieldButton>(); if (shield != null) { res.shield = (bool)shield.ReflectionGet("active"); } var engineState = cyclops.GetComponentInChildren <CyclopsEngineChangeState>(); if (engineState != null) { res.engineOn = engineState.motorMode.engineOn; res.engineStarting = (bool)engineState.ReflectionGet("startEngine"); res.motorMode = engineState.motorMode.cyclopsMotorMode; } var lighting = cyclops.GetComponentInChildren <CyclopsLightingPanel>(); if (lighting != null) { res.floodLights = lighting.floodlightsOn; res.internalLights = lighting.lightingOn; } var silentRunning = cyclops.GetComponentInChildren <CyclopsSilentRunningAbilityButton>(); if (silentRunning != null) { res.silentRunning = (bool)silentRunning.ReflectionGet("active"); } Multiplayer.main.Send(res); }
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 void UpdateVehicleMovement(Vehicle vehicle, SubRoot subroot) { animator.updating = false; if (body == null) { Create(); } body.SetActive(true); smoothTransform.SetDisabled(); SetSubRoot(subroot); SetPilotingChair(subroot?.GetComponentInChildren <PilotingChair>()); SetVehicle(vehicle); }
private static IEnumerator StartScanning(SubRoot subRoot) { while (UnityEngine.Time.timeScale <= 0) { yield return(null); } var mapRoom = subRoot.GetComponentInChildren <MapRoomFunctionality>(); if (mapRoom != null) { var waitSeconds = Config.Instance.waitSeconds; var numOfBatchRings = Config.Instance.numOfBatchRings; mapRoom.StartCoroutine(Coroutine.waitFor(mapRoom.ScanInSleepingBatchCellsNotQueuesCoroutine(numOfBatchRings), waitSeconds)); } }
private void TrackNewFCSConnectable(FCSConnectableDevice obj) { QuickLogger.Info("==========================================="); QuickLogger.Info("1"); if (obj == null) { return; } QuickLogger.Info("2"); SubRoot newSeaBase = obj.GetComponentInParent <SubRoot>(); //obj?.gameObject?.transform?.parent?.gameObject; QuickLogger.Info("3"); var fcsConnectableBase = FindManager(newSeaBase?.GetComponentInChildren <PrefabIdentifier>().Id); QuickLogger.Info("4"); #if DEBUG QuickLogger.Debug($"FCSConnectable Base Found: {newSeaBase?.name}", true); QuickLogger.Debug($"FCSConnectable found in base: {Habitat?.name}", true); #endif if (fcsConnectableBase == null || Habitat) { return; } if (fcsConnectableBase.Habitat == Habitat) { QuickLogger.Debug("Subscribing to OnContainerUpdate"); obj.GetStorage().OnContainerUpdate += OnFCSConnectableContainerUpdate; QuickLogger.Info("5"); QuickLogger.Debug("Adding FCSConnectable"); FCSConnectables.Add(obj.GetPrefabIDString(), obj); QuickLogger.Debug("Added FCSConnectable"); QuickLogger.Info("6"); } QuickLogger.Info("==========================================="); }
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; } }
/// <summary> /// Updates the Cyclops power index. This manages engine efficiency as well as the power cost of using Silent Running, Sonar, and Defense Shield. /// </summary> /// <param name="cyclops">The cyclops.</param> /// <param name="auxUpgradeConsoles">The aux upgrade consoles.</param> internal static void UpdatePowerSpeedRating(ref SubRoot cyclops, IList <AuxUpgradeConsole> auxUpgradeConsoles) { Equipment modules = cyclops.upgradeConsole.modules; int powerIndex = GetPowerIndex(modules, auxUpgradeConsoles); int speedIndex = GetSpeedIndex(modules, auxUpgradeConsoles); // Speed modules can affect power rating too float nextPowerRating = Mathf.Max(0.01f, EnginePowerRatings[powerIndex] - speedIndex * EnginePowerPenalty); if (LastKnownPowerRating != nextPowerRating) { cyclops.silentRunningPowerCost = SilentRunningPowerCosts[powerIndex]; cyclops.sonarPowerCost = SonarPowerCosts[powerIndex]; cyclops.shieldPowerCost = ShieldPowerCosts[powerIndex]; LastKnownPowerRating = nextPowerRating; cyclops.SetPrivateField("currPowerRating", nextPowerRating); // Inform the new power rating just like the original method would. ErrorMessage.AddMessage(Language.main.GetFormat("PowerRatingNowFormat", nextPowerRating)); } if (LastKnownSpeedIndex == -1) { // Store the original values before we start to change them // This will only run once var motorMode = cyclops.GetComponentInChildren <CyclopsMotorMode>(); OriginalSpeeds[0] = motorMode.motorModeSpeeds[0]; OriginalSpeeds[1] = motorMode.motorModeSpeeds[1]; OriginalSpeeds[2] = motorMode.motorModeSpeeds[2]; } if (speedIndex > SpeedIndexCount) { speedIndex = SpeedIndexCount; // Limit to Max ErrorMessage.AddMessage($"Speed rating already at maximum"); } if (LastKnownSpeedIndex != speedIndex) { float SlowMultiplier = 1f; float StandardMultiplier = 1f; float FlankMultiplier = 1f; // Calculate the speed multiplier with diminishing returns for (int s = 0; s < speedIndex; s++) { SlowMultiplier += SlowSpeedBonuses[s]; StandardMultiplier += StandardSpeedBonuses[s]; FlankMultiplier += FlankSpeedBonuses[s]; } // These will apply when changing speed modes var motorMode = cyclops.GetComponentInChildren <CyclopsMotorMode>(); motorMode.motorModeSpeeds[0] = OriginalSpeeds[0] * SlowMultiplier; motorMode.motorModeSpeeds[1] = OriginalSpeeds[1] * StandardMultiplier; motorMode.motorModeSpeeds[2] = OriginalSpeeds[2] * FlankMultiplier; // These will apply immediately var subControl = cyclops.GetComponentInChildren <SubControl>(); CyclopsMotorMode.CyclopsMotorModes currentMode = subControl.cyclopsMotorMode.cyclopsMotorMode; subControl.BaseForwardAccel = motorMode.motorModeSpeeds[(int)currentMode]; LastKnownSpeedIndex = speedIndex; ErrorMessage.AddMessage($"Speed rating is now at {(StandardMultiplier * 100):00}%"); if (speedIndex == SpeedIndexCount) { ErrorMessage.AddMessage($"Maximum speed rating reached"); } } }
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; } }