Skip to content

Commit

Permalink
done: Починить эффект ослепления от EMP
Browse files Browse the repository at this point in the history
  • Loading branch information
modern-nm committed Dec 10, 2023
1 parent 3d0acf7 commit a001864
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 5 deletions.
92 changes: 92 additions & 0 deletions Content.Client/SimpleStation14/Overlays/Shaders/StaticOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Content.Shared.SimpleStation14.Silicon.Components;
using Content.Shared.SimpleStation14.Silicon.Systems;
using Content.Shared.StatusEffect;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Client.SimpleStation14.Overlays.Shaders;

public sealed class StaticOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
private readonly ShaderInstance _staticShader;

private (TimeSpan, TimeSpan)? _time;
private float? _fullTimeLeft;
private float? _curTimeLeft;

public float MixAmount = 0;

public StaticOverlay()
{
IoCManager.InjectDependencies(this);
_staticShader = _prototypeManager.Index<ShaderPrototype>("SeeingStatic").InstanceUnique();
}

protected override void FrameUpdate(FrameEventArgs args)
{
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;

if (playerEntity == null)
return;

if (!_entityManager.TryGetComponent<SeeingStaticComponent>(playerEntity, out var staticComp)
|| !_entityManager.TryGetComponent<StatusEffectsComponent>(playerEntity, out var statusComp))
return;

var status = _entityManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>();

if (playerEntity == null || statusComp == null)
return;

if (!status.TryGetTime(playerEntity.Value, SeeingStaticSystem.StaticKey, out var timeTemp, statusComp))
return;

if (_time != timeTemp) // Resets the shader if the times change. This should factor in wheather it's a reset, or a increase, but I have a lot of cough syrup in me, so TODO.
{
_time = timeTemp;
_fullTimeLeft = null;
_curTimeLeft = null;
}

_fullTimeLeft ??= (float) (timeTemp.Value.Item2 - timeTemp.Value.Item1).TotalSeconds;
_curTimeLeft ??= _fullTimeLeft;

_curTimeLeft -= args.DeltaSeconds;

MixAmount = Math.Clamp(_curTimeLeft.Value / _fullTimeLeft.Value * staticComp.Multiplier, 0, 1);
}

protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out EyeComponent? eyeComp))
return false;

if (args.Viewport.Eye != eyeComp.Eye)
return false;

return MixAmount > 0;
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;

var handle = args.WorldHandle;
_staticShader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_staticShader.SetParameter("mixAmount", MixAmount);
handle.UseShader(_staticShader);
handle.DrawRect(args.WorldBounds, Color.White);
handle.UseShader(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Content.Client.SimpleStation14.Overlays.Shaders;
using Content.Shared.SimpleStation14.Silicon.Components;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client.SimpleStation14.Silicon.Systems;

/// <summary>
/// System to handle the SeeingStatic overlay.
/// </summary>
public sealed class SeeingStaticSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;

private StaticOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SeeingStaticComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SeeingStaticComponent, ComponentShutdown>(OnShutdown);

SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);

_overlay = new();
}

private void OnPlayerAttached(EntityUid uid, SeeingStaticComponent component, LocalPlayerAttachedEvent args)
{
_overlayMan.AddOverlay(_overlay);
}

private void OnPlayerDetached(EntityUid uid, SeeingStaticComponent component, LocalPlayerDetachedEvent args)
{
_overlay.MixAmount = 0;
_overlayMan.RemoveOverlay(_overlay);
}

private void OnInit(EntityUid uid, SeeingStaticComponent component, ComponentInit args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
_overlayMan.AddOverlay(_overlay);
}

private void OnShutdown(EntityUid uid, SeeingStaticComponent component, ComponentShutdown args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
{
_overlay.MixAmount = 0;
_overlayMan.RemoveOverlay(_overlay);
}
}
}
3 changes: 2 additions & 1 deletion Content.Server/Bed/BedSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Content.Shared.Emag.Systems;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Timing;
using Content.Shared.SimpleStation14.Silicon.Components; // Parkstation-IPCs // I shouldn't have to modify this.

namespace Content.Server.Bed
{
Expand Down Expand Up @@ -70,7 +71,7 @@ public override void Update(float frameTime)

foreach (var healedEntity in strapComponent.BuckledEntities)
{
if (_mobStateSystem.IsDead(healedEntity))
if (_mobStateSystem.IsDead(healedEntity) || HasComp<SiliconComponent>(healedEntity)) // Parkstation-IPCs // I shouldn't have to modify this.
continue;

var damage = bedComponent.Damage;
Expand Down
5 changes: 3 additions & 2 deletions Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
private const string DamageType = "Shock";

// Yes, this is absurdly small for a reason.
public const float ElectrifiedDamagePerWatt = 0.0015f; // Parkstation-IPC // This information is allowed to be public, and was needed in BatteryElectrocuteChargeSystem.cs
private const float ElectrifiedScalePerWatt = 1E-6f;

private const float RecursiveDamageMultiplier = 0.75f;
Expand Down Expand Up @@ -312,7 +313,7 @@ public override bool TryDoElectrocution(
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
return false;

RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient, shockDamage), true); // Parkstation-IPC
return true;
}

