refactor toilet (#15406)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-04-14 08:45:58 +00:00
committed by GitHub
parent ab215d401f
commit ffe946729f
4 changed files with 26 additions and 29 deletions

View File

@@ -25,11 +25,11 @@ namespace Content.Server.Toilet
{ {
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly BodySystem _bodySystem = default!; [Dependency] private readonly BodySystem _body = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SecretStashSystem _secretStash = default!; [Dependency] private readonly SecretStashSystem _secretStash = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!; [Dependency] private readonly SharedToolSystem _tool = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -49,16 +49,17 @@ namespace Content.Server.Toilet
return; return;
// Check that victim has a head // Check that victim has a head
if (EntityManager.TryGetComponent<BodyComponent>(args.Victim, out var body) && // FIXME: since suiciding turns you into a ghost immediately, both messages are seen, not sure how this can be fixed
_bodySystem.BodyHasChildOfType(args.Victim, BodyPartType.Head, body)) if (TryComp<BodyComponent>(args.Victim, out var body) &&
_body.BodyHasChildOfType(args.Victim, BodyPartType.Head, body))
{ {
var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others", var othersMessage = Loc.GetString("toilet-component-suicide-head-message-others",
("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid)); ("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid));
_popupSystem.PopupEntity(othersMessage, uid, Filter.PvsExcept(args.Victim), true, PopupType.MediumCaution); _popup.PopupEntity(othersMessage, uid, Filter.PvsExcept(args.Victim), true, PopupType.MediumCaution);
var selfMessage = Loc.GetString("toilet-component-suicide-head-message", var selfMessage = Loc.GetString("toilet-component-suicide-head-message",
("owner", uid)); ("owner", uid));
_popupSystem.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution); _popup.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution);
args.SetHandled(SuicideKind.Asphyxiation); args.SetHandled(SuicideKind.Asphyxiation);
} }
@@ -66,11 +67,11 @@ namespace Content.Server.Toilet
{ {
var othersMessage = Loc.GetString("toilet-component-suicide-message-others", var othersMessage = Loc.GetString("toilet-component-suicide-message-others",
("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid)); ("victim", Identity.Entity(args.Victim, EntityManager)), ("owner", uid));
_popupSystem.PopupEntity(othersMessage, uid, Filter.PvsExcept(uid), true, PopupType.MediumCaution); _popup.PopupEntity(othersMessage, uid, Filter.PvsExcept(uid), true, PopupType.MediumCaution);
var selfMessage = Loc.GetString("toilet-component-suicide-message", var selfMessage = Loc.GetString("toilet-component-suicide-message",
("owner", uid)); ("owner", uid));
_popupSystem.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution); _popup.PopupEntity(selfMessage, uid, args.Victim, PopupType.LargeCaution);
args.SetHandled(SuicideKind.Blunt); args.SetHandled(SuicideKind.Blunt);
} }
@@ -78,7 +79,7 @@ namespace Content.Server.Toilet
private void OnInit(EntityUid uid, ToiletComponent component, ComponentInit args) private void OnInit(EntityUid uid, ToiletComponent component, ComponentInit args)
{ {
EntityManager.EnsureComponent<SecretStashComponent>(uid); EnsureComp<SecretStashComponent>(uid);
} }
private void OnMapInit(EntityUid uid, ToiletComponent component, MapInitEvent args) private void OnMapInit(EntityUid uid, ToiletComponent component, MapInitEvent args)
@@ -94,7 +95,7 @@ namespace Content.Server.Toilet
return; return;
// are player trying place or lift of cistern lid? // are player trying place or lift of cistern lid?
if (_toolSystem.UseTool(args.Used, args.User, uid, component.PryLidTime, component.PryingQuality, new ToiletPryDoAfterEvent())) if (_tool.UseTool(args.Used, args.User, uid, component.PryLidTime, component.PryingQuality, new ToiletPryDoAfterEvent()))
{ {
args.Handled = true; args.Handled = true;
} }
@@ -124,11 +125,8 @@ namespace Content.Server.Toilet
// just want to up/down seat? // just want to up/down seat?
// check that nobody seats on seat right now // check that nobody seats on seat right now
if (EntityManager.TryGetComponent(uid, out StrapComponent? strap)) if (TryComp<StrapComponent>(uid, out var strap) && strap.BuckledEntities.Count != 0)
{ return;
if (strap.BuckledEntities.Count != 0)
return;
}
ToggleToiletSeat(uid, component); ToggleToiletSeat(uid, component);
args.Handled = true; args.Handled = true;
@@ -167,7 +165,7 @@ namespace Content.Server.Toilet
private void UpdateSprite(EntityUid uid, ToiletComponent component) private void UpdateSprite(EntityUid uid, ToiletComponent component)
{ {
if (!EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) if (!TryComp<AppearanceComponent>(uid, out var appearance))
return; return;
_appearance.SetData(uid, ToiletVisuals.LidOpen, component.LidOpen, appearance); _appearance.SetData(uid, ToiletVisuals.LidOpen, component.LidOpen, appearance);

View File

@@ -1,11 +0,0 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Toilet
{
[Serializable, NetSerializable]
public enum ToiletVisuals
{
LidOpen,
SeatUp
}
}

View File

@@ -0,0 +1,10 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Toilet;
[Serializable, NetSerializable]
public enum ToiletVisuals
{
LidOpen,
SeatUp
}

View File

@@ -1,6 +1,6 @@
## ToiletComponent ## ToiletComponent
toilet-component-on-examine-found-hidden-item = There is [color=darkgreen]something[/color] inside cistern! toilet-component-on-examine-found-hidden-item = There is something inside of the cistern!
toilet-component-suicide-head-message-others = {CAPITALIZE(THE($victim))} sticks their head into {THE($owner)} and flushes it! toilet-component-suicide-head-message-others = {CAPITALIZE(THE($victim))} sticks their head into {THE($owner)} and flushes it!
toilet-component-suicide-head-message = You stick your head into {THE($owner)} and flush it! toilet-component-suicide-head-message = You stick your head into {THE($owner)} and flush it!
toilet-component-suicide-message-others = {CAPITALIZE(THE($victim))} bashes themselves with {THE($owner)}! toilet-component-suicide-message-others = {CAPITALIZE(THE($victim))} bashes themselves with {THE($owner)}!