Client LuaCsForBarotrauma
CharacterAbilitySpawnItemsToContainer.cs
1 using System.Collections.Generic;
2 
3 namespace Barotrauma.Abilities
4 {
6  {
7  // currently used only for spawning items to containers
8 
9  private readonly List<StatusEffect> statusEffects;
10  private readonly List<Item> openedContainers = new List<Item>();
11  private readonly float randomChance;
12  private readonly bool oncePerContainer;
13 
14  public CharacterAbilitySpawnItemsToContainer(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
15  {
16  statusEffects = CharacterAbilityGroup.ParseStatusEffects(CharacterTalent, abilityElement.GetChildElement("statuseffects"));
17  randomChance = abilityElement.GetAttributeFloat("randomchance", 1f);
18  oncePerContainer = abilityElement.GetAttributeBool("oncepercontainer", false);
19  }
20 
21  protected override void ApplyEffect(AbilityObject abilityObject)
22  {
23  if ((abilityObject as IAbilityItem)?.Item is Item item)
24  {
25  if (oncePerContainer)
26  {
27  if (openedContainers.Contains(item)) { return; }
28  openedContainers.Add(item);
29  }
30  if (randomChance < Rand.Range(0f, 1f, Rand.RandSync.Unsynced)) { return; }
31 
32  foreach (var statusEffect in statusEffects)
33  {
34  statusEffect.Apply(ActionType.OnAbility, EffectDeltaTime, item, item);
35  }
36  }
37  else
38  {
40  }
41  }
42  }
43 }
static List< StatusEffect > ParseStatusEffects(CharacterTalent characterTalent, ContentXElement statusEffectElements)
float EffectDeltaTime
Used primarily for StatusEffects. Default to constant outside interval abilities.
CharacterAbilitySpawnItemsToContainer(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
float GetAttributeFloat(string key, float def)
ContentXElement? GetChildElement(string name)
bool GetAttributeBool(string key, bool def)
ActionType
ActionTypes define when a StatusEffect is executed.
Definition: Enums.cs:26