Cardboard box fixes (#13087)
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.CardboardBox.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Shared.CardboardBox;
|
||||
using Content.Shared.CardboardBox.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Stealth;
|
||||
using Content.Shared.Stealth.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Shared.Stealth.Components;
|
||||
using Content.Shared.Stealth;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.CardboardBox;
|
||||
|
||||
@@ -23,16 +22,15 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly SharedStealthSystem _stealth = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly EntityStorageSystem _storage = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<CardboardBoxComponent, StorageBeforeCloseEvent>(OnBeforeStorageClosed);
|
||||
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterOpenEvent>(AfterStorageOpen);
|
||||
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterCloseEvent>(AfterStorageClosed);
|
||||
SubscribeLocalEvent<CardboardBoxComponent, InteractedNoHandEvent>(OnNoHandInteracted);
|
||||
SubscribeLocalEvent<CardboardBoxComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
|
||||
SubscribeLocalEvent<CardboardBoxComponent, DamageChangedEvent>(OnDamage);
|
||||
}
|
||||
@@ -46,26 +44,6 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
||||
_storage.OpenStorage(uid);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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.
|
||||
@@ -104,4 +82,23 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
||||
_damageable.TryChangeDamage(component.Mover, args.DamageDelta, origin: args.Origin);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEntInserted(EntityUid uid, CardboardBoxComponent component, EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (!TryComp(args.Entity, out MobMoverComponent? mover))
|
||||
return;
|
||||
|
||||
if (component.Mover != null)
|
||||
{
|
||||
// player movers take priority
|
||||
if (HasComp<ActorComponent>(component.Mover) || !HasComp<ActorComponent>(args.Entity))
|
||||
return;
|
||||
|
||||
RemComp<RelayInputMoverComponent>(component.Mover.Value);
|
||||
}
|
||||
|
||||
var relay = EnsureComp<RelayInputMoverComponent>(args.Entity);
|
||||
_mover.SetRelay(args.Entity, uid, relay);
|
||||
component.Mover = args.Entity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user