]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add disposals damage (#21489)
authorSlava0135 <40753025+Slava0135@users.noreply.github.com>
Wed, 15 Nov 2023 00:52:43 +0000 (03:52 +0300)
committerGitHub <noreply@github.com>
Wed, 15 Nov 2023 00:52:43 +0000 (19:52 -0500)
* system naming conventions

* remove obsolete warnings

* use EntityQueries

* tube comp clean up

* damage on turns

* remove OnRelayMovement because it didn't work

* reduce volume

* reduce damage to 1.0

Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs
Content.Server/Disposal/Tube/DisposalTubeSystem.cs
Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs

index 8b3cd4720defc9bbfe495dd2ad89edfff97a1ef5..f33079c1cf248e79d244b8577aecf8e2c70db376 100644 (file)
@@ -1,30 +1,38 @@
-using System.Linq;
-using Content.Server.Disposal.Unit.Components;
 using Content.Server.Disposal.Unit.EntitySystems;
-using Content.Shared.Construction.Components;
-using Content.Shared.Popups;
+using Content.Shared.Damage;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
 
-namespace Content.Server.Disposal.Tube.Components
+namespace Content.Server.Disposal.Tube.Components;
+
+[RegisterComponent]
+[Access(typeof(DisposalTubeSystem), typeof(DisposableSystem))]
+public sealed partial class DisposalTubeComponent : Component
 {
-    [RegisterComponent]
-    [Access(typeof(DisposalTubeSystem), typeof(DisposableSystem))]
-    public sealed partial class DisposalTubeComponent : Component
-    {
-        [DataField("containerId")] public string ContainerId { get; set; } = "DisposalTube";
+    [DataField]
+    public string ContainerId = "DisposalTube";
 
-        public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
-        public TimeSpan LastClang;
+    [ViewVariables]
+    public bool Connected;
 
-        public bool Connected;
-        [DataField("clangSound")] public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
+    [DataField]
+    public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
 
-        /// <summary>
-        ///     Container of entities that are currently inside this tube
-        /// </summary>
-        [ViewVariables]
-        [Access(typeof(DisposalTubeSystem), typeof(DisposableSystem))]
-        public Container Contents { get; set; } = default!;
-    }
+    /// <summary>
+    ///     Container of entities that are currently inside this tube
+    /// </summary>
+    [ViewVariables]
+    public Container Contents = default!;
+
+    /// <summary>
+    /// Damage dealt to containing entities on every turn
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public DamageSpecifier DamageOnTurn = new()
+    {
+        DamageDict = new()
+        {
+            { "Blunt", 1.0 },
+        }
+    };
 }
index 477a167fa27c54c8313a0f443d055f5c569f4316..33b260aa9498b566518c27b4c5888f5079f3cbb3 100644 (file)
@@ -44,7 +44,6 @@ namespace Content.Server.Disposal.Tube
             SubscribeLocalEvent<DisposalTubeComponent, ComponentRemove>(OnComponentRemove);
 
             SubscribeLocalEvent<DisposalTubeComponent, AnchorStateChangedEvent>(OnAnchorChange);
-            SubscribeLocalEvent<DisposalTubeComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
             SubscribeLocalEvent<DisposalTubeComponent, BreakageEventArgs>(OnBreak);
             SubscribeLocalEvent<DisposalTubeComponent, ComponentStartup>(OnStartup);
             SubscribeLocalEvent<DisposalTubeComponent, ConstructionBeforeDeleteEvent>(OnDeconstruct);
@@ -278,17 +277,6 @@ namespace Content.Server.Disposal.Tube
             UpdateAnchored(uid, component, Transform(uid).Anchored);
         }
 