Expand Down Expand Up @@ -362,7 +363,7 @@ private bool TryDoElectrocutionPowered(
electrocutionComponent.Electrocuting = uid;
electrocutionComponent.Source = sourceUid;

RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient, shockDamage), true); // Parkstation-IPC

return true;
}
Expand Down
19 changes: 18 additions & 1 deletion Content.Server/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,28 @@ public override void Initialize()
/// <param name="duration">The duration of the EMP effects.</param>
public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption, float duration)
{
/*
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
TryEmpEffects(uid, energyConsumption, duration);
}
Spawn(EmpPulseEffectPrototype, coordinates);
*/
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
var ev = new EmpPulseEvent(energyConsumption, false, false, TimeSpan.FromSeconds(duration)); // Parkstation-IPCs
RaiseLocalEvent(uid, ref ev);
if (ev.Affected)
{
Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates);
}
if (ev.Disabled)
{
var disabled = EnsureComp<EmpDisabledComponent>(uid);
disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration);
}
}
Spawn(EmpPulseEffectPrototype, coordinates);
}

/// <summary>
Expand Down Expand Up @@ -142,7 +159,7 @@ public sealed partial class EmpAttemptEvent : CancellableEntityEventArgs
}

[ByRefEvent]
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled, TimeSpan Duration);
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled, TimeSpan Duration); // Parkstation-IPCs

[ByRefEvent]
public record struct EmpDisabledRemoved();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Content.Server.Electrocution;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Electrocution;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.SimpleStation14.Power.Systems;

public sealed class BatteryElectrocuteChargeSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly BatterySystem _battery = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BatteryComponent, ElectrocutedEvent>(OnElectrocuted);
}

private void OnElectrocuted(EntityUid uid, BatteryComponent battery, ElectrocutedEvent args)
{
if (args.ShockDamage == null || args.ShockDamage <= 0)
return;

var damagePerWatt = ElectrocutionSystem.ElectrifiedDamagePerWatt * 2;

var damage = args.ShockDamage.Value * args.SiemensCoefficient;
var charge = Math.Min(damage / damagePerWatt, battery.MaxCharge * 0.25f) * _random.NextFloat(0.75f, 1.25f);

_battery.SetCharge(uid, battery.CurrentCharge + charge);

_popup.PopupEntity(Loc.GetString("battery-electrocute-charge"), uid, uid);
}
}
4 changes: 3 additions & 1 deletion Content.Shared/Electrocution/ElectrocutionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public sealed class ElectrocutedEvent : EntityEventArgs
public readonly EntityUid TargetUid;
public readonly EntityUid? SourceUid;
public readonly float SiemensCoefficient;
public readonly float? ShockDamage = null; // Parkstation-IPC

public ElectrocutedEvent(EntityUid targetUid, EntityUid? sourceUid, float siemensCoefficient)
public ElectrocutedEvent(EntityUid targetUid, EntityUid? sourceUid, float siemensCoefficient, float shockDamage) // Parkstation-IPC
{
TargetUid = targetUid;
SourceUid = sourceUid;
SiemensCoefficient = siemensCoefficient;
ShockDamage = shockDamage; // Parkstation-IPC
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
- type: Battery
maxCharge: 150000
startingCharge: 150000
#- type: RandomBatteryCharge
# batteryMaxMinMax: 0.85, 1.15
# batteryChargeMinMax: 0.40, 0.90
- type: Silicon
entityType: enum.SiliconType.Player
batteryPowered: true
Expand All @@ -58,6 +61,7 @@
2: 0.80
1: 0.45
0: 0.00
#- type: Carriable
- type: BatteryDrinker
- type: EncryptionKeyHolder
keySlots: 3
Expand All @@ -69,6 +73,7 @@
- type: Wires
boardName: "IPC"
layoutId: IPC
#- type: CharacterInformation
- type: SSDIndicator

- type: entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
- type: Clickable
- type: Damageable
damageContainer: Inorganic # Note that for dumb reasons, this essentially makes them a wall.
- type: PassiveDamage # Slight passive regen. Костыль.
allowedStates:
- Critical
damageCap: 20
damage:
groups:
Brute: 0.01
# - type: Bloodstream # This is left commented out because it's not necessary for a robot, but you may want it.
# bloodReagent: MotorOil
# bloodlossDamage:
Expand Down Expand Up @@ -171,6 +178,7 @@
- map: ["pocket1"]
- map: ["pocket2"]
- map: ["enum.HumanoidVisualLayers.Tail"]
#- map: ["enum.HumanoidVisualLayers.Wings"]
- map: ["clownedon"] # Dynamically generated
sprite: "Effects/creampie.rsi"
state: "creampie_human"
Expand Down
14 changes: 14 additions & 0 deletions Resources/Prototypes/SimpleStation14/Shaders/shaders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- type: shader
id: ColorTint
kind: source
path: "/Textures/SimpleStation14/Shaders/color_tint.swsl"

- type: shader
id: Ethereal
kind: source
path: "/Textures/SimpleStation14/Shaders/ethereal.swsl"

- type: shader
id: SeeingStatic
kind: source
path: "/Textures/SimpleStation14/Shaders/seeing_static.swsl"
2 changes: 2 additions & 0 deletions Resources/Prototypes/SimpleStation14/status_effects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- type: statusEffect
id: SeeingStatic
Loading

0 comments on commit a001864

Please sign in to comment.