Files
crystall-punk-14/Content.Server/StationEvents/Events/GasLeak.cs

148 lines
5.0 KiB
C#
Raw Normal View History

using Content.Server.Atmos.EntitySystems;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Configurations;
using Content.Shared.Atmos;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
2021-06-09 22:19:39 +02:00
namespace Content.Server.StationEvents.Events
{
internal sealed class GasLeak : StationEventSystem
{
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
Refactor how jobs are handed out (#5422) * Completely refactor how job spawning works * Remove remains of old system. * Squash the final bug, cleanup. * Attempt to fix tests * Adjusts packed's round-start crew roster, re-enables a bunch of old roles. Also adds the Central Command Official as a proper role. * pretty up ui * refactor StationSystem into the correct folder & namespace. * remove a log, make sure the lobby gets updated if a new map is spontaneously added. * re-add accidentally removed log * We do a little logging * we do a little resolving * we do a little documenting * Renamed OverflowJob to FallbackOverflowJob Allows stations to configure their own roundstart overflow job list. * narrator: it did not compile * oops * support having no overflow jobs * filescope for consistency * small fixes * Bumps a few role counts for Packed, namely engis * log moment * E * Update Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> * Update Content.Server/Maps/GameMapPrototype.cs Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> * factored job logic, cleanup. * e * Address reviews * Remove the concept of a "default" grid. It has no future in our new multi-station world * why was clickable using that in the first place * fix bad evil bug that almost slipped through also adds chemist * rms obsolete things from chemist * Adds a sanity fallback * address reviews * adds ability to set name * fuck * cleanup joingame
2021-11-26 03:02:46 -06:00
public override string Prototype => "GasLeak";
private static readonly Gas[] LeakableGases =
{
Gas.Miasma,
2021-02-12 10:45:22 +01:00
Gas.Plasma,
Gas.Tritium,
Gas.Frezon,
};
/// <summary>
/// Running cooldown of how much time until another leak.
/// </summary>
private float _timeUntilLeak;
/// <summary>
/// How long between more gas being added to the tile.
/// </summary>
private const float LeakCooldown = 1.0f;
// Event variables
StationSystem/jobs/partial spawning refactor (#7580) * Partial work on StationSystem refactor. * WIP station jobs API. * forgor to fire off grid events. * Partial implementation of StationSpawningSystem * whoops infinite loop. * Spawners should work now. * it compiles. * tfw * Vestigial code cleanup. * fix station deletion. * attempt to make tests go brr * add latejoin spawnpoints to test maps. * make sure the station still exists while destructing spawners. * forgot an exists check. * destruction order check. * hopefully fix final test. * fail-safe radstorm. * Deep-clean job code further. This is bugged!!!!! * Fix job bug. (init order moment) * whooo cleanup * New job selection algorithm that tries to distribute fairly across stations. * small nitpicks * Give the heads their weights to replace the head field. * make overflow assign take a station list. * moment * Fixes and test #1 of many. * please fix nullspace * AssignJobs should no longer even consider showing up on a trace. * add comment. * Introduce station configs, praying i didn't miss something. * in one small change stations are now fully serializable. * Further doc comments. * whoops. * Solve bug where assignjobs didn't account for roundstart. * Fix spawning, improve the API. Caught an oversight in stationsystem that should've broke everything but didn't, whoops. * Goodbye JobController. * minor fix.. * fix test fail, remove debug logs. * quick serialization fixes. * fixes.. * sus * partialing * Update Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Use dirtying to avoid rebuilding the list 2,100 times. * add a bajillion more lines of docs (mostly in AssignJobs so i don't ever forget how it works) * Update Content.IntegrationTests/Tests/Station/StationJobsTest.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Add the Mysteriously Missing Captain Check. * Put maprender back the way it belongs. * I love addressing reviews. * Update Content.Server/Station/Systems/StationJobsSystem.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * doc cleanup. * Fix bureaucratic error, add job slot tests. * zero cost abstractions when * cri * saner error. * Fix spawning failing certain tests due to gameticker not handling falliability correctly. Can't fix this until I refactor the rest of spawning code. * submodule gaming * Packedenger. * Documentation consistency. Co-authored-by: Kara <lunarautomaton6@gmail.com>
2022-05-10 13:43:30 -05:00
private EntityUid _targetStation;
2021-12-05 18:09:01 +01:00
private EntityUid _targetGrid;
private Vector2i _targetTile;
private EntityCoordinates _targetCoords;
private bool _foundTile;
private Gas _leakGas;
private float _molesPerSecond;
private const int MinimumMolesPerSecond = 20;
private float _endAfter = float.MaxValue;
/// <summary>
/// Don't want to make it too fast to give people time to flee.
/// </summary>
private const int MaximumMolesPerSecond = 50;
private const int MinimumGas = 250;
private const int MaximumGas = 1000;
private const float SparkChance = 0.05f;
public override void Started()
{
base.Started();
var mod = MathF.Sqrt(GetSeverityModifier());
// Essentially we'll pick out a target amount of gas to leak, then a rate to leak it at, then work out the duration from there.
2021-11-28 20:25:36 -06:00
if (TryFindRandomTile(out _targetTile, out _targetStation, out _targetGrid, out _targetCoords))
{
_foundTile = true;
_leakGas = RobustRandom.Pick(LeakableGases);
// Was 50-50 on using normal distribution.
var totalGas = RobustRandom.Next(MinimumGas, MaximumGas) * mod;
var startAfter = ((StationEventRuleConfiguration) Configuration).StartAfter;
_molesPerSecond = RobustRandom.Next(MinimumMolesPerSecond, MaximumMolesPerSecond);
_endAfter = totalGas / _molesPerSecond + startAfter;
Sawmill.Info($"Leaking {totalGas} of {_leakGas} over {_endAfter - startAfter} seconds at {_targetTile}");
}
// Look technically if you wanted to guarantee a leak you'd do this in announcement but having the announcement
// there just to fuck with people even if there is no valid tile is funny.
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!RuleStarted)
return;
if (Elapsed > _endAfter)
{
ForceEndSelf();
return;
}
_timeUntilLeak -= frameTime;
if (_timeUntilLeak > 0f) return;
_timeUntilLeak += LeakCooldown;
if (!_foundTile ||
2021-12-05 18:09:01 +01:00
_targetGrid == default ||
EntityManager.Deleted(_targetGrid) ||
!_atmosphere.IsSimulatedGrid(_targetGrid))
{
ForceEndSelf();
return;
}
var environment = _atmosphere.GetTileMixture(_targetGrid, null, _targetTile, true);
environment?.AdjustMoles(_leakGas, LeakCooldown * _molesPerSecond);
}
public override void Ended()
{
base.Ended();
Spark();
_foundTile = false;
2021-12-05 18:09:01 +01:00
_targetGrid = default;
_targetTile = default;
_targetCoords = default;
_leakGas = Gas.Oxygen;
_endAfter = float.MaxValue;
}
private void Spark()
{
if (RobustRandom.NextFloat() <= SparkChance)
{
if (!_foundTile ||
2021-12-05 18:09:01 +01:00
_targetGrid == default ||
(!EntityManager.EntityExists(_targetGrid) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted ||
!_atmosphere.IsSimulatedGrid(_targetGrid))
{
return;
}
// Don't want it to be so obnoxious as to instantly murder anyone in the area but enough that
// it COULD start potentially start a bigger fire.
2023-02-28 14:43:24 -06:00
_atmosphere.HotspotExpose(_targetGrid, _targetTile, 700f, 50f, null, true);
SoundSystem.Play("/Audio/Effects/sparks4.ogg", Filter.Pvs(_targetCoords), _targetCoords);
}
}
}
}