예제 #1
0
        private static void SurvivalPatchings(IDictionary <TechType, List <Action> > dictionary, GameObject obj, ref bool result)
        {
            TechType tt = CraftData.GetTechType(obj);

            if (dictionary.TryGetValue(tt, out List <Action> action))
            {
                action.ForEach((x) => x.Invoke());
                result = true;
            }
            if (result)
            {
#if SUBNAUTICA
#pragma warning disable CS0618 // Type or member is obsolete and yet IS still used by Subnautica itself.
                string sound = CraftData.GetUseEatSound(tt);
                if (!string.IsNullOrEmpty(sound))
                {
                    FMODUWE.PlayOneShot(sound, Player.main.transform.position); // only play the sound if its useable
                }
#pragma warning restore CS0618
#elif BELOWZERO
                FMODAsset asset = Player.main.GetUseSound(TechData.GetSoundType(tt));
                if (asset != null)
                {
                    FMODUWE.PlayOneShot(asset, Player.main.transform.position); // only play the sound if its useable
                }
#endif
            }
        }
예제 #2
0
        public static bool Prefix(ref Survival __instance, ref bool __result, GameObject useObj)
        {
            bool prefixFlag = true;

            if (useObj != null)
            {
                TechType      techType      = CraftData.GetTechType(useObj);
                NitrogenLevel nitrogenLevel = null;
                bool          nFlag         = false;

                if (Player.main.gameObject.GetComponent <NitrogenLevel>() != null)
                {
                    nitrogenLevel = Player.main.gameObject.GetComponent <NitrogenLevel>();
                    if (nitrogenLevel.safeNitrogenDepth >= 10f)
                    {
                        nFlag = true;
                    }
                }

                if (techType == TechType.FirstAidKit)
                {
                    if (Player.main.GetComponent <LiveMixin>().AddHealth(50f) > 0.1f)
                    {
                        prefixFlag = false;
                        __result   = true;
                    }

                    if (nFlag)
                    {
                        if (nitrogenLevel.safeNitrogenDepth > 10f)
                        {
                            nitrogenLevel.safeNitrogenDepth -= 10f;
                        }
                        else
                        {
                            nitrogenLevel.safeNitrogenDepth = 0f;
                        }

                        prefixFlag = false;
                        __result   = true;
                    }

                    if (__result)
                    {
                        string useEatSound = CraftData.GetUseEatSound(techType);
                        FMODUWE.PlayOneShot(useEatSound, Player.main.transform.position, 1f);
                    }
                }
            }
            return(prefixFlag);
        }
예제 #3
0
파일: Eat.cs 프로젝트: gurrenm3/Stats-Core
        /// <summary>
        /// This is a copy paste of the original <see cref="Survival.Eat(GameObject)"/> because there are too many things to transpile
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="useObj"></param>
        private void NewPrefixPatch(Survival __instance, GameObject useObj)
        {
            flag = false;
            if (useObj != null)
            {
                Eatable component = useObj.GetComponent <Eatable>();
                if (component != null)
                {
                    if (component.GetFoodValue() != 0f)
                    {
                        float miniFoodOverfill = __instance.GetStomachSize() - 1;
                        if (__instance.food <= miniFoodOverfill)
                        {
                            __instance.food = Mathf.Clamp(__instance.food + component.GetFoodValue(), 0f, __instance.GetStomachOverfillSize());
                        }
                        __instance.onEat.Trigger(component.GetFoodValue());
                        if (component.GetFoodValue() > 0f)
                        {
                            GoalManager.main.OnCustomGoalEvent("Eat_Something");
                        }
                        flag = true;
                    }

                    if (component.GetWaterValue() != 0f)
                    {
                        float minWaterOverfill = __instance.GetWaterCapacity() - 1;
                        if (__instance.water <= minWaterOverfill)
                        {
                            __instance.water = Mathf.Clamp(__instance.water + component.GetWaterValue(), 0f, __instance.GetWaterOverfillSize());
                        }
                        __instance.onDrink.Trigger(component.GetWaterValue());
                        if (component.GetWaterValue() > 0f)
                        {
                            GoalManager.main.OnCustomGoalEvent("Drink_Something");
                        }
                        flag = true;
                    }

                    var lowFoodThreshold  = __instance.GetLowFoodThreshold();
                    var lowWaterThreshold = __instance.GetLowWaterThreshold();

                    bool foodOkay  = (__instance.food > lowFoodThreshold && __instance.food - component.GetFoodValue() < lowFoodThreshold);
                    bool waterOkay = (__instance.water > lowWaterThreshold && __instance.water - component.GetWaterValue() < lowWaterThreshold);
                    if (foodOkay || waterOkay)
                    {
                        __instance.vitalsOkNotification.Play();
                    }
                }


                if (flag)
                {
                    TechType techType = CraftData.GetTechType(useObj);
                    if (techType == TechType.None)
                    {
                        Pickupable component2 = useObj.GetComponent <Pickupable>();
                        if (component2)
                        {
                            techType = component2.GetTechType();
                        }
                    }
                    FMODUWE.PlayOneShot(CraftData.GetUseEatSound(techType), Player.main.transform.position, 1f);
                    if (techType == TechType.Bladderfish)
                    {
                        Player.main.GetComponent <OxygenManager>().AddOxygen(__instance.GetO2FromBlatterfish());
                    }
                }
            }
        }