-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow AI and observers to see electrified doors (#33466)
- Loading branch information
1 parent
fcc908f
commit 736f70b
Showing
16 changed files
with
208 additions
and
37 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
Content.Client/Electrocution/ElectrocutionHUDVisualizerSystem.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,95 @@ | ||
using Content.Shared.Electrocution; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.Electrocution; | ||
|
||
/// <summary> | ||
/// Shows the Electrocution HUD to entities with the ShowElectrocutionHUDComponent. | ||
/// </summary> | ||
public sealed class ElectrocutionHUDVisualizerSystem : VisualizerSystem<ElectrocutionHUDVisualsComponent> | ||
{ | ||
[Dependency] private readonly IPlayerManager _playerMan = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<ShowElectrocutionHUDComponent, ComponentInit>(OnInit); | ||
SubscribeLocalEvent<ShowElectrocutionHUDComponent, ComponentShutdown>(OnShutdown); | ||
SubscribeLocalEvent<ShowElectrocutionHUDComponent, LocalPlayerAttachedEvent>(OnPlayerAttached); | ||
SubscribeLocalEvent<ShowElectrocutionHUDComponent, LocalPlayerDetachedEvent>(OnPlayerDetached); | ||
} | ||
|
||
private void OnPlayerAttached(Entity<ShowElectrocutionHUDComponent> ent, ref LocalPlayerAttachedEvent args) | ||
{ | ||
ShowHUD(); | ||
} | ||
|
||
private void OnPlayerDetached(Entity<ShowElectrocutionHUDComponent> ent, ref LocalPlayerDetachedEvent args) | ||
{ | ||
RemoveHUD(); | ||
} | ||
|
||
private void OnInit(Entity<ShowElectrocutionHUDComponent> ent, ref ComponentInit args) | ||
{ | ||
if (_playerMan.LocalEntity == ent) | ||
{ | ||
ShowHUD(); | ||
} | ||
} | ||
|
||
private void OnShutdown(Entity<ShowElectrocutionHUDComponent> ent, ref ComponentShutdown args) | ||
{ | ||
if (_playerMan.LocalEntity == ent) | ||
{ | ||
RemoveHUD(); | ||
} | ||
} | ||
|
||
// Show the HUD to the client. | ||
// We have to look for all current entities that can be electrified and toggle the HUD layer on if they are. | ||
private void ShowHUD() | ||
{ | ||
var electrifiedQuery = AllEntityQuery<ElectrocutionHUDVisualsComponent, AppearanceComponent, SpriteComponent>(); | ||
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) | ||
{ | ||
if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp)) | ||
continue; | ||
|
||
if (electrified) | ||
spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, true); | ||
else | ||
spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, false); | ||
} | ||
} | ||
|
||
// Remove the HUD from the client. | ||
// Find all current entities that can be electrified and hide the HUD layer. | ||
private void RemoveHUD() | ||
{ | ||
var electrifiedQuery = AllEntityQuery<ElectrocutionHUDVisualsComponent, AppearanceComponent, SpriteComponent>(); | ||
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) | ||
{ | ||
|
||
spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, false); | ||
} | ||
} | ||
|
||
// Toggle the HUD layer if an entity becomes (de-)electrified | ||
protected override void OnAppearanceChange(EntityUid uid, ElectrocutionHUDVisualsComponent comp, ref AppearanceChangeEvent args) | ||
{ | ||
if (args.Sprite == null) | ||
return; | ||
|
||
if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component)) | ||
return; | ||
|
||
var player = _playerMan.LocalEntity; | ||
if (electrified && HasComp<ShowElectrocutionHUDComponent>(player)) | ||
args.Sprite.LayerSetVisible(ElectrifiedLayers.HUD, true); | ||
else | ||
args.Sprite.LayerSetVisible(ElectrifiedLayers.HUD, false); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
Content.Shared/Electrocution/Components/ElectrocutionHUDVisualsComponent.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,7 @@ | ||
namespace Content.Shared.Electrocution; | ||
|
||
/// <summary> | ||
/// Handles toggling sprite layers for the electrocution HUD to show if an entity with the ElectrifiedComponent is electrified. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class ElectrocutionHUDVisualsComponent : Component; |
9 changes: 9 additions & 0 deletions
9
Content.Shared/Electrocution/Components/ShowElectrocutionHUDComponent.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,9 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Electrocution; | ||
|
||
/// <summary> | ||
/// Allow an entity to see the Electrocution HUD showing electrocuted doors. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class ShowElectrocutionHUDComponent : Component; |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.