diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index a594c9495..a7859797c 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -200,7 +200,7 @@ namespace Barotrauma public bool CanInteract { - get { return AllowInput && IsHumanoid && !LockHands; } + get { return AllowInput && IsHumanoid && !LockHands && !Removed; } } public Vector2 CursorPosition @@ -495,7 +495,7 @@ namespace Barotrauma { get { - return isDead || Stun > 0.0f || LockHands || IsUnconscious || Removed; + return !Removed && (isDead || Stun > 0.0f || LockHands || IsUnconscious); } } @@ -1129,7 +1129,7 @@ namespace Barotrauma public bool CanInteractWith(Character c, float maxDist = 200.0f) { - if (c == this || !c.Enabled || !c.IsHumanoid || !c.CanBeSelected) return false; + if (c == this || Removed || !c.Enabled || !c.IsHumanoid || !c.CanBeSelected) return false; maxDist = ConvertUnits.ToSimUnits(maxDist); if (Vector2.DistanceSquared(SimPosition, c.SimPosition) > maxDist * maxDist) return false; @@ -1955,6 +1955,12 @@ namespace Barotrauma public void Revive(bool isNetworkMessage) { + if (Removed) + { + DebugConsole.ThrowError("Attempting to revive an already removed character\n" + Environment.StackTrace); + return; + } + isDead = false; if (aiTarget != null) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs index ce564e36b..f23aeab61 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -52,7 +52,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { - if (character == null || reloadTimer>0.0f) return false; + if (character == null || reloadTimer > 0.0f) return false; if (!character.IsKeyDown(InputType.Aim) || hitting) return false; //don't allow hitting if the character is already hitting with another weapon @@ -172,6 +172,7 @@ namespace Barotrauma.Items.Components private void SetUser(Character character) { if (user == character) return; + if (user != null && user.Removed) user = null; if (user != null) { @@ -213,6 +214,13 @@ namespace Barotrauma.Items.Components private bool OnCollision(Fixture f1, Fixture f2, Contact contact) { + if (user == null || user.Removed) + { + RestoreCollision(); + hitting = false; + user = null; + } + Character targetCharacter = null; Limb targetLimb = null; Structure targetStructure = null; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs index d6bd5f065..0d4079573 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs @@ -58,13 +58,12 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { - if (character == null) return false; - if (!character.IsKeyDown(InputType.Aim) || character.Stun>0.0f) return false; + if (character == null || character.Removed) return false; + if (!character.IsKeyDown(InputType.Aim) || character.Stun > 0.0f) return false; IsActive = true; useState = 0.1f; - if (character.AnimController.InWater) { if (usableIn == UsableIn.Air) return true; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs index dca9b5c3a..c47b9733c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs @@ -70,7 +70,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { - if (character == null) return false; + if (character == null || character.Removed) return false; if (!character.IsKeyDown(InputType.Aim) || reloadTimer > 0.0f) return false; IsActive = true; reloadTimer = reload; @@ -81,7 +81,7 @@ namespace Barotrauma.Items.Components limbBodies.Add(l.body.FarseerBody); } - float degreeOfFailure = (100.0f - DegreeOfSuccess(character))/100.0f; + float degreeOfFailure = (100.0f - DegreeOfSuccess(character)) / 100.0f; degreeOfFailure *= degreeOfFailure; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index ac87842c5..500fa3e22 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -120,7 +120,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { - if (character == null) return false; + if (character == null || character.Removed) return false; if (!character.IsKeyDown(InputType.Aim)) return false; float degreeOfSuccess = DegreeOfSuccess(character)/100.0f; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs index 7d31ae1d8..acce40b2f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs @@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; - if (!picker.HasSelectedItem(item)) + if (picker == null || picker.Removed || !picker.HasSelectedItem(item)) { IsActive = false; return; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Ladder.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Ladder.cs index ad1185f03..71d3a79eb 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Ladder.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Ladder.cs @@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components public override bool Select(Character character) { - if (character == null || character.LockHands) return false; + if (character == null || character.LockHands || character.Removed) return false; character.AnimController.Anim = AnimController.Animation.Climbing; //picker.SelectedConstruction = item; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs index 3dbd1799a..a463a688b 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs @@ -74,8 +74,9 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { this.cam = cam; - + if (character == null + || character.Removed || character.SelectedConstruction != item || !character.CanInteractWith(item)) { @@ -147,7 +148,13 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character activator = null) { - if (character == null || activator != character || character.SelectedConstruction != item || !character.CanInteractWith(item)) + if (activator != character) + { + return false; + } + + if (character == null || character.Removed || + character.SelectedConstruction != item || !character.CanInteractWith(item)) { character = null; return false; @@ -162,9 +169,15 @@ namespace Barotrauma.Items.Components public override bool SecondaryUse(float deltaTime, Character character = null) { - if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item)) + if (this.character != character) { - character = null; + return false; + } + + if (this.character == null || character.Removed || + this.character.SelectedConstruction != item || !character.CanInteractWith(item)) + { + this.character = null; return false; } if (character == null) return false; @@ -224,6 +237,8 @@ namespace Barotrauma.Items.Components private void CancelUsing(Character character) { + if (character == null || character.Removed) return; + foreach (LimbPos lb in limbPositions) { Limb limb = character.AnimController.GetLimb(lb.limbType); @@ -241,10 +256,10 @@ namespace Barotrauma.Items.Components public override bool Select(Character activator) { - if (activator == null) return false; + if (activator == null || activator.Removed) return false; //someone already using the item - if (character != null) + if (character != null && !character.Removed) { if (character == activator) { @@ -256,8 +271,7 @@ namespace Barotrauma.Items.Components } else { - character = activator; - + character = activator; IsActive = true; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs index c67cbdf17..6456e56fa 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs @@ -275,6 +275,8 @@ namespace Barotrauma.Items.Components private bool OnProjectileCollision(Fixture target, Vector2 collisionNormal) { + if (User != null && User.Removed) User = null; + if (IgnoredBodies.Contains(target.Body)) return false; if (target.CollisionCategories == Physics.CollisionCharacter && !(target.Body.UserData is Limb))