private void OnEnable() { if (!_runStartUpOnEnable) { return; } Setup(); if (_fromSave) { QuickLogger.Info($"Loading {Mod.FriendlyName}"); var prefabIdentifier = GetComponent <PrefabIdentifier>(); var id = prefabIdentifier?.Id ?? string.Empty; var data = Mod.GetSaveData(id); if (data == null) { QuickLogger.Info($"No save found for PrefabId {id}"); return; } SetPinging(data.IsPinging); HealthManager.SetHealth(data.HealthLevel); OxygenManager.SetO2Level(data.OxygenLevel); _beaconID = data.BeaconID; _fromSave = false; ReattachBeaconAfterLoad(); QuickLogger.Info($"Loaded {Mod.FriendlyName}"); } }
private void Awake() { cachedOxygenManager = Player.main.oxygenMgr; cachedDayNight = DayNightCycle.main; cachedTemp = WaterTemperatureSimulation.main; SeraLogger.Message(Main.modName, "SpecialtyTanks is Awake() and running!"); }
[HarmonyPrefix] // Harmony Prefix public static bool Prefix(ref OxygenManager __instance) { // if (Player.main.currentMountedVehicle != null && !Player.main.currentMountedVehicle.IsPowered() && Player.main.currentMountedVehicle.modules.GetCount(Modules.VehicleOxygenUpgradeModule.TechTypeID) == 0) if (Player.main.currentMountedVehicle != null && !AirVentInfo.AirVentsOn) { return(false); } return(true); } // end public static bool Prefix(ref OxygenManager __instance)
// Use this for initialization void Start() { platformStartPoint = platformGenerator.position; playerStartPoint = thePlayer.transform.position; theScoreManager = FindObjectOfType <ScoreManager> (); theEnergyManager = FindObjectOfType <OxygenManager> (); backgroundSound = GameObject.Find("TheJungleBook").GetComponent <AudioSource> (); }
public void Update() { if (shouldReplenish == false) { return; } OxygenManager oxygen = Player.main.oxygenMgr; oxygen.AddOxygen(Time.deltaTime * OxygenPerSecond); }
public static bool AddOxygenAtSurface(OxygenManager __instance, ref float timeInterval) { Player player = Player.main; // If this is the wrong oxygen manager, or air isnt bad if (player.oxygenMgr != __instance || !IsRadiativeAir(player)) { return(true); } // Cancel the method as they cannot breathe return(false); }
private void ExecutePatch() { oxygenManager = Player.main.GetComponent <OxygenManager>(); amountToConsume = Time.deltaTime * O2PerSecond; if (airBladder.inflating) { HandleInflating(); } else if (airBladder.deflating) { HandleDeflating(); } }
private void Update() { _timeLeft -= DayNightCycle.main.deltaTime; if (_timeLeft < 0) { OxygenManager?.GenerateOxygen(); _timeLeft = 1f; } HealthManager?.HealthChecks(); HealthManager?.UpdateHealthSystem(); PowerManager?.ConsumePower(); PowerManager?.UpdatePowerState(); }
internal void Save(SaveData newSaveData) { var prefabIdentifier = GetComponent <PrefabIdentifier>() ?? GetComponentInParent <PrefabIdentifier>(); var id = prefabIdentifier.Id; if (_saveData == null) { _saveData = new SaveDataEntry(); } _saveData.ID = id; _saveData.OxygenLevel = OxygenManager.GetO2Level(); _saveData.HealthLevel = HealthManager.GetHealth(); _saveData.BeaconID = (((_attachedBeacon != null) ? _attachedBeacon.GetComponent <UniqueIdentifier>().Id : null) ?? ""); _saveData.IsPinging = AnimationManager.GetBoolHash(_isPinging); newSaveData.Entries.Add(_saveData); }
public static bool Prefix(ref OxygenManager __instance, float __result, float secondsToAdd) { if (Main.config.bManualRefill) { if (sourcesInfo == null) { return(true); // Fail safe } #if SUBNAUTICA_STABLE List <Oxygen> oxySources = (List <Oxygen>)sourcesInfo.GetValue(__instance); #elif BELOWZERO List <IOxygenSource> oxySources = (List <IOxygenSource>)sourcesInfo.GetValue(__instance); #endif if (oxySources == null) { return(true); } float O2added = 0f; for (int i = 0; i < oxySources.Count; i++) { #if SUBNAUTICA_STABLE if (!oxySources[i].isPlayer) #elif BELOWZERO if (!oxySources[i].IsPlayer()) #endif { continue; } float num = oxySources[i].AddOxygen(secondsToAdd); secondsToAdd -= num; O2added += num; if (Utils.NearlyEqual(secondsToAdd, 0f, 1.401298E-45f)) { break; } } __result = O2added; return(false); } return(true); }
/// <summary> /// (Cross-Game compatible) Reduces the amount of time it takes for the player to take one breath. /// </summary> /// <param name="oxygenManager"></param> /// <param name="amount">Amount to reduce breath time by.</param> public static void ReduceBreathPeriod(this OxygenManager oxygenManager, float amount) => AirData.BreathPeriod -= amount;
/// <summary> /// (Cross-Game compatible) Returns how long it takes for the player to take one breath. /// </summary> /// <param name="oxygenManager"></param> /// <returns></returns> public static float GetBreathPeriod(this OxygenManager oxygenManager) => AirData.BreathPeriod;
/// <summary> /// (Cross-Game compatible) Reduces the amount of O2 thats recovered per second on the surface of the ocean. /// </summary> /// <param name="oxygenManager"></param> /// <param name="amount"></param> public static void ReduceO2UnitsPerSecondSurface(this OxygenManager oxygenManager, float amount) => oxygenManager.oxygenUnitsPerSecondSurface -= amount;
/// <summary> /// (Cross-Game compatible) Returns the amount of O2 thats recovered per second on the surface of the ocean. /// </summary> /// <param name="oxygenManager"></param> /// <returns></returns> public static float GetO2UnitsPerSecondSurface(this OxygenManager oxygenManager) => oxygenManager.oxygenUnitsPerSecondSurface;
/// <summary> /// (Cross-Game compatible) Returns all of the oxygen sources affecting the player. Player's lungs are the first source. /// </summary> #if Subnautica public static List <Oxygen> GetAllSources(this OxygenManager oxygenManager) => oxygenManager.sources;
private void Awake() { Instance = this; waterController = FindObjectOfType <WaterController>(); }
[HarmonyPostfix] // Harmony postfix public static void Postfix(Vehicle __instance) { if (Player.main.currentMountedVehicle != null) { if (Player.main.currentMountedVehicle == __instance && Config.UseEnergyToggleValue && !AirVentInfo.AirVentsOn) { var efficiencyLoaded = __instance.modules.GetCount(TechType.VehiclePowerUpgradeModule); //float energyCost = 0.1f; // vanilla 0.1f per sec float energyCost = Player.main.currentMountedVehicle.oxygenEnergyCost; if (Config.UseEasyEnergyToggleValue) { switch (efficiencyLoaded) { case 0: energyCost *= 0.4f; break; case 1: energyCost *= 0.25f; break; default: energyCost *= 0.1f; break; } } else { switch (efficiencyLoaded) { case 0: energyCost *= 0.5f; break; case 1: energyCost *= 0.4f; break; case 2: energyCost *= 0.3f; break; case 3: energyCost *= 0.2f; break; default: energyCost *= 0.1f; break; } } // Consume energy for continuously replenishing oxygen OxygenManager oxygenMgr = Player.main.oxygenMgr; oxygenMgr.GetTotal(out float oxygenAvailable, out float oxygenCapacity); if (!OtherModsInfo.RefillableOxygenTankPresent) { if (oxygenAvailable == oxygenCapacity) { ConsumeOxygenEnergy(__instance, energyCost); } } else { //if (!Player.main.oxygenMgr.HasOxygenTank()) if (Player.main.currentMountedVehicle.modules.GetCount(VehicleOxygenUpgradeModule.TechTypeID) > 0) { ConsumeOxygenEnergy(__instance, energyCost); } } } // end if (main.currentMountedVehicle != null && Config.UseEnergyToggleValue) if (KeyCodeUtils.GetKeyDown(Config.ToggleAirVentsKeybindValue)) { //if (Mathf.RoundToInt(Player.main.GetDepth()) < Objects.AirVentInfo.DepthDetection) if (Player.main.GetDepth() < AirVentInfo.DepthDetection) { if (AirVentInfo.AirVentsOn == false) { AirVentInfo.AirVentsOn = true; } else { AirVentInfo.AirVentsOn = false; } } } // (Mathf.RoundToInt(Player.main.GetDepth()) > Objects.AirVentInfo.DepthDetection) if (Player.main.GetDepth() > AirVentInfo.DepthDetection) { if (AirVentInfo.AirVentsOn == true) { AirVentInfo.AirVentsOn = false; } } else { if (Config.AirVentsAutoToggleValue) { if (AirVentInfo.AirVentsOn == false) { AirVentInfo.AirVentsOn = true; } } } } // end if (Player.main.currentMountedVehicle != null) } // end public static void Postfix(Vehicle __instance)
// Use this for initialization void Start() { GameOverScreen.SetActive(false); Instance = this; timer = maxTime; }
// Use this for initialization void Start() { theEnergyManager = FindObjectOfType <OxygenManager> (); energySound = GameObject.Find("CoinSound").GetComponent <AudioSource> (); }
public static bool Prefix(Vehicle __instance) { var mainCam = MainCameraControl.main; //var cameraToPlayerMan = CameraToPlayerManager.main; bool inVehicleNow = (Player.main.inSeamoth || Player.main.inExosuit); if (isInVehicle) { if (inVehicleNow) { // do nothing } else { isInVehicle = false; } } else { if (inVehicleNow) { isInVehicle = true; isNewlyInVehicle = true; } else { // do nothing } } if (!inVehicleNow) { if (releaseFlag) { cameraRelinquish(); releaseFlag = false; } return(true); } releaseFlag = true; if (isNewlyInVehicle) { isNewlyInVehicle = false; //BasicText message = new BasicText(); //message.ShowMessage("This Message Will Fade In 10 Seconds", 10); } if (Player.main.motorMode == Player.MotorMode.Seaglide) { // hack the controls } bool triggerState = (Input.GetAxisRaw("ControllerAxis3") > 0) || (Input.GetAxisRaw("ControllerAxis3") < 0); if (isTriggerDown) { if (triggerState) { //do nothing } else { isTriggerDown = false; isTriggerNewlyUp = true; } } else { if (triggerState) { isTriggerDown = true; isTriggerNewlyDown = true; } else { //do nothing } } // add locomotion back in if ((Input.GetKey(Options.freeLookKey) || isTriggerDown) && __instance == Player.main.currentMountedVehicle)// and we're using controller) { Vector3 myDirection = Vector3.zero; myDirection.z = Input.GetAxis("ControllerAxis1"); myDirection.x = -Input.GetAxis("ControllerAxis2"); myDirection.y = GameInput.GetButtonHeld(GameInput.Button.MoveUp) ? (GameInput.GetButtonHeld(GameInput.Button.MoveDown) ? 0 : 1) : (GameInput.GetButtonHeld(GameInput.Button.MoveDown) ? -1 : 0); Vector3 myModDir = __instance.transform.forward * myDirection.x + __instance.transform.right * myDirection.z + __instance.transform.up * myDirection.y; myModDir = Vector3.Normalize(myModDir); __instance.GetComponent <Rigidbody>().velocity += myModDir * Time.deltaTime * 10f; __instance.GetComponent <Rigidbody>().velocity = Vector3.ClampMagnitude(__instance.GetComponent <Rigidbody>().velocity, 10f); } void cameraRelinquish() { mainCam.ResetCamera(); mainCam.cinematicMode = false; mainCam.lookAroundMode = true; VehicleAwakePatch.myFreeMan.isFreeLooking = false; } if (Input.GetKeyDown(Options.freeLookKey) || isTriggerNewlyDown) { Debug.Log("FreeLook: button pressed. Taking control of the camera."); VehicleAwakePatch.myFreeMan.isFreeLooking = true; isTriggerNewlyDown = false; resetCameraFlag = false; // invoke a camera vulnerability mainCam.cinematicMode = true; mainCam.lookAroundMode = false; return(false); } else if (Input.GetKeyUp(Options.freeLookKey) || isTriggerNewlyUp) { isTriggerNewlyUp = false; Debug.Log("FreeLook: button released. Relinquishing control of the camera."); resetCameraFlag = true; } if (!resetCameraFlag && (Input.GetKey(Options.freeLookKey) || isTriggerDown)) { resetCameraFlag = false; moveCamera(Player.main.currentMountedVehicle); // adding oxygen is something vehicle.update would usually do, // so we do it naively here as well. // I'm not sure that Time.deltaTime seconds worth of oxygen per frame is the right amount... OxygenManager oxygenMgr = Player.main.oxygenMgr; oxygenMgr.AddOxygen(Time.deltaTime); return(false); } if (resetCameraFlag) { mainCam.rotationX = Mathf.SmoothDampAngle(mainCam.rotationX, 0f, ref xVelocity, smoothTime); mainCam.rotationY = Mathf.SmoothDampAngle(mainCam.rotationY, 0f, ref yVelocity, smoothTime); mainCam.camRotationX = mainCam.rotationX; mainCam.camRotationY = mainCam.rotationY; mainCam.cameraOffsetTransform.localEulerAngles = new Vector3(-mainCam.camRotationY, mainCam.camRotationX, 0); double threshold = 1; if (Mathf.Abs(mainCam.camRotationX) < threshold && Mathf.Abs(mainCam.camRotationY) < threshold) { cameraRelinquish(); resetCameraFlag = false; } // need to retain control in order to finish snapping back to center return(false); } // nothing from the key and the camera has been reset, so we don't need control //cameraRelinquish(); return(true); }
/// <summary> /// (Cross-Game compatible) Returns how much Oxygen is consumed per breath. /// </summary> /// <param name="oxygenManager"></param> /// <returns></returns> public static float GetO2PerBreath(this OxygenManager oxygenManager) => AirData.OxygenPerBreath;
public static bool Prefix(MainCameraControl __instance) { var mainCam = MainCameraControl.main; //var cameraToPlayerMan = CameraToPlayerManager.main; bool inVehicleNow = (Player.main.IsPilotingSeatruck() || Player.main.inExosuit); if (isInVehicle) { if (inVehicleNow) { // do nothing } else { isInVehicle = false; } } else { if (inVehicleNow) { isInVehicle = true; isNewlyInVehicle = true; } else { // do nothing } } if (!inVehicleNow) { if (releaseFlag) { cameraRelinquish(); releaseFlag = false; } return(true); } releaseFlag = true; if (isNewlyInVehicle) { isNewlyInVehicle = false; //BasicText message = new BasicText(); //message.ShowMessage("This Message Will Fade In 10 Seconds", 10); } if (Player.main.motorMode == Player.MotorMode.Seaglide) { // hack the controls } bool triggerState = (Input.GetAxisRaw("ControllerAxis3") > 0) || (Input.GetAxisRaw("ControllerAxis3") < 0); if (isTriggerDown) { if (triggerState) { //do nothing } else { isTriggerDown = false; isTriggerNewlyUp = true; } } else { if (triggerState) { isTriggerDown = true; isTriggerNewlyDown = true; } else { //do nothing } } void cameraRelinquish() { mainCam.ResetCamera(); mainCam.cinematicMode = false; mainCam.lookAroundMode = true; FreeLookPatcher.isFreeLooking = false; } if (Input.GetKeyDown(FreeLookPatcher.Config.FreeLookKey) || isTriggerNewlyDown) { Debug.Log("FreeLook: button pressed. Taking control of the camera."); FreeLookPatcher.isFreeLooking = true; isTriggerNewlyDown = false; resetCameraFlag = false; // invoke a camera vulnerability mainCam.cinematicMode = true; mainCam.lookAroundMode = false; return(false); } else if (Input.GetKeyUp(FreeLookPatcher.Config.FreeLookKey) || isTriggerNewlyUp) { isTriggerNewlyUp = false; Debug.Log("FreeLook: button released. Relinquishing control of the camera."); resetCameraFlag = true; } if (!resetCameraFlag && (Input.GetKey(FreeLookPatcher.Config.FreeLookKey) || isTriggerDown)) { resetCameraFlag = false; moveCamera(); // adding oxygen is something vehicle.update would usually do, // so we do it naively here as well. // I'm not sure that Time.deltaTime seconds worth of oxygen per frame is the right amount... OxygenManager oxygenMgr = Player.main.oxygenMgr; oxygenMgr.AddOxygen(Time.deltaTime); return(false); } if (resetCameraFlag) { mainCam.rotationX = Mathf.SmoothDampAngle(mainCam.rotationX, 0f, ref xVelocity, smoothTime); mainCam.rotationY = Mathf.SmoothDampAngle(mainCam.rotationY, 0f, ref yVelocity, smoothTime); mainCam.camRotationX = mainCam.rotationX; mainCam.camRotationY = mainCam.rotationY; mainCam.transform.localEulerAngles = new Vector3(-mainCam.camRotationY, mainCam.camRotationX, 0); double threshold = 1; if (Mathf.Abs(mainCam.camRotationX) < threshold && Mathf.Abs(mainCam.camRotationY) < threshold) { cameraRelinquish(); resetCameraFlag = false; } // need to retain control in order to finish snapping back to center return(false); } // nothing from the key and the camera has been reset, so we don't need control //cameraRelinquish(); return(true); }
/// <summary> /// (Cross-Game compatible) Reduces how much Oxygen is consumed per breath. /// </summary> /// <param name="oxygenManager"></param> /// <param name="amount">Amount to reduce by.</param> public static void ReduceO2PerBreath(this OxygenManager oxygenManager, float amount) => AirData.OxygenPerBreath -= amount;
public static void Postfix(OxygenManager __instance) { __instance.AddOxygen(Time.deltaTime); }