/// <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); }
/// <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); } }