EntityStorage ECS (#9291)
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Standing;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public sealed class BodyBagEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
protected override bool AddToContents(EntityUid entity)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<SharedBodyComponent>(entity) && !EntitySystem.Get<StandingStateSystem>().IsDown(entity)) return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Content.Server/Morgue/Components/CrematoriumComponent.cs
Normal file
31
Content.Server/Morgue/Components/CrematoriumComponent.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Content.Shared.Sound;
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class CrematoriumComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not the crematorium is currently cooking
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool Cooking;
|
||||
|
||||
/// <summary>
|
||||
/// The time it takes to cook
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int BurnMilis = 5000;
|
||||
|
||||
public CancellationTokenSource? CremateCancelToken;
|
||||
|
||||
[DataField("cremateStartSound")]
|
||||
public SoundSpecifier CremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
|
||||
|
||||
[DataField("crematingSound")]
|
||||
public SoundSpecifier CrematingSound = new SoundPathSpecifier("/Audio/Effects/burning.ogg");
|
||||
|
||||
[DataField("cremateFinishSound")]
|
||||
public SoundSpecifier CremateFinishSound = new SoundPathSpecifier("/Audio/Machines/ding.ogg");
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
|
||||
using System.Threading;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(MorgueEntityStorageComponent))]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
#pragma warning disable 618
|
||||
public sealed class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent
|
||||
#pragma warning restore 618
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[DataField("cremateStartSound")] private SoundSpecifier _cremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
|
||||
[DataField("crematingSound")] private SoundSpecifier _crematingSound = new SoundPathSpecifier("/Audio/Effects/burning.ogg");
|
||||
[DataField("cremateFinishSound")] private SoundSpecifier _cremateFinishSound = new SoundPathSpecifier("/Audio/Machines/ding.ogg");
|
||||
|
||||
[ViewVariables]
|
||||
public bool Cooking { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _burnMilis = 5000;
|
||||
|
||||
private CancellationTokenSource? _cremateCancelToken;
|
||||
|
||||
public override bool CanOpen(EntityUid user, bool silent = false)
|
||||
{
|
||||
if (Cooking)
|
||||
{
|
||||
if (!silent)
|
||||
Owner.PopupMessage(user, Loc.GetString("crematorium-entity-storage-component-is-cooking-safety-message"));
|
||||
return false;
|
||||
}
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
public void TryCremate()
|
||||
{
|
||||
if (Cooking) return;
|
||||
if (Open) return;
|
||||
|
||||
SoundSystem.Play(_cremateStartSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
Cremate();
|
||||
}
|
||||
|
||||
public void Cremate()
|
||||
{
|
||||
if (Open)
|
||||
CloseStorage();
|
||||
|
||||
if(_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(CrematoriumVisuals.Burning, true);
|
||||
Cooking = true;
|
||||
|
||||
SoundSystem.Play(_crematingSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
_cremateCancelToken?.Cancel();
|
||||
|
||||
_cremateCancelToken = new CancellationTokenSource();
|
||||
Owner.SpawnTimer(_burnMilis, () =>
|
||||
{
|
||||
if (_entities.Deleted(Owner))
|
||||
return;
|
||||
if(_entities.TryGetComponent(Owner, out appearanceComponent))
|
||||
appearanceComponent.SetData(CrematoriumVisuals.Burning, false);
|
||||
Cooking = false;
|
||||
|
||||
if (Contents.ContainedEntities.Count > 0)
|
||||
{
|
||||
for (var i = Contents.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = Contents.ContainedEntities[i];
|
||||
Contents.Remove(item);
|
||||
_entities.DeleteEntity(item);
|
||||
}
|
||||
|
||||
var ash = _entities.SpawnEntity("Ash", _entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
Contents.Insert(ash);
|
||||
}
|
||||
|
||||
TryOpenStorage(Owner);
|
||||
|
||||
SoundSystem.Play(_cremateFinishSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
}, _cremateCancelToken.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class EntityStorageLayingDownOverrideComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
26
Content.Server/Morgue/Components/MorgueComponent.cs
Normal file
26
Content.Server/Morgue/Components/MorgueComponent.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Content.Shared.Sound;
|
||||
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class MorgueComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not the morgue beeps if a living player is inside.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("doSoulBeep")]
|
||||
public bool DoSoulBeep = true;
|
||||
|
||||
[ViewVariables]
|
||||
public float AccumulatedFrameTime = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time between each beep.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public float BeepTime = 10f;
|
||||
|
||||
[DataField("occupantHasSoulAlarmSound")]
|
||||
public SoundSpecifier OccupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Directions;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
[Virtual]
|
||||
public class MorgueEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
private const CollisionGroup TrayCanOpenMask = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("trayPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
private string? _trayPrototypeId;
|
||||
|
||||
[ViewVariables]
|
||||
private EntityUid? _tray;
|
||||
|
||||
[ViewVariables]
|
||||
public ContainerSlot? TrayContainer { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("doSoulBeep")]
|
||||
public bool DoSoulBeep = true;
|
||||
|
||||
[DataField("occupantHasSoulAlarmSound")]
|
||||
private SoundSpecifier _occupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
appearance.SetData(MorgueVisuals.Open, false);
|
||||
TrayContainer = Owner.EnsureContainer<ContainerSlot>("morgue_tray", out _);
|
||||
}
|
||||
|
||||
public override Vector2 ContentsDumpPosition()
|
||||
{
|
||||
if (_tray != null)
|
||||
return _entMan.GetComponent<TransformComponent>(_tray.Value).WorldPosition;
|
||||
return base.ContentsDumpPosition();
|
||||
}
|
||||
|
||||
protected override bool AddToContents(EntityUid entity)
|
||||
{
|
||||
if (_entMan.HasComponent<SharedBodyComponent>(entity) && !EntitySystem.Get<StandingStateSystem>().IsDown(entity))
|
||||
return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
|
||||
public override bool CanOpen(EntityUid user, bool silent = false)
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner,
|
||||
_entMan.GetComponent<TransformComponent>(Owner).Coordinates.Offset(_entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetCardinalDir()),
|
||||
collisionMask: TrayCanOpenMask
|
||||
))
|
||||
{
|
||||
if (!silent)
|
||||
Owner.PopupMessage(user, Loc.GetString("morgue-entity-storage-component-cannot-open-no-space"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
protected override void OpenStorage()
|
||||
{
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData(MorgueVisuals.Open, true);
|
||||
appearance.SetData(MorgueVisuals.HasContents, false);
|
||||
appearance.SetData(MorgueVisuals.HasMob, false);
|
||||
appearance.SetData(MorgueVisuals.HasSoul, false);
|
||||
}
|
||||
|
||||
if (_tray == null)
|
||||
{
|
||||
_tray = _entMan.SpawnEntity(_trayPrototypeId, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var trayComp = _tray.Value.EnsureComponent<MorgueTrayComponent>();
|
||||
trayComp.Morgue = Owner;
|
||||
}
|
||||
else
|
||||
{
|
||||
TrayContainer?.Remove(_tray.Value);
|
||||
}
|
||||
|
||||
_entMan.GetComponent<TransformComponent>(_tray.Value).Coordinates = new EntityCoordinates(Owner, 0, -1);
|
||||
|
||||
base.OpenStorage();
|
||||
}
|
||||
|
||||
private void CheckContents()
|
||||
{
|
||||
var count = 0;
|
||||
var hasMob = false;
|
||||
var hasSoul = false;
|
||||
foreach (var entity in Contents.ContainedEntities)
|
||||
{
|
||||
count++;
|
||||
if (!hasMob && _entMan.HasComponent<SharedBodyComponent>(entity))
|
||||
hasMob = true;
|
||||
if (!hasSoul && _entMan.TryGetComponent<ActorComponent?>(entity, out var actor) && actor.PlayerSession != null)
|
||||
hasSoul = true;
|
||||
}
|
||||
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData(MorgueVisuals.HasContents, count > 0);
|
||||
appearance.SetData(MorgueVisuals.HasMob, hasMob);
|
||||
appearance.SetData(MorgueVisuals.HasSoul, hasSoul);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CloseStorage()
|
||||
{
|
||||
base.CloseStorage();
|
||||
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
appearance.SetData(MorgueVisuals.Open, false);
|
||||
CheckContents();
|
||||
|
||||
if (_tray != null)
|
||||
{
|
||||
TrayContainer?.Insert(_tray.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<EntityUid> DetermineCollidingEntities()
|
||||
{
|
||||
if (_tray == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var entityLookup = EntitySystem.Get<EntityLookupSystem>();
|
||||
foreach (var entity in entityLookup.GetEntitiesIntersecting(_tray.Value, flags: LookupFlags.None))
|
||||
{
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
|
||||
//Called every 10 seconds
|
||||
public void Update()
|
||||
{
|
||||
CheckContents();
|
||||
|
||||
if (DoSoulBeep && _entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance) &&
|
||||
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
{
|
||||
SoundSystem.Play(_occupantHasSoulAlarmSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public sealed class MorgueTrayComponent : Component, IActivate
|
||||
{
|
||||
[ViewVariables]
|
||||
public EntityUid Morgue { get; set; }
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (Morgue != default && !entMan.Deleted(Morgue) && entMan.TryGetComponent<MorgueEntityStorageComponent?>(Morgue, out var comp))
|
||||
{
|
||||
comp.Activate(new ActivateEventArgs(eventArgs.User, Morgue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user