Add water cups to water coolers (#22073)
* add water cup bin to water cooler * Fix punctuation, and add proper components/tags on init * I forgor and refactoring event construction
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -31,6 +34,13 @@ public sealed class BinSystem : EntitySystem
|
||||
SubscribeLocalEvent<BinComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
SubscribeLocalEvent<BinComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<BinComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
SubscribeLocalEvent<BinComponent, GetVerbsEvent<AlternativeVerb>>(OnAltInteractHand);
|
||||
SubscribeLocalEvent<BinComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, BinComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushText(Loc.GetString("bin-component-on-examine-text", ("count", component.Items.Count)));
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, BinComponent component, ComponentStartup args)
|
||||
@@ -76,19 +86,38 @@ public sealed class BinSystem : EntitySystem
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alt interact acts the same as interacting with your hands normally, but allows fallback interaction if the item
|
||||
/// has priority. E.g. a water cup on a water cooler fills itself on a normal click,
|
||||
/// but you can use alternative interactions to restock the cup bin
|
||||
/// </summary>
|
||||
private void OnAltInteractHand(EntityUid uid, BinComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (args.Using != null)
|
||||
{
|
||||
var canReach = args.CanAccess && args.CanInteract;
|
||||
InsertIntoBin(args.User, args.Target, (EntityUid) args.Using, component, false, canReach);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterInteractUsing(EntityUid uid, BinComponent component, AfterInteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
InsertIntoBin(args.User, uid, args.Used, component, args.Handled, args.CanReach);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void InsertIntoBin(EntityUid user, EntityUid target, EntityUid itemInHand, BinComponent component, bool handled, bool canReach)
|
||||
{
|
||||
if (handled || !canReach)
|
||||
return;
|
||||
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
if (!TryInsertIntoBin(uid, args.Used, component))
|
||||
if (!TryInsertIntoBin(target, itemInHand, component))
|
||||
return;
|
||||
|
||||
_admin.Add(LogType.Pickup, LogImpact.Low, $"{ToPrettyString(uid):player} inserted {ToPrettyString(args.User)} into bin {ToPrettyString(uid)}.");
|
||||
args.Handled = true;
|
||||
_admin.Add(LogType.Pickup, LogImpact.Low, $"{ToPrettyString(target):player} inserted {ToPrettyString(user)} into bin {ToPrettyString(target)}.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user