/// <summary> /// Returns true if the provided CombatEntity has enough resources to use an Ability. /// </summary> /// <param name="attacker">The attacking CombatEntity.</param> /// <param name="ability">The ability being used by the CombatEntity.</param> /// <returns></returns> private bool HasEnoughResources(CombatEntity attacker, Ability ability, out string failureReason) { failureReason = ""; int actionPointCost = ResourceCalculator.GetTotalActionPointCost(attacker, ability); int manaCost = ResourceCalculator.GetTotalManaCost(attacker, ability); int healthCost = ResourceCalculator.GetTotalHealthCost(attacker, ability); if (attacker.Resources.CurrentActionPoints < actionPointCost) { failureReason = BattleErrorWriter.WriteInsufficientActionPoints(attacker, ability); return(false); } if (attacker.Resources.CurrentMana < manaCost) { failureReason = BattleErrorWriter.WriteInsufficientMana(attacker, ability); return(false); } if (attacker.Resources.CurrentHealth < healthCost) { failureReason = BattleErrorWriter.WriteInsufficientHealth(attacker, ability); return(false); } return(true); }
/// <summary> /// Returns a string indicating that the entity cannot use an ability because it doesn't have enough /// action points. /// </summary> /// <param name="entity">The CombatEntity of focus.</param> /// <param name="ability">The ability being used.</param> public static string WriteInsufficientActionPoints(CombatEntity entity, Ability ability) { int totalActionPointCost = ResourceCalculator.GetTotalActionPointCost(entity, ability); return($"{entity.Name} does not have enough Action Points to use {ability.Name}. {ability.Name} " + $"requires {totalActionPointCost} Action Points, {entity.Name} has {entity.Resources.CurrentActionPoints}."); }
/// <summary> /// Consumes the resources required to use the ability from the attacker. /// </summary> /// <param name="attacker">The CombatEntity using the ability.</param> /// <param name="ability">The Ability to get consumed resource amounts from.</param> private static void ConsumeResources(CombatEntity attacker, Ability ability) { int actionPointCost = ResourceCalculator.GetTotalActionPointCost(attacker, ability); int manaCost = ResourceCalculator.GetTotalManaCost(attacker, ability); int healthCost = ResourceCalculator.GetTotalHealthCost(attacker, ability); attacker.Resources.CurrentActionPoints -= actionPointCost; attacker.Resources.CurrentMana -= manaCost; attacker.Resources.CurrentHealth -= healthCost; }