Exemple #1
0
        /// <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
        /// health.
        /// </summary>
        /// <param name="entity">The CombatEntity of focus.</param>
        /// <param name="ability">The ability being used.</param>
        public static string WriteInsufficientHealth(CombatEntity entity, Ability ability)
        {
            int totalHealthCost = ResourceCalculator.GetTotalHealthCost(entity, ability);

            return($"{entity.Name} does not have enough Health to use {ability.Name}. {ability.Name} " +
                   $"requires {totalHealthCost} Health, {entity.Name} has {entity.Resources.CurrentHealth}.");
        }
Exemple #3
0
        /// <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;
        }