Files
tbd-station-14/Content.Server/GameObjects/Components/Items/Storage/CursedEntityStorageComponent.cs
ColdAutumnRain f5dc62b533 Removed EntityManager member variable from Components and EntitySystems (#2502)
* Removed EntityManager member variable from Components and EntitySystems

* Removed EntityManager with minor corecctions

* Update PathfindingSystem.cs

* Update InteractionSystem.cs

* Update Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>

* Update Content.Client/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/PDA/PDAComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Singularity/SingularityComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Singularity/SingularityComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Stack/StackComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: Clyybber <darkmine956@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
2020-11-18 15:45:53 +01:00

56 lines
1.9 KiB
C#

using System.Linq;
using Content.Shared.Audio;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage
{
[ComponentReference(typeof(EntityStorageComponent))]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IStorageComponent))]
[RegisterComponent]
public class CursedEntityStorageComponent : EntityStorageComponent
{
[Dependency] private IRobustRandom _robustRandom = default!;
public override string Name => "CursedEntityStorage";
protected override void CloseStorage()
{
base.CloseStorage();
// No contents, we do nothing
if (Contents.ContainedEntities.Count == 0) return;
var lockers = Owner.EntityManager.GetEntities(new TypeEntityQuery(typeof(EntityStorageComponent))).ToList();
if (lockers.Contains(Owner))
lockers.Remove(Owner);
var lockerEnt = _robustRandom.Pick(lockers);
if (lockerEnt == null) return; // No valid lockers anywhere.
var locker = lockerEnt.GetComponent<EntityStorageComponent>();
if(locker.Open)
locker.TryCloseStorage(Owner);
foreach (var entity in Contents.ContainedEntities.ToArray())
{
Contents.ForceRemove(entity);
locker.Insert(entity);
}
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/teleport_departure.ogg", Owner, AudioHelpers.WithVariation(0.125f));
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/teleport_arrival.ogg", lockerEnt, AudioHelpers.WithVariation(0.125f));
}
}
}