Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -21,7 +21,8 @@ namespace Barotrauma
//can either be a tag or an identifier
public readonly string[] itemIdentifiers;
public readonly ItemContainer container;
public readonly Item item;
private readonly Item item;
public Item ItemToContain { get; private set; }
private AIObjectiveGetItem getItemObjective;
private AIObjectiveGoTo goToObjective;
@@ -30,10 +31,13 @@ namespace Barotrauma
public bool AllowToFindDivingGear { get; set; } = true;
public bool AllowDangerousPressure { get; set; }
public float ConditionLevel { get; set; }
public float ConditionLevel { get; set; } = 1;
public bool Equip { get; set; }
public bool RemoveEmpty { get; set; } = true;
public bool MoveWholeStack { get; set; }
public AIObjectiveContainItem(Character character, Item item, ItemContainer container, AIObjectiveManager objectiveManager, float priorityModifier = 1)
: base(character, objectiveManager, priorityModifier)
{
@@ -66,14 +70,14 @@ namespace Barotrauma
}
if (item != null)
{
return container.Inventory.Items.Contains(item);
return container.Inventory.Contains(item);
}
else
{
int containedItemCount = 0;
foreach (Item i in container.Inventory.Items)
foreach (Item it in container.Inventory.AllItems)
{
if (i != null && CheckItem(i))
if (CheckItem(it))
{
containedItemCount++;
}
@@ -82,7 +86,7 @@ namespace Barotrauma
}
}
private bool CheckItem(Item i) => itemIdentifiers.Any(id => i.Prefab.Identifier == id || i.HasTag(id)) && i.ConditionPercentage > ConditionLevel;
private bool CheckItem(Item i) => itemIdentifiers.Any(id => i.Prefab.Identifier == id || i.HasTag(id)) && i.ConditionPercentage >= ConditionLevel && !i.IsThisOrAnyContainerIgnoredByAI();
protected override void Act(float deltaTime)
{
@@ -91,58 +95,44 @@ namespace Barotrauma
Abandon = true;
return;
}
Item itemToContain = item ?? character.Inventory.FindItem(i => CheckItem(i) && i.Container != container.Item, recursive: true);
if (itemToContain != null)
ItemToContain = item ?? character.Inventory.FindItem(i => CheckItem(i) && i.Container != container.Item, recursive: true);
if (ItemToContain != null)
{
if (!character.CanInteractWith(itemToContain))
if (!character.CanInteractWith(ItemToContain, checkLinked: false))
{
Abandon = true;
return;
}
if (character.CanInteractWith(container.Item, out _, checkLinked: false))
if (character.CanInteractWith(container.Item, checkLinked: false))
{
if (RemoveEmpty)
{
foreach (var emptyItem in container.Inventory.Items)
{
if (emptyItem == null) { continue; }
if (emptyItem.Condition <= 0)
{
emptyItem.Drop(character);
}
}
HumanAIController.UnequipEmptyItems(container.Item);
}
// Contain the item
if (itemToContain.ParentInventory == character.Inventory)
Inventory originalInventory = ItemToContain.ParentInventory;
var slots = originalInventory?.FindIndices(ItemToContain);
if (container.Inventory.TryPutItem(ItemToContain, null))
{
if (!container.Inventory.CanBePut(itemToContain))
if (MoveWholeStack && slots != null)
{
Abandon = true;
}
else
{
character.Inventory.RemoveItem(itemToContain);
if (container.Inventory.TryPutItem(itemToContain, null))
foreach (int slot in slots)
{
IsCompleted = true;
}
else
{
itemToContain.Drop(character);
Abandon = true;
foreach (Item item in originalInventory.GetItemsAt(slot).ToList())
{
container.Inventory.TryPutItem(item, null);
}
}
IsCompleted = true;
}
}
else
{
if (container.Combine(itemToContain, character))
if (ItemToContain.ParentInventory == character.Inventory)
{
IsCompleted = true;
}
else
{
Abandon = true;
ItemToContain.Drop(character);
}
Abandon = true;
}
}
else
@@ -151,7 +141,7 @@ namespace Barotrauma
{
DialogueIdentifier = "dialogcannotreachtarget",
TargetName = container.Item.Name,
abortCondition = () => !itemToContain.IsOwnedBy(character)
abortCondition = obj => !ItemToContain.IsOwnedBy(character)
},
onAbandon: () => Abandon = true,
onCompleted: () => RemoveSubObjective(ref goToObjective));