-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syndicate and CentComm Radio Implanters (#33533)
* Add Syndicate Radio Implant * Fix description grammar * remove unused var * Update - Small fixes * Un mess with imports * Remove unused tag * Correction * Clear lists instead of remove * Update 0 check * Add Centcomm implant * Correct centcom channel * Correct params * No more crying * Update Content.Shared/Implants/Components/RadioImplantComponent.cs * Update Content.Server/Implants/RadioImplantSystem.cs * Update Content.Server/Implants/RadioImplantSystem.cs --------- Co-authored-by: slarticodefast <[email protected]>
- Loading branch information
1 parent
e938512
commit 84328ee
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Content.Server.Radio.Components; | ||
using Content.Shared.Implants; | ||
using Content.Shared.Implants.Components; | ||
using Robust.Shared.Containers; | ||
|
||
namespace Content.Server.Implants; | ||
|
||
public sealed class RadioImplantSystem : EntitySystem | ||
{ | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RadioImplantComponent, ImplantImplantedEvent>(OnImplantImplanted); | ||
SubscribeLocalEvent<RadioImplantComponent, EntGotRemovedFromContainerMessage>(OnRemove); | ||
} | ||
|
||
/// <summary> | ||
/// If implanted with a radio implant, installs the necessary intrinsic radio components | ||
/// </summary> | ||
private void OnImplantImplanted(Entity<RadioImplantComponent> ent, ref ImplantImplantedEvent args) | ||
{ | ||
if (args.Implanted == null) | ||
return; | ||
|
||
var activeRadio = EnsureComp<ActiveRadioComponent>(args.Implanted.Value); | ||
foreach (var channel in ent.Comp.RadioChannels) | ||
{ | ||
if (activeRadio.Channels.Add(channel)) | ||
ent.Comp.ActiveAddedChannels.Add(channel); | ||
} | ||
|
||
EnsureComp<IntrinsicRadioReceiverComponent>(args.Implanted.Value); | ||
|
||
var intrinsicRadioTransmitter = EnsureComp<IntrinsicRadioTransmitterComponent>(args.Implanted.Value); | ||
foreach (var channel in ent.Comp.RadioChannels) | ||
{ | ||
if (intrinsicRadioTransmitter.Channels.Add(channel)) | ||
ent.Comp.TransmitterAddedChannels.Add(channel); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Removes intrinsic radio components once the Radio Implant is removed | ||
/// </summary> | ||
private void OnRemove(Entity<RadioImplantComponent> ent, ref EntGotRemovedFromContainerMessage args) | ||
{ | ||
if (TryComp<ActiveRadioComponent>(args.Container.Owner, out var activeRadioComponent)) | ||
{ | ||
foreach (var channel in ent.Comp.ActiveAddedChannels) | ||
{ | ||
activeRadioComponent.Channels.Remove(channel); | ||
} | ||
ent.Comp.ActiveAddedChannels.Clear(); | ||
|
||
if (activeRadioComponent.Channels.Count == 0) | ||
{ | ||
RemCompDeferred<ActiveRadioComponent>(args.Container.Owner); | ||
} | ||
} | ||
|
||
if (!TryComp<IntrinsicRadioTransmitterComponent>(args.Container.Owner, out var radioTransmitterComponent)) | ||
return; | ||
|
||
foreach (var channel in ent.Comp.TransmitterAddedChannels) | ||
{ | ||
radioTransmitterComponent.Channels.Remove(channel); | ||
} | ||
ent.Comp.TransmitterAddedChannels.Clear(); | ||
|
||
if (radioTransmitterComponent.Channels.Count == 0 || activeRadioComponent?.Channels.Count == 0) | ||
{ | ||
RemCompDeferred<IntrinsicRadioTransmitterComponent>(args.Container.Owner); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Content.Shared/Implants/Components/RadioImplantComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Content.Shared.Radio; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared.Implants.Components; | ||
|
||
/// <summary> | ||
/// Gives the user access to a given channel without the need for a headset. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class RadioImplantComponent : Component | ||
{ | ||
/// <summary> | ||
/// The radio channel(s) to grant access to. | ||
/// </summary> | ||
[DataField(required: true)] | ||
public HashSet<ProtoId<RadioChannelPrototype>> RadioChannels = new(); | ||
|
||
/// <summary> | ||
/// The radio channels that have been added by the implant to a user's ActiveRadioComponent. | ||
/// Used to track which channels were successfully added (not already in user) | ||
/// </summary> | ||
/// <remarks> | ||
/// Should not be modified outside RadioImplantSystem.cs | ||
/// </remarks> | ||
[DataField] | ||
public HashSet<ProtoId<RadioChannelPrototype>> ActiveAddedChannels = new(); | ||
|
||
/// <summary> | ||
/// The radio channels that have been added by the implant to a user's IntrinsicRadioTransmitterComponent. | ||
/// Used to track which channels were successfully added (not already in user) | ||
/// </summary> | ||
/// <remarks> | ||
/// Should not be modified outside RadioImplantSystem.cs | ||
/// </remarks> | ||
[DataField] | ||
public HashSet<ProtoId<RadioChannelPrototype>> TransmitterAddedChannels = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters