Desk bells can be rung with activate (#24047)

* Desk bells can be rung with activate

Important

* Remove obsoletions too while I'm at it.
This commit is contained in:
Pieter-Jan Briers
2024-01-14 02:43:59 +01:00
committed by GitHub
parent 055d62f560
commit f191c90999
3 changed files with 36 additions and 9 deletions

View File

@@ -20,16 +20,36 @@ public sealed class InteractionPopupSystem : EntitySystem
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InteractionPopupComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<InteractionPopupComponent, ActivateInWorldEvent>(OnActivateInWorld);
}
private void OnActivateInWorld(EntityUid uid, InteractionPopupComponent component, ActivateInWorldEvent args)
{
if (!component.OnActivate)
return;
SharedInteract(uid, component, args, args.Target, args.User);
}
private void OnInteractHand(EntityUid uid, InteractionPopupComponent component, InteractHandEvent args)
{
if (args.Handled || args.User == args.Target)
SharedInteract(uid, component, args, args.Target, args.User);
}
private void SharedInteract(
EntityUid uid,
InteractionPopupComponent component,
HandledEntityEventArgs args,
EntityUid target,
EntityUid user)
{
if (args.Handled || user == target)
return;
//Handling does nothing and this thing annoyingly plays way too often.
@@ -64,7 +84,7 @@ public sealed class InteractionPopupSystem : EntitySystem
sfx = component.InteractSuccessSound;
if (component.InteractSuccessSpawn != null)
Spawn(component.InteractSuccessSpawn, Transform(uid).MapPosition);
Spawn(component.InteractSuccessSpawn, _transform.GetMapCoordinates(uid));
}
else
{
@@ -75,25 +95,25 @@ public sealed class InteractionPopupSystem : EntitySystem
sfx = component.InteractFailureSound;
if (component.InteractFailureSpawn != null)
Spawn(component.InteractFailureSpawn, Transform(uid).MapPosition);
Spawn(component.InteractFailureSpawn, _transform.GetMapCoordinates(uid));
}
if (component.MessagePerceivedByOthers != null)
{
var msgOthers = Loc.GetString(component.MessagePerceivedByOthers,
("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
_popupSystem.PopupEntity(msg, uid, args.User);
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(args.User, entityManager: EntityManager), true);
("user", Identity.Entity(user, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
_popupSystem.PopupEntity(msg, uid, user);
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
}
else
_popupSystem.PopupEntity(msg, uid, args.User); //play only for the initiating entity.
_popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
if (sfx is not null) //not all cases will have sound.
{
if (component.SoundPerceivedByOthers)
_audio.PlayPvs(sfx, args.Target); //play for everyone in range
_audio.PlayPvs(sfx, target); //play for everyone in range
else
_audio.PlayEntity(sfx, Filter.Entities(args.User, args.Target), args.Target, true); //play only for the initiating entity and its target.
_audio.PlayEntity(sfx, Filter.Entities(user, target), target, true); //play only for the initiating entity and its target.
}
component.LastInteractTime = curTime;