Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into plasmaman
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofallars committed Jan 19, 2025
2 parents 6b11853 + 09b5c3e commit ad8125c
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 174 deletions.
94 changes: 94 additions & 0 deletions Content.Client/Electrocution/ElectrocutionHUDVisualizerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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);
}
}
101 changes: 0 additions & 101 deletions Content.Client/Electrocution/ElectrocutionOverlaySystem.cs

This file was deleted.

15 changes: 8 additions & 7 deletions Content.IntegrationTests/Tests/Commands/SuicideCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,14 @@ await server.WaitAssertion(() =>
consoleHost.GetSessionShell(playerMan.Sessions.First()).ExecuteCommand("suicide");
var lethalDamageThreshold = mobThresholdsComp.Thresholds.Keys.Last();

Assert.Multiple(() =>
{
Assert.That(mobStateSystem.IsDead(player, mobStateComp));
Assert.That(entManager.TryGetComponent<GhostComponent>(mindComponent.CurrentEntity, out var ghostComp) &&
!ghostComp.CanReturnToBody);
Assert.That(damageableComp.Damage.DamageDict["Slash"], Is.EqualTo(lethalDamageThreshold / 2));
});
if (damageableComp.DamageContainerID is not "Silicon")
Assert.Multiple(() =>
{
Assert.That(mobStateSystem.IsDead(player, mobStateComp));
Assert.That(entManager.TryGetComponent<GhostComponent>(mindComponent.CurrentEntity, out var ghostComp) &&
!ghostComp.CanReturnToBody);
Assert.That(damageableComp.Damage.DamageDict["Slash"], Is.EqualTo(lethalDamageThreshold / 2));
});
});

await pair.CleanReturnAsync();
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Chat/SuicideSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void OnDamageableSuicide(Entity<DamageableComponent> victim, ref Suicide
return;
}

args.DamageType ??= "Blunt";
args.DamageType ??= "Slash";
_suicide.ApplyLethalDamage(victim, args.DamageType);
args.Handled = true;
}
Expand Down
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;
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;
2 changes: 1 addition & 1 deletion Content.Shared/Electrocution/SharedElectrocution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Content.Shared.Electrocution;
public enum ElectrifiedLayers : byte
{
Sparks,
Overlay,
HUD,
}

[Serializable, NetSerializable]
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/random-barks/hissing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bark-hissing-1 = Hsssss
bark-hissing-2 = Hssssssss
bark-hissing-3 = I sssee you
bark-hissing-4 = I will catch you
bark-hissing-5 = Meat...
bark-hissing-6 = I'm hhhungry!
bark-hissing-7 = Ssseek... food...
bark-hissing-8 = Hsss... Get there
Expand Down
4 changes: 2 additions & 2 deletions Resources/Prototypes/DeltaV/Catalog/Shipyard/civilian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
id: Helix
name: NTMC Helix
description: A large mobile health clinic for servicing distant outposts.
price: 46000
price: 47000
path: /Maps/Shuttles/DeltaV/helix.yml
categories:
- Civilian
Expand All @@ -36,7 +36,7 @@
id: Prospector
name: NT-7 Prospector
description: A small mining vessel designed to assist salvage operations.
price: 21000
price: 22000
path: /Maps/Shuttles/DeltaV/prospector.yml
categories:
- Civilian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@
prototypes:
- RandomWoodenWall
- RandomWoodenSupport
chance: 0.9
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Mobs/Player/observer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
skipChecks: true
- type: Ghost
- type: GhostHearing
- type: ElectrocutionOverlay
- type: ShowElectrocutionHUD
- type: IntrinsicRadioReceiver
- type: ActiveRadio
receiveAllChannels: true
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Mobs/Player/silicon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- type: IgnoreUIRange
- type: StationAiHeld
- type: StationAiOverlay
- type: ElectrocutionOverlay
- type: ShowElectrocutionHUD
- type: ActionGrant
actions:
- ActionJumpToCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
sprite: Interface/Misc/ai_hud.rsi
shader: unshaded
visible: false
map: ["enum.ElectrifiedLayers.Overlay"]
map: ["enum.ElectrifiedLayers.HUD"]
- type: AnimationPlayer
- type: Physics
- type: Fixtures
Expand Down Expand Up @@ -77,6 +77,7 @@
- type: DoorBolt
- type: Appearance
- type: WiresVisuals
- type: ElectrocutionHUDVisuals
- type: ApcPowerReceiver
powerLoad: 20
- type: ExtensionCableReceiver
Expand Down
Loading

0 comments on commit ad8125c

Please sign in to comment.