Inheritance: AbstractDesire
Beispiel #1
0
            private static bool Prefix(StatusBar __instance, ref float __result)
            {
                if (__instance.m_StatusBarType != StatusBar.StatusBarType.Hunger)
                {
                    return(true);
                }

                HungerRevamped hungerRevamped = HungerRevamped.Instance;
                Hunger         hunger         = hungerRevamped.hunger;

                float hungerFraction = hunger.m_CurrentReserveCalories / hunger.m_MaxReserveCalories;

                if (hungerFraction < 0.005f || hungerFraction > 0.999f)
                {
                    __result = 0f;
                }
                else
                {
                    if (hunger.IsAddingCaloriesOverTime())
                    {
                        __result = -hunger.GetCaloriesToAddOverTime();
                    }
                    else
                    {
                        __result = 0.8f * (hunger.GetCurrentCalorieBurnPerHour() + hungerRevamped.GetStoredCaloriesChangePerHour());
                    }
                }

                return(false);
            }
        internal HungerTuple SimulateHungerBar(float calorieBurnPerHour, float hours)
        {
            const int simulationStepsPerHour = 10;

            int   steps       = Mathf.CeilToInt(simulationStepsPerHour * hours);
            float todHours    = hours / steps;
            float calorieBurn = calorieBurnPerHour * todHours;

            float maxHunger = this.hunger.m_MaxReserveCalories;
            float hunger    = this.hunger.m_CurrentReserveCalories;
            float stored    = (float)storedCalories;

            // Approximate solution using midpoint method
            // This seems to be good enough of an approximation for this problem
            for (int i = 0; i < steps; ++i)
            {
                float midpointDelta  = todHours / 2 * GetStoredCaloriesChangePerHour(hunger / maxHunger, stored, calorieBurnPerHour);
                float midpointHunger = hunger - (midpointDelta + calorieBurn / 2);
                float midpointStored = stored + midpointDelta;

                // Ensure that 0 stored calories can always be reached
                midpointStored = Mathf.Clamp(midpointStored, 1f, (float)Tuning.maximumStoredCalories);

                float deltaStored = todHours * GetStoredCaloriesChangePerHour(midpointHunger / maxHunger, midpointStored, calorieBurnPerHour);
                deltaStored = ClampCalorieChange(deltaStored, hunger, maxHunger, stored);
                stored     += deltaStored;
                hunger     -= deltaStored + calorieBurn;
            }

            stored = Mathf.Clamp(stored, 0f, (float)Tuning.maximumStoredCalories);
            hunger = Mathf.Clamp(hunger, 0f, maxHunger);

            return(new HungerTuple(stored, hunger / maxHunger));
        }
Beispiel #3
0
        public void Update(Creature creature, DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Hunger.CurrentValue -= dt * creature.Stats.HungerGrowth;

            Health.CurrentValue = (creature.Hp - creature.MinHealth) / (creature.MaxHealth - creature.MinHealth);

            if (creature.Stats.CanSleep)
            {
                Energy.CurrentValue = (float)(100 * Math.Sin(PlayState.Time.GetTotalHours() * Math.PI / 24.0f));
            }
            else
            {
                Energy.CurrentValue = 100.0f;
            }

            if (Energy.IsUnhappy())
            {
                creature.DrawIndicator(IndicatorManager.StandardIndicators.Sleepy);
            }

            if (creature.Stats.CanEat && Hunger.IsUnhappy())
            {
                creature.DrawIndicator(IndicatorManager.StandardIndicators.Hungry);

                if (Hunger.CurrentValue <= 1e-12 && (DateTime.Now - LastHungerDamageTime).TotalSeconds > HungerDamageRate)
                {
                    creature.Damage(1.0f / (creature.Stats.HungerResistance) * HungerDamageRate);
                    LastHungerDamageTime = DateTime.Now;
                }
            }
        }
