SubscribeLocalEvent<MicrowaveComponent, EntInsertedIntoContainerMessage>(OnContentUpdate);
SubscribeLocalEvent<MicrowaveComponent, EntRemovedFromContainerMessage>(OnContentUpdate);
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
+ SubscribeLocalEvent<MicrowaveComponent, ContainerIsInsertingAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<MicrowaveComponent, AnchorStateChangedEvent>(OnAnchorChanged);
UpdateUserInterfaceState(uid, component);
}
+ private void OnInsertAttempt(Entity<MicrowaveComponent> ent, ref ContainerIsInsertingAttemptEvent args)
+ {
+ if (ent.Comp.Broken)
+ {
+ args.Cancel();
+ return;
+ }
+
+ if (TryComp<ItemComponent>(args.EntityUid, out var item))
+ {
+ if (_item.GetSizePrototype(item.Size) > _item.GetSizePrototype(ent.Comp.MaxItemSize))
+ {
+ args.Cancel();
+ return;
+ }
+ }
+ else
+ {
+ args.Cancel();
+ return;
+ }
+
+ if (ent.Comp.Storage.Count >= ent.Comp.Capacity)
+ args.Cancel();
+ }
+
private void OnInteractUsing(Entity<MicrowaveComponent> ent, ref InteractUsingEvent args)
{
if (args.Handled)
return;
}
- var teleEnt = GetTeleportingEntity((uid, xform));
- var otherTeleEnt = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
+ var (teleEnt, cont) = GetTeleportingEntity((uid, xform));
+ var (otherTeleEnt, otherCont) = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
+
+ if (otherCont != null && !_container.CanInsert(teleEnt, otherCont) ||
+ cont != null && !_container.CanInsert(otherTeleEnt, cont))
+ {
+ _popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-fail",
+ ("entity", Identity.Entity(linkedEnt, EntityManager))),
+ teleEnt,
+ teleEnt,
+ PopupType.MediumCaution);
+ return;
+ }
_popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-other",
("entity", Identity.Entity(linkedEnt, EntityManager))),
DestroyLink(linked, user); // the linked one is shown globally
}
- private EntityUid GetTeleportingEntity(Entity<TransformComponent> ent)
+ private (EntityUid, BaseContainer?) GetTeleportingEntity(Entity<TransformComponent> ent)
{
var parent = ent.Comp.ParentUid;
if (_container.TryGetOuterContainer(ent, ent, out var container))
parent = container.Owner;
if (HasComp<MapGridComponent>(parent) || HasComp<MapComponent>(parent))
- return ent;
+ return (ent, container);
if (!_xformQuery.TryGetComponent(parent, out var parentXform) || parentXform.Anchored)
- return ent;
+ return (ent, container);
if (!TryComp<PhysicsComponent>(parent, out var body) || body.BodyType == BodyType.Static)
- return ent;
+ return (ent, container);
return GetTeleportingEntity((parent, parentXform));
}