Example #1
0
    private void UsePotion()
    {
        InventorySlot     potionSlot = gameState.inventory.GetInventorySlotByType(Item.ItemType.HealingConsumable);
        HealingConsumable potion     = potionSlot.item as HealingConsumable;
        bool usedItem = gameState.inventory.ConsumeItem(Item.ItemType.HealingConsumable);

        if (usedItem)
        {
            playerCharacter.healthSystem.Heal(potion.healingAmount);
        }
    }
    private Consumable DetermineConsumableScore()
    {
        //Get all types of consumables
        //Check if a specific type exists, if so then increase points
        //For example, if need health and contains HealingConsumable, increase points and set that to selectedConsumable
        //Store all types in list, List<HealingConsumable>...

        Consumable        selectedAbsoluteConsumable = null;
        HealingConsumable selectedHealingConsumable  = null;
        //Seperate all current consumables into list
        List <HealingConsumable> healingConsumables = data.Consumables.Where(c => c is HealingConsumable)
                                                      .Select(c => c as HealingConsumable)
                                                      .ToList();
        int healingScore = -1;

        if (data.MaxHealth != data.CurrentHealth && healingConsumables.Count > 0)
        {
            selectedHealingConsumable = healingConsumables[0];
            healingScore = (data.MaxHealth - data.CurrentHealth) + selectedHealingConsumable.HealingValue;
            for (int i = 1; i < healingConsumables.Count; i++)
            {
                int _value = (data.MaxHealth - data.CurrentHealth) + healingConsumables[i].HealingValue;
                if (_value < healingScore)
                {
                    healingScore = _value;
                    selectedHealingConsumable = healingConsumables[i];
                }
            }
        }

        if (selectedHealingConsumable != null)
        {
            int healthDifference = data.MaxHealth - data.CurrentHealth;
            //print("Healing score: "+ healingScore + " health diff: "+healthDifference);
            //Potion would replenish all health
            if (selectedHealingConsumable.HealingValue == healthDifference)
            {
                consumableScore += 75;
            }
            else if (selectedHealingConsumable.HealingValue < healthDifference)
            {
                consumableScore += 150;
            }

            //else if(healingScore < healthDifference && healthDiffernce > )
            //TODO change this
            selectedAbsoluteConsumable = selectedHealingConsumable;
        }

        return(selectedAbsoluteConsumable);
    }