From eb7f0edf7d8aab088980220c7024618985f6f1d7 Mon Sep 17 00:00:00 2001 From: dffdff2423 Date: Wed, 31 Jul 2024 17:37:08 -0500 Subject: [PATCH] Fix a few issues with painting (#337) --- Content.Server/Paint/PaintSystem.cs | 50 ++++++++++++++++++----------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Content.Server/Paint/PaintSystem.cs b/Content.Server/Paint/PaintSystem.cs index a0f5dc6145..a00b876c19 100644 --- a/Content.Server/Paint/PaintSystem.cs +++ b/Content.Server/Paint/PaintSystem.cs @@ -15,6 +15,8 @@ namespace Content.Server.Paint; +// TODO: This file does not exist upstream and should be namespaced + /// /// Colors target and consumes reagent on each color success. /// @@ -68,10 +70,12 @@ private void OnPaintVerb(EntityUid uid, PaintComponent component, GetVerbsEvent< }; args.Verbs.Add(verb); } - private void PrepPaint(EntityUid uid, PaintComponent component, EntityUid target, EntityUid user) + private void PrepPaint(EntityUid can, PaintComponent comp, EntityUid target, EntityUid user) { + if (!CanPaintEntity(new Entity(can, comp), target, user)) + return; - var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.Delay, new PaintDoAfterEvent(), uid, target: target, used: uid) + var doAfterEventArgs = new DoAfterArgs(EntityManager, user, comp.Delay, new PaintDoAfterEvent(), can, target: target, used: can) { BreakOnMove = true, NeedHand = true, @@ -81,6 +85,29 @@ private void PrepPaint(EntityUid uid, PaintComponent component, EntityUid target _doAfterSystem.TryStartDoAfter(doAfterEventArgs); } + private bool CanPaintEntity(Entity can, EntityUid target, EntityUid user) + { + if (!_openable.IsOpen(target)) + { + _popup.PopupEntity(Loc.GetString("paint-closed", ("used", can)), user, user, PopupType.Medium); + return false; + } + + if (HasComp(target) || HasComp(target)) + { + _popup.PopupEntity(Loc.GetString("paint-failure-painted", ("target", target)), user, user, PopupType.Medium); + return false; + } + + if (_whitelistSystem.IsWhitelistPass(can.Comp.Blacklist, target) || HasComp(target) || HasComp(target)) + { + _popup.PopupEntity(Loc.GetString("paint-failure", ("target", target)), user, user, PopupType.Medium); + return false; + } + + return true; + } + private void OnPaint(Entity entity, ref PaintDoAfterEvent args) { if (args.Target == null || args.Used == null) @@ -92,23 +119,8 @@ private void OnPaint(Entity entity, ref PaintDoAfterEvent args) if (args.Target is not { Valid: true } target) return; - if (!_openable.IsOpen(entity)) - { - _popup.PopupEntity(Loc.GetString("paint-closed", ("used", args.Used)), args.User, args.User, PopupType.Medium); - return; - } - - if (HasComp(target) || HasComp(target)) - { - _popup.PopupEntity(Loc.GetString("paint-failure-painted", ("target", args.Target)), args.User, args.User, PopupType.Medium); - return; - } - - if (_whitelistSystem.IsWhitelistFail(entity.Comp.Blacklist, target) || HasComp(target) || HasComp(target)) - { - _popup.PopupEntity(Loc.GetString("paint-failure", ("target", args.Target)), args.User, args.User, PopupType.Medium); + if (!CanPaintEntity(entity, args.Target.Value, args.User)) return; - } if (TryPaint(entity, target)) { @@ -128,7 +140,7 @@ private void OnPaint(Entity entity, ref PaintDoAfterEvent args) if (!_inventory.TryGetSlotEntity(target, slot.Name, out var slotEnt)) continue; - if (HasComp(slotEnt.Value) || _whitelistSystem.IsWhitelistFail(entity.Comp.Blacklist, slotEnt.Value) + if (HasComp(slotEnt.Value) || _whitelistSystem.IsWhitelistPass(entity.Comp.Blacklist, slotEnt.Value) || HasComp(slotEnt.Value) || HasComp( slotEnt.Value))