Add disposals damage (#21489)
* 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
This commit is contained in:
@@ -1,30 +1,38 @@
|
|||||||
using System.Linq;
|
|
||||||
using Content.Server.Disposal.Unit.Components;
|
|
||||||
using Content.Server.Disposal.Unit.EntitySystems;
|
using Content.Server.Disposal.Unit.EntitySystems;
|
||||||
using Content.Shared.Construction.Components;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Popups;
|
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Containers;
|
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]
|
[DataField]
|
||||||
[Access(typeof(DisposalTubeSystem), typeof(DisposableSystem))]
|
public string ContainerId = "DisposalTube";
|
||||||
public sealed partial class DisposalTubeComponent : Component
|
|
||||||
|
[ViewVariables]
|
||||||
|
public bool Connected;
|
||||||
|
|
||||||
|
[DataField]
|
||||||
|
public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
||||||
|
|
||||||
|
/// <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()
|
||||||
{
|
{
|
||||||
[DataField("containerId")] public string ContainerId { get; set; } = "DisposalTube";
|
DamageDict = new()
|
||||||
|
{
|
||||||
public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
|
{ "Blunt", 1.0 },
|
||||||
public TimeSpan LastClang;
|
}
|
||||||
|
};
|
||||||
public bool Connected;
|
|
||||||
[DataField("clangSound")] 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!;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ namespace Content.Server.Disposal.Tube
|
|||||||
SubscribeLocalEvent<DisposalTubeComponent, ComponentRemove>(OnComponentRemove);
|
SubscribeLocalEvent<DisposalTubeComponent, ComponentRemove>(OnComponentRemove);
|
||||||
|
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, AnchorStateChangedEvent>(OnAnchorChange);
|
SubscribeLocalEvent<DisposalTubeComponent, AnchorStateChangedEvent>(OnAnchorChange);
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
|
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, BreakageEventArgs>(OnBreak);
|
SubscribeLocalEvent<DisposalTubeComponent, BreakageEventArgs>(OnBreak);
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, ComponentStartup>(OnStartup);
|
SubscribeLocalEvent<DisposalTubeComponent, ComponentStartup>(OnStartup);
|
||||||
SubscribeLocalEvent<DisposalTubeComponent, ConstructionBeforeDeleteEvent>(OnDeconstruct);
|
SubscribeLocalEvent<DisposalTubeComponent, ConstructionBeforeDeleteEvent>(OnDeconstruct);
|
||||||
@@ -278,17 +277,6 @@ namespace Content.Server.Disposal.Tube
|
|||||||
UpdateAnchored(uid, component, Transform(uid).Anchored);
|
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)
|
private void OnBreak(EntityUid uid, DisposalTubeComponent component, BreakageEventArgs args)
|
||||||
{
|
{
|
||||||
DisconnectTube(uid, component);
|
DisconnectTube(uid, component);
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ using Content.Server.Disposal.Tube;
|
|||||||
using Content.Server.Disposal.Tube.Components;
|
using Content.Server.Disposal.Tube.Components;
|
||||||
using Content.Server.Disposal.Unit.Components;
|
using Content.Server.Disposal.Unit.Components;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Disposal.Components;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using JetBrains.Annotations;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
|
|
||||||
@@ -16,13 +17,15 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
{
|
{
|
||||||
public sealed class DisposableSystem : EntitySystem
|
public sealed class DisposableSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly DisposalUnitSystem _disposalUnit = default!;
|
||||||
[Dependency] private readonly DisposalUnitSystem _disposalUnitSystem = default!;
|
[Dependency] private readonly DisposalTubeSystem _disposalTube = default!;
|
||||||
[Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!;
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
[Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
[Dependency] private readonly MapSystem _map = default!;
|
||||||
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -33,7 +36,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
|
|
||||||
private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
|
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)
|
public bool TryInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null)
|
||||||
@@ -47,7 +50,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (TryComp<PhysicsComponent>(toInsert, out var physBody))
|
if (TryComp<PhysicsComponent>(toInsert, out var physBody))
|
||||||
_physicsSystem.SetCanCollide(toInsert, false, body: physBody);
|
_physics.SetCanCollide(toInsert, false, body: physBody);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,7 +60,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
if (!Resolve(uid, ref holder))
|
if (!Resolve(uid, ref holder))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_containerSystem.CanInsert(toInsert, holder.Container))
|
if (!_container.CanInsert(toInsert, holder.Container))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -86,11 +89,13 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
|
|
||||||
EntityUid? disposalId = null;
|
EntityUid? disposalId = null;
|
||||||
DisposalUnitComponent? duc = 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;
|
disposalId = contentUid;
|
||||||
break;
|
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())
|
foreach (var entity in holder.Container.ContainedEntities.ToArray())
|
||||||
{
|
{
|
||||||
RemComp<BeingDisposedComponent>(entity);
|
RemComp<BeingDisposedComponent>(entity);
|
||||||
|
|
||||||
var meta = MetaData(entity);
|
var meta = metaQuery.GetComponent(entity);
|
||||||
holder.Container.Remove(entity, EntityManager, meta: meta, reparent: false, force: true);
|
holder.Container.Remove(entity, EntityManager, meta: meta, reparent: false, force: true);
|
||||||
|
|
||||||
var xform = Transform(entity);
|
var xform = transformQuery.GetComponent(entity);
|
||||||
if (xform.ParentUid != uid)
|
if (xform.ParentUid != uid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (duc != null)
|
if (duc != null)
|
||||||
duc.Container.Insert(entity, EntityManager, xform, meta: meta);
|
duc.Container.Insert(entity, EntityManager, xform, meta: meta);
|
||||||
else
|
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)
|
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();
|
holder.Air.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +190,17 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
ExitDisposals(holderUid, holder, holderTransform);
|
ExitDisposals(holderUid, holder, holderTransform);
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +241,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
var newPosition = destination * progress;
|
var newPosition = destination * progress;
|
||||||
|
|
||||||
// This is some supreme shit code.
|
// This is some supreme shit code.
|
||||||
_xformSystem.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
_transform.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +250,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
Comp<DisposalTubeComponent>(currentTube).Contents.Remove(uid, reparent: false, force: true);
|
Comp<DisposalTubeComponent>(currentTube).Contents.Remove(uid, reparent: false, force: true);
|
||||||
|
|
||||||
// Find next tube
|
// Find next tube
|
||||||
var nextTube = _disposalTubeSystem.NextTubeFor(currentTube, holder.CurrentDirection);
|
var nextTube = _disposalTube.NextTubeFor(currentTube, holder.CurrentDirection);
|
||||||
if (!EntityManager.EntityExists(nextTube))
|
if (!EntityManager.EntityExists(nextTube))
|
||||||
{
|
{
|
||||||
ExitDisposals(uid, holder);
|
ExitDisposals(uid, holder);
|
||||||
|
|||||||
Reference in New Issue
Block a user