-
-
Notifications
You must be signed in to change notification settings - Fork 217
feat: port ItemCondition from LustStation #4066
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
Merged
ThereDrD0
merged 1 commit into
space-sunrise:master
from
Soragy-bot:port/interactions-panel-from-lust-station
Mar 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
Content.Shared/_Sunrise/InteractionsPanel/Data/Conditions/ItemCondition.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| using Content.Shared.Hands.Components; | ||
| using Content.Shared.Hands.EntitySystems; | ||
| using Robust.Shared.Containers; | ||
| using Robust.Shared.Prototypes; | ||
| using Robust.Shared.Serialization; | ||
|
|
||
| namespace Content.Shared._Sunrise.InteractionsPanel.Data.Conditions; | ||
|
|
||
| [Serializable, NetSerializable, DataDefinition] | ||
| public sealed partial class ItemCondition : IAppearCondition | ||
| { | ||
| [DataField] | ||
| public bool CheckInitiator { get; private set; } = true; | ||
|
|
||
| [DataField] | ||
| public bool CheckTarget { get; private set; } | ||
|
|
||
| [DataField] | ||
| public List<EntProtoId> ItemWhiteList { get; private set; } = new(); | ||
|
|
||
| [DataField] | ||
| public bool CheckEquipped { get; private set; } | ||
|
|
||
| [DataField] | ||
| public List<string> EquipmentSlots { get; private set; } = new(); | ||
|
|
||
| public bool IsMet(EntityUid initiator, EntityUid target, EntityManager entityManager) | ||
| { | ||
| var handsSystem = entityManager.EntitySysManager.GetEntitySystem<SharedHandsSystem>(); | ||
|
|
||
| if (CheckInitiator) | ||
| { | ||
| if (!HasRequiredItem(initiator, entityManager, handsSystem)) | ||
| return false; | ||
| } | ||
|
|
||
| if (CheckTarget) | ||
| { | ||
| if (!HasRequiredItem(target, entityManager, handsSystem)) | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private bool HasRequiredItem(EntityUid entity, EntityManager entityManager, SharedHandsSystem handsSystem) | ||
| { | ||
| if (entityManager.TryGetComponent<HandsComponent>(entity, out var handsComponent)) | ||
| { | ||
| foreach (var heldEntity in handsSystem.EnumerateHeld((entity, handsComponent))) | ||
| { | ||
| if (IsMatchingItem(heldEntity, entityManager)) | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if (CheckEquipped && entityManager.TryGetComponent<ContainerManagerComponent>(entity, out var containerManager)) | ||
| { | ||
| foreach (var (key, container) in containerManager.Containers) | ||
| { | ||
| if (EquipmentSlots.Count > 0 && !EquipmentSlots.Contains(key)) | ||
| continue; | ||
|
|
||
| foreach (var containedEntity in container.ContainedEntities) | ||
| { | ||
| if (IsMatchingItem(containedEntity, entityManager)) | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool IsMatchingItem(EntityUid entity, EntityManager entityManager) | ||
| { | ||
| if (!entityManager.TryGetComponent<MetaDataComponent>(entity, out var meta)) | ||
| return false; | ||
|
|
||
| return meta.EntityPrototype != null && ItemWhiteList.Contains(meta.EntityPrototype.ID); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пустой whitelist делает условие невыполнимым.
Если
ItemWhiteListпуст (значение по умолчанию), тоIsMatchingItemвсегда возвращаетfalse, и условие никогда не будет выполнено приCheckInitiator = true(также по умолчанию).Рассмотрите добавление валидации или раннего возврата
true, если whitelist пуст (если это интерпретируется как "любой предмет подходит").💡 Возможное исправление
private bool IsMatchingItem(EntityUid entity, EntityManager entityManager) { + // Пустой whitelist = любой предмет подходит + if (ItemWhiteList.Count == 0) + return true; + if (!entityManager.TryGetComponent<MetaDataComponent>(entity, out var meta)) return false; return meta.EntityPrototype != null && ItemWhiteList.Contains(meta.EntityPrototype.ID); }🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поведение намеренное. ItemWhiteList — это вайтлист конкретных предметов, а не "наличие хоть какого-то предмета". Пустой список означает, что предметы для проверки не заданы, поэтому false — корректный результат.
Если CheckInitiator = true и ItemWhiteList пуст — это ошибка конфигурации в YAML, а не баг кода.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Soragy-bot, понял, спасибо за пояснение. Согласен — еслиItemWhiteListпуст, это ошибка конфигурации в YAML, а не баг кода. Поведение корректно.(>‿‿>)
✏️ Learnings added
🧠 Learnings used