Skip to content

Commit

Permalink
Add Silicon Law cues to Every method a Silicon can have their laws ch…
Browse files Browse the repository at this point in the history
…ange (space-wizards#32887)

* Silicon Law Sound cue refactor

- Added CueEntityMind to Silicon Law system to more uniformally
send sounds to minds

- Switch all previous MindPlaySound to instead call to the new method

* Change SiliconLawEui to cue the mind

* CR: TryGetComponent and Change the Documentation

- Remove GetComponentOrNull for  _entityManager.TryGetComponent

- Change SiliconLawProviderComponent.LawUploadSound to be more general
rather than just referencing lawboards

* Update Content.Server/Silicons/Laws/SiliconLawEui.cs

* Update Content.Shared/Silicons/Laws/Components/SiliconLawProviderComponent.cs

* Silicon-law-cue-refactor - CR:

- Roll the cuing into NotifyLawsChanged via an optional variable for the
cue

- Modify "SetLaws" to take in an optional soundProvider for the cue

- modify Emagged, Ion, Eui and SetLaws to instead send the sound cue via
NotifyLawsChanged

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
  • Loading branch information
poklj and slarticodefast authored Nov 4, 2024
1 parent 4ba8e35 commit a3f10cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Content.Server/Silicons/Laws/SiliconLawEui.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Administration.Managers;
using Content.Server.Administration.Managers;
using Content.Server.EUI;
using Content.Shared.Administration;
using Content.Shared.Eui;
Expand Down Expand Up @@ -52,8 +52,8 @@ public override void HandleMessage(EuiMessageBase msg)
return;

var player = _entityManager.GetEntity(message.Target);

_siliconLawSystem.SetLaws(message.Laws, player);
if (_entityManager.TryGetComponent<SiliconLawProviderComponent>(player, out var playerProviderComp))
_siliconLawSystem.SetLaws(message.Laws, player, playerProviderComp.LawUploadSound);
}

private bool IsAllowed()
Expand Down
22 changes: 11 additions & 11 deletions Content.Server/Silicons/Laws/SiliconLawSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Toolshed;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;

namespace Content.Server.Silicons.Laws;

Expand Down Expand Up @@ -113,7 +115,7 @@ private void OnIonStormLaws(EntityUid uid, SiliconLawProviderComponent component
component.Lawset = args.Lawset;

// gotta tell player to check their laws
NotifyLawsChanged(uid);
NotifyLawsChanged(uid, component.LawUploadSound);

// new laws may allow antagonist behaviour so make it clear for admins
if (TryComp<EmagSiliconLawComponent>(uid, out var emag))
Expand Down Expand Up @@ -149,14 +151,11 @@ protected override void OnGotEmagged(EntityUid uid, EmagSiliconLawComponent comp
return;

base.OnGotEmagged(uid, component, ref args);
NotifyLawsChanged(uid);
NotifyLawsChanged(uid, component.EmaggedSound);
EnsureEmaggedRole(uid, component);

_stunSystem.TryParalyze(uid, component.StunTime, true);

if (!_mind.TryGetMind(uid, out var mindId, out _))
return;
_roles.MindPlaySound(mindId, component.EmaggedSound);
}

private void OnEmagMindAdded(EntityUid uid, EmagSiliconLawComponent component, MindAddedMessage args)
Expand Down Expand Up @@ -237,14 +236,17 @@ public SiliconLawset GetLaws(EntityUid uid, SiliconLawBoundComponent? component
return ev.Laws;
}

public void NotifyLawsChanged(EntityUid uid)
public void NotifyLawsChanged(EntityUid uid, SoundSpecifier? cue = null)
{
if (!TryComp<ActorComponent>(uid, out var actor))
return;

var msg = Loc.GetString("laws-update-notify");
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", msg));
_chatManager.ChatMessageToOne(ChatChannel.Server, msg, wrappedMessage, default, false, actor.PlayerSession.Channel, colorOverride: Color.Red);

if (cue != null && _mind.TryGetMind(uid, out var mindId, out _))
_roles.MindPlaySound(mindId, cue);
}

/// <summary>
Expand All @@ -269,7 +271,7 @@ public SiliconLawset GetLawset(ProtoId<SiliconLawsetPrototype> lawset)
/// <summary>
/// Set the laws of a silicon entity while notifying the player.
/// </summary>
public void SetLaws(List<SiliconLaw> newLaws, EntityUid target)
public void SetLaws(List<SiliconLaw> newLaws, EntityUid target, SoundSpecifier? cue = null)
{
if (!TryComp<SiliconLawProviderComponent>(target, out var component))
return;
Expand All @@ -278,7 +280,7 @@ public void SetLaws(List<SiliconLaw> newLaws, EntityUid target)
component.Lawset = new SiliconLawset();

component.Lawset.Laws = newLaws;
NotifyLawsChanged(target);
NotifyLawsChanged(target, cue);
}

protected override void OnUpdaterInsert(Entity<SiliconLawUpdaterComponent> ent, ref EntInsertedIntoContainerMessage args)
Expand All @@ -292,9 +294,7 @@ protected override void OnUpdaterInsert(Entity<SiliconLawUpdaterComponent> ent,

while (query.MoveNext(out var update))
{
SetLaws(lawset, update);
if (provider.LawUploadSound != null && _mind.TryGetMind(update, out var mindId, out _))
_roles.MindPlaySound(mindId, provider.LawUploadSound);
SetLaws(lawset, update, provider.LawUploadSound);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class SiliconLawProviderComponent : Component

/// <summary>
/// The sound that plays for the Silicon player
/// when the particular lawboard has been inserted.
/// when the law change is processed for the provider.
/// </summary>
[DataField]
public SoundSpecifier? LawUploadSound = new SoundPathSpecifier("/Audio/Misc/cryo_warning.ogg");
Expand Down

0 comments on commit a3f10cc

Please sign in to comment.