forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: РИТЭГ теперь периодически теряет свой запас радиации
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
Content.Server/SS220/RadiationDecrease/RadiationDecreaseSystem.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,77 @@ | ||
using Content.Server.Power.Components; | ||
using Content.Shared.Radiation.Components; | ||
using Content.Shared.SS220.RadiationDecrease; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Server.SS220.RadiationDecrease; | ||
|
||
public sealed partial class RadiationDecreaseSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IGameTiming _gameTiming = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<RadiationDecreaseComponent, ComponentInit>(OnCompInit); | ||
} | ||
|
||
private void OnCompInit(EntityUid uid, RadiationDecreaseComponent comp, ComponentInit args) | ||
{ | ||
if (TryComp<RadiationSourceComponent>(uid, out var radSourceComponent) && radSourceComponent.Intensity != 0) | ||
{ | ||
comp.Intensity = radSourceComponent.Intensity; | ||
} | ||
if (TryComp<PowerSupplierComponent>(uid, out var supplyComp) && supplyComp.MaxSupply != 0) | ||
{ | ||
comp.Supply = supplyComp.MaxSupply; | ||
} | ||
} | ||
|
||
public override void Update(float delta) | ||
{ | ||
base.Update(delta); | ||
var query = EntityQueryEnumerator<RadiationDecreaseComponent>(); | ||
while (query.MoveNext(out var uid, out var comp)) | ||
{ | ||
if (TryComp<RadiationSourceComponent>(uid, out var radSourceComponent) && radSourceComponent.Intensity != 0) | ||
{ | ||
var decreasePerSecond = comp.Intensity / comp.TotalAliveTime; | ||
|
||
var curTime = _gameTiming.CurTime; | ||
|
||
if (curTime - comp.LastTimeDecreaseRad < comp.CoolDown) | ||
{ | ||
return; | ||
} | ||
|
||
comp.LastTimeDecreaseRad = curTime; | ||
if (radSourceComponent.Intensity - decreasePerSecond < 0) // without if - crash Pow3r | ||
{ | ||
radSourceComponent.Intensity = 0; | ||
decreasePerSecond = 0; | ||
} | ||
radSourceComponent.Intensity -= decreasePerSecond; | ||
} | ||
|
||
if (TryComp<PowerSupplierComponent>(uid, out var powerSupply) && powerSupply.MaxSupply != 0) | ||
{ | ||
var decreasePerSecond = comp.Supply / comp.TotalAliveTime; | ||
|
||
var curTime = _gameTiming.CurTime; | ||
|
||
if (curTime - comp.LastTimeDecreaseSupply < comp.CoolDown) | ||
{ | ||
return; | ||
} | ||
|
||
comp.LastTimeDecreaseSupply = curTime; | ||
if (powerSupply.MaxSupply - decreasePerSecond < 0) // without if - crash Pow3r | ||
{ | ||
powerSupply.MaxSupply = 0; | ||
decreasePerSecond = 0; | ||
} | ||
powerSupply.MaxSupply -= decreasePerSecond; | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Content.Shared/SS220/RadiationDecrease/RadiationDecreaseComponent.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,19 @@ | ||
namespace Content.Shared.SS220.RadiationDecrease; | ||
|
||
/// <summary> | ||
/// Decrease radiation per second in Damaged RTG | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class RadiationDecreaseComponent : Component | ||
{ | ||
public readonly int TotalAliveTime = 1200; // 20 minutes | ||
|
||
public readonly TimeSpan CoolDown = TimeSpan.FromSeconds(1f); | ||
|
||
public TimeSpan LastTimeDecreaseRad = TimeSpan.Zero; | ||
public TimeSpan LastTimeDecreaseSupply = TimeSpan.Zero; | ||
|
||
public float Intensity = 0; // radiation capacity in RadiationSourceComponent | ||
public float Supply = 0; // powersupp in PowerSupplierComponent | ||
|
||
} |
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