tweaked slow stacking logic

This commit is contained in:
Adam Salah 2025-07-15 01:14:54 -04:00
parent 747fc76846
commit a1a2823a96
3 changed files with 22 additions and 15 deletions

View File

@ -26,7 +26,7 @@ public abstract class Entity : LevelObject
private StatusHandler _statusHandler;
// status modifiers
private float _speedStatusModifier = 1;
private float _speedStatusModifier = 1f;
//Enemy Spotted
private bool _isEnemyDetected = false;

View File

@ -5,8 +5,8 @@ using UnityEngine;
public class Slow : Status
{
private float _latestSpeedModifier;
private float _cumulativeSpeedModifier = 1;
private float _previousSpeedModifier = 1f;
private float _speedModifier = 1f;
public override void Apply(float duration)
{
@ -14,18 +14,15 @@ public class Slow : Status
_duration = Mathf.Max(_duration, duration);
// slow entity
EntityLinked.SpeedStatusModifier *= _latestSpeedModifier;
// store cumulative speed modifier to revert it later
_cumulativeSpeedModifier *= _latestSpeedModifier;
EntityLinked.SpeedStatusModifier /= _previousSpeedModifier;
Debug.Log(_speedModifier);
EntityLinked.SpeedStatusModifier *= _speedModifier;
}
public override void Unapply()
{
// bring entity to normal speed
Debug.Log(EntityLinked.SpeedStatusModifier);
EntityLinked.SpeedStatusModifier /= _cumulativeSpeedModifier;
Debug.Log(EntityLinked.SpeedStatusModifier);
EntityLinked.SpeedStatusModifier /= _speedModifier;
// stop effect
Destroy(this);
@ -35,8 +32,13 @@ public class Slow : Status
/// A higher intensity results in a stronger slow.
/// Example: An intensity of 0.99 multiplies the entity's speed by 0.01 (which would result in a really low speed)
/// </summary>
public float Intensity {
get => 1 - _latestSpeedModifier;
set => _latestSpeedModifier = 1 - value;
public float Intensity
{
get => 1 - _speedModifier;
set
{
_previousSpeedModifier = _speedModifier;
_speedModifier = Mathf.Min(_speedModifier, 1 - value);
}
}
}

View File

@ -27,7 +27,7 @@ public class StatusHandler : MonoBehaviour
// check if status already exists
activeStatuses.TryGetValue(Enum.StatusType.Slow, out status);
// if status doesn't exist, create it
// if status doesn't exist, instantiate it
if (!status)
{
switch (type)
@ -37,8 +37,13 @@ public class StatusHandler : MonoBehaviour
break;
default: break;
}
// if key value pair doesn't exist, create it
if (!activeStatuses.ContainsKey(type))
{
activeStatuses.Add(type, status);
}
}
// link entity to status
status.EntityLinked = _entityLinked;