Beispiel #4
0
            private static void Postfix(string name)
            {
                string json = SaveGameSlots.LoadDataFromSlot(name, SAVE_SLOT_NAME);

                if (string.IsNullOrEmpty(json))
                {
                    return;
                }

                HungerRevamped hungerRevamped = HungerRevamped.Instance;

                JSON.Load(json).Populate(saveDataProxy);

                hungerRevamped.storedCalories     = saveDataProxy.storedCalories + Tuning.defaultStoredCalories;
                hungerRevamped.wellFedHungerScore = saveDataProxy.wellFedHungerScore;
                hungerRevamped.deferredFoodPoisonings.Clear();
                if (saveDataProxy.deferredFoodPoisonings != null)
                {
                    hungerRevamped.deferredFoodPoisonings.AddRange(saveDataProxy.deferredFoodPoisonings);
                }

                Hunger hunger = GameManager.GetHungerComponent();

                hunger.m_CurrentReserveCalories = Mathf.Min(hunger.m_CurrentReserveCalories, hunger.m_MaxReserveCalories);
            }
Beispiel #5
0
 public void Start()
 {
     crunchSound = GetComponent <AudioSource>();
     originalPos = transform.position;
     plateVec    = platingArea.gameObject.transform.position;
     babyHunger  = baby.GetComponent <Hunger>();
 }
Beispiel #6
0
            private static void Postfix(Panel_Rest __instance)
            {
                PlayerManager playerManager = GameManager.GetPlayerManagerComponent();
                Hunger        hunger        = GameManager.GetHungerComponent();

                float calorieBurnRate;

                if (__instance.m_ShowPassTime)
                {
                    calorieBurnRate = playerManager.CalculateModifiedCalorieBurnRate(hunger.m_CalorieBurnPerHourStanding);
                }
                else
                {
                    calorieBurnRate = playerManager.CalculateModifiedCalorieBurnRate(hunger.m_CalorieBurnPerHourSleeping);
                }

                if (!GameManager.GetPassTime().IsPassingTime())
                {
                    lastSimulation = HungerRevamped.Instance.SimulateHungerBar(calorieBurnRate, __instance.m_SleepHours);
                }

                UILabel storedCaloriesLabel = __instance.m_CalorieReservesLabel;
                int     storedCalories      = Mathf.RoundToInt(lastSimulation.storedCalories);

                storedCaloriesLabel.text = storedCalories.ToString();

                UILabel hungerPercentLabel = __instance.m_EstimatedCaloriesBurnedLabel.GetComponent <UILabel>();
                int     hungerPercent      = Mathf.FloorToInt(lastSimulation.hungerRatio * 100f);

                hungerPercentLabel.text  = hungerPercent.ToString() + "%";
                hungerPercentLabel.color = (lastSimulation.hungerRatio >= Tuning.hungerLevelStarving) ? Color.white : __instance.m_NegativeTemperatureColor;
            }
Beispiel #7
0
            private static void Postfix(Panel_FirstAid __instance)
            {
                Color red   = __instance.m_PoorHealthStatusColor;
                Color green = InterfaceManager.m_Panel_ActionsRadial.m_FirstAidBuffColor;

                // Replace hunger bar calories with stored calories
                double storedCalories = HungerRevamped.Instance.storedCalories;

                __instance.m_CalorieStoreLabel.text  = Convert.ToInt64(storedCalories).ToString();
                __instance.m_CalorieStoreLabel.color = (storedCalories < 250.0) ? red : Color.white;

                // Set status labels to red when below starving hunger ratio
                Hunger hunger      = HungerRevamped.Instance.hunger;
                float  hungerRatio = Mathf.Clamp01(hunger.m_CurrentReserveCalories / hunger.m_MaxReserveCalories);

                __instance.m_HungerPercentLabel.color = (hungerRatio < Tuning.hungerLevelStarving) ? red : Color.white;
                __instance.m_HungerStatusLabel.color  = (hungerRatio < Tuning.hungerLevelStarving) ? red : green;

                // Adjust hunger status labels (starving, ravenous, hungry, peckish, full)
                int hungerLevel = 0;

                while (hungerLevel < HUNGER_LEVELS.Length && hungerRatio >= HUNGER_LEVELS[hungerLevel])
                {
                    ++hungerLevel;
                }
                __instance.m_HungerStatusLabel.text = Localization.Get(__instance.m_HungerStatusLocIDs[hungerLevel]);

                // Adjust stored calories freezing bonus
                Transform container   = __instance.m_WindchillLabel.gameObject.transform.parent.parent;
                UILabel   label       = container.Find("StoredCaloriesWarmthLabel/Stat Value").GetComponent <UILabel>();
                float     warmthBonus = HungerRevamped.Instance.GetStoredCaloriesWarmthBonus();

                label.text  = Utils.GetTemperatureString(warmthBonus, true, true, false);
                label.color = (warmthBonus >= 0) ? Color.white : __instance.m_PoorHealthStatusColor;
            }
Beispiel #8
0
    void UpdateHunger()
    {
        Timestamp currentTime = timeManager.GetTime();
        uint      hoursUntilDeadFromHunger = timeManager.HoursBetweenTimestamps(currentTime, timeWhenDeadToHunger);

        if (hoursUntilDeadFromHunger == 0)
        {
            Debug.Log("Character died due to hunger");
            Kill();
        }
        else if (hoursUntilDeadFromHunger < hoursBelowForVeryHungry)
        {
            hunger = Hunger.VERY_HUNGRY;
        }
        else if (hoursUntilDeadFromHunger < hoursBelowForHungry)
        {
            hunger = Hunger.HUNGRY;
        }
        else if (hoursUntilDeadFromHunger < hoursBelowForSlightlyHungry)
        {
            hunger = Hunger.SLIGHTLY_HUNGRY;
        }
        else
        {
            hunger = Hunger.WELL_FED;
        }
    }
    void Start()
    {
        farmManager   = GetComponent <FarmManager> ();
        playerHunger  = GameObject.Find("Player").GetComponent <Hunger> ();
        reportManager = GetComponent <ReportManager> ();

        GenerateHungerBar();
    }
Beispiel #10
0
        public void TestHunger()
        {
            var hunger = new Hunger();

            hunger.Execute(_tamagotchi);

            Assert.IsTrue(_tamagotchi.Hunger >= 15 && _tamagotchi.Hunger <= 35);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Dwarf  dwarf1   = new Dwarf();
            Hunger findFood = new Hunger(dwarf1);

            findFood.Tick();
            findFood.IncreaseHunger();
        }
Beispiel #12
0
        void Start()
        {
            playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <Health>();
            playerHunger = playerHealth.GetComponent <Hunger>();

            UpdatePlayerHealthUI(playerHealth.CurrentHealth, playerHealth.maxHealth);
            UpdatePlayerHungerUI(playerHunger.CurrentHunger, playerHunger.maxHunger);
        }
Beispiel #13
0
    private void Awake()
    {
        fish     = GetComponent <Fish>();
        hunger   = GetComponent <Hunger>();
        animator = GetComponent <Animator>();

        fishMouth = transform.Find("Fish Mouth");
    }
