public static void Heal(this IEffectHolder holder, double heal, PopupHelper popupHelper) { var damageEffects = holder.GetEffects <EffectDamage>().ToList(); var totalDamage = damageEffects.Sum(x => x.Amount); var totalHeal = heal + Math.Max(0, totalDamage - holder.GetStat(Stat.HP)); var healAmounts = Util.ProportionalSplit(damageEffects.Select(x => x.Amount), totalHeal); int i = 0; foreach (var damage in damageEffects) { damage.Amount -= healAmounts[i]; if (damage.Amount <= 0) { damage.Remove(); } i++; } popupHelper?.Add(new MessageHeal(holder, heal)); }
public static void TakeDamage(this IEffectHolder holder, double damage, Element element, PopupHelper popupHelper) { popupHelper?.Add(new MessageDamage(holder, damage, element)); Effect.Apply(new EffectDamage(holder, damage, element)); }