Reviewed-on: #11 Reviewed-by: Ader_Alisma <ader.alisma.1@ens.etsmtl.ca> Co-authored-by: Adam Salah <adam-hamid.salah-salah.1@ens.etsmtl.ca> Co-committed-by: Adam Salah <adam-hamid.salah-salah.1@ens.etsmtl.ca>
64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class StatusHandler : MonoBehaviour
|
|
{
|
|
private Entity _entityLinked;
|
|
private Dictionary<Enum.StatusType, Status> activeStatuses = new();
|
|
|
|
public void ApplySlow(float intensity, float duration)
|
|
{
|
|
// check if effect already applied
|
|
Slow slow = (Slow)GetStatus(Enum.StatusType.Slow);
|
|
|
|
// init effect params
|
|
slow.Intensity = intensity;
|
|
|
|
// apply effect
|
|
slow.Apply(duration);
|
|
}
|
|
|
|
// please add status to switch case everytime you design one!
|
|
private Status GetStatus(Enum.StatusType type)
|
|
{
|
|
Status status;
|
|
|
|
// check if status already exists
|
|
activeStatuses.TryGetValue(type, out status);
|
|
|
|
// if status doesn't exist, instantiate it
|
|
if (!status)
|
|
{
|
|
switch (type)
|
|
{
|
|
case Enum.StatusType.Slow:
|
|
status = gameObject.AddComponent<Slow>();
|
|
break;
|
|
default: break;
|
|
}
|
|
|
|
// if key value pair doesn't exist, create it
|
|
// else update the existing one
|
|
if (!activeStatuses.ContainsKey(type))
|
|
{
|
|
activeStatuses.Add(type, status);
|
|
}
|
|
else
|
|
{
|
|
activeStatuses[type] = status;
|
|
}
|
|
}
|
|
|
|
// link entity to status
|
|
status.EntityLinked = _entityLinked;
|
|
|
|
return status;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_entityLinked = gameObject.GetComponent<Entity>();
|
|
}
|
|
}
|