///<summary> ///Adds a Resistance on the BattleEntity ///</summary> ///<param name="element">The element the BattleEntity is resistant to</param> ///<param name="resistanceHolder">The data for the Resistance</param> public void AddResistance(Elements element, ResistanceHolder resistanceHolder) { if (HasResistance(element) == false) { Resistances.Add(element, new List <ResistanceHolder>()); } Resistances[element].Add(resistanceHolder); Debug.Log($"Added {resistanceHolder.ResistanceType} Resistance 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 Resistance on the BattleEntity /// </summary> /// <param name="element">The Element the BattleEntity is resistant to</param> public void RemoveResistance(Elements element, ResistanceHolder resistanceHolder) { if (HasResistance(element) == false) { Debug.LogWarning($"{Entity.Name} does not have a resistance for {element}"); return; } bool removed = Resistances[element].Remove(resistanceHolder); if (Resistances[element].Count == 0) { Resistances.Remove(element); } if (removed == true) { Debug.Log($"Removed {resistanceHolder.ResistanceType} Resistance to the {element} Element on {Entity.Name}!"); } }
/// <summary> /// Gets this entity's total resistance to a particular Element /// </summary> /// <param name="element">The element to test a resistance towards</param> /// <returns>A copy of the ResistanceHolder associated with the element if found, otherwise default resistance data</returns> public ResistanceHolder GetResistance(Elements element) { if (HasResistance(element) == false) { //Debug.Log($"{Entity.Name} does not have a resistance for {element}"); return(ResistanceHolder.Default); } ResistanceHolder resistanceHolder = default(ResistanceHolder); //Get the total resistance Resistances[element].ForEach((resistance) => { resistanceHolder.Value += resistance.Value; //Stronger ResistanceTypes are prioritized if (resistance.ResistanceType > resistanceHolder.ResistanceType) { resistanceHolder.ResistanceType = resistance.ResistanceType; } }); return(resistanceHolder); }