(1aa050263) Cherry pick from human-ai: Fix bots not knowing how to use the integrated controllers, effectively failing to use the doors with integrated buttons.

This commit is contained in:
Joonas Rikkonen
2019-05-03 13:48:48 +03:00
parent 3701f0e957
commit bd659383b4
7 changed files with 252 additions and 142 deletions
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework;
using System;
using System.Linq;
using Barotrauma.Extensions;
namespace Barotrauma
{
@@ -367,7 +368,11 @@ namespace Barotrauma
//toggle the door if it's the previous node and open, or if it's current node and closed
if (door.IsOpen != shouldBeOpen)
{
var buttons = door.Item.GetConnectedComponents<Controller>(true);
var buttons = door.Item.GetComponents<Controller>();
if (buttons.None())
{
buttons = door.Item.GetConnectedComponents<Controller>(true);
}
Controller closestButton = null;
float closestDist = 0.0f;
@@ -428,8 +433,12 @@ namespace Barotrauma
//door closed and the character can't open doors -> node can't be traversed
if (!canOpenDoors || character.LockHands) { return null; }
var doorButtons = nextNode.Waypoint.ConnectedDoor.Item.GetConnectedComponents<Controller>();
if (!doorButtons.Any())
var doorButtons = nextNode.Waypoint.ConnectedDoor.Item.GetComponents<Controller>();
if (doorButtons.None())
{
doorButtons = nextNode.Waypoint.ConnectedDoor.Item.GetConnectedComponents<Controller>();
}
if (doorButtons.None())
{
if (!nextNode.Waypoint.ConnectedDoor.HasRequiredItems(character, false)) { return null; }
}
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.Extensions;
namespace Barotrauma
{
@@ -62,8 +63,15 @@ namespace Barotrauma
if (useController)
{
var controllers = component.Item.GetConnectedComponents<Controller>();
if (controllers.Any()) controller = controllers[0];
var controllers = component.Item.GetComponents<Controller>();
if (controllers.None())
{
controllers = component.Item.GetConnectedComponents<Controller>();
}
if (controllers.Any())
{
controller = controllers.First();
}
}
canBeCompleted = true;
@@ -4,6 +4,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using System.Linq;
using Barotrauma.Extensions;
namespace Barotrauma
{
@@ -142,8 +144,15 @@ namespace Barotrauma
{
if (UseController)
{
var controllers = targetItem.Item.GetConnectedComponents<Controller>();
if (controllers.Count > 0) ConnectedController = controllers[0];
var controllers = targetItem.Item.GetComponents<Controller>();
if (controllers.None())
{
controllers = targetItem.Item.GetConnectedComponents<Controller>();
}
if (controllers.Any())
{
ConnectedController = controllers.First();
}
}
TargetEntity = targetItem.Item;
TargetItemComponent = targetItem;