Files
tbd-station-14/Content.Server/SprayPainter/SprayPainterSystem.cs
Plykiya 190ceda02e Add BreakOnDropItem, update do afters, remove unnecessary declarations (#30361)
* Add BreakOnDropItem, update do afters, remove unnecessary declarations

* bola

* Changed my mind about the nuke

* gennies too

* Make the comments more clear.

* Sorry for the trailing commas

* Revert "Sorry for the trailing commas"

This reverts commit e60fd9a30977393df3344948e6d5c0ce035723cd.

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
2024-08-08 13:39:46 +02:00

68 lines
2.1 KiB
C#

using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.EntitySystems;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.SprayPainter;
using Content.Shared.SprayPainter.Components;
namespace Content.Server.SprayPainter;
/// <summary>
/// Handles spraying pipes using a spray painter.
/// Airlocks are handled in shared.
/// </summary>
public sealed class SprayPainterSystem : SharedSprayPainterSystem
{
[Dependency] private readonly AtmosPipeColorSystem _pipeColor = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SprayPainterComponent, SprayPainterPipeDoAfterEvent>(OnPipeDoAfter);
SubscribeLocalEvent<AtmosPipeColorComponent, InteractUsingEvent>(OnPipeInteract);
}
private void OnPipeDoAfter(Entity<SprayPainterComponent> ent, ref SprayPainterPipeDoAfterEvent args)
{
if (args.Handled || args.Cancelled)
return;
if (args.Args.Target is not {} target)
return;
if (!TryComp<AtmosPipeColorComponent>(target, out var color))
return;
Audio.PlayPvs(ent.Comp.SpraySound, ent);
_pipeColor.SetColor(target, color, args.Color);
args.Handled = true;
}
private void OnPipeInteract(Entity<AtmosPipeColorComponent> ent, ref InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp<SprayPainterComponent>(args.Used, out var painter) || painter.PickedColor is not {} colorName)
return;
if (!painter.ColorPalette.TryGetValue(colorName, out var color))
return;
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, painter.PipeSprayTime, new SprayPainterPipeDoAfterEvent(color), args.Used, target: ent, used: args.Used)
{
BreakOnMove = true,
BreakOnDamage = true,
// multiple pipes can be sprayed at once just not the same one
DuplicateCondition = DuplicateConditions.SameTarget,
NeedHand = true,
};
args.Handled = DoAfter.TryStartDoAfter(doAfterEventArgs);
}
}