public static bool Prefix(HintSwimToSurface __instance, ref bool __result, int ___numShown)
        {
            Player main = Player.main;

            if (main == null)
            {
                __result = false;
                return(false);
            }
            if (___numShown >= __instance.maxNumToShow)
            {
                __result = false;
                return(false);
            }
            if (Ocean.main == null)
            {
                __result = false;
                return(false);
            }
            float   oxygenAvailable = main.GetOxygenAvailable();
            float   depthOf         = Ocean.GetDepthOf(main.gameObject);
            Vehicle vehicle         = main.GetVehicle();

            __result = (oxygenAvailable <__instance.oxygenThreshold && depthOf> 0f && main.IsSwimming()) || (vehicle != null && !vehicle.IsPowered());
            return(false);
        }
        internal float GetDepth()
        {
#if SUBNAUTICA
            return(gameObject == null ? 0f : Ocean.main.GetDepthOf(gameObject));
#elif BELOWZERO
            return(gameObject == null ? 0f : Ocean.GetDepthOf(gameObject));
#endif
        }
Esempio n. 3
0
        public static bool GetDepthClass(Player __instance, ref Ocean.DepthClass __result)
        {
            Ocean.DepthClass result      = Ocean.DepthClass.Surface;
            CrushDamage      crushDamage = null;

            var currSub = __instance.currentSub;
            var mode    = (Mode)PlayerPatches.mode.GetValue(__instance);
            var living  = (Living)__instance;

            if ((currSub != null && !currSub.isBase) || mode == Mode.LockedPiloting)
            {
                crushDamage = ((!(currSub != null)) ? living.gameObject.GetComponentInParent <CrushDamage>() : currSub.gameObject.GetComponent <CrushDamage>());
            }
            if (crushDamage != null)
            {
                result = crushDamage.GetDepthClass();
                __instance.crushDepth = crushDamage.crushDepth;
            }
            else
            {
                var c = GameModeUtilsPatches.currentConfig.Oxygen;

                __instance.crushDepth = 0f;
                float depthOf = Ocean.GetDepthOf(living.gameObject);
                if (depthOf > c.DeficiencyDepths[1])
                {
                    result = Ocean.DepthClass.Crush;
                }
                else if (depthOf > c.DeficiencyDepths[0])
                {
                    result = Ocean.DepthClass.Unsafe;
                }
                else if (depthOf > __instance.GetSurfaceDepth())
                {
                    result = Ocean.DepthClass.Safe;
                }
            }

            __result = result;
            return(false);
        }
Esempio n. 4
0
        public static void Postfix()
        {
            if (modCheck)
            {
                TechTypeHandler.TryGetModdedTechType("ScubaManifold", out scubaManifold);
                TechTypeHandler.TryGetModdedTechType("photosynthesissmalltank", out photosynthesisSmall);
                TechTypeHandler.TryGetModdedTechType("photosynthesistank", out photosynthesisTank);
                TechTypeHandler.TryGetModdedTechType("chemosynthesistank", out chemosynthesisTank);
                modCheck = false;
            }

            if (scubaManifold != TechType.None && photosynthesisSmall != TechType.None && photosynthesisTank != TechType.None && chemosynthesisTank != TechType.None)
            {
                var tankSlot = Inventory.main.equipment.GetTechTypeInSlot("Tank");
                if (GameModeUtils.RequiresOxygen() && Player.main.IsSwimming() && tankSlot == scubaManifold)
                {
                    var photosynthesisTanks = Inventory.main.container.GetCount(photosynthesisSmall) + Inventory.main.container.GetCount(photosynthesisTank);
                    var chemosynthesisTanks = Inventory.main.container.GetCount(chemosynthesisTank);

                    if (photosynthesisTanks > 0)
                    {
                        var playerDepth =
#if SN1
                            Ocean.main.GetDepthOf(Player.main.gameObject);
#else
                            Ocean.GetDepthOf(Player.main.gameObject);
#endif
                        var currentLight            = DayNightCycle.main.GetLocalLightScalar();
                        var photosynthesisDepthCalc = (currentLight > 0.9f ? 0.9f : currentLight) * Time.deltaTime * (Main.Config.multipleTanks ? photosynthesisTanks : 1) * (200f - playerDepth > 0f ? ((200 - playerDepth) / 200f) : 0);
                        Player.main.oxygenMgr.AddOxygen(photosynthesisDepthCalc);
                    }

                    if (chemosynthesisTanks > 0)
                    {
                        var waterTemp = WaterTemperatureSimulation.main.GetTemperature(Player.main.transform.position);
                        var chemosynthesisTempCalc = (waterTemp > 30f ? waterTemp : 0) * Time.deltaTime * 0.01f * (Main.Config.multipleTanks ? chemosynthesisTanks : 1);
                        Player.main.oxygenMgr.AddOxygen(chemosynthesisTempCalc);
                    }
                }
            }
        }
        public static bool Prefix(LowOxygenAlert __instance, ref Utils.ScalarMonitor ___secondsMonitor, Player ___player, ref float ___lastOxygenCapacity)
        {
            ___secondsMonitor.Update(___player.GetOxygenAvailable());
            float oxygenCapacity = ___player.GetOxygenCapacity();

            if (Utils.NearlyEqual(oxygenCapacity, ___lastOxygenCapacity, 1.401298E-45f) || oxygenCapacity < ___lastOxygenCapacity)
            {
                for (int i = __instance.alertList.Count - 1; i >= 0; i--)
                {
                    LowOxygenAlert.Alert alert = __instance.alertList[i];
                    if (oxygenCapacity >= alert.minO2Capacity && ___secondsMonitor.JustDroppedBelow((float)alert.oxygenTriggerSeconds) && Ocean.GetDepthOf(Utils.GetLocalPlayer()) > alert.minDepth && (___player.IsSwimming() || (___player.GetMode() == Player.Mode.LockedPiloting && !___player.GetVehicle().IsPowered()) || (___player.IsInSub() && !___player.CanBreathe())))
                    {
                        Subtitles.Add(alert.notification.text);
                        alert.soundSFX.Play();
                        break;
                    }
                }
            }
            ___lastOxygenCapacity = oxygenCapacity;
            return(false);
        }
 public static float GetDepth(GameObject gameObject)
 {
     return(gameObject == null ? 0f : Ocean.GetDepthOf(gameObject));
 }