Client LuaCsForBarotrauma
CharacterAbilityRegenerateLoot.cs
1
using
Barotrauma
.
Items
.
Components
;
2
using
System.Collections.Generic;
3
4
namespace
Barotrauma.Abilities
5
{
6
class
CharacterAbilityRegenerateLoot
:
CharacterAbility
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
}
Barotrauma.Abilities.AbilityObject
Definition:
AbilityObjects.cs:6
Barotrauma.Abilities.CharacterAbilityGroup
Definition:
CharacterAbilityGroup.cs:9
Barotrauma.Abilities.CharacterAbility
Definition:
CharacterAbility.cs:7
Barotrauma.Abilities.CharacterAbilityRegenerateLoot
Definition:
CharacterAbilityRegenerateLoot.cs:7
Barotrauma.Abilities.CharacterAbilityRegenerateLoot.ApplyEffect
override void ApplyEffect(AbilityObject abilityObject)
Definition:
CharacterAbilityRegenerateLoot.cs:32
Barotrauma.Abilities.CharacterAbilityRegenerateLoot.CharacterAbilityRegenerateLoot
CharacterAbilityRegenerateLoot(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
Definition:
CharacterAbilityRegenerateLoot.cs:26
Barotrauma.ContentXElement
Definition:
ContentXElement.cs:13
Barotrauma.ContentXElement.GetAttributeFloat
float GetAttributeFloat(string key, float def)
Barotrauma.Item
Definition:
BarotraumaShared/SharedSource/Items/Item.cs:26
Barotrauma.Items.Components.ItemContainer
Definition:
BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs:15
Barotrauma.Abilities.IAbilityItem
Definition:
AbilityInterfaces.cs:9
Barotrauma.Abilities
Definition:
AbilityCondition.cs:5
Barotrauma.Items.Components
Definition:
BarotraumaShared/SharedSource/Items/Components/DockingPort.cs:15
Barotrauma.Items
Definition:
BarotraumaShared/SharedSource/Items/Components/DockingPort.cs:15
Barotrauma
Definition:
AchievementManager.cs:12
Barotrauma
BarotraumaShared
SharedSource
Characters
Talents
Abilities
CustomAbilities
CharacterAbilityRegenerateLoot.cs
Generated by
1.9.1