Beispiel #14
0
        protected override AICharacter RandomBuild(Pg.Level level)
        {
            var lvl = ((int)level);

            Name = Name.ValueIfNotNullOrElse("Orc");
            // God - can be null
            Stats = Stats.ValueIfNotNullOrElse(new GodsWill_ASCIIRPG.Stats(
                                                   StatsBuilder.RandomStats(
                                                       new Dictionary <StatsType, int>()
            {
                { StatsType.Strength, 2 },
                { StatsType.Toughness, 2 },
                { StatsType.Mental, -2 },
                { StatsType.InnatePower, -2 },
            })));
            var toughMod = ((Stats)Stats)[StatsType.Toughness].ModifierOfStat();

            MaximumPf = CurrentPf.ValueIfNotNullOrElse(Orc.healthDice.Max
                                                       + Dice.Throws(Orc.healthDice, lvl)
                                                       + lvl * toughMod);
            CurrentPf = MaximumPf.ValueIfNotNullOrElse((int)MaximumPf);
            Hunger    = Hunger.ValueIfNotNullOrElse((Orc.hungerDice.Max
                                                     + Dice.Throws(Orc.hungerDice, lvl))
                                                    * toughMod);
            MyAI               = MyAI.ValueIfNotNullOrElse(new SimpleAI());
            MySensingMethod    = MySensingMethod.ValueIfNotNullOrElse(AI.SensingAlgorythms.AllAround);
            PerceptionDistance = PerceptionDistance.ValueIfNotNullOrElse(5);
            //WornArmor - Can be null
            //EmbracedShield - Can be null
            //HandledWeapon - Can be null
            Backpack    = Backpack.ValueIfNotNullOrElse(new Backpack());
            Symbol      = Symbol.ValueIfNotNullOrElse("o");
            Color       = Color.ValueIfNotNullOrElse(System.Drawing.Color.DarkOliveGreen);
            Description = Description.ValueIfNotNullOrElse("A greenish, smelly human-like creature. Strong, but usually not very smart.");
            Position    = Position.ValueIfNotNullOrElse(new Coord());
            AlliedTo    = AlliedTo.ValueIfNotNullOrElse(Allied.Enemy);

            var orc = new Orc(Name,
                              (int)CurrentPf,
                              (int)MaximumPf,
                              (int)Hunger,
                              MyAI,
                              MySensingMethod,
                              (int)PerceptionDistance,
                              (Stats)Stats,
                              WornArmor,
                              EmbracedShield,
                              HandledWeapon,
                              Backpack,
                              God,
                              Symbol,
                              (System.Drawing.Color)Color,
                              Description,
                              (Coord)Position,
                              (Allied)AlliedTo);

            return(orc);
        }
        /// <remarks>
        /// Method <c>ToString</c> generates view of pizza table.
        /// Method takes parameter <c>yournick</c> type of string which is current Name of player
        /// </remarks>
        /// <param Name="yourNick"></param>
        /// <returns>
        ///     The returned value is string representation of Pizza view.
        /// </returns>
        public string ToString(string yourNick)
        {
            StringBuilder builder = new StringBuilder();

            int entireLength = 30;

            builder.Append(new string('-', entireLength)).Append("\n");

            int spaceLength = entireLength - "|".Length - "|".Length - yourNick.Length;

            int leftSpaceLength;
            int rightSpaceLength;

            if (spaceLength % 2 == 0)
            {
                int result = spaceLength / 2;
                leftSpaceLength  = result;
                rightSpaceLength = result;
            }
            else
            {
                int result = (spaceLength - 1) / 2;
                leftSpaceLength  = result;
                rightSpaceLength = result + 1;
            }

            builder.Append("|")
            .Append(new string(' ', leftSpaceLength))
            .Append(yourNick)
            .Append(new string(' ', rightSpaceLength))
            .Append("|").Append("\n");

            builder.Append(new string('-', entireLength)).Append("\n");

            builder.Append("|").Append(new string(' ', entireLength - 2)).Append("|").Append("\n");

            ProcessFieldsToTable(entireLength, "Pizza", Name.ToString(), builder);

            builder.Append("|").Append(new string(' ', entireLength - 2)).Append("|").Append("\n");

            ProcessFieldsToTable(entireLength, "Hunger", Hunger.ToString(), builder);
            ProcessFieldsToTable(entireLength, "Sharpness", Sharpness.ToString(), builder);
            ProcessFieldsToTable(entireLength, "Flavor", Flavor.ToString(), builder);
            ProcessFieldsToTable(entireLength, "Smell", Smell.ToString(), builder);

            builder.Append("|").Append(new string(' ', entireLength - 2)).Append("|").Append("\n");

            ProcessFieldsToTable(entireLength, "Shape", Shape.ToString(), builder);

            builder.Append("|").Append(new string(' ', entireLength - 2)).Append("|").Append("\n");

            ProcessFieldsToTable(entireLength, "Score", Score.ToString(), builder);

            builder.Append("|").Append(new string(' ', entireLength - 2)).Append("|").Append("\n");
            builder.Append(new string('-', entireLength)).Append("\n");

            return(builder.ToString());
        }
Beispiel #16
0
        public void Decrease_Always_ShouldSubtractDecreaseRatexDeltaFromValue()
        {
            var hunger    = new Hunger(3.0f, 2.0f);
            var happiness = new Happiness(0.0f, 3.0f);

            hunger.Decrease(3.0f);
            happiness.Decrease(2.0f);

            Assert.Equal(-3.0f, hunger.Value);
            Assert.Equal(-6.0f, happiness.Value);
        }
Beispiel #17
0
    // Start is called before the first frame update
    void Start()
    {
        slider = GetComponent <Slider>();
        var player = GameObject.FindGameObjectWithTag("Player");

        text   = GetComponentInChildren <TextMeshProUGUI>();
        hunger = player.GetComponent <Hunger>();
        hunger.OnHungerValueChanged += OnHungerChanged_EH;

        slider.maxValue = hunger.maxHunger;
    }
Beispiel #18
0
    void Start()
    {
        rigidbody2D = GetComponent <Rigidbody2D>();
        hunger      = GetComponent <Hunger>();
        collider2D  = GetComponent <Collider2D>();

        animator = GetComponent <Animator>();
        renderer = GetComponent <SpriteRenderer>();

        playerAudio = GetComponent <AudioSource>();
    }
Beispiel #19
0
        public void Boost_Always_ShouldAddAmountToValue()
        {
            var hunger    = new Hunger(3.0f, 2.0f);
            var happiness = new Happiness(0.0f, 3.0f);

            hunger.Boost(3.0f);
            happiness.Boost(2.0f);

            Assert.Equal(6.0f, hunger.Value);
            Assert.Equal(2.0f, happiness.Value);
        }
Beispiel #20
0
    void Start()
    {
        float initialDelay = 0.0f;
        float interval     = 1.0f;

        this.genes     = GetComponent <Genes>();
        this.hunger    = GetComponent <Hunger>();
        this.thirst    = GetComponent <Thirst>();
        this.reproduce = GetComponent <Reproduce>();

        InvokeRepeating("metabolize", initialDelay, interval);
    }
    public static void UpgradeMaxHunger(float increasePercentage = 0.05f)
    {
        maxHunger *= 1 + increasePercentage;
        if (!inited)
        {
            Init();
        }
        Hunger hungerScript = player.GetComponent <Hunger>();

        hungerScript.addToHunger(maxHunger * increasePercentage);
        SaveGame();
    }
        protected override void OnTriggerEnter2D(Collider2D other)
        {
            if (other.gameObject.CompareTag("Player"))
            {
                playerHunger = other.GetComponent <Hunger>();

                if (playerHunger.CurrentHunger != playerHunger.maxHunger)
                {
                    Pickup();
                    Destroy(this.gameObject);
                }
            }
        }
        public static void DrankAlcohol(float amount, float uptakeGameSeconds)
        {
            if (instance == null)
            {
                Implementation.Log("ModHealthManager not initialized.");
                return;
            }

            Hunger hunger                  = GameManager.GetHungerComponent();
            float  hungerScale             = Mathf.Clamp01(Math.Max(MIN_UPTAKE_SCALE, hunger.GetCalorieReserves() / hunger.m_MaxReserveCalories));
            float  scaledUptakeGameSeconds = uptakeGameSeconds * hungerScale;

            instance.alcoholUptakes.Add(AlcoholUptake.Create(amount, scaledUptakeGameSeconds));
        }
    public int tiempoEnPerderVida = 10, tiempoEnPerderHambre = 173;//segundos en los que tarda en perder vida (1296) o hambre De 100hp a 0 tarda 36 horas si no se ha alimentado y de 500 a 0 de hambre tarda 24 horas

    void Start()
    {
        accessToHealth = GameObject.Find("zombie").GetComponent <HealthBar>();
        accessToHunger = GameObject.Find("zombie").GetComponent <Hunger>();
        clock          = System.DateTime.Now;//asigno el reloj.
        mes            = clock.Month;
        dia            = clock.Day;
        hora           = clock.Hour;
        minuto         = clock.Minute;
        segundo        = clock.Second;
        //solo carga el juego si no ha sido reseteado.
        //if (PlayerPrefs.GetInt("reseted")==0)
        LoadParameters();
    }
