Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'OnNotContaining' StatusEffect ActionType. #14261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Barotrauma/BarotraumaShared/SharedSource/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public enum ActionType
/// </summary>
OnAbility = 23,
/// <summary>
/// Executes continuously when a specific Containable is NOT inside an ItemContainer. Only valid for Containables defined in an ItemContainer component.
/// </summary>
OnNotContaining = 24,
/// <summary>
/// Executes when the character dies. Only valid for characters.
/// </summary>
OnDeath = OnBroken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,27 @@ void Inject(Item item)
effect.Apply(ActionType.OnContaining, deltaTime, item, targets);
if (wearing) { effect.Apply(ActionType.OnWearing, deltaTime, item, targets); }
}

for (int i = 0; i < slotRestrictions.Length; i++)
{
foreach (StatusEffect effect in slotRestrictions[i].ContainableItems.SelectMany(ci => ci.StatusEffects.Where(se => se.type == ActionType.OnNotContaining && Inventory.GetItemsAt(i).None(ci.MatchesItem))))
Copy link
Collaborator

@Regalis11 Regalis11 Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates a ton of garbage due to the captured variables. Particularly bad in this case, because this executes potentially tons of times per frame.

{
targets.Clear();
if (effect.HasTargetType(StatusEffect.TargetType.This))
{
targets.AddRange(item.AllPropertyObjects);
}
if (effect.HasTargetType(StatusEffect.TargetType.Character) && item.ParentInventory?.Owner is Character character)
{
targets.Add(character);
}
if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters))
{
effect.AddNearbyTargets(item.WorldPosition, targets);
}
effect.Apply(ActionType.OnNotContaining, deltaTime, item, targets);
}
}
}

/// <summary>
Expand Down