* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using Content.Shared.Drunk;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client.Drunk;
|
|
|
|
public sealed class DrunkSystem : SharedDrunkSystem
|
|
{
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
|
|
|
private DrunkOverlay _overlay = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<DrunkComponent, ComponentInit>(OnDrunkInit);
|
|
SubscribeLocalEvent<DrunkComponent, ComponentShutdown>(OnDrunkShutdown);
|
|
|
|
SubscribeLocalEvent<DrunkComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<DrunkComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
_overlay = new();
|
|
}
|
|
|
|
private void OnPlayerAttached(EntityUid uid, DrunkComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void OnPlayerDetached(EntityUid uid, DrunkComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
_overlay.CurrentBoozePower = 0;
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
|
|
private void OnDrunkInit(EntityUid uid, DrunkComponent component, ComponentInit args)
|
|
{
|
|
if (_player.LocalEntity == uid)
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void OnDrunkShutdown(EntityUid uid, DrunkComponent component, ComponentShutdown args)
|
|
{
|
|
if (_player.LocalEntity == uid)
|
|
{
|
|
_overlay.CurrentBoozePower = 0;
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
}
|
|
}
|