using System.Numerics; using Content.Shared.CardboardBox.Components; using Content.Shared.Interaction; using Content.Shared.Stealth; using Content.Shared.Stealth.Components; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; using Content.Shared.Vehicle.Systems; using Content.Shared.Vehicle; using Robust.Shared.Audio.Systems; using Robust.Shared.Network; using Robust.Shared.Physics.Systems; using Robust.Shared.Timing; namespace Content.Shared.CardboardBox; public abstract partial class SharedCardboardBoxSystem : EntitySystem { [Dependency] private IGameTiming _timing = default!; [Dependency] private INetManager _net = default!; [Dependency] private SharedAudioSystem _audio = default!; [Dependency] private SharedEntityStorageSystem _storage = default!; [Dependency] private SharedPhysicsSystem _physics = default!; [Dependency] private SharedStealthSystem _stealth = default!; [Dependency] private VehicleSystem _vehicle = default!; [SubscribeLocalEvent] private void OnInteracted(Entity ent, ref ActivateInWorldEvent args) { if (args.Handled) return; if (!TryComp(ent, out var box)) return; if (!args.Complex) { if (box.Open || !box.Contents.Contains(args.User)) return; } args.Handled = true; _storage.ToggleOpen(args.User, ent, box); } [SubscribeLocalEvent] private void BeforeStorageOpen(Entity ent, ref StorageBeforeOpenEvent args) { if (ent.Comp.Quiet) return; if (!_vehicle.TryGetOperator(ent.Owner, out var operatorEnt)) return; if (_timing.CurTime <= ent.Comp.EffectCooldown) return; if (_net.IsServer) RaiseNetworkEvent(new PlayBoxEffectMessage(GetNetEntity(ent), GetNetEntity(operatorEnt.Value.Owner))); _audio.PlayPredicted(ent.Comp.EffectSound, ent, args.User); ent.Comp.EffectCooldown = _timing.CurTime + ent.Comp.CooldownDuration; Dirty(ent); } [SubscribeLocalEvent] private void AfterStorageOpen(Entity ent, ref StorageAfterOpenEvent args) { // If this box has a stealth/chameleon effect, disable the stealth effect while the box is open. if (!TryComp(ent, out var stealth)) return; _stealth.SetEnabled(ent, false, stealth); } [SubscribeLocalEvent] private void AfterStorageClosed(Entity ent, ref StorageAfterCloseEvent args) { // If this box has a stealth/chameleon effect, enable the stealth effect. if (!TryComp(ent, out var stealth)) return; _stealth.SetVisibility(ent, stealth.MaxVisibility, stealth); _stealth.SetEnabled(ent, true, stealth); } [SubscribeLocalEvent] private void OnOperatorSet(Entity ent, ref VehicleOperatorSetEvent args) { if (args.NewOperator != null || args.OldOperator == null) return; _physics.SetLinearVelocity(ent, Vector2.Zero); } }