예제 #1
0
        internal static bool Prefix(Survival __instance)
        {
            weakness = 1;

            var weakSpeedThreshold = __instance.GetWeakSpeedThreshold();

            if (__instance.food < __instance.GetLowFoodThreshold())
            {
                weakness -= (weakSpeedThreshold - __instance.food) * 0.02f;
            }
            if (__instance.water < __instance.GetLowWaterThreshold())
            {
                weakness -= (weakSpeedThreshold - __instance.water) * 0.02f;
            }

            return(false);
        }
예제 #2
0
        private void NewPrefixPatch(Survival __instance, float timePassed)
        {
            totalFoodThirstDamage = 0f;
            const float minimumPastTime = 1.401298E-45f;

            if (minimumPastTime > timePassed)
            {
                return;
            }

            float startingFood  = __instance.food;
            float startingWater = __instance.water;

            UpdateFood(__instance, timePassed);
            UpdateWater(__instance, timePassed);

            __instance.UpdateWarningSounds(__instance.foodWarningSounds, __instance.food, startingFood, __instance.GetLowFoodThreshold(),
                                           __instance.GetCriticalFoodThreshold());

            __instance.UpdateWarningSounds(__instance.waterWarningSounds, __instance.water, startingWater, __instance.GetLowWaterThreshold(),
                                           __instance.GetCriticalWaterThreshold());
        }
예제 #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)
        {
            bool flag = false;

            if (useObj != null)
            {
                Eatable component = useObj.GetComponent <Eatable>();
                if (component != null)
                {
                    bool flag2 = component.maxCharges == 0 || component.charges > 0;
                    if (component.GetFoodValue() != 0f && flag2)
                    {
                        if (__instance.food <= __instance.GetStomachSize() - 1)
                        {
                            __instance.food = Mathf.Clamp(__instance.food + component.GetFoodValue(), __instance.GetMinStomachSize(), __instance.GetStomachOverfillSize());
                        }
                        __instance.onEat.Trigger(component.GetFoodValue());
                        if (component.GetFoodValue() > 0f)
                        {
                            GoalManager.main.OnCustomGoalEvent("Eat_Something");
                        }
                        result = component.removeOnUse;
                        flag   = true;
                    }
                    if (component.GetWaterValue() != 0f && flag2)
                    {
                        __instance.water = Mathf.Clamp(__instance.water + component.GetWaterValue(), __instance.GetMinWater(), __instance.GetWaterOverfillSize());
                        __instance.onDrink.Trigger(component.GetWaterValue());
                        if (component.GetWaterValue() > 0f)
                        {
                            GoalManager.main.OnCustomGoalEvent("Drink_Something");
                        }
                        result = component.removeOnUse;
                        flag   = true;
                    }
                    float healthValue = component.GetHealthValue();
                    if (healthValue != 0f && flag2)
                    {
                        if (healthValue > 0f)
                        {
                            __instance.liveMixin.AddHealth(healthValue);
                            GoalManager.main.OnCustomGoalEvent("Heal_Damage");
                        }
                        else if (healthValue <= -1f)
                        {
                            __instance.liveMixin.TakeDamage(-healthValue, default(Vector3), DamageType.FoodPoison, null);
                        }
                        result = component.removeOnUse;
                        flag   = true;
                    }
                    float coldMeterValue = component.GetColdMeterValue();
                    if (coldMeterValue != 0f && flag2)
                    {
                        __instance.bodyTemperature.AddCold(coldMeterValue);
                        result = component.removeOnUse;
                        flag   = true;
                    }
                    if (!__instance.InConversation() && ((__instance.food > __instance.GetLowFoodThreshold() && __instance.food - component.GetFoodValue() < __instance.GetLowFoodThreshold()) || (__instance.water > __instance.GetLowWaterThreshold() && __instance.water - component.GetWaterValue() < __instance.GetLowWaterThreshold())))
                    {
                        __instance.vitalsOkNotification.Play();
                    }
                }
                if (flag)
                {
                    TechType techType = CraftData.GetTechType(useObj);
                    if (techType == TechType.None)
                    {
                        Pickupable component2 = useObj.GetComponent <Pickupable>();
                        if (component2)
                        {
                            techType = component2.GetTechType();
                        }
                    }
                    FMODAsset useSound = __instance.player.GetUseSound(TechData.GetSoundType(techType));
                    if (useSound)
                    {
                        Utils.PlayFMODAsset(useSound, __instance.player.transform.position, 20f);
                    }
                    if (component.IsRotten())
                    {
                        Utils.PlayFMODAsset(__instance.ateRottenFoodSound, __instance.player.transform.position, 20f);
                    }
                    if (techType == TechType.Bladderfish)
                    {
                        Player.main.GetComponent <OxygenManager>().AddOxygen(__instance.GetO2FromBlatterfish());
                    }
                    if (component.maxCharges > 0)
                    {
                        component.ConsumeCharge();
                    }
                }
            }
        }
예제 #4
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());
                    }
                }
            }
        }