Added checks for character removal to a bunch of places. Some of these may not necessary, but at least MeleeWeapon, Projectile and Controller still accessed the user after the user had been removed.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user