-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
done: Починить эффект ослепления от EMP
- Loading branch information
Showing
14 changed files
with
416 additions
and
5 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
Content.Client/SimpleStation14/Overlays/Shaders/StaticOverlay.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,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); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Content.Client/SimpleStation14/Silicon/Systems/SeeingStaticSystem.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,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); | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
Content.Server/SimpleStation14/Power/Systems/BatteryElectrocuteChargeSystem.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,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); | ||
} | ||
} |
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
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" |
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,2 @@ | ||
- type: statusEffect | ||
id: SeeingStatic |
Oops, something went wrong.