diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 58529890328bcf87eca29e0b66d895c217f5d4b9..673cc3bd9eeb3fb4abc4f9ee56b3f5827d17834a 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -180,7 +180,7 @@ namespace BigSock { return false; // Start new IFrames - SetIFrames(IFrameDuration); + AddIFrames(IFrameDuration); // Trigger the event for taking damage. OnTakeDamage?.Invoke(this, attack.Actor, attack); @@ -456,13 +456,36 @@ namespace BigSock { public partial class Character { /* - Indicates whether or not the characer is a live. + Indicates whether or not the characer is alive. */ public bool Alive { get; private set; } = true; + /* + How long between each time the character can take damage. + */ + public TimeSpan IFrameDuration { + get => _iFrameDuration; + private set => _iFrameDuration = value; + } + public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333); + + + + + /* + Is the character visible. + */ + public bool IsInvisible => NextTimeVisible > DateTime.Now; + + /* + Stores the next time the character can recieve damage. + */ + public DateTime NextTimeVisible { get; private set; } = DateTime.Now; + + /* - Indicates whether or not the characer is a live. + Is the character invincible. */ public bool HasIFrames => NextTimeCanTakeDamage > DateTime.Now; @@ -471,21 +494,60 @@ namespace BigSock { */ public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; + + /* - How long between each time the character can take damage. + Adds a status effect to the character. */ - public TimeSpan IFrameDuration { - get => _iFrameDuration; - private set => _iFrameDuration = value; + public bool AddStatusEffect(StatusEffectType statusType, TimeSpan amount) { + switch(statusType) { + case StatusEffectType.Invincible: return AddIFrames(amount); + case StatusEffectType.Invisible: return AddInvisibility(amount); + default: return false; + } + } + + + + /* + Adds invisibility for the character. + */ + public bool AddInvisibility(TimeSpan amount) { + // Get when the status effect would expire. + var wouldExpire = DateTime.Now + IFrameDuration; + + // Only if that's later than current. + if(wouldExpire > NextTimeVisible) { + // If character currently doesn't have the status effect. + if(NextTimeVisible < DateTime.Now) { + ApplyInvisibility(); + } + + // Set new time. + NextTimeVisible = wouldExpire; + return true; + } + return false; + } + /* + Appies invisibility to the character. + */ + private void ApplyInvisibility() { + + } + /* + Removes invisibility for the character. + */ + private void RemoveInvisibility() { + } - public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333); /* - Sets IFrames for the character. + Adds IFrames for the character. */ - public bool SetIFrames(TimeSpan amount) { + public bool AddIFrames(TimeSpan amount) { // Get when the IFrames would expire. var nextCanTakeDamage = DateTime.Now + IFrameDuration; @@ -502,7 +564,6 @@ namespace BigSock { } return false; } - /* Appies IFrames to the character. */