diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index d063af95b3e72bc4898d67ad490ff2811f8ed7fc..58529890328bcf87eca29e0b66d895c217f5d4b9 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -6,7 +6,10 @@ using UnityEngine.InputSystem; using BigSock.Item; namespace BigSock { - // Common class for all characters. + + /* + Common class for all characters. + */ public partial class Character : Entity { /* @@ -74,27 +77,6 @@ namespace BigSock { public int level; - /* - Indicates whether or not the characer is a live. - */ - public bool Alive { get; private set; } = true; - - /* - Stores the next time the character can recieve damage. - */ - public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; - - /* - 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); - - - protected Rigidbody2D rb; @@ -194,11 +176,11 @@ namespace BigSock { if(!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack)); // Check if player has IFrames - if(NextTimeCanTakeDamage > DateTime.Now) + if(HasIFrames) return false; // Start new IFrames - NextTimeCanTakeDamage = DateTime.Now + IFrameDuration; + SetIFrames(IFrameDuration); // Trigger the event for taking damage. OnTakeDamage?.Invoke(this, attack.Actor, attack); @@ -285,6 +267,8 @@ namespace BigSock { + + /* Items */ @@ -464,4 +448,73 @@ namespace BigSock { } + + + /* + Status effects. + */ + public partial class Character { + + /* + Indicates whether or not the characer is a live. + */ + public bool Alive { get; private set; } = true; + + + /* + Indicates whether or not the characer is a live. + */ + public bool HasIFrames => NextTimeCanTakeDamage > DateTime.Now; + + /* + Stores the next time the character can recieve damage. + */ + public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; + + /* + 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); + + + + /* + Sets IFrames for the character. + */ + public bool SetIFrames(TimeSpan amount) { + // Get when the IFrames would expire. + var nextCanTakeDamage = DateTime.Now + IFrameDuration; + + // Only if that's later than current. + if(nextCanTakeDamage > NextTimeCanTakeDamage) { + // If character currently doesn't have the status effect. + if(NextTimeCanTakeDamage < DateTime.Now) { + ApplyIFrames(); + } + + // Set new time. + NextTimeCanTakeDamage = nextCanTakeDamage; + return true; + } + return false; + } + + /* + Appies IFrames to the character. + */ + private void ApplyIFrames() { + + } + /* + Removes IFrames for the character. + */ + private void RemoveIFrames() { + + } + + } }