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
@@ -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);
}