Cardboard Box and Stealth Components (#11569)
This commit is contained in:
61
Content.Server/CardboardBox/CardboardBoxSystem.cs
Normal file
61
Content.Server/CardboardBox/CardboardBoxSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.CardboardBox.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.CardboardBox;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.CardboardBox;
|
||||
|
||||
public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedMoverController _mover = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<CardboardBoxComponent, StorageBeforeCloseEvent>(OnBeforeStorageClosed);
|
||||
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterOpenEvent>(AfterStorageOpen);
|
||||
}
|
||||
|
||||
private void OnBeforeStorageClosed(EntityUid uid, CardboardBoxComponent component, StorageBeforeCloseEvent args)
|
||||
{
|
||||
var mobMover = args.Contents.Where(HasComp<MobMoverComponent>).ToList();
|
||||
|
||||
//Grab the first mob to set as the mover and to prevent other mobs from entering.
|
||||
foreach (var mover in mobMover)
|
||||
{
|
||||
//Set the movement relay for the box as the first mob
|
||||
if (component.Mover == null && args.Contents.Contains(mover))
|
||||
{
|
||||
var relay = EnsureComp<RelayInputMoverComponent>(mover);
|
||||
_mover.SetRelay(mover, uid, relay);
|
||||
component.Mover = mover;
|
||||
}
|
||||
|
||||
if (mover != component.Mover)
|
||||
args.Contents.Remove(mover);
|
||||
}
|
||||
}
|
||||
|
||||
private void AfterStorageOpen(EntityUid uid, CardboardBoxComponent component, StorageAfterOpenEvent args)
|
||||
{
|
||||
//Remove the mover after the box is opened and play the effect if it hasn't been played yet.
|
||||
if (component.Mover != null)
|
||||
{
|
||||
RemComp<RelayInputMoverComponent>(component.Mover.Value);
|
||||
if (_timing.CurTime > component.EffectCooldown)
|
||||
{
|
||||
RaiseNetworkEvent(new PlayBoxEffectMessage(component.Owner, component.Mover.Value), Filter.PvsExcept(component.Owner));
|
||||
_audio.PlayPvs(component.EffectSound, component.Owner);
|
||||
component.EffectCooldown = _timing.CurTime + CardboardBoxComponent.MaxEffectCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
component.Mover = null;
|
||||
}
|
||||
}
|
||||
8
Content.Server/Stealth/StealthSystem.cs
Normal file
8
Content.Server/Stealth/StealthSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Stealth;
|
||||
|
||||
namespace Content.Server.Stealth;
|
||||
|
||||
public sealed class StealthSystem : SharedStealthSystem
|
||||
{
|
||||
|
||||
}
|
||||
@@ -37,6 +37,15 @@ public sealed class EntityStorageComponent : Component, IGasMixtureHolder
|
||||
[DataField("isCollidableWhenOpen")]
|
||||
public bool IsCollidableWhenOpen;
|
||||
|
||||
/// <summary>
|
||||
/// If true, it opens the storage when the entity inside of it moves
|
||||
/// If false, it prevents the storage from opening when the entity inside of it moves.
|
||||
/// This is for objects that you want the player to move while inside, like large cardboard boxes, without opening the storage.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("openOnMove")]
|
||||
public bool OpenOnMove = true;
|
||||
|
||||
//The offset for where items are emptied/vacuumed for the EntityStorage.
|
||||
[DataField("enteringOffset")]
|
||||
public Vector2 EnteringOffset = new(0, 0);
|
||||
|
||||
@@ -149,7 +149,10 @@ namespace Content.Server.Storage.EntitySystems
|
||||
return;
|
||||
|
||||
component.LastInternalOpenAttempt = _gameTiming.CurTime;
|
||||
_entityStorage.TryOpenStorage(args.Entity, component.Owner);
|
||||
if (component.OpenOnMove)
|
||||
{
|
||||
_entityStorage.TryOpenStorage(args.Entity, component.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user