Esempio n. 1
0
        /// <summary>
        /// Applies the effects of a DelayedAbility to all of its targets.
        /// </summary>
        /// <param name="ability">The DelayedAbility to apply.</param>
        /// <param name="targets">The CombatEntity targets of the DelayedAbility.</param>
        private void ApplyEffects(DelayedAbility ability, IEnumerable <CombatEntity> targets)
        {
            foreach (var target in targets)
            {
                var damage  = DamageCalculator.GetTotalDamage(ability.StoredDamage, target);
                int healing = ability.StoredHealing;
                healing += target.Resources.MaxHealth * ability.BaseAbility.PercentHeal / 100;

                target.Resources.CurrentHealth += healing;
                target.Resources.CurrentHealth -= DamageCalculator.GetDamageTypesAsInt(damage);
                if (target.Resources.CurrentHealth > 0)
                {
                    _statusEffectManager.Apply(target, ability.Actor, ability.BaseAbility.AppliedStatusEffects, ability.IsCrit);
                }
                else
                {
                    _statusEffectManager.RemoveAll(target);
                }
            }

            if (ability.BaseAbility.SelfAppliedStatusEffects.Any())
            {
                _statusEffectManager.Apply(ability.Actor, ability.Actor, ability.BaseAbility.SelfAppliedStatusEffects, ability.IsCrit);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Applies the effects of the ability being used on all of it's targets.
        /// </summary>
        /// <param name="attacker">The entity performing the ability.</param>
        /// <param name="ability">The ability to apply the effects of.</param>
        /// <param name="targets">The targets of the ability.</param>
        private void ApplyEffects(CombatEntity attacker, Ability ability, IEnumerable <CombatEntity> targets)
        {
            bool isCrit = IsCritical(attacker, ability);

            foreach (var target in targets)
            {
                var damage  = DamageCalculator.GetTotalDamage(attacker, target, ability, isCrit);
                var healing = DamageCalculator.GetHeal(attacker, ability, isCrit);
                healing += target.Resources.MaxHealth * ability.PercentHeal / 100;

                target.Resources.CurrentHealth += healing;
                target.Resources.CurrentHealth -= DamageCalculator.GetDamageTypesAsInt(damage);
                if (target.Resources.CurrentHealth > 0)
                {
                    _statusEffectManager.Apply(target, attacker, ability.AppliedStatusEffects, isCrit);
                    if (target.Resources.CurrentHealth > target.Resources.MaxHealth)
                    {
                        target.Resources.CurrentHealth = target.Resources.MaxHealth;
                    }
                }
                else
                {
                    _statusEffectManager.RemoveAll(target);
                    target.Resources.CurrentHealth = 0;
                }
            }

            if (ability.SelfAppliedStatusEffects.Any())
            {
                _statusEffectManager.Apply(attacker, attacker, ability.SelfAppliedStatusEffects, isCrit);
            }
        }
        /// <summary>
        /// Applies damage and healing from all StatusEffects afflicting a CombatEntity and reduces their timers by 1.
        /// Removes any StatusEffects that are expired.
        /// </summary>
        /// <param name="entity">The CombatEntity to apply damage and healing to.</param>
        public void ApplyEffects(CombatEntity entity)
        {
            var removeStatuses = new List <AppliedStatusEffect>();

            foreach (var statusEffect in entity.StatusEffects)
            {
                var damage      = DamageCalculator.GetTotalDamage(statusEffect.CumulativeDamage, entity);
                var totalChange = DamageCalculator.GetDamageTypesAsInt(damage) - statusEffect.CumulativeHeal;
                entity.Resources.CurrentHealth -= totalChange;

                statusEffect.Duration--;
                if (statusEffect.Duration == 0)
                {
                    removeStatuses.Add(statusEffect);
                }
            }

            if (entity.Resources.CurrentHealth <= 0)
            {
                RemoveAll(entity);
            }
            else
            {
                if (entity.Resources.CurrentHealth > entity.Resources.MaxHealth)
                {
                    entity.Resources.CurrentHealth = entity.Resources.MaxHealth;
                }

                entity.StatusEffects = entity.StatusEffects.Except(removeStatuses).ToList();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns true if an ability should be used for offensive purposes rather than defensive.
        /// </summary>
        /// <param name="ability">The ability to check.</param>
        /// <returns></returns>
        private bool IsAbilityOffensive(Ability ability)
        {
            bool isOffensive = ability.IsOffensive.GetValueOrDefault();

            if (ability.IsOffensive == null)
            {
                var initialDamage  = DamageCalculator.GetDamageTypesAsInt(ability.Damage);
                var initialHealing = ability.Heal;

                var damagePerStat = DamageCalculator.GetDamagePerStatAsInt(ability.DamagePerStat);
                var healPerStat   = ability.HealPerStat.GetTotalStats();

                var percentDamage = DamageCalculator.GetDamageTypesAsInt(ability.PercentDamage);
                var percentHeal   = ability.PercentHeal;

                // Compare heal vs damage, whichever is higher makes the ability defensive vs offensive
                // Places priority on percentage over per stat values and per stat values over flat values
                if (percentHeal > percentDamage)
                {
                    return(false);
                }
                else if (percentHeal < percentDamage)
                {
                    return(true);
                }
                else if (healPerStat > damagePerStat)
                {
                    return(false);
                }
                else if (healPerStat < damagePerStat)
                {
                    return(true);
                }
                else if (initialHealing > initialDamage)
                {
                    return(false);
                }
                else if (initialHealing < initialDamage)
                {
                    return(true);
                }

                // Ability deals no damage and heals no health, check status effects
                if (ability.AppliedStatusEffects.Any())
                {
                    return(AreStatusEffectsOffensive(ability.AppliedStatusEffects));
                }
                else
                {
                    return(AreStatusEffectsOffensive(ability.AppliedStatusEffects));
                }
            }

            return(isOffensive);
        }
Esempio n. 5
0
        /// <summary>
        /// Goes through all status effects and check if the net effects are offensive or defensive.
        /// </summary>
        /// <param name="statusEffects">An IEnumerable of StatusEffects to loop through.</param>
        /// <returns>Returns true if the status effects are mostly offensive.</returns>
        private bool AreStatusEffectsOffensive(IEnumerable <StatusEffect> statusEffects)
        {
            int seInitialDamage  = 0;
            int seInitialHealing = 0;
            int seDamagePerStat  = 0;
            int seHealPerStat    = 0;
            int sePercentHeal    = 0;
            int percentStats     = 0;
            int totalStats       = 0;

            // Get totals of all status effects being applied
            foreach (var statusEffect in statusEffects)
            {
                seInitialDamage  += DamageCalculator.GetDamageTypesAsInt(statusEffect.DamagePerTurn);
                seInitialHealing += statusEffect.HealPerTurn;
                seDamagePerStat  += DamageCalculator.GetDamagePerStatAsInt(statusEffect.DamagePerStatPerTurn);
                seHealPerStat    += statusEffect.HealPerStatPerTurn.GetTotalStats();
                sePercentHeal    += statusEffect.PercentHealPerTurn;
                percentStats     += statusEffect.ModifiedStatPercentages.GetTotalStats();
                totalStats       += statusEffect.ModifiedStats.GetTotalStats();
            }

            // Goes through the list of comparisons from highest priority to lowest.
            if (sePercentHeal > 0)
            {
                return(false);
            }
            else if (sePercentHeal < 0)
            {
                return(true);
            }
            else if (percentStats > 0)
            {
                return(false);
            }
            else if (percentStats < 0)
            {
                return(true);
            }
            else if (seHealPerStat > seDamagePerStat)
            {
                return(false);
            }
            else if (seHealPerStat < seDamagePerStat)
            {
                return(true);
            }
            else if (totalStats > 0)
            {
                return(false);
            }
            else if (totalStats < 0)
            {
                return(true);
            }
            else if (seInitialHealing > seDamagePerStat)
            {
                return(false);
            }
            else if (seInitialHealing < seDamagePerStat)
            {
                return(true);
            }

            // Status effects have no net effects, use in any way
            else
            {
                return(false);
            }
        }