Made statuseffects stackable by default, fixed statuseffects only being considered the same if they're caused by the same item, applying the same non-stackable statuseffect again refreshes the timer of the existing statuseffect. Closes #309

This commit is contained in:
Joonas Rikkonen
2018-03-05 16:59:23 +02:00
parent 6ddcd65f18
commit a57bec2a27
2 changed files with 13 additions and 8 deletions

View File

@@ -26,7 +26,7 @@ namespace Barotrauma
public override void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target) public override void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target)
{ {
if (this.type != type || !HasRequiredItems(entity)) return; 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 (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.Count == 1 && d.Targets[0] == target)) return;
if (targetNames != null && !targetNames.Contains(target.Name)) return; if (targetNames != null && !targetNames.Contains(target.Name)) return;
@@ -44,7 +44,7 @@ namespace Barotrauma
public override void Apply(ActionType type, float deltaTime, Entity entity, List<ISerializableEntity> targets) public override void Apply(ActionType type, float deltaTime, Entity entity, List<ISerializableEntity> targets)
{ {
if (this.type != type || !HasRequiredItems(entity)) return; if (this.type != type || !HasRequiredItems(entity)) return;
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Entity == entity && d.Targets.SequenceEqual(targets))) return; if (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.SequenceEqual(targets))) return;
//remove invalid targets //remove invalid targets
if (targetNames != null) if (targetNames != null)

View File

@@ -14,7 +14,7 @@ namespace Barotrauma
public StatusEffect Parent; public StatusEffect Parent;
public Entity Entity; public Entity Entity;
public List<ISerializableEntity> Targets; public List<ISerializableEntity> Targets;
public float StartTimer; public float Timer;
} }
partial class StatusEffect partial class StatusEffect
@@ -54,7 +54,7 @@ namespace Barotrauma
public bool CheckConditionalAlways; //Always do the conditional checks for the duration/delay. If false, only check conditional on apply. public bool CheckConditionalAlways; //Always do the conditional checks for the duration/delay. If false, only check conditional on apply.
public bool Stackable; //Can the same status effect be applied several times to the same targets? public bool Stackable = true; //Can the same status effect be applied several times to the same targets?
private readonly int useItemCount; private readonly int useItemCount;
@@ -308,7 +308,12 @@ namespace Barotrauma
if (duration > 0.0f && !Stackable) if (duration > 0.0f && !Stackable)
{ {
//ignore if not stackable and there's already an identical statuseffect //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; DurationListElement existingEffect = DurationList.Find(d => d.Parent == this && d.Targets.SequenceEqual(targets));
if (existingEffect != null)
{
existingEffect.Timer = Math.Max(existingEffect.Timer, duration);
return;
}
} }
Apply(deltaTime, entity, targets); Apply(deltaTime, entity, targets);
@@ -349,7 +354,7 @@ namespace Barotrauma
{ {
DurationListElement element = new DurationListElement(); DurationListElement element = new DurationListElement();
element.Parent = this; element.Parent = this;
element.StartTimer = duration; element.Timer = duration;
element.Entity = entity; element.Entity = entity;
element.Targets = targets; element.Targets = targets;
@@ -458,9 +463,9 @@ namespace Barotrauma
} }
} }
element.StartTimer -= deltaTime; element.Timer -= deltaTime;
if (element.StartTimer > 0.0f) continue; if (element.Timer > 0.0f) continue;
DurationList.Remove(element); DurationList.Remove(element);
} }
} }