Beispiel #25
0
            private static void Prefix(Hunger __instance)
            {
                if (__instance.m_StartHasBeenCalled)
                {
                    return;
                }

                float burnRateScale = GameManager.GetExperienceModeManagerComponent().GetCalorieBurnScale();

                __instance.m_MaxReserveCalories       = Tuning.maximumHungerCalories * burnRateScale;
                __instance.m_StarvingCalorieThreshold = Tuning.hungerLevelStarving * __instance.m_MaxReserveCalories;

                HungerRevamped.Instance = new HungerRevamped(__instance);
            }
    public override bool decide(StateController controller)
    {
        Hunger    hunger    = controller.GetComponent <Hunger>();
        Thirst    thirst    = controller.GetComponent <Thirst>();
        Reproduce reproduce = controller.GetComponent <Reproduce>();

        if (hunger.currentHunger >= thirst.currentThirst && hunger.currentHunger >= reproduce.currentReproduce)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #27
0
        internal HungerRevamped(Hunger hunger)
        {
            this.hunger            = hunger;
            deferredFoodPoisonings = new List <DeferredFoodPoisoning>();

            if (GameManager.InCustomMode() || IsRelentlessNightGame())
            {
                storedCalories = CustomModeSettings.settings.startingStoredCalories;
            }
            else
            {
                storedCalories = Tuning.startingStoredCalories;
            }
            wellFedHungerScore = Tuning.startingWellFedHungerScore;
        }
Beispiel #28
0
    // the food this animal is currently moving toward, if any

    void Start()
    {
        maxSpeed                   = 1f;
        spawnPosition              = animalBody.position;
        timeSinceDirectionChange   = 0f;
        timeBetweenDirectionChange = 0f;
        roamDistance               = 2f;
        GetComponent <Rigidbody>().freezeRotation = true;
        gameObject.AddComponent <Hunger>();
        hunger = gameObject.GetComponent <Hunger>();
        hunger.hungerPoints = hungerPoints;
        hunger.hungerTimer  = hungerTimer;
        hunger.coinsOnEat   = coinsOnEat;
        SpecificStart();
        animalCollider = GetComponent <BoxCollider>();
    }
Beispiel #29
0
    public void SwapPet(int newActivePet) //This is a function we can call on our buttons to swap the pets. The number represents what element in the list it is.
    {
        foreach (Pet pet in m_Pets)
        {
            pet.gameObject.SetActive(false);
        }

        m_ActivePet = newActivePet;

        m_Pets[m_ActivePet].gameObject.SetActive(true);

        CurrentPetHappinessScript = m_Pets[m_ActivePet].GetComponent <Happiness>();
        CurrentPetHungerScript    = m_Pets[m_ActivePet].GetComponent <Hunger>();

        UpdateListeners();
    }
    public Conditions(Creature own)
    {
        Own  = own;
        list = new List <ACondition>();
        Age age = new Age(Own);

        list.Add(age);
        Energy energy = new Energy(Own);

        list.Add(energy);
        Hunger hunger = new Hunger(Own);

        list.Add(hunger);
        Health health = new Health(Own);

        list.Add(health);
        Pregnant pregnant = new Pregnant(Own);

        list.Add(pregnant);
        //bars
        RectTransform[] arr = Own.GetComponentsInChildren <RectTransform>();
        foreach (var item in arr)
        {
            switch (item.name)
            {
            case "Health":
                health.Bar = item;
                break;

            case "Energy":
                energy.Bar = item;
                break;

            case "Hunger":
                hunger.Bar = item;
                break;

            case "Age":
                age.Bar = item;
                break;

            case "Pregnant":
                pregnant.Bar = item;
                break;
            }
        }
    }