741e26251d
Added tags to Status Effects, which also allows for fancy stuff like checking for tags over duration elements for more interesting interactions. Adds "stackable" variable which dictates whether or not the same duration/delay effect can be applied to the same target(s) at the same time. This is a bit imperfect at the moment. Adds Chloromydride which is a non-stackable chem stabilizing critical health which stops its effects once the health is stabilized. TODO: Remove target from Targets if he already has it, and if targets becomes empty, return; TODO: Conditional tag-checking and status effect tag-checking, plus more "special" checks like SpeciesName and other non-serialized options. TODO: StatusEffect Cancel component to stop delayed/duration effects
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
class DelayedListElement
|
|
{
|
|
public DelayedEffect Parent;
|
|
public Entity Entity;
|
|
public List<ISerializableEntity> Targets;
|
|
public float StartTimer;
|
|
}
|
|
class DelayedEffect : StatusEffect
|
|
{
|
|
public static List<DelayedListElement> DelayList = new List<DelayedListElement>();
|
|
|
|
private float delay;
|
|
|
|
public DelayedEffect(XElement element)
|
|
: base(element)
|
|
{
|
|
delay = element.GetAttributeFloat("delay", 1.0f);
|
|
}
|
|
|
|
public override void Apply(ActionType type, float deltaTime, Entity entity, List<ISerializableEntity> targets)
|
|
{
|
|
if (this.type != type || !HasRequiredItems(entity)) return;
|
|
if (!base.Stackable && DelayList.Find(d => d.Parent == this && d.Entity == entity && d.Targets == targets) != null) return;
|
|
|
|
DelayedListElement element = new DelayedListElement();
|
|
element.Parent = this;
|
|
element.StartTimer = delay;
|
|
element.Entity = entity;
|
|
element.Targets = targets;
|
|
|
|
DelayList.Add(element);
|
|
}
|
|
|
|
public static void Update(float deltaTime)
|
|
{
|
|
for (int i = DelayList.Count - 1; i >= 0; i--)
|
|
{
|
|
DelayedListElement element = DelayList[i];
|
|
if (element.Parent.CheckConditionalAlways && !element.Parent.HasRequiredConditions(element.Targets))
|
|
{
|
|
DelayList.Remove(element);
|
|
continue;
|
|
}
|
|
|
|
element.StartTimer -= deltaTime;
|
|
|
|
if (element.StartTimer > 0.0f) continue;
|
|
|
|
element.Parent.Apply(1.0f, element.Entity, element.Targets);
|
|
DelayList.Remove(element);
|
|
}
|
|
}
|
|
}
|
|
} |