/// <summary> /// Returns true if a consumable was consumed or a healing attack was used and false otherwise /// </summary> /// <param name="user">The enemy consuming the consumable</param> /// <param name="stat">The stat to evaluate</param> /// <returns>True if a consumable was consumed and false otherwise</returns> public static bool AutoConsume(Enemy user, GameBase.Stats stat, double statPercentage) { if (user.InventoryConsumables.Count < 1) { return(false); } int i = (int)stat; if (user.PercentStats[i] >= statPercentage) { return(false); } Consumable consumable = FindUsableConsumable(user, stat); Attack bestHealyAttack = user.FindBestHealingAttack(user, stat); if (consumable != null && bestHealyAttack != null) { if (consumable.GetLifetimeStatGain(user, stat) > (bestHealyAttack.GetLifetimeStatLoss(user, stat) * -1) / (bestHealyAttack.ChargeUp + 1)) { user.Consume(consumable); } else { user.DoAttack(bestHealyAttack, user); } return(true); } else if (consumable != null) { user.Consume(consumable); return(true); } else if (bestHealyAttack != null) { user.DoAttack(bestHealyAttack, user); return(true); } else { return(false); } }
public static Consumable FindUsableConsumable(Enemy user, GameBase.Stats stat) { if (user.InventoryConsumables.Count < 1) { return(null); } int statToRecover = user.ArmoredStats[(int)stat] - user.CurrentStats[(int)stat]; int minimumDifference = int.MaxValue; Consumable selectedConsumable = null; //Find the consumable that completly heals the user without wasting very good consumables foreach (Consumable consumable in user.InventoryConsumables) { //The higher the user's intellect, the less likely they will use a potion with more negative side effects. //This check is ignored if the potion's util is above or equal to 10 if (user.ArmoredStats[(int)GameBase.Stats.Int] > consumable.GetUtils(user) && consumable.GetUtils(user) < 10) { continue; } int hpGain = consumable.GetLifetimeStatGain(user, stat); if (hpGain > statToRecover) { if (statToRecover - hpGain < minimumDifference) { selectedConsumable = consumable; minimumDifference = statToRecover - hpGain; } } } //Consumable that can fully replenish does not exist. if (selectedConsumable == null) { int maxStat = 0; foreach (Consumable consumable in user.InventoryConsumables) { //The higher the user's intellect, the less likely they will use a potion with more negative side effects. //This check is ignored if the potion's util is above or equal to 10 if (user.ArmoredStats[(int)GameBase.Stats.Int] > consumable.GetUtils(user) && consumable.GetUtils(user) < 10) { continue; } else if (consumable.GetLifetimeStatGain(user, stat) > maxStat) { selectedConsumable = consumable; maxStat = consumable.GetLifetimeStatGain(user, stat); } } } return(selectedConsumable); //If recovering mana is better, just recover mana //if (selectedConsumable != null && stat == GameBase.Stats.Mana && (int)Math.Round(user.LeveledStats[1] * 0.3) > selectedConsumable.GetLifetimeStatGain(user, GameBase.Stats.Mana)) // user.RecoverMana(); ////Else consume the item if it is not null //else if (selectedConsumable != null) // user.Consume(selectedConsumable); ////Else throw exception //else // return null; }