Files
tbd-station-14/Content.Server/Containers/ThrowInsertContainerSystem.cs
metalgearsloth 63dfd21b14 Predict dumping (#32394)
* Predict dumping

- This got soaped really fucking hard.
- Dumping is predicted, this required disposals to be predicte.d
- Disposals required mailing (because it's tightly coupled), and a smidge of other content systems.
- I also had to fix a compnetworkgenerator issue at the same time so it wouldn't mispredict.

* Fix a bunch of stuff

* nasty merge

* Some reviews

* Some more reviews while I stash

* Fix merge

* Fix merge

* Half of review

* Review

* re(h)f

* lizards

* feexes

* feex
2025-04-19 16:20:40 +10:00

56 lines
2.0 KiB
C#

using Content.Server.Administration.Logs;
using Content.Shared.Containers;
using Content.Shared.Database;
using Content.Shared.Popups;
using Content.Shared.Throwing;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Random;
namespace Content.Server.Containers;
public sealed class ThrowInsertContainerSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ThrowInsertContainerComponent, ThrowHitByEvent>(OnThrowCollide);
}
private void OnThrowCollide(Entity<ThrowInsertContainerComponent> ent, ref ThrowHitByEvent args)
{
var container = _containerSystem.GetContainer(ent, ent.Comp.ContainerId);
if (!_containerSystem.CanInsert(args.Thrown, container))
return;
var beforeThrowArgs = new BeforeThrowInsertEvent(args.Thrown);
RaiseLocalEvent(ent, ref beforeThrowArgs);
if (beforeThrowArgs.Cancelled)
return;
if (_random.Prob(ent.Comp.Probability))
{
_audio.PlayPvs(ent.Comp.MissSound, ent);
_popup.PopupEntity(Loc.GetString(ent.Comp.MissLocString), ent);
return;
}
if (!_containerSystem.Insert(args.Thrown, container))
throw new InvalidOperationException("Container insertion failed but CanInsert returned true");
_audio.PlayPvs(ent.Comp.InsertSound, ent);
if (args.Component.Thrower != null)
_adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.Component.Thrower.Value):player} landed in {ToPrettyString(ent)}");
}
}