]> git.smokeofanarchy.ru Git - space-station-14.git/blob
e5b1e119c14c40c6931e7b6bead0577c6f80bd1e
[space-station-14.git] /
1 using Robust.Shared.Containers;
2 using Robust.Shared.Network;
3
4 namespace Content.Shared.EntityEffects.Effects.EntitySpawning;
5
6 /// <summary>
7 /// Spawns a given number of entities of a given prototype in a specified container owned by this entity.
8 /// Acts like <see cref="SpawnEntityEntityEffectSystem"/> if it cannot spawn the prototype in the specified container.
9 /// Amount is modified by scale.
10 /// </summary>
11 /// <inheritdoc cref="EntityEffectSystem{T,TEffect}"/>
12 public sealed partial class SpawnEntityInContainerOrDropEntityEffectSystem : EntityEffectSystem<ContainerManagerComponent, SpawnEntityInContainerOrDrop>
13 {
14     [Dependency] private readonly INetManager _net = default!;
15
16     protected override void Effect(Entity<ContainerManagerComponent> entity, ref EntityEffectEvent<SpawnEntityInContainerOrDrop> args)
17     {
18         var quantity = args.Effect.Number * (int)Math.Floor(args.Scale);
19         var proto = args.Effect.Entity;
20         var container = args.Effect.ContainerName;
21
22         var xform = Transform(entity);
23
24         if (args.Effect.Predicted)
25         {
26             for (var i = 0; i < quantity; i++)
27             {
28                 PredictedSpawnInContainerOrDrop(proto, entity, container, xform, entity.Comp);
29             }
30         }
31         else if (_net.IsServer)
32         {
33             for (var i = 0; i < quantity; i++)
34             {
35                 SpawnInContainerOrDrop(proto, entity, container, xform, entity.Comp);
36             }
37         }
38     }
39 }
40
41 /// <inheritdoc cref="BaseSpawnEntityEntityEffect{T}"/>
42 public sealed partial class SpawnEntityInContainerOrDrop : BaseSpawnEntityEntityEffect<SpawnEntityInContainerOrDrop>
43 {
44     /// <summary>
45     /// Name of the container we're trying to spawn into.
46     /// </summary>
47     [DataField(required: true)]
48     public string ContainerName;
49 }