(f6c34b377) Fix crawlers not reacting to any targets if properly latched on walls.

This commit is contained in:
Joonas Rikkonen
2019-04-11 18:26:42 +03:00
parent 9b0e0ab278
commit a57b7184fb
9 changed files with 41 additions and 41 deletions
@@ -487,7 +487,7 @@ namespace Barotrauma
}
else
{
if (!IsProperlyLatched)
if (!IsProperlyLatchedOnSub)
{
UpdateWallTarget();
}
@@ -1003,11 +1003,12 @@ namespace Barotrauma
private void UpdateEating(float deltaTime)
{
if (SelectedAiTarget == null)
if (SelectedAiTarget == null) //SelectedAiTarget.Entity is Character c && !c.IsDead
{
State = AIState.Idle;
return;
}
Character targetChar = SelectedAiTarget.Entity as Character;
Limb mouthLimb = Array.Find(Character.AnimController.Limbs, l => l != null && l.MouthPos.HasValue);
if (mouthLimb == null) mouthLimb = Character.AnimController.GetLimb(LimbType.Head);
@@ -1039,14 +1040,14 @@ namespace Barotrauma
#region Targeting
private bool IsProperlyLatched => LatchOntoAI != null && LatchOntoAI.IsAttached && SelectedAiTarget?.Entity == wallTarget?.Structure;
private bool IsProperlyLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub && SelectedAiTarget?.Entity == wallTarget?.Structure;
//goes through all the AItargets, evaluates how preferable it is to attack the target,
//whether the Character can see/hear the target and chooses the most preferable target within
//sight/hearing range
public AITarget UpdateTargets(Character character, out TargetingPriority priority)
{
if (IsProperlyLatched)
if (IsProperlyLatchedOnSub)
{
// If attached to a valid target, just keep the target.
// Priority not used in this case.
@@ -54,6 +54,8 @@ namespace Barotrauma
get { return attachJoints.Count > 0; }
}
public bool IsAttachedToSub => IsAttached && attachTargetBody?.UserData is Entity entity && (entity is Submarine sub || entity?.Submarine != null);
public LatchOntoAI(XElement element, EnemyAIController enemyAI)
{
attachToWalls = element.GetAttributeBool("attachtowalls", false);
@@ -207,10 +209,10 @@ namespace Barotrauma
break;
}
if (attachTargetBody != null && deattachTimer < 0.0f)
if (IsAttached && attachTargetBody != null && deattachTimer < 0.0f)
{
Entity entity = attachTargetBody.UserData as Entity;
Submarine attachedSub = entity is Submarine ? (Submarine)entity : entity?.Submarine;
Submarine attachedSub = entity is Submarine sub ? sub : entity?.Submarine;
if (attachedSub != null)
{
float velocity = attachedSub.Velocity == Vector2.Zero ? 0.0f : attachedSub.Velocity.Length();