CatStation/Content.Shared/EntityEffects/Effects/TrapInContainerEntityEffectSystem.cs
ScarKy0 eefa7073c7
Changeling Fleshtomb (#45851)
* init

* make it proper

* listing, random humanoid appearance to shared

* oops

* moar

* pre-pr cleanup

* examine change

* partial review

* ye

* comment

* examinable

* sounds

* TrapInContainer >>>>>

* textures

* ambience

* fix

* Change collection to use leftclicking

* last minute balance change fuck everything

---------

Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-09-24 12:31:06 +00:00

58 lines
2.2 KiB
C#

using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityEffects.Effects;
/// <summary>
/// Spawns an entity with a container and traps the target inside of it.
/// </summary>
/// <inheritdoc cref="EntityEffectSystem{T,TEffect}"/>
public sealed partial class TrapInContainerEntityEffectSystem : EntityEffectSystem<TransformComponent, TrapInContainer>
{
[Dependency] private SharedContainerSystem _container = default!;
[Dependency] private INetManager _net = default!;
protected override void Effect(Entity<TransformComponent> entity, ref EntityEffectEvent<TrapInContainer> args)
{
// PredictedSpawn together with inserting things into containers is a bad combo
// I don't know how to predict this without Predicted Spawning v2.0
// This is because currently PredictedSpawn spawns and bulldozes clientside entities on every prediction tick
// and this causes client to crap itself when receiving server states for an entity that no longer exists if mixed with container insertion etc.
// God save me.
if (!_net.IsServer)
return;
var containerEntity = SpawnAtPosition(args.Effect.Entity, entity.Comp.Coordinates);
if (!_container.TryGetContainer(containerEntity, args.Effect.Container, out var container))
{
QueueDel(containerEntity);
return;
}
if (!_container.Insert(entity.Owner, container, force: true))
QueueDel(containerEntity);
}
}
public sealed partial class TrapInContainer : EntityEffectBase<TrapInContainer>
{
/// <summary>
/// The container entity to spawn.
/// </summary>
[DataField(required: true)]
public EntProtoId Entity;
/// <summary>
/// What container the entity should be trapped in.
/// </summary>
[DataField]
public string Container = "entity_storage";
/// <inheritdoc/>
public override string EntityEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString("entity-effect-guidebook-make-trap-in-container",
("chance", Probability),
("entityname", prototype.Index<EntityPrototype>(prototype.Index(Entity).Name)));
}