using Content.Server._DV.Mail.Components; using Content.Shared.Damage; using Robust.Shared.Containers; namespace Content.Server._DV.Mail.EntitySystems { /// /// A placeholder for another entity, spawned when an entity is taken out of a container, with the placeholder deleted shortly after. /// Useful for storing instant effect entities, e.g. smoke, in the mail. /// Note: for items with ghost roles, ensure that the item is not damageable. /// public sealed class DelayedItemSystem : EntitySystem { public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnRemovedFromContainer); } /// /// EntGotRemovedFromContainerMessage handler - spawn the intended entity after removed from a container and delete the. /// private void OnRemovedFromContainer(EntityUid uid, DelayedItemComponent component, EntGotRemovedFromContainerMessage args) { SpawnAtPosition(component.Item, Transform(uid).Coordinates); QueueDel(uid); } /// /// OnDamageChanged handler - item has taken damage (e.g. inside the envelope), spawn the intended entity in the same container as the placeholder and delete the placeholder. /// private void OnDamageChanged(EntityUid uid, DelayedItemComponent component, DamageChangedEvent args) { SpawnAtPosition(component.Item, Transform(uid).Coordinates); QueueDel(uid); } } }