public void EatFood(ConsumableItem food, int number)
        {
            float cal = food.GetCalories() * number;

            bodyManager.AddCalories(cal);

            float size = food.GetSize() * number;

            fullnessPoints.value += size;
        }
Esempio n. 2
0
        private IEnumerator BuildConsumableList()
        {
            float upperBound = fullness.GetMaxAttributeValue() * (maxFullness - hungerValue) / 100;
            int   invSize    = inventory.GetSize();

            consumableIndex.Clear();
            for (int i = 0; i < invSize; i++)
            {
                ConsumableItem food = inventory.GetItemInSlot(i) as ConsumableItem;
                if (food == null)
                {
                    continue;
                }

                if (food.GetSize() <= upperBound)
                {
                    consumableIndex.Add(i);
                }

                yield return(null);
            }
        }
Esempio n. 3
0
        private string GetItemToEat()
        {
            int foodIndex = consumableIndex[Random.Range(0, consumableIndex.Count)];

            currentFood = inventory.GetItemInSlot(foodIndex) as ConsumableItem;
            int   qty        = inventory.GetCountInSlot(foodIndex);
            float foodSize   = currentFood.GetSize();
            float lowerBound = fullness.GetMaxAttributeValue() * (preferredFullness - starveValue) / 100;
            int   qtyToEat   = 1;

            if (foodSize < lowerBound)
            {
                qtyToEat = Mathf.Min(qty, Mathf.CeilToInt(lowerBound / foodSize));
            }

            // Remove item from consumable list if it'll empty the slot's stack
            if (qtyToEat >= qty)
            {
                consumableIndex.Remove(foodIndex);
            }

            // Cache info about the item for action completion
            consumedItem         = new int[2];
            consumedItem[0]      = foodIndex;
            consumedItem[1]      = qtyToEat;
            actionModifier       = 1f;
            timeToAct            = foodSize / eatingSpeed;
            isEatingActive       = true;
            timeSinceActionStart = 0;
            string s = "Eating " + qtyToEat + " " + currentFood.GetDisplayName();

            Sprite sprite = currentFood.GetIcon();

            SpawnHitTimer(sprite);

            return(s);
        }