From ab2149abf011476337cea173b0651bd30b935ebc Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:13:34 +1100 Subject: [PATCH] Adds yeeting to disposal bins (#2218) * Adds yeeting to disposal bins Kobe * Thanks zum * ? Co-authored-by: Metal Gear Sloth --- .../Disposal/DisposalUnitComponent.cs | 25 +++++++++++++------ .../Disposal/SharedDisposalUnitComponent.cs | 24 ++++++++++-------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 10e0573a0a..2aecb8196c 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -7,11 +7,13 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Power.ApcNetComponents; +using Content.Server.GameObjects.Components.Projectiles; using Content.Server.GameObjects.EntitySystems.DoAfter; using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Server.Utility; using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Disposal; +using Content.Shared.GameObjects.Components.Items; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.Verbs; using Content.Shared.Interfaces; @@ -28,6 +30,7 @@ using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -42,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Disposal [ComponentReference(typeof(SharedDisposalUnitComponent))] [ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IInteractUsing))] - public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IActivate, IInteractUsing, IDragDropOn + public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IActivate, IInteractUsing, IDragDropOn, IThrowCollide { [Dependency] private readonly IGameTiming _gameTiming = default!; @@ -96,11 +99,6 @@ namespace Content.Server.GameObjects.Components.Disposal !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; - [ViewVariables] - public bool Anchored => - !Owner.TryGetComponent(out CollidableComponent? collidable) || - collidable.Anchored; - [ViewVariables] private PressureState State => _pressure >= 1 ? PressureState.Ready : PressureState.Pressurizing; @@ -411,8 +409,7 @@ namespace Content.Server.GameObjects.Components.Disposal { return; } - - + if (!Anchored) { appearance.SetData(Visuals.VisualState, VisualState.UnAnchored); @@ -685,6 +682,18 @@ namespace Content.Server.GameObjects.Components.Disposal _ = TryInsert(eventArgs.Dropped, eventArgs.User); return true; } + + void IThrowCollide.HitBy(ThrowCollideEventArgs eventArgs) + { + if (!CanInsert(eventArgs.Thrown) || + IoCManager.Resolve().NextDouble() > 0.75 || + !_container.Insert(eventArgs.Thrown)) + { + return; + } + + AfterInsert(eventArgs.Thrown); + } [Verb] private sealed class SelfInsertVerb : Verb diff --git a/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs b/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs index 1638c7c7cc..b45cb157d5 100644 --- a/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs +++ b/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs @@ -1,25 +1,28 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; -using System.Linq; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.UserInterface; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; -using Robust.Shared.IoC; using Robust.Shared.Physics; using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Disposal { public abstract class SharedDisposalUnitComponent : Component, ICollideSpecial { - [Dependency] private readonly IEntityManager _entityManager = default!; - public override string Name => "DisposalUnit"; private readonly List _intersecting = new List(); + [ViewVariables] + public bool Anchored => + !Owner.TryGetComponent(out CollidableComponent? collidable) || + collidable.Anchored; + [Serializable, NetSerializable] public enum Visuals { @@ -71,7 +74,7 @@ namespace Content.Shared.GameObjects.Components.Disposal bool ICollideSpecial.PreventCollide(IPhysBody collided) { if (IsExiting(collided.Entity)) return true; - if (!Owner.TryGetComponent(out IContainerManager manager)) return false; + if (!Owner.TryGetComponent(out IContainerManager? manager)) return false; if (manager.ContainsEntity(collided.Entity)) { @@ -98,13 +101,12 @@ namespace Content.Shared.GameObjects.Components.Disposal { if(_intersecting.Count == 0) return; - var intersectingEntities = _entityManager.GetEntitiesIntersecting(Owner); for (var i = _intersecting.Count - 1; i >= 0; i--) { - if (!intersectingEntities.Contains(_intersecting[i])) - { + var entity = _intersecting[i]; + + if (!Owner.EntityManager.IsIntersecting(entity, Owner)) _intersecting.RemoveAt(i); - } } } @@ -127,7 +129,7 @@ namespace Content.Shared.GameObjects.Components.Disposal Engaged = engaged; } - public bool Equals(DisposalUnitBoundUserInterfaceState other) + public bool Equals(DisposalUnitBoundUserInterfaceState? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true;