/// <inheritdoc /> public virtual bool CanInsert(EntityUid toinsert, IEntityManager?entMan = null) { DebugTools.Assert(!Deleted); // cannot insert into itself. if (Owner == toinsert) { return(false); } IoCManager.Resolve(ref entMan); // no, you can't put maps or grids into containers if (entMan.HasComponent <IMapComponent>(toinsert) || entMan.HasComponent <IMapGridComponent>(toinsert)) { return(false); } // Crucial, prevent circular insertion. if (entMan.GetComponent <TransformComponent>(toinsert) .ContainsEntity(entMan.GetComponent <TransformComponent>(Owner))) { return(false); } //Improvement: Traverse the entire tree to make sure we are not creating a loop. //raise events var insertAttemptEvent = new ContainerIsInsertingAttemptEvent(this, toinsert); entMan.EventBus.RaiseLocalEvent(Owner, insertAttemptEvent); if (insertAttemptEvent.Cancelled) { return(false); } var gettingInsertedAttemptEvent = new ContainerGettingInsertedAttemptEvent(this, toinsert); entMan.EventBus.RaiseLocalEvent(toinsert, gettingInsertedAttemptEvent); if (gettingInsertedAttemptEvent.Cancelled) { return(false); } return(true); }
/// <summary> /// Verify that the entity being inserted is actually rechargeable. /// </summary> private void OnInsertAttempt(EntityUid uid, ChargerComponent component, ContainerIsInsertingAttemptEvent args) { if (!component.Initialized) { return; } if (args.Container.ID != component.ChargerSlot.ID) { return; } if (!TryComp(args.EntityUid, out PowerCellSlotComponent? cellSlot)) { return; } if (!cellSlot.FitsInCharger || !cellSlot.CellSlot.HasItem) { args.Cancel(); } }
private void OnCellInsertAttempt(EntityUid uid, PowerCellSlotComponent component, ContainerIsInsertingAttemptEvent args) { if (!component.Initialized) { return; } if (args.Container.ID != component.CellSlot.ID) { return; } if (!HasComp <PowerCellComponent>(args.EntityUid)) { args.Cancel(); } }
private void OnCellInsertAttempt(EntityUid uid, PowerCellSlotComponent component, ContainerIsInsertingAttemptEvent args) { if (!component.Initialized) { return; } if (args.Container.ID != component.CellSlot.ID) { return; } if (!TryComp(args.EntityUid, out PowerCellComponent? cell) || cell.CellSize != component.SlotSize) { args.Cancel(); } }