private void AddEjectVerbs(EntityUid uid, SharedItemSlotsComponent component, GetAlternativeVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanPickup(args.User)) { return; } foreach (var(slotName, slot) in component.Slots) { if (slot.ContainerSlot.ContainedEntity == null) { continue; } Verb verb = new(); verb.Text = slot.Name; verb.Category = VerbCategory.Eject; verb.Act = () => TryEjectContent(uid, slotName, args.User, component); args.Verbs.Add(verb); } }
public ItemSlotChangedEvent(SharedItemSlotsComponent slotsComponent, string slotName, ItemSlot slot) { SlotsComponent = slotsComponent; SlotName = slotName; Slot = slot; ContainedItem = slot.ContainerSlot.ContainedEntity?.Uid; }
private void OnInteractUsing(EntityUid uid, SharedItemSlotsComponent itemSlots, InteractUsingEvent args) { if (args.Handled) { return; } args.Handled = TryInsertContent(uid, args.Used, args.User, itemSlots); }
private void OnComponentInit(EntityUid uid, SharedItemSlotsComponent itemSlots, ComponentInit args) { // create container for each slot foreach (var pair in itemSlots.Slots) { var slotName = pair.Key; var slot = pair.Value; slot.ContainerSlot = ContainerHelpers.EnsureContainer <ContainerSlot>(itemSlots.Owner, slotName); } }
/// <summary> /// Check if slot has some content in it (without ejecting item) /// </summary> /// <returns>Null if doesn't have any content</returns> public IEntity?PeekItemInSlot(SharedItemSlotsComponent itemSlots, string slotName) { if (!itemSlots.Slots.TryGetValue(slotName, out var slot)) { return(null); } var item = slot.ContainerSlot.ContainedEntity; return(item); }
public void InsertContent(SharedItemSlotsComponent itemSlots, ItemSlot slot, string slotName, IEntity item) { // insert item slot.ContainerSlot.Insert(item); RaiseLocalEvent(itemSlots.Owner.Uid, new ItemSlotChangedEvent(itemSlots, slotName, slot)); // play sound if (slot.InsertSound != null) { SoundSystem.Play(Filter.Pvs(itemSlots.Owner), slot.InsertSound.GetSound(), itemSlots.Owner); } }
/// <summary> /// Tries to insert item in known slot. Doesn't interact with user /// </summary> /// <returns>False if failed to insert item</returns> public bool TryInsertContent(SharedItemSlotsComponent itemSlots, IEntity item, string slotName) { if (!itemSlots.Slots.TryGetValue(slotName, out var slot)) { return(false); } if (!CanInsertContent(item, slot)) { return(false); } InsertContent(itemSlots, slot, slotName, item); return(true); }
private void OnMapInit(EntityUid uid, SharedItemSlotsComponent itemSlots, MapInitEvent args) { foreach (var pair in itemSlots.Slots) { var slot = pair.Value; var slotName = pair.Key; // Check if someone already put item inside container if (slot.ContainerSlot.ContainedEntity != null) { continue; } // Try to spawn item inside each slot if (!string.IsNullOrEmpty(slot.StartingItem)) { var item = EntityManager.SpawnEntity(slot.StartingItem, itemSlots.Owner.Transform.Coordinates); slot.ContainerSlot.Insert(item); RaiseLocalEvent(uid, new ItemSlotChangedEvent(itemSlots, slotName, slot)); } } }
private void AddInsertVerbs(EntityUid uid, SharedItemSlotsComponent component, GetInteractionVerbsEvent args) { if (args.Using == null || !args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanDrop(args.User)) { return; } foreach (var(slotName, slot) in component.Slots) { if (!CanInsertContent(args.Using, slot)) { continue; } Verb verb = new(); verb.Text = slot.Name != string.Empty ? slot.Name : args.Using.Name; verb.Category = VerbCategory.Insert; verb.Act = () => InsertContent(component, slot, slotName, args.Using); args.Verbs.Add(verb); } }