-
-
Save rightfold/cf1e776ee85099c4af4753172f72e3a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Buff | |
{ | |
public float MeleeRangeFactor { get; protected set; } = 1f; | |
public float KnockbackFactor { get; protected set; } = 1f; | |
public float DamageFactor { get; protected set; } = 1f; | |
public static Buff Knockback = new Buff() { KnockbackFactor = 1.5f }; | |
} | |
abstract class Character { | |
private readonly Dictionary<Buff, TimeSpan> Buffs; | |
public void Buff(Buff buff, TimeSpan timeSpan) | |
{ | |
if (Buffs.ContainsKey(buff)) | |
{ | |
Buffs[buff] += timeSpan; | |
} | |
else | |
{ | |
Buffs.Add(buff, timeSpan); | |
} | |
} | |
private void AgeBuffs(CanvasTimingInformation dt) | |
{ | |
foreach (var buff in Buffs.Keys.ToList()) | |
{ | |
Buffs[buff] -= dt.ElapsedTime; | |
if (Buffs[buff] <= TimeSpan.Zero) | |
{ | |
Buffs.Remove(buff); | |
} | |
} | |
} | |
public abstract float BaseMeleeRange { get; } | |
public abstract float BaseKnockback { get; } | |
public abstract int BaseDamage { get; } | |
public float MeleeRange => Buffs.Keys.Aggregate(BaseMeleeRange, (r, b) => r * b.MeleeRangeFactor); | |
public float Knockback => Buffs.Keys.Aggregate(BaseKnockback, (r, b) => r * b.KnockbackFactor); | |
public int Damage => (int)Buffs.Keys.Aggregate((float)BaseDamage, (r, b) => r * b.DamageFactor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment