Skip to content

Commit

Permalink
Fix a few issues with painting (cosmatic-drift-14#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
dffdff2423 committed Jul 31, 2024
1 parent 672b594 commit eb7f0ed
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions Content.Server/Paint/PaintSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace Content.Server.Paint;

// TODO: This file does not exist upstream and should be namespaced

/// <summary>
/// Colors target and consumes reagent on each color success.
/// </summary>
Expand Down Expand Up @@ -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<PaintComponent>(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,
Expand All @@ -81,6 +85,29 @@ private void PrepPaint(EntityUid uid, PaintComponent component, EntityUid target
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
}

private bool CanPaintEntity(Entity<PaintComponent> 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<PaintedComponent>(target) || HasComp<RandomSpriteComponent>(target))
{
_popup.PopupEntity(Loc.GetString("paint-failure-painted", ("target", target)), user, user, PopupType.Medium);
return false;
}

if (_whitelistSystem.IsWhitelistPass(can.Comp.Blacklist, target) || HasComp<HumanoidAppearanceComponent>(target) || HasComp<SubFloorHideComponent>(target))
{
_popup.PopupEntity(Loc.GetString("paint-failure", ("target", target)), user, user, PopupType.Medium);
return false;
}

return true;
}

private void OnPaint(Entity<PaintComponent> entity, ref PaintDoAfterEvent args)
{
if (args.Target == null || args.Used == null)
Expand All @@ -92,23 +119,8 @@ private void OnPaint(Entity<PaintComponent> 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<PaintedComponent>(target) || HasComp<RandomSpriteComponent>(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<HumanoidAppearanceComponent>(target) || HasComp<SubFloorHideComponent>(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))
{
Expand All @@ -128,7 +140,7 @@ private void OnPaint(Entity<PaintComponent> entity, ref PaintDoAfterEvent args)
if (!_inventory.TryGetSlotEntity(target, slot.Name, out var slotEnt))
continue;

if (HasComp<PaintedComponent>(slotEnt.Value) || _whitelistSystem.IsWhitelistFail(entity.Comp.Blacklist, slotEnt.Value)
if (HasComp<PaintedComponent>(slotEnt.Value) || _whitelistSystem.IsWhitelistPass(entity.Comp.Blacklist, slotEnt.Value)
|| HasComp<RandomSpriteComponent>(slotEnt.Value) ||
HasComp<HumanoidAppearanceComponent>(
slotEnt.Value))
Expand Down

0 comments on commit eb7f0ed

Please sign in to comment.