(94ad97066) Refactor combat objective. The bots should now be able to reload and seek more ammunition. When they run out of ammunition, they first try to use another weapon and only if no other weapon is found, they seek more ammunition. Had to change the contain item and get item objectives a bit. Hopefully doesn't break things too much.

This commit is contained in:
Joonas Rikkonen
2019-05-16 06:13:15 +03:00
parent 298f1a79b0
commit ce7b9c4f52
41 changed files with 634 additions and 348 deletions
@@ -41,10 +41,10 @@ namespace Barotrauma
this.targetItem = targetItem;
}
public AIObjectiveGetItem(Character character, string itemIdentifier, AIObjectiveManager objectiveManager, bool equip = false, float priorityModifier = 1)
: this(character, new string[] { itemIdentifier }, objectiveManager, equip, priorityModifier) { }
public AIObjectiveGetItem(Character character, string itemIdentifier, AIObjectiveManager objectiveManager, bool equip = false, bool checkInventory = true, float priorityModifier = 1)
: this(character, new string[] { itemIdentifier }, objectiveManager, equip, checkInventory, priorityModifier) { }
public AIObjectiveGetItem(Character character, string[] itemIdentifiers, AIObjectiveManager objectiveManager, bool equip = false, float priorityModifier = 1)
public AIObjectiveGetItem(Character character, string[] itemIdentifiers, AIObjectiveManager objectiveManager, bool equip = false, bool checkInventory = true, float priorityModifier = 1)
: base(character, objectiveManager, priorityModifier)
{
currSearchIndex = -1;
@@ -54,7 +54,10 @@ namespace Barotrauma
{
itemIdentifiers[i] = itemIdentifiers[i].ToLowerInvariant();
}
CheckInventory();
if (checkInventory)
{
CheckInventory();
}
}
private void CheckInventory()
@@ -225,8 +228,7 @@ namespace Barotrauma
public override bool IsDuplicate(AIObjective otherObjective)
{
AIObjectiveGetItem getItem = otherObjective as AIObjectiveGetItem;
if (getItem == null) { return false; }
if (!(otherObjective is AIObjectiveGetItem getItem)) { return false; }
if (getItem.equip != equip) { return false; }
if (getItem.itemIdentifiers != null && itemIdentifiers != null)
{
@@ -246,7 +248,11 @@ namespace Barotrauma
public override bool IsCompleted()
{
if (itemIdentifiers != null)
if (targetItem != null)
{
return HasItem(targetItem);
}
else if (itemIdentifiers != null)
{
foreach (string itemName in itemIdentifiers)
{
@@ -258,14 +264,19 @@ namespace Barotrauma
}
return false;
}
else if (targetItem != null)
return false;
}
private bool HasItem(Item item)
{
bool isEquipped = !equip || character.HasEquippedItem(item);
if (character.Inventory.Items.Contains(item) && isEquipped) { return true; }
Item rootContainer = item.GetRootContainer();
if (rootContainer != null && rootContainer.ParentInventory is CharacterInventory)
{
return character.Inventory.Items.Contains(targetItem) && (!equip || character.HasEquippedItem(targetItem));
}
else
{
return false;
return rootContainer.ParentInventory.Owner == character;
}
return false;
}
}
}