diff --git a/Assets/Prefabs/bolasProjectile.prefab b/Assets/Prefabs/bolasProjectile.prefab index 9a25838..5288fd8 100644 --- a/Assets/Prefabs/bolasProjectile.prefab +++ b/Assets/Prefabs/bolasProjectile.prefab @@ -73,7 +73,7 @@ MonoBehaviour: _angle: 0 _speed: 2 _slowIntensity: 0.25 - _slowDuration: 10 + _slowDuration: 5 --- !u!1 &6962989256011107503 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Status/Slow.cs b/Assets/Scripts/Status/Slow.cs index 6304903..098ad06 100644 --- a/Assets/Scripts/Status/Slow.cs +++ b/Assets/Scripts/Status/Slow.cs @@ -1,24 +1,31 @@ using System.Collections; using System.Collections.Generic; +using Unity.VisualScripting.YamlDotNet.Core.Tokens; using UnityEngine; public class Slow : Status { - private float _speedModifier; + private float _latestSpeedModifier; + private float _cumulativeSpeedModifier = 1; public override void Apply(float duration) { // reset slow duration - _duration += duration; + _duration = Mathf.Max(_duration, duration); // slow entity - EntityLinked.SpeedStatusModifier *= _speedModifier; + EntityLinked.SpeedStatusModifier *= _latestSpeedModifier; + + // store cumulative speed modifier to revert it later + _cumulativeSpeedModifier *= _latestSpeedModifier; } public override void Unapply() { // bring entity to normal speed - EntityLinked.SpeedStatusModifier /= _speedModifier; + Debug.Log(EntityLinked.SpeedStatusModifier); + EntityLinked.SpeedStatusModifier /= _cumulativeSpeedModifier; + Debug.Log(EntityLinked.SpeedStatusModifier); // stop effect Destroy(this); @@ -29,7 +36,7 @@ public class Slow : Status /// Example: An intensity of 0.99 multiplies the entity's speed by 0.01 (which would result in a really low speed) /// public float Intensity { - get => 1 - _speedModifier; - set => _speedModifier = _speedModifier == 0 ? 1 - value : _speedModifier + (1 - _speedModifier) * value; + get => 1 - _latestSpeedModifier; + set => _latestSpeedModifier = 1 - value; } } diff --git a/Assets/Scripts/StatusHandler.cs b/Assets/Scripts/StatusHandler.cs index a8f7a9e..6b948ea 100644 --- a/Assets/Scripts/StatusHandler.cs +++ b/Assets/Scripts/StatusHandler.cs @@ -23,7 +23,11 @@ public class StatusHandler : MonoBehaviour private Status GetStatus(Enum.StatusType type) { Status status; + + // check if status already exists activeStatuses.TryGetValue(Enum.StatusType.Slow, out status); + + // if status doesn't exist, create it if (!status) { switch (type) @@ -33,8 +37,12 @@ public class StatusHandler : MonoBehaviour break; default: break; } + activeStatuses.Add(type, status); } + + // link entity to status status.EntityLinked = _entityLinked; + return status; }