diff --git a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs
index e7d287f790..d0a90f40a4 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs
@@ -10,6 +10,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
+using static Barotrauma.EntitySpawner;
namespace Barotrauma
{
@@ -151,7 +152,11 @@ public enum SpawnPositionType
///
/// The position of the entity the StatusEffect is targeting. If there are multiple targets, an item is spawned at all of them.
///
- Target
+ Target,
+ ///
+ /// The inventories of the entities the StatusEffect is targeting. If there are multiple targets, the items are spawned in all of them.
+ ///
+ TargetInventory
}
public enum SpawnRotationType
@@ -2138,7 +2143,7 @@ entity is Item item &&
void ProcessItemSpawnInfo(ItemSpawnInfo spawnInfo)
{
- if (spawnInfo.SpawnPosition == ItemSpawnInfo.SpawnPositionType.Target)
+ if (spawnInfo.SpawnPosition is ItemSpawnInfo.SpawnPositionType.Target or ItemSpawnInfo.SpawnPositionType.TargetInventory)
{
foreach (var target in targets)
{
@@ -2192,7 +2197,7 @@ void SpawnItem(ItemSpawnInfo chosenItemSpawnInfo, Entity entity, PhysicsBody sou
SetUser(parentItem.GetComponent()?.User);
}
- if (chosenItemSpawnInfo.SpawnPosition == ItemSpawnInfo.SpawnPositionType.Target && targetEntity != null)
+ if (chosenItemSpawnInfo.SpawnPosition is ItemSpawnInfo.SpawnPositionType.Target or ItemSpawnInfo.SpawnPositionType.TargetInventory && targetEntity != null)
{
entity = targetEntity;
position = entity.WorldPosition;
@@ -2318,6 +2323,7 @@ void SpawnItem(ItemSpawnInfo chosenItemSpawnInfo, Entity entity, PhysicsBody sou
});
break;
case ItemSpawnInfo.SpawnPositionType.ThisInventory:
+ case ItemSpawnInfo.SpawnPositionType.TargetInventory:
{
Inventory inventory = null;
if (entity is Character character && character.Inventory != null)
@@ -2343,16 +2349,7 @@ void SpawnItem(ItemSpawnInfo chosenItemSpawnInfo, Entity entity, PhysicsBody sou
{
Entity.Spawner.AddItemToSpawnQueue(chosenItemSpawnInfo.ItemPrefab, inventory, spawnIfInventoryFull: chosenItemSpawnInfo.SpawnIfInventoryFull, onSpawned: item =>
{
- if (chosenItemSpawnInfo.Equip && entity is Character character && character.Inventory != null)
- {
- //if the item is both pickable and wearable, try to wear it instead of picking it up
- List allowedSlots =
- item.GetComponents().Count() > 1 ?
- new List(item.GetComponent()?.AllowedSlots ?? item.GetComponent().AllowedSlots) :
- new List(item.AllowedSlots);
- allowedSlots.Remove(InvSlotType.Any);
- character.Inventory.TryPutItem(item, null, allowedSlots);
- }
+ if (chosenItemSpawnInfo.Equip) TryEquipItem(item, inventory);
OnItemSpawned(item, chosenItemSpawnInfo);
});
}
@@ -2373,6 +2370,7 @@ void SpawnItem(ItemSpawnInfo chosenItemSpawnInfo, Entity entity, PhysicsBody sou
{
Entity.Spawner.AddItemToSpawnQueue(chosenItemSpawnInfo.ItemPrefab, inventory, spawnIfInventoryFull: chosenItemSpawnInfo.SpawnIfInventoryFull, onSpawned: (Item newItem) =>
{
+ if (chosenItemSpawnInfo.Equip) TryEquipItem(newItem, inventory);
OnItemSpawned(newItem, chosenItemSpawnInfo);
});
}
@@ -2419,6 +2417,18 @@ void SpawnItem(ItemSpawnInfo chosenItemSpawnInfo, Entity entity, PhysicsBody sou
}
break;
}
+
+ void TryEquipItem(Item newItem, Inventory inventory)
+ {
+ if (inventory is not CharacterInventory charInventory) { return; }
+
+ // If the item is wearable, try to wear it instead of picking it up.
+ IEnumerable wearableSlots = newItem.GetComponents().SelectMany(wearable => wearable.AllowedSlots).Distinct();
+ List allowedSlots = (wearableSlots.Any() ? wearableSlots : newItem.AllowedSlots).ToList();
+ allowedSlots.Remove(InvSlotType.Any);
+ charInventory.TryPutItem(newItem, null, allowedSlots);
+ }
+
void OnItemSpawned(Item newItem, ItemSpawnInfo itemSpawnInfo)
{
newItem.Condition = newItem.MaxCondition * itemSpawnInfo.Condition;