Client LuaCsForBarotrauma
CharacterAbilityPutItem.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  private readonly Identifier itemIdentifier;
6  private readonly int amount;
7  public override bool AppliesEffectOnIntervalUpdate => true;
8  public CharacterAbilityPutItem(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
9  {
10  itemIdentifier = abilityElement.GetAttributeIdentifier("itemidentifier", "");
11  amount = abilityElement.GetAttributeInt("amount", 1);
12  if (itemIdentifier.IsEmpty)
13  {
14  DebugConsole.ThrowError($"Error in talent \"{characterAbilityGroup.CharacterTalent.DebugIdentifier}\" - itemIdentifier not defined.",
15  contentPackage: abilityElement.ContentPackage);
16  }
17  }
18 
19  protected override void ApplyEffect()
20  {
21  if (itemIdentifier.IsEmpty)
22  {
23  DebugConsole.ThrowError("Cannot put item in inventory - itemIdentifier not defined.",
24  contentPackage: CharacterTalent.Prefab.ContentPackage);
25  return;
26  }
27 
28  ItemPrefab itemPrefab = ItemPrefab.Find(null, itemIdentifier);
29  if (itemPrefab == null)
30  {
31  DebugConsole.ThrowError("Cannot put item in inventory - item prefab " + itemIdentifier + " not found.",
32  contentPackage: CharacterTalent.Prefab.ContentPackage);
33  return;
34  }
35  for (int i = 0; i < amount; i++)
36  {
37  if (GameMain.GameSession?.RoundEnding ?? true)
38  {
39  Item item = new Item(itemPrefab, Character.WorldPosition, Character.Submarine);
41  {
42  foreach (Item containedItem in Character.Inventory.AllItemsMod)
43  {
44  if (containedItem.OwnInventory?.TryPutItem(item, Character) ?? false) { break; }
45  }
46  }
47  }
48  else
49  {
51  }
52  }
53  }
54  }
55 }
CharacterAbilityPutItem(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
override bool TryPutItem(Item item, Character user, IEnumerable< InvSlotType > allowedSlots=null, bool createNetworkEvent=true, bool ignoreCondition=false)
If there is room, puts the item in the inventory and returns true, otherwise returns false
readonly TalentPrefab Prefab
ContentPackage? ContentPackage
int GetAttributeInt(string key, int def)
Identifier GetAttributeIdentifier(string key, string def)
static EntitySpawner Spawner
Definition: Entity.cs:31
virtual Vector2 WorldPosition
Definition: Entity.cs:49
Submarine Submarine
Definition: Entity.cs:53
void AddItemToSpawnQueue(ItemPrefab itemPrefab, Vector2 worldPosition, float? condition=null, int? quality=null, Action< Item > onSpawned=null)
static GameSession?? GameSession
Definition: GameMain.cs:88
IEnumerable< Item > AllItemsMod
All items contained in the inventory. Allows modifying the contents of the inventory while being enum...
IEnumerable< InvSlotType > AllowedSlots
override bool TryPutItem(Item item, Character user, IEnumerable< InvSlotType > allowedSlots=null, bool createNetworkEvent=true, bool ignoreCondition=false)
If there is room, puts the item in the inventory and returns true, otherwise returns false
static ItemPrefab Find(string name, Identifier identifier)
ContentPackage? ContentPackage
Definition: Prefab.cs:37