Fixed exceptions if a character is removed when an AI character is attacking it
This commit is contained in:
@@ -196,7 +196,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private void UpdateAttack(float deltaTime)
|
private void UpdateAttack(float deltaTime)
|
||||||
{
|
{
|
||||||
if (selectedAiTarget == null)
|
if (selectedAiTarget == null || selectedAiTarget.Entity == null || selectedAiTarget.Entity.Removed)
|
||||||
{
|
{
|
||||||
state = AiState.None;
|
state = AiState.None;
|
||||||
return;
|
return;
|
||||||
@@ -204,15 +204,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
selectedTargetMemory.Priority -= deltaTime;
|
selectedTargetMemory.Priority -= deltaTime;
|
||||||
|
|
||||||
Vector2 attackSimPosition = Character.Submarine==null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
|
Vector2 attackSimPosition = Character.Submarine == null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
|
||||||
if (wallAttackPos != Vector2.Zero && targetEntity != null)
|
if (wallAttackPos != Vector2.Zero && targetEntity != null)
|
||||||
{
|
{
|
||||||
attackSimPosition = wallAttackPos;
|
attackSimPosition = wallAttackPos;
|
||||||
|
|
||||||
if (selectedAiTarget.Entity != null && Character.Submarine==null && selectedAiTarget.Entity.Submarine != null) attackSimPosition += ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
|
if (selectedAiTarget.Entity != null && Character.Submarine == null && selectedAiTarget.Entity.Submarine != null) attackSimPosition += ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coolDownTimer>0.0f)
|
if (coolDownTimer > 0.0f)
|
||||||
{
|
{
|
||||||
UpdateCoolDown(attackSimPosition, deltaTime);
|
UpdateCoolDown(attackSimPosition, deltaTime);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
using Lidgren.Network;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Barotrauma.Networking;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using FarseerPhysics;
|
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1728,6 +1728,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public AttackResult AddDamage(Vector2 worldPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound, float attackForce = 0.0f)
|
public AttackResult AddDamage(Vector2 worldPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound, float attackForce = 0.0f)
|
||||||
{
|
{
|
||||||
|
if (Removed) return new AttackResult();
|
||||||
|
|
||||||
SetStun(stun);
|
SetStun(stun);
|
||||||
|
|
||||||
Limb closestLimb = null;
|
Limb closestLimb = null;
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ namespace Barotrauma
|
|||||||
private ushort id;
|
private ushort id;
|
||||||
|
|
||||||
protected AITarget aiTarget;
|
protected AITarget aiTarget;
|
||||||
//protected float soundRange;
|
|
||||||
//protected float sightRange;
|
public bool Removed
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
public ushort ID
|
public ushort ID
|
||||||
{
|
{
|
||||||
@@ -125,6 +129,7 @@ namespace Barotrauma
|
|||||||
public virtual void Remove()
|
public virtual void Remove()
|
||||||
{
|
{
|
||||||
dictionary.Remove(ID);
|
dictionary.Remove(ID);
|
||||||
|
Removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DumpIds(int count)
|
public static void DumpIds(int count)
|
||||||
|
|||||||
Reference in New Issue
Block a user