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:
@@ -26,7 +26,7 @@ namespace Barotrauma
|
||||
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 (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.Count == 1 && d.Targets[0] == target)) 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)
|
||||
{
|
||||
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
|
||||
if (targetNames != null)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Barotrauma
|
||||
public StatusEffect Parent;
|
||||
public Entity Entity;
|
||||
public List<ISerializableEntity> Targets;
|
||||
public float StartTimer;
|
||||
public float Timer;
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
@@ -308,7 +308,12 @@ namespace Barotrauma
|
||||
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;
|
||||
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);
|
||||
@@ -349,7 +354,7 @@ namespace Barotrauma
|
||||
{
|
||||
DurationListElement element = new DurationListElement();
|
||||
element.Parent = this;
|
||||
element.StartTimer = duration;
|
||||
element.Timer = duration;
|
||||
element.Entity = entity;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user