Bunch of fixes to statuseffects:

- 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).
This commit is contained in:
Joonas Rikkonen
2018-02-12 11:25:40 +02:00
parent 43d6ee5e06
commit ff883ae882
2 changed files with 57 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
@@ -22,16 +23,43 @@ namespace Barotrauma
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 (!base.Stackable && DelayList.Find(d => d.Parent == this && d.Entity == entity && d.Targets == targets) != null) return;
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.SequenceEqual(targets))) return;
DelayedListElement element = new DelayedListElement();
element.Parent = this;
element.StartTimer = delay;
element.Entity = entity;
element.Targets = targets;
//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);
}

View File

@@ -26,7 +26,7 @@ namespace Barotrauma
}
private TargetType targetTypes;
private HashSet<string> targetNames;
protected HashSet<string> targetNames;
private List<RelatedItem> requiredItems;
@@ -278,19 +278,38 @@ namespace Barotrauma
if (targetNames != null && !targetNames.Contains(target.Name)) return;
if (duration > 0.0f && !Stackable && DurationList.Find(d => d.Parent == this && d.Entity == entity && d.Targets.Contains(target)) != null) return;
if (duration > 0.0f && !Stackable)
{
//ignore if not stackable and there's already an identical statuseffect
if (DurationList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.Count == 1 && d.Targets[0] == target)) return;
}
List<ISerializableEntity> targets = new List<ISerializableEntity>();
targets.Add(target);
if (!HasRequiredConditions(targets)) return;
Apply(type, deltaTime, entity, targets);
Apply(deltaTime, entity, targets);
}
public virtual void Apply(ActionType type, float deltaTime, Entity entity, List<ISerializableEntity> targets)
{
if (this.type != type || !HasRequiredItems(entity) || !HasRequiredConditions(targets)) return;
if (this.type != type) return;
//remove invalid targets
if (targetNames != null)
{
targets.RemoveAll(t => !targetNames.Contains(t.Name));
if (targets.Count == 0) return;
}
if (!HasRequiredItems(entity) || !HasRequiredConditions(targets)) return;
if (duration > 0.0f && !Stackable)
{
//ignore if not stackable and there's already an identical statuseffect
if (DurationList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.SequenceEqual(targets))) return;
}
Apply(deltaTime, entity, targets);
}