Files
crystall-punk-14/Content.Server/AirlockPainter/AirlockPainterSystem.cs

119 lines
4.8 KiB
C#
Raw Normal View History

2023-01-02 22:39:11 -06:00
using Content.Server.Administration.Logs;
2022-04-16 05:31:12 +00:00
using Content.Server.Popups;
using Content.Server.UserInterface;
using Content.Shared.AirlockPainter;
using Content.Shared.AirlockPainter.Prototypes;
using Content.Shared.DoAfter;
2023-01-02 22:39:11 -06:00
using Content.Shared.Database;
2022-04-16 05:31:12 +00:00
using Content.Shared.Doors.Components;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
namespace Content.Server.AirlockPainter
{
/// <summary>
/// A system for painting airlocks using airlock painter
/// </summary>
[UsedImplicitly]
public sealed class AirlockPainterSystem : SharedAirlockPainterSystem
{
2023-01-02 22:39:11 -06:00
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
2022-04-16 05:31:12 +00:00
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
2022-04-16 05:31:12 +00:00
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
2022-04-16 05:31:12 +00:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AirlockPainterComponent, AfterInteractEvent>(AfterInteractOn);
SubscribeLocalEvent<AirlockPainterComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<AirlockPainterComponent, AirlockPainterSpritePickedMessage>(OnSpritePicked);
SubscribeLocalEvent<AirlockPainterComponent, AirlockPainterDoAfterEvent>(OnDoAfter);
2022-04-16 05:31:12 +00:00
}
private void OnDoAfter(EntityUid uid, AirlockPainterComponent component, AirlockPainterDoAfterEvent args)
2022-04-16 05:31:12 +00:00
{
component.IsSpraying = false;
if (args.Handled || args.Cancelled)
return;
2023-01-02 22:39:11 -06:00
if (args.Args.Target != null)
{
_audio.PlayPvs(component.SpraySound, uid);
_appearance.SetData(args.Args.Target.Value, DoorVisuals.BaseRSI, args.Sprite);
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Args.User):user} painted {ToPrettyString(args.Args.Target.Value):target}");
2022-04-16 05:31:12 +00:00
}
args.Handled = true;
2022-04-16 05:31:12 +00:00
}
private void OnActivate(EntityUid uid, AirlockPainterComponent component, ActivateInWorldEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
DirtyUI(uid, component);
2023-07-08 09:02:17 -07:00
if (_userInterfaceSystem.TryGetUi(uid, AirlockPainterUiKey.Key, out var bui))
_userInterfaceSystem.OpenUi(bui, actor.PlayerSession);
2022-04-16 05:31:12 +00:00
args.Handled = true;
}
private void AfterInteractOn(EntityUid uid, AirlockPainterComponent component, AfterInteractEvent args)
{
if (component.IsSpraying || args.Target is not { Valid: true } target || !args.CanReach)
return;
if (!EntityManager.TryGetComponent<PaintableAirlockComponent>(target, out var airlock))
return;
if (!_prototypeManager.TryIndex<AirlockGroupPrototype>(airlock.Group, out var grp))
{
Log.Error("Group not defined: %s", airlock.Group);
2022-04-16 05:31:12 +00:00
return;
}
string style = Styles[component.Index];
if (!grp.StylePaths.TryGetValue(style, out var sprite))
{
string msg = Loc.GetString("airlock-painter-style-not-available");
_popupSystem.PopupEntity(msg, args.User, args.User);
2022-04-16 05:31:12 +00:00
return;
}
component.IsSpraying = true;
var doAfterEventArgs = new DoAfterArgs(args.User, component.SprayTime, new AirlockPainterDoAfterEvent(sprite), uid, target: target, used: uid)
2022-04-16 05:31:12 +00:00
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
2023-01-02 22:39:11 -06:00
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is painting {ToPrettyString(uid):target} to '{style}' at {Transform(uid).Coordinates:targetlocation}");
2022-04-16 05:31:12 +00:00
}
private void OnSpritePicked(EntityUid uid, AirlockPainterComponent component, AirlockPainterSpritePickedMessage args)
{
component.Index = args.Index;
DirtyUI(uid, component);
}
private void DirtyUI(EntityUid uid,
AirlockPainterComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_userInterfaceSystem.TrySetUiState(uid, AirlockPainterUiKey.Key,
new AirlockPainterBoundUserInterfaceState(component.Index));
}
}
}