From 9251dbf83a0e3455392fe7a76acc0364ca9d7556 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Thu, 21 Dec 2017 21:40:54 +0300 Subject: [PATCH] Overhaul DelayedEffect to support application to multiple targets Fix DelayedEffect being unusable by monsters due to monsters calling Single Target Apply in their Attack, which DelayedEffect doesn't override, by making Apply (single target) call Apply (multiple targets) which THEN calls the protected Apply function. Nerf Amanitin to require two injections to be lethal. First injection only stops oxygen from regenerating and slightly saps HP. Add Cause of Death to Health HUD --- .../Source/Items/Components/StatusHUD.cs | 1 + .../Content/Items/Medical/medical.xml | 5 +- .../Source/Characters/Character.cs | 8 ++- .../Source/Characters/DelayedEffect.cs | 50 +++++++++---------- .../Source/Characters/StatusEffect.cs | 9 ++-- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/StatusHUD.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/StatusHUD.cs index 148e1a4e3..9bc1f2af4 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/StatusHUD.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/StatusHUD.cs @@ -115,6 +115,7 @@ namespace Barotrauma.Items.Components if (target.IsDead) { texts.Add("Deceased"); + texts.Add("Cause of Death: " + target.CauseOfDeath.ToString()); } else { diff --git a/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml b/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml index ff3a5885d..8f1521911 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Medical/medical.xml @@ -175,7 +175,6 @@ - @@ -502,7 +501,7 @@ category="Material" spritecolor="1.0,0.3,0.3,1.0" Tags="smallitem,chem,medical" - description="A devious poison with a delayed effect."> + description="A devious poison with a delayed effect. Requires higher dosage to be lethal."> @@ -515,7 +514,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 6819a412f..9193e6813 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -371,6 +371,7 @@ namespace Barotrauma { if (!MathUtils.IsValid(value)) return; if (GameMain.Client != null) return; + if (!DoesBleed) return; float newBleeding = MathHelper.Clamp(value, 0.0f, 5.0f); if (newBleeding == bleeding) return; @@ -1585,8 +1586,11 @@ namespace Barotrauma if (needsAir) UpdateOxygen(deltaTime); - Health -= bleeding * deltaTime; - Bleeding -= BleedingDecreaseSpeed * deltaTime; + if (DoesBleed) + { + Health -= bleeding * deltaTime; + Bleeding -= BleedingDecreaseSpeed * deltaTime; + } if (health <= minHealth) Kill(CauseOfDeath.Bloodloss); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/DelayedEffect.cs b/Barotrauma/BarotraumaShared/Source/Characters/DelayedEffect.cs index e0d68a6be..1b5a90848 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/DelayedEffect.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/DelayedEffect.cs @@ -3,23 +3,19 @@ using System.Xml.Linq; namespace Barotrauma { + class DelayedListElement + { + public DelayedEffect Parent; + public Entity Entity; + public List Targets; + public float StartTimer; + } class DelayedEffect : StatusEffect { - public static List List = new List(); + public static List List = new List(); private float delay; - private float startTimer; - - private Entity entity; - - private List targets; - - public float StartTimer - { - get { return startTimer; } - } - public DelayedEffect(XElement element) : base(element) { @@ -29,24 +25,28 @@ namespace Barotrauma public override void Apply(ActionType type, float deltaTime, Entity entity, List targets) { if (this.type != type) return; - - startTimer = delay; - this.entity = entity; + DelayedListElement element = new DelayedListElement(); + element.Parent = this; + element.StartTimer = delay; + element.Entity = entity; + element.Targets = targets; - this.targets = targets; - - List.Add(this); + List.Add(element); } - public void Update(float deltaTime) + public static void Update(float deltaTime) { - startTimer -= deltaTime; + for (int i = DelayedEffect.List.Count - 1; i >= 0; i--) + { + DelayedListElement element = DelayedEffect.List[i]; - if (startTimer > 0.0f) return; + element.StartTimer -= deltaTime; - base.Apply(1.0f, entity, targets); - List.Remove(this); + if (element.StartTimer > 0.0f) continue; + + element.Parent.Apply(1.0f, element.Entity, element.Targets); + List.Remove(element); + } } - } -} +} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/Source/Characters/StatusEffect.cs b/Barotrauma/BarotraumaShared/Source/Characters/StatusEffect.cs index 1ef9c181f..af6bac60f 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/StatusEffect.cs @@ -190,7 +190,7 @@ namespace Barotrauma } } - private bool HasRequiredItems(Entity entity) + public virtual bool HasRequiredItems(Entity entity) { if (requiredItems == null) return true; foreach (RelatedItem requiredItem in requiredItems) @@ -218,7 +218,7 @@ namespace Barotrauma List targets = new List(); targets.Add(target); - Apply(deltaTime, entity, targets); + Apply(type, deltaTime, entity, targets); } public virtual void Apply(ActionType type, float deltaTime, Entity entity, List targets) @@ -359,10 +359,7 @@ namespace Barotrauma public static void UpdateAll(float deltaTime) { - for (int i = DelayedEffect.List.Count-1; i>= 0; i--) - { - DelayedEffect.List[i].Update(deltaTime); - } + DelayedEffect.Update(deltaTime); } public static void StopAll()