/// <summary> /// Attempts to afflict the entity with a StatusEffect based on its properties and status percentage for the StatusEffect. /// </summary> /// <param name="inflictionChance">The chance of inflicting the StatusEffect.</param> /// <param name="status">The StatusEffect to afflict the entity with.</param> /// <returns>true if the StatusEffect was successfully afflicted, false otherwise.</returns> public bool TryAfflictStatus(double inflictionChance, StatusEffect status) { //Test for StatusEffect immunity - if the entity is immune to a particular alignment, don't allow the StatusEffect to be inflicted bool positiveStatusImmune = GetAdditionalProperty <bool>(AdditionalProperty.PositiveStatusImmune); bool negativeStatusImmune = GetAdditionalProperty <bool>(AdditionalProperty.NegativeStatusImmune); bool neutralStatusImmune = GetAdditionalProperty <bool>(AdditionalProperty.NeutralStatusImmune); if ((status.Alignment == StatusEffect.StatusAlignments.Positive && positiveStatusImmune == true) || (status.Alignment == StatusEffect.StatusAlignments.Negative && negativeStatusImmune == true) || (status.Alignment == StatusEffect.StatusAlignments.Neutral && neutralStatusImmune == true)) { return(false); } StatusPropertyHolder statusProperty = GetStatusProperty(status.StatusType); //If the entity is immune to this particular StatusEffect, don't allow it to be inflicted if (statusProperty.Immune == true) { Debug.Log($"{Entity.Name} is immune to {status.StatusType}!"); return(false); } //Test the percentage double percentage = statusProperty.StatusPercentage; return(UtilityGlobals.TestRandomCondition(inflictionChance, percentage)); }
/// <summary> /// Helper method to add and remove immunities. /// All StatusProperties on the BattleEntity are preserved. /// </summary> /// <param name="statusType">The StatusType to add or remove an immunity for.</param> /// <param name="immune">Whether the BattleEntity is immune to the StatusType or not.</param> private void AddRemoveImmunity(Enumerations.StatusTypes statusType, bool immune) { //Get the StatusProperty StatusPropertyHolder statusProperty = EntityEquipped.EntityProperties.GetStatusProperty(statusType); //Fill in all of the existing StatusProperty's information to preserve it //The only difference is the immunity value EntityEquipped.EntityProperties.AddStatusProperty(statusType, new StatusPropertyHolder(statusProperty.StatusPercentage, statusProperty.AdditionalTurns, immune)); }
/// <summary> /// Adds a StatusProperty for a particular StatusEffect to the entity. /// If a StatusProperty already exists for a StatusEffect, it will be replaced. /// </summary> /// <param name="statusType">The StatusType of the StatusEffect.</param> /// <param name="statusProperty">The StatusPropertyHolder associated with the StatusEffect.</param> public void AddStatusProperty(StatusTypes statusType, StatusPropertyHolder statusProperty) { if (HasStatusProperty(statusType) == true) { Debug.Log($"Replacing {nameof(StatusPropertyHolder)} for the {statusType} Status as {Entity.Name} already has one!"); StatusProperties.Remove(statusType); } StatusProperties.Add(statusType, statusProperty); }