/// <summary> /// Returns a string describing this buff result. /// </summary> /// <param name="buff">The buff result.</param> public static string Describe <TSource>(this BuffActionResult <TSource> buff) { var target = buff.Target; if (target.IsDead) { return(null); } var descriptions = new List <string>(); foreach (var change in buff.StatMultiplierChanges) { var description = DescribeStatChange(buff, change); if (description is not null) { descriptions.Add(description); } } return(string.Join("\n", descriptions)); }
/// <summary> /// Returns a string describing the given stat change in the context of the given buff result. /// </summary> /// <param name="buff">The buff result.</param> /// <param name="statChange">The stat change.</param> private static string DescribeStatChange <TSource>( BuffActionResult <TSource> buff, KeyValuePair <StatCategory, double> statChange) { var percentage = (int)(statChange.Value * 100); if (percentage == 0) { return(null); } var target = buff.Target; var stat = statChange.Key; if (buff.IsSelfInflicted) { if (percentage > 0) { return(buff.Source switch { Item item => $"{target.Name}'s {item.Name} increased their {stat} by {percentage}%!", _ => $"{target.Name}'s {stat} rose by {percentage}%!", });
/// <summary> /// Receives effects from the given buff and returns the result. /// </summary> /// <param name="multipliers">The effects of incoming buff.</param> /// <param name="user">The character who used the incoming buff.</param> /// <typeparam name="TSource">The type of the source of the incoming buff.</typeparam> public virtual BuffActionResult <TSource> ReceiveBuff <TSource>( IDictionary <StatCategory, double> multipliers, Character user) { BuffActionResult <TSource> result; if (CanProtectFrom(user)) { var protectUser = ConsumeProtect(); result = new BuffActionResult <TSource> { Applied = false, User = user, Target = this, TargetProtected = true, ProtectUser = protectUser, Tags = new HashSet <string>(), }; } else { var startingMultipliers = Stats.MultipliersAsDictionary(); foreach (var mult in multipliers) { var statCategory = mult.Key; switch (statCategory) { case StatCategory.Attack: Stats.Attack.Multiplier += mult.Value; break; case StatCategory.Defence: Stats.Defence.Multiplier += mult.Value; break; case StatCategory.Speed: Stats.Speed.Multiplier += mult.Value; break; default: throw new ArgumentException($"Unrecognised stat category {statCategory}!"); } } var endingMultipliers = Stats.MultipliersAsDictionary(); result = new BuffActionResult <TSource> { Applied = true, User = user, Target = this, TargetProtected = false, StartingStatMultipliers = startingMultipliers, EndingStatMultipliers = endingMultipliers, Tags = new HashSet <string>(), }; } return(result); }