-        private void OnRelayMovement(EntityUid uid, DisposalTubeComponent component, ref ContainerRelayMovementEntityEvent args)
-        {
-            if (_gameTiming.CurTime < component.LastClang + DisposalTubeComponent.ClangDelay)
-            {
-                return;
-            }
-
-            component.LastClang = _gameTiming.CurTime;
-            _audioSystem.PlayPvs(component.ClangSound, uid);
-        }
-
         private void OnBreak(EntityUid uid, DisposalTubeComponent component, BreakageEventArgs args)
         {
             DisconnectTube(uid, component);
index 3edc2a5fa7839265ada0492656b367fa9e2049f4..7c4827f8c8b84f28c028b5e15f96c8e9eaaaacba 100644 (file)
@@ -4,11 +4,12 @@ using Content.Server.Disposal.Tube;
 using Content.Server.Disposal.Tube.Components;
 using Content.Server.Disposal.Unit.Components;
 using Content.Shared.Body.Components;
-using Content.Shared.Disposal.Components;
+using Content.Shared.Damage;
 using Content.Shared.Item;
-using JetBrains.Annotations;
+using Robust.Server.GameObjects;
+using Robust.Shared.Audio;
 using Robust.Shared.Containers;
-using Robust.Shared.Map;
+using Robust.Shared.Map.Components;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Systems;
 
@@ -16,13 +17,15 @@ namespace Content.Server.Disposal.Unit.EntitySystems
 {
     public sealed class DisposableSystem : EntitySystem
     {
-        [Dependency] private readonly IMapManager _mapManager = default!;
-        [Dependency] private readonly DisposalUnitSystem _disposalUnitSystem = default!;
-        [Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!;
-        [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
-        [Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
-        [Dependency] private readonly SharedContainerSystem _containerSystem = default!;
-        [Dependency] private readonly SharedTransformSystem _xformSystem = default!;
+        [Dependency] private readonly DisposalUnitSystem _disposalUnit = default!;
+        [Dependency] private readonly DisposalTubeSystem _disposalTube = default!;
+        [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
+        [Dependency] private readonly SharedPhysicsSystem _physics = default!;
+        [Dependency] private readonly SharedContainerSystem _container = default!;
+        [Dependency] private readonly SharedTransformSystem _transform = default!;
+        [Dependency] private readonly MapSystem _map = default!;
+        [Dependency] private readonly DamageableSystem _damageable = default!;
+        [Dependency] private readonly SharedAudioSystem _audio = default!;
 
         public override void Initialize()
         {
@@ -33,7 +36,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
 
         private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
         {
-            holder.Container = _containerSystem.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent));
+            holder.Container = _container.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent));
         }
 
         public bool TryInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null)
@@ -47,7 +50,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
                 return false;
 
             if (TryComp<PhysicsComponent>(toInsert, out var physBody))
-                _physicsSystem.SetCanCollide(toInsert, false, body: physBody);
+                _physics.SetCanCollide(toInsert, false, body: physBody);
 
             return true;
         }
@@ -57,7 +60,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
             if (!Resolve(uid, ref holder))
                 return false;
 
-            if (!_containerSystem.CanInsert(toInsert, holder.Container))
+            if (!_container.CanInsert(toInsert, holder.Container))
             {
                 return false;
             }
@@ -86,11 +89,13 @@ namespace Content.Server.Disposal.Unit.EntitySystems
 
             EntityUid? disposalId = null;
             DisposalUnitComponent? duc = null;
-            if (_mapManager.TryGetGrid(holderTransform.GridUid, out var grid))
+            var gridUid = holderTransform.GridUid;
+            if (TryComp<MapGridComponent>(gridUid, out var grid))
             {
-                foreach (var contentUid in grid.GetLocal(holderTransform.Coordinates))
+                var ducQuery = GetEntityQuery<DisposalUnitComponent>();
+                foreach (var contentUid in _map.GetLocal(gridUid.Value, grid, holderTransform.Coordinates))
                 {
-                    if (EntityManager.TryGetComponent(contentUid, out duc))
+                    if (ducQuery.TryGetComponent(contentUid, out duc))
                     {
                         disposalId = contentUid;
                         break;
@@ -98,36 +103,39 @@ namespace Content.Server.Disposal.Unit.EntitySystems
                 }
             }
 
+            var physQuery = GetEntityQuery<PhysicsComponent>();
+            var metaQuery = GetEntityQuery<MetaDataComponent>();
+            var transformQuery = GetEntityQuery<TransformComponent>();
             foreach (var entity in holder.Container.ContainedEntities.ToArray())
             {
                 RemComp<BeingDisposedComponent>(entity);
 
-                var meta = MetaData(entity);
+                var meta = metaQuery.GetComponent(entity);
                 holder.Container.Remove(entity, EntityManager, meta: meta, reparent: false, force: true);
 
-                var xform = Transform(entity);
+                var xform = transformQuery.GetComponent(entity);
                 if (xform.ParentUid != uid)
                     continue;
 
                 if (duc != null)
                     duc.Container.Insert(entity, EntityManager, xform, meta: meta);
                 else
-                    _xformSystem.AttachToGridOrMap(entity, xform);
+                    _transform.AttachToGridOrMap(entity, xform);
 
-                if (EntityManager.TryGetComponent(entity, out PhysicsComponent? physics))
+                if (physQuery.TryGetComponent(entity, out var physics))
                 {
-                    _physicsSystem.WakeBody(entity, body: physics);
+                    _physics.WakeBody(entity, body: physics);
                 }
             }
 
             if (disposalId != null && duc != null)
             {
-                _disposalUnitSystem.TryEjectContents(disposalId.Value, duc);
+                _disposalUnit.TryEjectContents(disposalId.Value, duc);
             }
 
-            if (_atmosphereSystem.GetContainingMixture(uid, false, true) is { } environment)
+            if (_atmosphere.GetContainingMixture(uid, false, true) is { } environment)
             {
-                _atmosphereSystem.Merge(environment, holder.Air);
+                _atmosphere.Merge(environment, holder.Air);
                 holder.Air.Clear();
             }
 
@@ -182,6 +190,17 @@ namespace Content.Server.Disposal.Unit.EntitySystems
                 ExitDisposals(holderUid, holder, holderTransform);
                 return false;
             }
+
+            // damage entities on turns and play sound
+            if (holder.CurrentDirection != holder.PreviousDirection)
+            {
+                foreach (var ent in holder.Container.ContainedEntities)
+                {
+                    _damageable.TryChangeDamage(ent, to.DamageOnTurn);
+                }
+                _audio.PlayPvs(to.ClangSound, toUid, AudioParams.Default.WithVolume(-5f));
+            }
+
             return true;
         }
 
@@ -222,7 +241,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
                     var newPosition = destination * progress;
 
                     // This is some supreme shit code.
-                    _xformSystem.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
+                    _transform.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
                     continue;
                 }
 
@@ -231,7 +250,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
                 Comp<DisposalTubeComponent>(currentTube).Contents.Remove(uid, reparent: false, force: true);
 
                 // Find next tube
-                var nextTube = _disposalTubeSystem.NextTubeFor(currentTube, holder.CurrentDirection);
+                var nextTube = _disposalTube.NextTubeFor(currentTube, holder.CurrentDirection);
                 if (!EntityManager.EntityExists(nextTube))
                 {
                     ExitDisposals(uid, holder);