mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-08 23:37:25 +00:00
+33









deltanedas
Justin
Psychpsyo
Psychpsyo
slarticodefast
SlamBamActionman
chromiumboy
ShadowCommander
Chief-Engineer
deathride58
deltanedas
PJBot
BramvanZijp
Ilya246
Moomoobeef
Saphire Lattice
FluffMe
Theodore Lukin
August Sun
august-sun
lzk
metalgearsloth
Preston Smith
Milon
Flareguy
Alzore
Boaz1111
Jarmer123
SpaceLizard
PopGamer46
RumiTiger
ScarKy0
Minemoder5000
UBlueberry
Brandon Li
Vasilis
K-Dynamic
Ubaser
AftrLite
nikthechampiongr
Centronias
joshepvodka
Scribbles0
2620eb48a8
* Fix multiplying colors of differing nullabilities (#32991) * revert the temporary hack * Make atmos alert computer colors private variables (#32992) * Add flash reaction effect (#32377) add flash reaction effect * Automatic changelog update * Fix loneop spawnrate by reverting it to not use the shuttle event system. (#32942) Fix loneop spawnrate by reverting it to not use the custom shuttle event system. * Automatic changelog update * add atmosia to devmap (#32460) change * bowls now make drinking sounds (#32819) * Automatic changelog update * Add health analyzer unrevivability warning (#32636) * Add health analyzer unrevivability warning * Remove errornous comment * Automatic changelog update * Removed the name "Hujsak" (#32998) removed hujsak * fix pie throwing sound not playing (#33017) * Automatic changelog update * Fix TestSuicideByHeldItem and TestSuicideByHeldItemSpreadDamage (#33030) * make ai speak robotically (#33025) * Automatic changelog update * Extends the minimum round time for meteor swarm events (#32876) * adjusted minimum timers in meteorswarms.yml * Updated timer minimum from 20 to 15 minutes * Reduced minimum timer to 10 minutes as a result of other meteor changes --------- Co-authored-by: august-sun <45527070+august.sun@users.noreply.github.com> * Automatic changelog update * add StartDelay bool to actions (#33026) * add StartDelay bool to actions * forgot summary * Updated an incorrect sprite in the smite menu (#33043) changed the synth sprite used in the icon for the instrumentify smite out for the more accurate supersynth sprite * fix lava expeds (#33042) Co-authored-by: deltanedas <@deltanedas:kde.org> * Automatic changelog update * Fix separated game screen bumping (#33046) I don't really understand why RecordedSplitContainer exists but removing it looks identical and fixes the panel bumping occasionally. * Automatic changelog update * Fix: Make Plushie Damage Unexaminable (#33061) Set hidden to true * fix chameleon projector bot whitelist (#33055) fix * Various Vaugely Connected Sprite Updates™: Encryption Keys, Station Map, Brig Timer (#32786) * various resprites (encryption keys + signal screens + station map) * brig timer update * fixes n shit * Give proto-kinetic crushers, glaives, and daggers better inhands. Update the crusher and glaive icons. (#32212) * inhands * better inhands * indent * Automatic changelog update * Make the security belt contain more useful items by default (#32291) * replace tear gas and flashbang with holobarrier and sec radio * holobarrier-belt-fix * revert changes of 32291 * Automatic changelog update * Add 3 bottle boxes to nanomed plus (#33018) three bottle boxes in nanomed plus * Automatic changelog update * Nukie med bundle now costs 24 tc and contains a unique defibrillator (#32720) * a-few-injectors * comment * defib-ops-when * Automatic changelog update * Pill Bottles can only store pills now (#33074) * no longer absurd * Update Resources/Prototypes/Entities/Objects/Specific/chemistry.yml --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Automatic changelog update * Add a spare bible to PietyVend (#32363) Update chapel.yml * Automatic changelog update * [#28722 fix] Add notification for dependent wearables being dropped (#33078) * add notification for dependent wearables being dropped * fix dropped item popup redundancy - did a check to see if any item was dropped, instead of making a notification for each item being dropped. * change popup to client-only variant * fix redundant messages, add plural locale string * fix conventions, fix locale input to be more intuitive --------- Co-authored-by: Justin <justinbrick1@gmail.com> * Automatic changelog update * More pda space (#32601) * Rebalance the max programs that a PDA can hold * Give Caps PDA more programs too. * Make the max programs a static 8 * I forgor sec and med * CaseCase * Empty commit to re-run checks * The final change, I hope. * Automatic changelog update * Fixed spelling mistake in water blaster description. (#33087) Fixed minor spelling mistake * [#20285 fix] Carp Plush and Rehydratables can now be put into mop bucket (#33079) * Make shark plush janitor-bucketable * fix bucketed grey shark texture * Make sprites less shiny and adapt copyright notice * Made shark way way less shiny * Allow carp plush and rehydratables in mop bucket. * Remove old mop bucket shark sprites * Fix post-merge bugs * Fix errors * Move ReactiveContainer stuff to shared That should mean it is now predicted. * Custom eject verb for the mop bucket * Fixes OnSolutionChange, removes pop-up as there already is one. * .ftl is not necessary as the custom pop-up was removed * Review fixes * Update Content.Shared/Chemistry/Components/ReactiveContainerComponent.cs * Update Content.Shared/Chemistry/EntitySystems/ReactiveContainerSystem.cs --------- Co-authored-by: Psychpsyo <psychpsyo@gmail.com> Co-authored-by: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Automatic changelog update * remove now duplicated nyano PlushieCarp tag * Fixes tailthump breaking positional audio by making it mono (#33092) * Automatic changelog update * ExaminableDamage now puts its message at the bottom and in color (#32820) * the examineableDamage component now puts its messages at the bottom, and in color * god help us if something is priority -100 :godo: * Automatic changelog update * Lower in-round votekick requirements (#32953) Initial commit * Allow votekicks to be initiated in the lobby (#32528) Initial commit * Automatic changelog update * Fixes bolt lights of previously unpowered bolted doors (#33063) fix * Automatic changelog update * Muffins (#29318) * Update meta.json * Add files via upload * Update misc.yml * Update meal_recipes.yml * Update meta.json * Add files via upload * Update plate.yml * Update food_baked_single.yml * Update dinnerware.yml * Update cooking.yml * Update misc.yml * Add files via upload * Delete Resources/Textures/Objects/Consumable/Food/Baked/misc.rsi/muffin-cherry.png * Add files via upload * Update meta.json * Update misc.yml * Update meal_recipes.yml * Update meta.json * Fix meta.json * Fix meta.json again * Update misc.yml * Update misc.yml * Update misc.yml * Update misc.yml * Update meta.json * Update meta.json * Update misc.yml * Update meal_recipes.yml * Update Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/misc.yml Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update dinnerware.yml * Delete cherry * Add files via upload * Delete banana * Add banana * Delete chocolate * Add chocolate * lathe recipe fix --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Automatic changelog update * Borgs can no longer see mindshield + AI can no longer toggle off seeing job icons (#33069) * :( * Removed the sprite + updated RSI * Automatic changelog update * Add CanLoad for biomes (#33050) CPUJob to come later. * Remove CargoPallet component from the cargo pallet (#33022) * Change cargo shuttle pallets to catwalks. * Remove CargoPallet component from the cargo pallet. * Undo cargo shuttle changes. * Automatic changelog update * Minor antagonist guidebook changes (#32824) * took a two month nap. accidentally pushed too many buttons. let's try this again. added thieves to antagonists.xml * even after that nap, i don't feel well-rested at all. * please don't kill me for using webedit * capitalization, typo * Apply suggestions from code review (more period moving) Thanks Evan, very cool Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * guess you could say im not pro-proper noun * typo * Update Resources/ServerInfo/Guidebook/Antagonist/Nuclear Operatives.xml * ok Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> * Give Nukies a Hand Labeler (#33053) * Add hand-labeler to nukie planet * Rearrange nukie chem table * Fix `ItemSlotSystem` popup Logic (#28856) * move popup call out of `CanInsert` into `OnInteractUsing` * im stupid and `reason` is completely unnecessary Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * return early when `itemSlots.Slots.Count == 0` * tweak logic for triggering popups * change popup logic again * Consolidate whitelist check * Get any popup message not just last failed slot * Apply suggestions from code review Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com> * yoink Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> --------- Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com> * Add cvars to votekick to customize requirements for the initiator. (#32490) * Automatic changelog update * Add on-call functionality for adminning (#30443) * Add on-call functionality for adminning The first time an ahelp gets SOS it gets relayed to the specified channel with the specified ping. Every time after that it doesn't until it gets a non-SOS response received. * Remove redundant name Pretty sure this already gets chucked on the name of the msg itself I think it just didn't show in screenshot because they were subsequent. * Update Content.Server/Administration/Systems/BwoinkSystem.cs Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> --------- Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Co-authored-by: deathride58 <deathride58@users.noreply.github.com> * Automatic changelog update * Pills are explosion resistant (partially reverts #15851) (#32458) * idk how to revert a pr so I just deleted some lines * pill destructible with explosion resistance * comment for explosion resist * "and" to "but" --------- Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> * Automatic changelog update * Hasten handcraft gauze recipe & decrease techfab gauze cost (#32744) * med lathe gauze price reduction * gauze craft doafter time * 3 second doafter craft * Automatic changelog update * Service workers antagonist fix. (#31359) * add * Revert "add" This reverts commit 25da34b0fead5812fe5800c9bf5dd7b10ef48d7d. * antagonism allowed™️ * Automatic changelog update * Adds a new AME sound effect! (#33097) * Changes the AME sound effect to not be the default MetalThud. * Was told on discord to make a minor change to autorerun the tests due to the Build & Test Debug failing! * Attribution and licensing, as requsted by deathride58 * Fixes the high-pitched squeak audible to some people! * Audio file tweaked by SlamBamActionMan to eliminate a weird squeak they were still able to hear. Thanks! * Automatic changelog update * Allow for the ai's laws to be changed from its core and eye (#32461) * Allow for the ai's laws to be changed from its core and eye * Address reviews * Automatic changelog update * clean up tools lathe recipes (#31521) * clean up tools lathe recipes * add medical and cooking tools * add result * add result to others * review * engine --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Automatic changelog update * Intercoms and Radios both pick up proximate speech (#32737) * Deduping of recent messages should consider the channel it's being sent to * rerun actions * Automatic changelog update * Adds headphones to loadouts (#33067) added headphones to trinkets * Automatic changelog update * Cardboard Box Capacity 4 -> 5 (#32743) * capacity upgrade * comment update * remove our duplicate pill whitelist * fix * remove broken crew monitor from dev map, how did it even get there --------- Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com> Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com> Co-authored-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com> Co-authored-by: Ilya246 <57039557+Ilya246@users.noreply.github.com> Co-authored-by: Moomoobeef <62638182+Moomoobeef@users.noreply.github.com> Co-authored-by: Saphire Lattice <lattice@saphi.re> Co-authored-by: FluffMe <1780586+FluffMe@users.noreply.github.com> Co-authored-by: Theodore Lukin <66275205+pheenty@users.noreply.github.com> Co-authored-by: August Sun <45527070+august-sun@users.noreply.github.com> Co-authored-by: august-sun <45527070+august.sun@users.noreply.github.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Preston Smith <92108534+thetolbean@users.noreply.github.com> Co-authored-by: Milon <plmilonpl@gmail.com> Co-authored-by: Flareguy <78941145+Flareguy@users.noreply.github.com> Co-authored-by: Alzore <140123969+Blackern5000@users.noreply.github.com> Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com> Co-authored-by: Jarmer123 <148848017+Jarmer123@users.noreply.github.com> Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Co-authored-by: Justin <justinbrick1@gmail.com> Co-authored-by: SpaceLizard <the.justice.league.of.canada@gmail.com> Co-authored-by: Psychpsyo <psychpsyo@gmail.com> Co-authored-by: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Co-authored-by: deathride58 <deathride58@users.noreply.github.com> Co-authored-by: PopGamer46 <yt1popgamer@gmail.com> Co-authored-by: RumiTiger <154005209+RumiTiger@users.noreply.github.com> Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Co-authored-by: Minemoder5000 <minemoder50000@gmail.com> Co-authored-by: UBlueberry <161545003+UBlueberry@users.noreply.github.com> Co-authored-by: Brandon Li <48413902+aspiringLich@users.noreply.github.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: Vasilis <vasilis@pikachu.systems> Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Co-authored-by: K-Dynamic <20566341+K-Dynamic@users.noreply.github.com> Co-authored-by: Ubaser <134914314+UbaserB@users.noreply.github.com> Co-authored-by: AftrLite <61218133+AftrLite@users.noreply.github.com> Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Co-authored-by: Centronias <me@centronias.com> Co-authored-by: joshepvodka <86210200+joshepvodka@users.noreply.github.com> Co-authored-by: Scribbles0 <91828755+Scribbles0@users.noreply.github.com>
882 lines
33 KiB
C#
882 lines
33 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Destructible;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Verbs;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Containers.ItemSlots
|
|
{
|
|
/// <summary>
|
|
/// A class that handles interactions related to inserting/ejecting items into/from an item slot.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Note when using popups on entities with many slots with InsertOnInteract, EjectOnInteract or EjectOnUse:
|
|
/// A single use will try to insert to/eject from every slot and generate a popup for each that fails.
|
|
/// </remarks>
|
|
public sealed partial class ItemSlotsSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
[Dependency] private readonly SharedContainerSystem _containers = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
InitializeLock();
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<ItemSlotsComponent, ComponentInit>(Oninitialize);
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, InteractUsingEvent>(OnInteractUsing);
|
|
SubscribeLocalEvent<ItemSlotsComponent, InteractHandEvent>(OnInteractHand);
|
|
SubscribeLocalEvent<ItemSlotsComponent, UseInHandEvent>(OnUseInHand);
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<AlternativeVerb>>(AddAlternativeVerbs);
|
|
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<InteractionVerb>>(AddInteractionVerbsVerbs);
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, BreakageEventArgs>(OnBreak);
|
|
SubscribeLocalEvent<ItemSlotsComponent, DestructionEventArgs>(OnBreak);
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, ComponentGetState>(GetItemSlotsState);
|
|
SubscribeLocalEvent<ItemSlotsComponent, ComponentHandleState>(HandleItemSlotsState);
|
|
|
|
SubscribeLocalEvent<ItemSlotsComponent, ItemSlotButtonPressedEvent>(HandleButtonPressed);
|
|
}
|
|
|
|
#region ComponentManagement
|
|
|
|
/// <summary>
|
|
/// Spawn in starting items for any item slots that should have one.
|
|
/// </summary>
|
|
private void OnMapInit(EntityUid uid, ItemSlotsComponent itemSlots, MapInitEvent args)
|
|
{
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (slot.HasItem || string.IsNullOrEmpty(slot.StartingItem))
|
|
continue;
|
|
|
|
var item = Spawn(slot.StartingItem, Transform(uid).Coordinates);
|
|
|
|
if (slot.ContainerSlot != null)
|
|
_containers.Insert(item, slot.ContainerSlot);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ensure item slots have containers.
|
|
/// </summary>
|
|
private void Oninitialize(EntityUid uid, ItemSlotsComponent itemSlots, ComponentInit args)
|
|
{
|
|
foreach (var (id, slot) in itemSlots.Slots)
|
|
{
|
|
slot.ContainerSlot = _containers.EnsureContainer<ContainerSlot>(uid, id);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Given a new item slot, store it in the <see cref="ItemSlotsComponent"/> and ensure the slot has an item
|
|
/// container.
|
|
/// </summary>
|
|
public void AddItemSlot(EntityUid uid, string id, ItemSlot slot, ItemSlotsComponent? itemSlots = null)
|
|
{
|
|
itemSlots ??= EnsureComp<ItemSlotsComponent>(uid);
|
|
DebugTools.AssertOwner(uid, itemSlots);
|
|
|
|
if (itemSlots.Slots.TryGetValue(id, out var existing))
|
|
{
|
|
if (existing.Local)
|
|
Log.Error(
|
|
$"Duplicate item slot key. Entity: {EntityManager.GetComponent<MetaDataComponent>(uid).EntityName} ({uid}), key: {id}");
|
|
else
|
|
// server state takes priority
|
|
slot.CopyFrom(existing);
|
|
}
|
|
|
|
slot.ContainerSlot = _containers.EnsureContainer<ContainerSlot>(uid, id);
|
|
itemSlots.Slots[id] = slot;
|
|
Dirty(uid, itemSlots);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove an item slot. This should generally be called whenever a component that added a slot is being
|
|
/// removed.
|
|
/// </summary>
|
|
public void RemoveItemSlot(EntityUid uid, ItemSlot slot, ItemSlotsComponent? itemSlots = null)
|
|
{
|
|
if (Terminating(uid) || slot.ContainerSlot == null)
|
|
return;
|
|
|
|
_containers.ShutdownContainer(slot.ContainerSlot);
|
|
|
|
// Don't log missing resolves. when an entity has all of its components removed, the ItemSlotsComponent may
|
|
// have been removed before some other component that added an item slot (and is now trying to remove it).
|
|
if (!Resolve(uid, ref itemSlots, logMissing: false))
|
|
return;
|
|
|
|
itemSlots.Slots.Remove(slot.ContainerSlot.ID);
|
|
|
|
if (itemSlots.Slots.Count == 0)
|
|
EntityManager.RemoveComponent(uid, itemSlots);
|
|
else
|
|
Dirty(uid, itemSlots);
|
|
}
|
|
|
|
public bool TryGetSlot(EntityUid uid,
|
|
string slotId,
|
|
[NotNullWhen(true)] out ItemSlot? itemSlot,
|
|
ItemSlotsComponent? component = null)
|
|
{
|
|
itemSlot = null;
|
|
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
return component.Slots.TryGetValue(slotId, out itemSlot);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Interactions
|
|
|
|
/// <summary>
|
|
/// Attempt to take an item from a slot, if any are set to EjectOnInteract.
|
|
/// </summary>
|
|
private void OnInteractHand(EntityUid uid, ItemSlotsComponent itemSlots, InteractHandEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (!slot.EjectOnInteract || slot.Item == null || !CanEject(uid, args.User, slot, popup: args.User))
|
|
continue;
|
|
|
|
args.Handled = true;
|
|
TryEjectToHands(uid, slot, args.User, true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to eject an item from the first valid item slot.
|
|
/// </summary>
|
|
private void OnUseInHand(EntityUid uid, ItemSlotsComponent itemSlots, UseInHandEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (!slot.EjectOnUse || slot.Item == null || !CanEject(uid, args.User, slot, popup: args.User))
|
|
continue;
|
|
|
|
args.Handled = true;
|
|
TryEjectToHands(uid, slot, args.User, true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to insert a held item in any fitting item slot. If a valid slot already contains an item, it will
|
|
/// swap it out and place the old one in the user's hand.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This only handles the event if the user has an applicable entity that can be inserted. This allows for
|
|
/// other interactions to still happen (e.g., open UI, or toggle-open), despite the user holding an item.
|
|
/// Maybe this is undesirable.
|
|
/// </remarks>
|
|
private void OnInteractUsing(EntityUid uid, ItemSlotsComponent itemSlots, InteractUsingEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands))
|
|
return;
|
|
|
|
if (itemSlots.Slots.Count == 0)
|
|
return;
|
|
|
|
// If any slot can be inserted into don't show popup.
|
|
// If any whitelist passes, but slot is locked, then show locked.
|
|
// If whitelist fails all, show whitelist fail.
|
|
|
|
// valid, insertable slots (if any)
|
|
var slots = new List<ItemSlot>();
|
|
|
|
string? whitelistFailPopup = null;
|
|
string? lockedFailPopup = null;
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (!slot.InsertOnInteract)
|
|
continue;
|
|
|
|
if (CanInsert(uid, args.Used, args.User, slot, slot.Swap))
|
|
{
|
|
slots.Add(slot);
|
|
}
|
|
else
|
|
{
|
|
var allowed = CanInsertWhitelist(args.Used, slot);
|
|
if (lockedFailPopup == null && slot.LockedFailPopup != null && allowed && slot.Locked)
|
|
lockedFailPopup = slot.LockedFailPopup;
|
|
|
|
if (whitelistFailPopup == null && slot.WhitelistFailPopup != null)
|
|
whitelistFailPopup = slot.WhitelistFailPopup;
|
|
}
|
|
}
|
|
|
|
if (slots.Count == 0)
|
|
{
|
|
// it's a bit weird that the popupMessage is stored with the item slots themselves, but in practice
|
|
// the popup messages will just all be the same, so it's probably fine.
|
|
//
|
|
// doing a check to make sure that they're all the same or something is probably frivolous
|
|
if (lockedFailPopup != null)
|
|
_popupSystem.PopupClient(Loc.GetString(lockedFailPopup), uid, args.User);
|
|
else if (whitelistFailPopup != null)
|
|
_popupSystem.PopupClient(Loc.GetString(whitelistFailPopup), uid, args.User);
|
|
return;
|
|
}
|
|
|
|
// Drop the held item onto the floor. Return if the user cannot drop.
|
|
if (!_handsSystem.TryDrop(args.User, args.Used, handsComp: hands))
|
|
return;
|
|
|
|
slots.Sort(SortEmpty);
|
|
|
|
foreach (var slot in slots)
|
|
{
|
|
if (slot.Item != null)
|
|
_handsSystem.TryPickupAnyHand(args.User, slot.Item.Value, handsComp: hands);
|
|
|
|
Insert(uid, slot, args.Used, args.User, excludeUserAudio: true);
|
|
|
|
if (slot.InsertSuccessPopup.HasValue)
|
|
_popupSystem.PopupClient(Loc.GetString(slot.InsertSuccessPopup), uid, args.User);
|
|
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert
|
|
|
|
/// <summary>
|
|
/// Insert an item into a slot. This does not perform checks, so make sure to also use <see
|
|
/// cref="CanInsert"/> or just use <see cref="TryInsert"/> instead.
|
|
/// </summary>
|
|
/// <param name="excludeUserAudio">If true, will exclude the user when playing sound. Does nothing client-side.
|
|
/// Useful for predicted interactions</param>
|
|
private void Insert(EntityUid uid,
|
|
ItemSlot slot,
|
|
EntityUid item,
|
|
EntityUid? user,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
bool? inserted = slot.ContainerSlot != null ? _containers.Insert(item, slot.ContainerSlot) : null;
|
|
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
|
|
|
|
// Logging
|
|
if (inserted != null && inserted.Value && user != null)
|
|
_adminLogger.Add(LogType.Action,
|
|
LogImpact.Low,
|
|
$"{ToPrettyString(user.Value)} inserted {ToPrettyString(item)} into {slot.ContainerSlot?.ID + " slot of "}{ToPrettyString(uid)}");
|
|
|
|
_audioSystem.PlayPredicted(slot.InsertSound, uid, excludeUserAudio ? user : null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check whether a given item can be inserted into a slot. Unless otherwise specified, this will return
|
|
/// false if the slot is already filled.
|
|
/// </summary>
|
|
public bool CanInsert(EntityUid uid,
|
|
EntityUid usedUid,
|
|
EntityUid? user,
|
|
ItemSlot slot,
|
|
bool swap = false)
|
|
{
|
|
if (slot.ContainerSlot == null)
|
|
return false;
|
|
|
|
if (slot.HasItem && (!swap || swap && !CanEject(uid, user, slot)))
|
|
return false;
|
|
|
|
if (!CanInsertWhitelist(usedUid, slot))
|
|
return false;
|
|
|
|
if (slot.Locked)
|
|
return false;
|
|
|
|
var ev = new ItemSlotInsertAttemptEvent(uid, usedUid, user, slot);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
RaiseLocalEvent(usedUid, ref ev);
|
|
if (ev.Cancelled)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _containers.CanInsert(usedUid, slot.ContainerSlot, assumeEmpty: swap);
|
|
}
|
|
|
|
private bool CanInsertWhitelist(EntityUid usedUid, ItemSlot slot)
|
|
{
|
|
if (_whitelistSystem.IsWhitelistFail(slot.Whitelist, usedUid)
|
|
|| _whitelistSystem.IsBlacklistPass(slot.Blacklist, usedUid))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to insert item into a specific slot.
|
|
/// </summary>
|
|
/// <returns>False if failed to insert item</returns>
|
|
public bool TryInsert(EntityUid uid,
|
|
string id,
|
|
EntityUid item,
|
|
EntityUid? user,
|
|
ItemSlotsComponent? itemSlots = null,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
if (!Resolve(uid, ref itemSlots))
|
|
return false;
|
|
|
|
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
|
return false;
|
|
|
|
return TryInsert(uid, slot, item, user, excludeUserAudio: excludeUserAudio);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to insert item into a specific slot.
|
|
/// </summary>
|
|
/// <returns>False if failed to insert item</returns>
|
|
public bool TryInsert(EntityUid uid,
|
|
ItemSlot slot,
|
|
EntityUid item,
|
|
EntityUid? user,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
if (!CanInsert(uid, item, user, slot))
|
|
return false;
|
|
|
|
Insert(uid, slot, item, user, excludeUserAudio: excludeUserAudio);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to insert item into a specific slot from an entity's hand.
|
|
/// Does not check action blockers.
|
|
/// </summary>
|
|
/// <returns>False if failed to insert item</returns>
|
|
public bool TryInsertFromHand(EntityUid uid,
|
|
ItemSlot slot,
|
|
EntityUid user,
|
|
HandsComponent? hands = null,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
if (!Resolve(user, ref hands, false))
|
|
return false;
|
|
|
|
if (hands.ActiveHand?.HeldEntity is not { } held)
|
|
return false;
|
|
|
|
if (!CanInsert(uid, held, user, slot))
|
|
return false;
|
|
|
|
// hands.Drop(item) checks CanDrop action blocker
|
|
if (!_handsSystem.TryDrop(user, hands.ActiveHand))
|
|
return false;
|
|
|
|
Insert(uid, slot, held, user, excludeUserAudio: excludeUserAudio);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to insert an item into any empty slot.
|
|
/// </summary>
|
|
/// <param name="ent">The entity that has the item slots.</param>
|
|
/// <param name="item">The item to be inserted.</param>
|
|
/// <param name="user">The entity performing the interaction.</param>
|
|
/// <param name="excludeUserAudio">
|
|
/// If true, will exclude the user when playing sound. Does nothing client-side.
|
|
/// Useful for predicted interactions
|
|
/// </param>
|
|
/// <returns>False if failed to insert item</returns>
|
|
public bool TryInsertEmpty(Entity<ItemSlotsComponent?> ent, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp, false))
|
|
return false;
|
|
|
|
var slots = new List<ItemSlot>();
|
|
foreach (var slot in ent.Comp.Slots.Values)
|
|
{
|
|
if (slot.ContainerSlot?.ContainedEntity != null)
|
|
continue;
|
|
|
|
if (CanInsert(ent, item, user, slot))
|
|
slots.Add(slot);
|
|
}
|
|
|
|
if (slots.Count == 0)
|
|
return false;
|
|
|
|
if (user != null && _handsSystem.IsHolding(user.Value, item))
|
|
{
|
|
if (!_handsSystem.TryDrop(user.Value, item))
|
|
return false;
|
|
}
|
|
|
|
slots.Sort(SortEmpty);
|
|
|
|
foreach (var slot in slots)
|
|
{
|
|
if (TryInsert(ent, slot, item, user, excludeUserAudio: excludeUserAudio))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private static int SortEmpty(ItemSlot a, ItemSlot b)
|
|
{
|
|
var aEnt = a.ContainerSlot?.ContainedEntity;
|
|
var bEnt = b.ContainerSlot?.ContainedEntity;
|
|
if (aEnt == null && bEnt == null)
|
|
return a.Priority.CompareTo(b.Priority);
|
|
|
|
if (aEnt == null)
|
|
return -1;
|
|
|
|
return 1;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Eject
|
|
|
|
/// <summary>
|
|
/// Check whether an ejection from a given slot may happen.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If a popup entity is given, this will generate a popup message if any are configured on the the item slot.
|
|
/// </remarks>
|
|
public bool CanEject(EntityUid uid, EntityUid? user, ItemSlot slot, EntityUid? popup = null)
|
|
{
|
|
if (slot.Locked)
|
|
{
|
|
if (popup.HasValue && slot.LockedFailPopup.HasValue)
|
|
_popupSystem.PopupClient(Loc.GetString(slot.LockedFailPopup), uid, popup.Value);
|
|
return false;
|
|
}
|
|
|
|
if (slot.ContainerSlot?.ContainedEntity is not { } item)
|
|
return false;
|
|
|
|
var ev = new ItemSlotEjectAttemptEvent(uid, item, user, slot);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
RaiseLocalEvent(item, ref ev);
|
|
if (ev.Cancelled)
|
|
return false;
|
|
|
|
return _containers.CanRemove(item, slot.ContainerSlot);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eject an item from a slot. This does not perform checks (e.g., is the slot locked?), so you should
|
|
/// probably just use <see cref="TryEject"/> instead.
|
|
/// </summary>
|
|
/// <param name="excludeUserAudio">If true, will exclude the user when playing sound. Does nothing client-side.
|
|
/// Useful for predicted interactions</param>
|
|
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
|
{
|
|
bool? ejected = slot.ContainerSlot != null ? _containers.Remove(item, slot.ContainerSlot) : null;
|
|
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
|
|
|
|
// Logging
|
|
if (ejected != null && ejected.Value && user != null)
|
|
_adminLogger.Add(LogType.Action,
|
|
LogImpact.Low,
|
|
$"{ToPrettyString(user.Value)} ejected {ToPrettyString(item)} from {slot.ContainerSlot?.ID + " slot of "}{ToPrettyString(uid)}");
|
|
|
|
_audioSystem.PlayPredicted(slot.EjectSound, uid, excludeUserAudio ? user : null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try to eject an item from a slot.
|
|
/// </summary>
|
|
/// <returns>False if item slot is locked or has no item inserted</returns>
|
|
public bool TryEject(EntityUid uid,
|
|
ItemSlot slot,
|
|
EntityUid? user,
|
|
[NotNullWhen(true)] out EntityUid? item,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
item = null;
|
|
|
|
// This handles logic with the slot itself
|
|
if (!CanEject(uid, user, slot))
|
|
return false;
|
|
|
|
item = slot.Item;
|
|
|
|
// This handles user logic
|
|
if (user != null && item != null && !_actionBlockerSystem.CanPickup(user.Value, item.Value))
|
|
return false;
|
|
|
|
Eject(uid, slot, item!.Value, user, excludeUserAudio);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try to eject item from a slot.
|
|
/// </summary>
|
|
/// <returns>False if the id is not valid, the item slot is locked, or it has no item inserted</returns>
|
|
public bool TryEject(EntityUid uid,
|
|
string id,
|
|
EntityUid? user,
|
|
[NotNullWhen(true)] out EntityUid? item,
|
|
ItemSlotsComponent? itemSlots = null,
|
|
bool excludeUserAudio = false)
|
|
{
|
|
item = null;
|
|
|
|
if (!Resolve(uid, ref itemSlots))
|
|
return false;
|
|
|
|
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
|
return false;
|
|
|
|
return TryEject(uid, slot, user, out item, excludeUserAudio);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try to eject item from a slot directly into a user's hands. If they have no hands, the item will still
|
|
/// be ejected onto the floor.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// False if the id is not valid, the item slot is locked, or it has no item inserted. True otherwise, even
|
|
/// if the user has no hands.
|
|
/// </returns>
|
|
public bool TryEjectToHands(EntityUid uid, ItemSlot slot, EntityUid? user, bool excludeUserAudio = false)
|
|
{
|
|
if (!TryEject(uid, slot, user, out var item, excludeUserAudio))
|
|
return false;
|
|
|
|
if (user != null)
|
|
_handsSystem.PickupOrDrop(user.Value, item.Value);
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Verbs
|
|
|
|
private void AddAlternativeVerbs(EntityUid uid,
|
|
ItemSlotsComponent itemSlots,
|
|
GetVerbsEvent<AlternativeVerb> args)
|
|
{
|
|
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Add the insert-item verbs
|
|
if (args.Using != null && _actionBlockerSystem.CanDrop(args.User))
|
|
{
|
|
var canInsertAny = false;
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
// Disable slot insert if InsertOnInteract is true
|
|
if (slot.InsertOnInteract || !CanInsert(uid, args.Using.Value, args.User, slot))
|
|
continue;
|
|
|
|
var verbSubject = slot.Name != string.Empty
|
|
? Loc.GetString(slot.Name)
|
|
: Name(args.Using.Value);
|
|
|
|
AlternativeVerb verb = new()
|
|
{
|
|
IconEntity = GetNetEntity(args.Using),
|
|
Act = () => Insert(uid, slot, args.Using.Value, args.User, excludeUserAudio: true)
|
|
};
|
|
|
|
if (slot.InsertVerbText != null)
|
|
{
|
|
verb.Text = Loc.GetString(slot.InsertVerbText);
|
|
verb.Icon = new SpriteSpecifier.Texture(
|
|
new("/Textures/Interface/VerbIcons/insert.svg.192dpi.png"));
|
|
}
|
|
else if (slot.EjectOnInteract)
|
|
{
|
|
// Inserting/ejecting is a primary interaction for this entity. Instead of using the insert
|
|
// category, we will use a single "Place <item>" verb.
|
|
verb.Text = Loc.GetString("place-item-verb-text", ("subject", verbSubject));
|
|
verb.Icon = new SpriteSpecifier.Texture(
|
|
new("/Textures/Interface/VerbIcons/drop.svg.192dpi.png"));
|
|
}
|
|
else
|
|
{
|
|
verb.Category = VerbCategory.Insert;
|
|
verb.Text = verbSubject;
|
|
}
|
|
|
|
verb.Priority = slot.Priority;
|
|
args.Verbs.Add(verb);
|
|
canInsertAny = true;
|
|
}
|
|
|
|
// If can insert then insert. Don't run eject verbs.
|
|
if (canInsertAny)
|
|
return;
|
|
}
|
|
|
|
// Add the eject-item verbs
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (slot.EjectOnInteract || slot.DisableEject)
|
|
// For this item slot, ejecting/inserting is a primary interaction. Instead of an eject category
|
|
// alt-click verb, there will be a "Take item" primary interaction verb.
|
|
continue;
|
|
|
|
if (!CanEject(uid, args.User, slot))
|
|
continue;
|
|
|
|
if (!_actionBlockerSystem.CanPickup(args.User, slot.Item!.Value))
|
|
continue;
|
|
|
|
var verbSubject = slot.Name != string.Empty
|
|
? Loc.GetString(slot.Name)
|
|
: EntityManager.GetComponent<MetaDataComponent>(slot.Item.Value).EntityName ?? string.Empty;
|
|
|
|
AlternativeVerb verb = new()
|
|
{
|
|
IconEntity = GetNetEntity(slot.Item),
|
|
Act = () => TryEjectToHands(uid, slot, args.User, excludeUserAudio: true)
|
|
};
|
|
|
|
if (slot.EjectVerbText == null)
|
|
{
|
|
verb.Text = verbSubject;
|
|
verb.Category = VerbCategory.Eject;
|
|
}
|
|
else
|
|
{
|
|
verb.Text = Loc.GetString(slot.EjectVerbText);
|
|
}
|
|
|
|
verb.Priority = slot.Priority;
|
|
args.Verbs.Add(verb);
|
|
}
|
|
}
|
|
|
|
private void AddInteractionVerbsVerbs(EntityUid uid,
|
|
ItemSlotsComponent itemSlots,
|
|
GetVerbsEvent<InteractionVerb> args)
|
|
{
|
|
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
|
return;
|
|
|
|
// If there are any slots that eject on left-click, add a "Take <item>" verb.
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (!slot.EjectOnInteract || !CanEject(uid, args.User, slot))
|
|
continue;
|
|
|
|
if (!_actionBlockerSystem.CanPickup(args.User, slot.Item!.Value))
|
|
continue;
|
|
|
|
var verbSubject = slot.Name != string.Empty
|
|
? Loc.GetString(slot.Name)
|
|
: Name(slot.Item!.Value);
|
|
|
|
InteractionVerb takeVerb = new()
|
|
{
|
|
IconEntity = GetNetEntity(slot.Item),
|
|
Act = () => TryEjectToHands(uid, slot, args.User, excludeUserAudio: true)
|
|
};
|
|
|
|
if (slot.EjectVerbText == null)
|
|
takeVerb.Text = Loc.GetString("take-item-verb-text", ("subject", verbSubject));
|
|
else
|
|
takeVerb.Text = Loc.GetString(slot.EjectVerbText);
|
|
|
|
takeVerb.Priority = slot.Priority;
|
|
args.Verbs.Add(takeVerb);
|
|
}
|
|
|
|
// Next, add the insert-item verbs
|
|
if (args.Using == null || !_actionBlockerSystem.CanDrop(args.User))
|
|
return;
|
|
|
|
foreach (var slot in itemSlots.Slots.Values)
|
|
{
|
|
if (!slot.InsertOnInteract || !CanInsert(uid, args.Using.Value, args.User, slot))
|
|
continue;
|
|
|
|
var verbSubject = slot.Name != string.Empty
|
|
? Loc.GetString(slot.Name)
|
|
: Name(args.Using.Value);
|
|
|
|
InteractionVerb insertVerb = new()
|
|
{
|
|
IconEntity = GetNetEntity(args.Using),
|
|
Act = () => Insert(uid, slot, args.Using.Value, args.User, excludeUserAudio: true)
|
|
};
|
|
|
|
if (slot.InsertVerbText != null)
|
|
{
|
|
insertVerb.Text = Loc.GetString(slot.InsertVerbText);
|
|
insertVerb.Icon =
|
|
new SpriteSpecifier.Texture(
|
|
new ResPath("/Textures/Interface/VerbIcons/insert.svg.192dpi.png"));
|
|
}
|
|
else if (slot.EjectOnInteract)
|
|
{
|
|
// Inserting/ejecting is a primary interaction for this entity. Instead of using the insert
|
|
// category, we will use a single "Place <item>" verb.
|
|
insertVerb.Text = Loc.GetString("place-item-verb-text", ("subject", verbSubject));
|
|
insertVerb.Icon =
|
|
new SpriteSpecifier.Texture(
|
|
new ResPath("/Textures/Interface/VerbIcons/drop.svg.192dpi.png"));
|
|
}
|
|
else
|
|
{
|
|
insertVerb.Category = VerbCategory.Insert;
|
|
insertVerb.Text = verbSubject;
|
|
}
|
|
|
|
insertVerb.Priority = slot.Priority;
|
|
args.Verbs.Add(insertVerb);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BUIs
|
|
|
|
private void HandleButtonPressed(EntityUid uid, ItemSlotsComponent component, ItemSlotButtonPressedEvent args)
|
|
{
|
|
if (!component.Slots.TryGetValue(args.SlotId, out var slot))
|
|
return;
|
|
|
|
if (args.TryEject && slot.HasItem)
|
|
TryEjectToHands(uid, slot, args.Actor, true);
|
|
else if (args.TryInsert && !slot.HasItem)
|
|
TryInsertFromHand(uid, slot, args.Actor);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Eject items from (some) slots when the entity is destroyed.
|
|
/// </summary>
|
|
private void OnBreak(EntityUid uid, ItemSlotsComponent component, EntityEventArgs args)
|
|
{
|
|
foreach (var slot in component.Slots.Values)
|
|
{
|
|
if (slot.EjectOnBreak && slot.HasItem)
|
|
{
|
|
SetLock(uid, slot, false, component);
|
|
TryEject(uid, slot, null, out var _);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the contents of some item slot.
|
|
/// </summary>
|
|
/// <returns>The item in the slot, or null if the slot is empty or the entity doesn't have an <see cref="ItemSlotsComponent"/>.</returns>
|
|
public EntityUid? GetItemOrNull(EntityUid uid, string id, ItemSlotsComponent? itemSlots = null)
|
|
{
|
|
if (!Resolve(uid, ref itemSlots, logMissing: false))
|
|
return null;
|
|
|
|
return itemSlots.Slots.GetValueOrDefault(id)?.Item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lock an item slot. This stops items from being inserted into or ejected from this slot.
|
|
/// </summary>
|
|
public void SetLock(EntityUid uid, string id, bool locked, ItemSlotsComponent? itemSlots = null)
|
|
{
|
|
if (!Resolve(uid, ref itemSlots))
|
|
return;
|
|
|
|
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
|
return;
|
|
|
|
SetLock(uid, slot, locked, itemSlots);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lock an item slot. This stops items from being inserted into or ejected from this slot.
|
|
/// </summary>
|
|
public void SetLock(EntityUid uid, ItemSlot slot, bool locked, ItemSlotsComponent? itemSlots = null)
|
|
{
|
|
if (!Resolve(uid, ref itemSlots))
|
|
return;
|
|
|
|
slot.Locked = locked;
|
|
Dirty(uid, itemSlots);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update the locked state of the managed item slots.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Note that the slot's ContainerSlot performs its own networking, so we don't need to send information
|
|
/// about the contained entity.
|
|
/// </remarks>
|
|
private void HandleItemSlotsState(EntityUid uid, ItemSlotsComponent component, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not ItemSlotsComponentState state)
|
|
return;
|
|
|
|
foreach (var (key, slot) in component.Slots)
|
|
{
|
|
if (!state.Slots.ContainsKey(key))
|
|
RemoveItemSlot(uid, slot, component);
|
|
}
|
|
|
|
foreach (var (serverKey, serverSlot) in state.Slots)
|
|
{
|
|
if (component.Slots.TryGetValue(serverKey, out var itemSlot))
|
|
{
|
|
itemSlot.CopyFrom(serverSlot);
|
|
itemSlot.ContainerSlot = _containers.EnsureContainer<ContainerSlot>(uid, serverKey);
|
|
}
|
|
else
|
|
{
|
|
var slot = new ItemSlot(serverSlot);
|
|
slot.Local = false;
|
|
AddItemSlot(uid, serverKey, slot);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GetItemSlotsState(EntityUid uid, ItemSlotsComponent component, ref ComponentGetState args)
|
|
{
|
|
args.State = new ItemSlotsComponentState(component.Slots);
|
|
}
|
|
}
|
|
}
|