- Fixed the multi-target StatusEffect.Apply method ignoring target names and always allowing stacking. - Fixed delayed effects not working if the single-target StatusEffect.Apply method is used. - Fixed delayed effects ignoring target names. - Fixed delayed effects comparing the equality of the target lists, not the elements in the list (if the contents of the lists are identical the statuseffects should be considered identical).
87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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, ISerializableEntity target)
|
|
{
|
|
if (this.type != type || !HasRequiredItems(entity)) return;
|
|
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.Count == 1 && d.Targets[0] == target)) return;
|
|
|
|
if (targetNames != null && !targetNames.Contains(target.Name)) return;
|
|
|
|
DelayedListElement element = new DelayedListElement
|
|
{
|
|
Parent = this,
|
|
StartTimer = delay,
|
|
Entity = entity,
|
|
Targets = new List<ISerializableEntity>() { target }
|
|
};
|
|
|
|
DelayList.Add(element);
|
|
}
|
|
|
|
public override void Apply(ActionType type, float deltaTime, Entity entity, List<ISerializableEntity> targets)
|
|
{
|
|
if (this.type != type || !HasRequiredItems(entity)) return;
|
|
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.SequenceEqual(targets))) return;
|
|
|
|
//remove invalid targets
|
|
if (targetNames != null)
|
|
{
|
|
targets.RemoveAll(t => !targetNames.Contains(t.Name));
|
|
if (targets.Count == 0) return;
|
|
}
|
|
|
|
DelayedListElement element = new DelayedListElement
|
|
{
|
|
Parent = this,
|
|
StartTimer = delay,
|
|
Entity = entity,
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |