/// <summary> /// Adds a Weakness on the BattleEntity /// </summary> /// <param name="element">The Element the BattleEntity is weak to</param> /// <param name="weaknessHolder">The data for the Weakness</param> public void AddWeakness(Elements element, WeaknessHolder weaknessHolder) { if (HasWeakness(element) == false) { Weaknesses.Add(element, new List <WeaknessHolder>()); } Weaknesses[element].Add(weaknessHolder); Debug.Log($"Added {weaknessHolder.WeaknessType} Weakness to {Entity.Name} for the {element} Element!"); }
/// <summary> /// Calculates the result of elemental damage on a BattleEntity, based on its weaknesses and resistances to that Element. /// </summary> /// <param name="victim">The BattleEntity being damaged.</param> /// <param name="element">The element the entity is attacked with.</param> /// <param name="damage">The initial damage of the attack.</param> /// <returns>An ElementDamageHolder stating the result and final damage dealt to this entity.</returns> private static ElementDamageResultHolder GetElementalDamage(BattleEntity victim, Elements element, int damage) { ElementDamageResultHolder elementDamageResult = new ElementDamageResultHolder(ElementInteractionResult.Damage, damage); //NOTE: If an entity is both resistant and weak to a particular element, they cancel out. //I decided to go with this approach because it's the simplest for this situation, which //doesn't seem desirable to begin with but could be interesting in its application WeaknessHolder weakness = victim.EntityProperties.GetWeakness(element); ResistanceHolder resistance = victim.EntityProperties.GetResistance(element); //If there's both a weakness and resistance, return if (weakness.WeaknessType != WeaknessTypes.None && resistance.ResistanceType != ResistanceTypes.None) { return(elementDamageResult); } //Handle weaknesses if (weakness.WeaknessType == WeaknessTypes.PlusDamage) { elementDamageResult.Damage += weakness.Value; } else if (weakness.WeaknessType == WeaknessTypes.KO) { elementDamageResult.InteractionResult = ElementInteractionResult.KO; } //Handle resistances if (resistance.ResistanceType == ResistanceTypes.MinusDamage) { elementDamageResult.Damage -= resistance.Value; } else if (resistance.ResistanceType == ResistanceTypes.NoDamage) { elementDamageResult.Damage = BattleGlobals.MinDamage; } else if (resistance.ResistanceType == ResistanceTypes.Heal) { elementDamageResult.InteractionResult = ElementInteractionResult.Heal; } return(elementDamageResult); }
/// <summary> /// Removes a Weakness on the BattleEntity /// </summary> /// <param name="element">The Element the BattleEntity is weak to</param> public void RemoveWeakness(Elements element, WeaknessHolder weakness) { if (HasWeakness(element) == false) { Debug.LogWarning($"{Entity.Name} does not have a weakness for {element}"); return; } bool removed = Weaknesses[element].Remove(weakness); if (Weaknesses[element].Count == 0) { Weaknesses.Remove(element); } if (removed == true) { Debug.Log($"Removed {weakness.WeaknessType} Weakness to the {element} Element on {Entity.Name}!"); } }
/// <summary> /// Gets this entity's total weakness to a particular Element /// </summary> /// <param name="element">The Element to test a weakness for</param> /// <returns>A copy of the WeaknessHolder associated with the element if found, otherwise default weakness data</returns> public WeaknessHolder GetWeakness(Elements element) { if (HasWeakness(element) == false) { //Debug.Log($"{Name} does not have a weakness for {element}"); return(WeaknessHolder.Default); } WeaknessHolder weaknessHolder = default(WeaknessHolder); //Get the total Weakness Weaknesses[element].ForEach((weakness) => { weaknessHolder.Value += weakness.Value; //Stronger WeaknessTypes are prioritized if (weakness.WeaknessType > weaknessHolder.WeaknessType) { weaknessHolder.WeaknessType = weakness.WeaknessType; } }); return(weaknessHolder); }