Client LuaCsForBarotrauma
CharacterAbilityRegenerateLoot.cs
2 using System.Collections.Generic;
3 
4 namespace Barotrauma.Abilities
5 {
7  {
12  private readonly float randomChance;
13 
14  // separate random chance used for the ability itself to prevent the player
15  // from opening/reopening a container until it spawns loot
16 
20  private readonly float randomChancePerItem = 1.0f;
21 
22  // not maintained through death, so it's possible for players to respawn and re-loot chests
23  // seems like a minor issue for now
24  private readonly HashSet<Item> openedContainers = new HashSet<Item>();
25 
26  public CharacterAbilityRegenerateLoot(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
27  {
28  randomChance = abilityElement.GetAttributeFloat(nameof(randomChance), 1f);
29  randomChancePerItem = abilityElement.GetAttributeFloat(nameof(randomChancePerItem), 1f);
30  }
31 
32  protected override void ApplyEffect(AbilityObject abilityObject)
33  {
34  if ((abilityObject as IAbilityItem)?.Item is not Item item) { return; }
35  if (openedContainers.Contains(item)) { return; }
36 
37  openedContainers.Add(item);
38  if (randomChance < Rand.Range(0f, 1f, Rand.RandSync.Unsynced)) { return; }
39 
40  if (item.GetComponent<ItemContainer>() is ItemContainer itemContainer)
41  {
42  AutoItemPlacer.RegenerateLoot(item.Submarine, itemContainer, skipItemProbability: 1.0f - randomChancePerItem);
43  }
44 
45  }
46  }
47 }
override void ApplyEffect(AbilityObject abilityObject)
CharacterAbilityRegenerateLoot(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
float GetAttributeFloat(string key, float def)