From edc67dd280089d40dd040e19f83c9f2878b5eb5f Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:46:21 +0300 Subject: [PATCH] Storm nerf (#1107) * weather lightning nerf * port storm weather to gamerule events * fix --- .../GameTicking/Rules/CP14WeatherRule.cs | 58 ++++++++ .../Components/CP14WeatherRuleComponent.cs | 11 ++ .../CP14WeatherControllerComponent.cs | 6 +- .../CP14WeatherControllerSystem.cs | 3 + .../WeatherEffect/CP14WeatherEffectJob.cs | 21 ++- .../WeatherEffect/CP14WeatherEffectSystem.cs | 47 ++++--- Content.Shared/Weather/WeatherPrototype.cs | 2 +- .../_CP14/WeatherEffect/CP14WeatherEffect.cs | 19 +++ .../Locale/en-US/_CP14/events/events.ftl | 2 +- .../Locale/ru-RU/_CP14/events/events.ftl | 2 +- Resources/Maps/_CP14/comoss.yml | 1 - .../_CP14/Entities/Effects/sky_lightning.yml | 1 - .../Prototypes/_CP14/GameRules/events.yml | 24 +++- Resources/Prototypes/_CP14/weather.yml | 125 ++++++++++-------- 14 files changed, 225 insertions(+), 97 deletions(-) create mode 100644 Content.Server/_CP14/GameTicking/Rules/CP14WeatherRule.cs create mode 100644 Content.Server/_CP14/GameTicking/Rules/Components/CP14WeatherRuleComponent.cs diff --git a/Content.Server/_CP14/GameTicking/Rules/CP14WeatherRule.cs b/Content.Server/_CP14/GameTicking/Rules/CP14WeatherRule.cs new file mode 100644 index 0000000000..998ba35e8a --- /dev/null +++ b/Content.Server/_CP14/GameTicking/Rules/CP14WeatherRule.cs @@ -0,0 +1,58 @@ +using Content.Server._CP14.GameTicking.Rules.Components; +using Content.Server._CP14.WeatherControl; +using Content.Server.GameTicking.Rules; +using Content.Server.Station.Components; +using Content.Server.Station.Systems; +using Content.Server.StationEvents.Events; +using Content.Server.Weather; +using Content.Shared.GameTicking.Components; +using Content.Shared.Station.Components; +using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; + +namespace Content.Server._CP14.GameTicking.Rules; + +public sealed class CP14WeatherRule : StationEventSystem +{ + [Dependency] private readonly WeatherSystem _weather = default!; + [Dependency] private readonly StationSystem _station = default!; + [Dependency] private readonly IPrototypeManager _proto = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + protected override void Started(EntityUid uid, CP14WeatherRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) + { + base.Started(uid, component, gameRule, args); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var mapUid, out var map, out var station)) + { + if (!_proto.TryIndex(component.Weather, out var indexedWeather)) + continue; + + if (TryComp(mapUid, out var controller)) + { + controller.Enabled = false; + } + + _weather.SetWeather(map.MapId, indexedWeather, null); + } + } + + protected override void Ended(EntityUid uid, CP14WeatherRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args) + { + base.Ended(uid, component, gameRule, args); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var mapUid, out var map, out var station)) + { + if (TryComp(mapUid, out var controller)) + { + controller.NextWeatherTime = _timing.CurTime + TimeSpan.FromSeconds(controller.ClearDuration.Max); + controller.Enabled = true; + } + + _weather.SetWeather(map.MapId, null, null); + } + } +} diff --git a/Content.Server/_CP14/GameTicking/Rules/Components/CP14WeatherRuleComponent.cs b/Content.Server/_CP14/GameTicking/Rules/Components/CP14WeatherRuleComponent.cs new file mode 100644 index 0000000000..98199a3621 --- /dev/null +++ b/Content.Server/_CP14/GameTicking/Rules/Components/CP14WeatherRuleComponent.cs @@ -0,0 +1,11 @@ +using Content.Shared.Weather; +using Robust.Shared.Prototypes; + +namespace Content.Server._CP14.GameTicking.Rules.Components; + +[RegisterComponent] +public sealed partial class CP14WeatherRuleComponent : Component +{ + [DataField(required: true)] + public ProtoId Weather = default!; +} diff --git a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs index e38aca3a39..482330365d 100644 --- a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs +++ b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs @@ -1,3 +1,4 @@ +using Content.Server._CP14.GameTicking.Rules; using Content.Shared._CP14.WeatherControl; using Content.Shared.Destructible.Thresholds; @@ -6,9 +7,12 @@ namespace Content.Server._CP14.WeatherControl; /// /// is the controller that hangs on the prototype map. It regulates which weather rules are run and where they are run. /// -[RegisterComponent, AutoGenerateComponentPause, Access(typeof(CP14WeatherControllerSystem))] +[RegisterComponent, AutoGenerateComponentPause, Access(typeof(CP14WeatherControllerSystem), typeof(CP14WeatherRule))] public sealed partial class CP14WeatherControllerComponent : Component { + [DataField] + public bool Enabled = true; + /// /// random time with no weather. /// diff --git a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs index 67f2d1b8ed..6aaac8c793 100644 --- a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs +++ b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs @@ -29,6 +29,9 @@ public sealed class CP14WeatherControllerSystem : EntitySystem if (_timing.CurTime <= weather.NextWeatherTime) continue; + if (!weather.Enabled) + continue; + var weatherData = _random.Pick(weather.Entries); if (!_proto.TryIndex(weatherData.Visuals, out var weatherVisualsIndexed)) diff --git a/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectJob.cs b/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectJob.cs index e52128c2d3..f26e853632 100644 --- a/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectJob.cs +++ b/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectJob.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Threading; using System.Threading.Tasks; using Content.Shared._CP14.WeatherEffect; @@ -20,12 +21,12 @@ public sealed class CP14WeatherEffectJob : Job private readonly Entity _mapUid; private readonly MapId _mapId; - private readonly List _effects; + private readonly CP14WeatherEffectConfig _config; private EntityQuery _weatherBlockQuery; private readonly HashSet> _entitiesOnMap = new(); - private readonly HashSet> _affectedEntities = new(); + private List> _affectedEntities = new(); public CP14WeatherEffectJob( double maxTime, @@ -36,7 +37,7 @@ public sealed class CP14WeatherEffectJob : Job IRobustRandom random, Entity mapUid, MapId mapId, - List effects, + CP14WeatherEffectConfig config, EntityQuery weatherBlockQuery, CancellationToken cancellation = default ) : base(maxTime, cancellation) @@ -50,7 +51,7 @@ public sealed class CP14WeatherEffectJob : Job _mapUid = mapUid; _mapId = mapId; - _effects = effects; + _config = config; _weatherBlockQuery = weatherBlockQuery; } @@ -64,7 +65,7 @@ public sealed class CP14WeatherEffectJob : Job foreach (var ent in _entitiesOnMap) { //All weatherblocker entites should be affected by weather - if (_weatherBlockQuery.HasComp(ent)) + if (_config.CanAffectOnWeatherBlocker && _weatherBlockQuery.HasComp(ent)) { _affectedEntities.Add(ent); continue; @@ -79,10 +80,18 @@ public sealed class CP14WeatherEffectJob : Job } } + _random.Shuffle(_affectedEntities); + + // Limit the number of affected entities if specified + if (_config.MaxEntities.HasValue && _affectedEntities.Count > _config.MaxEntities.Value) + { + _affectedEntities = _affectedEntities.Take(_config.MaxEntities.Value).ToList(); + } + //Apply weather effects to affected entities foreach (var entity in _affectedEntities) { - foreach (var effect in _effects) + foreach (var effect in _config.Effects) { effect.ApplyEffect(_entManager, _random, entity); } diff --git a/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectSystem.cs b/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectSystem.cs index c871c29e5c..f89e0d4213 100644 --- a/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectSystem.cs +++ b/Content.Server/_CP14/WeatherEffect/CP14WeatherEffectSystem.cs @@ -22,17 +22,12 @@ public sealed class CP14WeatherEffectSystem : EntitySystem private readonly List<(CP14WeatherEffectJob Job, CancellationTokenSource CancelToken)> _weatherJobs = new(); private const double JobMaxTime = 0.002; - private readonly TimeSpan ProcessFreq = TimeSpan.FromSeconds(5f); - private TimeSpan NextProcessTime = TimeSpan.Zero; - private EntityQuery _weatherBlockQuery; public override void Initialize() { base.Initialize(); _weatherBlockQuery = GetEntityQuery(); - - NextProcessTime = _timing.CurTime + ProcessFreq; } public override void Update(float frameTime) @@ -50,10 +45,6 @@ public sealed class CP14WeatherEffectSystem : EntitySystem } } - if (_timing.CurTime <= NextProcessTime) - return; - - NextProcessTime = _timing.CurTime + ProcessFreq; ProcessWeather(); } @@ -62,26 +53,34 @@ public sealed class CP14WeatherEffectSystem : EntitySystem var query = EntityQueryEnumerator(); while (query.MoveNext(out var mapUid, out var weather, out var mapComp)) { - foreach (var (proto, data) in weather.Weather) + foreach (var (proto, _) in weather.Weather) { if (!_proto.TryIndex(proto, out var indexedWeather)) continue; - var cancelToken = new CancellationTokenSource(); - var job = new CP14WeatherEffectJob( - JobMaxTime, - EntityManager, - _lookup, - _weather, - _mapSystem, - _random, - (mapUid, mapComp), - Transform(mapUid).MapID, - indexedWeather.Effects, - _weatherBlockQuery); + foreach (var config in indexedWeather.Config) + { + if (_timing.CurTime <= config.NextEffectTime) + continue; - _weatherJobs.Add((job, cancelToken)); - _weatherQueue.EnqueueJob(job); + config.NextEffectTime = _timing.CurTime + config.Frequency; + + var cancelToken = new CancellationTokenSource(); + var job = new CP14WeatherEffectJob( + JobMaxTime, + EntityManager, + _lookup, + _weather, + _mapSystem, + _random, + (mapUid, mapComp), + Transform(mapUid).MapID, + config, + _weatherBlockQuery); + + _weatherJobs.Add((job, cancelToken)); + _weatherQueue.EnqueueJob(job); + } } } } diff --git a/Content.Shared/Weather/WeatherPrototype.cs b/Content.Shared/Weather/WeatherPrototype.cs index aa5c95a9c7..abc874aca9 100644 --- a/Content.Shared/Weather/WeatherPrototype.cs +++ b/Content.Shared/Weather/WeatherPrototype.cs @@ -39,5 +39,5 @@ public sealed partial class WeatherPrototype : IPrototype /// CP14 Effects /// [DataField] - public List Effects = new(); + public List Config = new(); } diff --git a/Content.Shared/_CP14/WeatherEffect/CP14WeatherEffect.cs b/Content.Shared/_CP14/WeatherEffect/CP14WeatherEffect.cs index d7ca7e8076..e7e946311b 100644 --- a/Content.Shared/_CP14/WeatherEffect/CP14WeatherEffect.cs +++ b/Content.Shared/_CP14/WeatherEffect/CP14WeatherEffect.cs @@ -12,3 +12,22 @@ public abstract partial class CP14WeatherEffect public abstract void ApplyEffect(IEntityManager entManager, IRobustRandom random, EntityUid target); } + +[DataDefinition] +public sealed partial class CP14WeatherEffectConfig +{ + [DataField] + public List Effects = new(); + + [DataField] + public int? MaxEntities = null; + + [DataField] + public TimeSpan Frequency = TimeSpan.FromSeconds(5f); + + [DataField] + public TimeSpan NextEffectTime = TimeSpan.Zero; + + [DataField] + public bool CanAffectOnWeatherBlocker = true; +} diff --git a/Resources/Locale/en-US/_CP14/events/events.ftl b/Resources/Locale/en-US/_CP14/events/events.ftl index 9399d96285..faaef1531d 100644 --- a/Resources/Locale/en-US/_CP14/events/events.ftl +++ b/Resources/Locale/en-US/_CP14/events/events.ftl @@ -1,2 +1,2 @@ cp14-event-announcement-demiplane-outbreak = A sense of danger pierces the air... Something from other worlds is invading your town. -cp14-event-announcement-unstable-demiplane = Tension is building... an wild demiplane has opened somewhere in the settlement. Close it down before the monsters come out. \ No newline at end of file +cp14-event-announcement-storm = Storm clouds are gathering on the horizon.... \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_CP14/events/events.ftl b/Resources/Locale/ru-RU/_CP14/events/events.ftl index fd9fbba4a7..d39ba9ac2a 100644 --- a/Resources/Locale/ru-RU/_CP14/events/events.ftl +++ b/Resources/Locale/ru-RU/_CP14/events/events.ftl @@ -1,2 +1,2 @@ cp14-event-announcement-demiplane-outbreak = Воздух пронзает чувство опасности... Что-то из других миров вторгается в ваш городок. -cp14-event-announcement-unstable-demiplane = Нарастает напряжение... где-то в городе открылся дикий демиплан. Закройте его, до того как из него вырвутся толпы монстров. \ No newline at end of file +cp14-event-announcement-storm = На горизонте сгущаются грозовые тучи... \ No newline at end of file diff --git a/Resources/Maps/_CP14/comoss.yml b/Resources/Maps/_CP14/comoss.yml index 48e9c456c2..c63efe584b 100644 --- a/Resources/Maps/_CP14/comoss.yml +++ b/Resources/Maps/_CP14/comoss.yml @@ -67,7 +67,6 @@ entities: entries: - visuals: CP14Mist - visuals: CP14Rain - - visuals: CP14Storm - type: LightCycle - type: SunShadow - type: SunShadowCycle diff --git a/Resources/Prototypes/_CP14/Entities/Effects/sky_lightning.yml b/Resources/Prototypes/_CP14/Entities/Effects/sky_lightning.yml index ad73efb9e2..d5abae182d 100644 --- a/Resources/Prototypes/_CP14/Entities/Effects/sky_lightning.yml +++ b/Resources/Prototypes/_CP14/Entities/Effects/sky_lightning.yml @@ -17,7 +17,6 @@ - type: Tag tags: - HideContextMenu - - type: AnimationPlayer - type: PointLight color: "#73efff" enabled: true diff --git a/Resources/Prototypes/_CP14/GameRules/events.yml b/Resources/Prototypes/_CP14/GameRules/events.yml index 69b4de3581..c011b82e07 100644 --- a/Resources/Prototypes/_CP14/GameRules/events.yml +++ b/Resources/Prototypes/_CP14/GameRules/events.yml @@ -27,9 +27,10 @@ - id: CP14MosquitoSpawn - id: CP14RabbitsSpawn - id: CP14FrogsSpawn + - id: CP14Storm - type: entity - parent: CP14BaseStationEventShortDelay + parent: CP14BaseStationEventLongDelay id: CP14ZombiesSpawn components: - type: StationEvent @@ -46,7 +47,7 @@ prob: 0.08 - type: entity - parent: CP14BaseStationEventShortDelay + parent: CP14BaseStationEventLongDelay id: CP14HydrasSpawn components: - type: StationEvent @@ -63,7 +64,7 @@ prob: 0.08 - type: entity - parent: CP14BaseStationEventShortDelay + parent: CP14BaseStationEventLongDelay id: CP14MosquitoSpawn components: - type: StationEvent @@ -111,4 +112,19 @@ - type: VentCrittersRule entries: - id: CP14MobGroupSpawnerFrogs - prob: 0.08 \ No newline at end of file + prob: 0.08 + +- type: entity + parent: CP14BaseStationEventLongDelay + id: CP14Storm + components: + - type: StationEvent + startAnnouncement: cp14-event-announcement-storm + startAudio: + collection: CP14LightningFar + earliestStart: 45 + minimumPlayers: 10 + duration: 180 + maxDuration: 600 + - type: CP14WeatherRule + weather: CP14Storm \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/weather.yml b/Resources/Prototypes/_CP14/weather.yml index 63059515c6..dc5e59156a 100644 --- a/Resources/Prototypes/_CP14/weather.yml +++ b/Resources/Prototypes/_CP14/weather.yml @@ -8,11 +8,12 @@ params: loop: true volume: -6 - effects: - - !type:ApplyEntityEffect - prob: 0.2 - effects: - - !type:ExtinguishReaction + config: + - effects: + - !type:ApplyEntityEffect + prob: 0.2 + effects: + - !type:ExtinguishReaction - type: weather id: CP14Storm @@ -24,14 +25,18 @@ params: loop: true volume: -6 - effects: - - !type:ApplyEntityEffect - prob: 0.4 + config: + - maxEntities: 2 + frequency: 10 + canAffectOnWeatherBlocker: false effects: - - !type:ExtinguishReaction - - !type:SpawnEntityOnTop - prob: 0.0001 - entity: CP14SkyLightning + - !type:ApplyEntityEffect + prob: 0.4 + effects: + - !type:ExtinguishReaction + - !type:SpawnEntityOnTop + prob: 0.25 + entity: CP14SkyLightning - type: weather id: CP14Mist @@ -45,23 +50,24 @@ - type: weather id: CP14ManaMist offsetSpeed: 0.56, -0.36 - color: "#3d81ff" + color: "#91a1bf" alpha: 0.7 sprite: sprite: /Textures/_CP14/Effects/parallax.rsi state: noise - effects: - - !type:ApplyEntityEffect - prob: 0.5 - effects: - - !type:CP14ManaChange - manaDelta: 8 - safe: true + config: + - effects: + - !type:ApplyEntityEffect + prob: 0.5 + effects: + - !type:CP14ManaChange + manaDelta: 8 + safe: true - type: weather id: CP14AntiManaMist offsetSpeed: -0.56, -0.31 - color: "#d929d9" + color: "#302a2a" alpha: 0.8 sprite: sprite: /Textures/_CP14/Effects/parallax.rsi @@ -71,25 +77,27 @@ params: loop: true volume: -18 - effects: - - !type:ApplyEntityEffect - prob: 0.5 - effects: - - !type:CP14ManaChange - manaDelta: -10 - safe: true + config: + - effects: + - !type:ApplyEntityEffect + prob: 0.5 + effects: + - !type:CP14ManaChange + manaDelta: -10 + safe: true - type: weather id: CP14SnowLight sprite: sprite: /Textures/_CP14/Effects/weather.rsi state: snowfall_light - #effects: - #- !type:ApplyEntityEffect - # prob: 1 - # effects: - # - !type:AdjustTemperature - # amount: -20000 + #config: + #- effects: + #- !type:ApplyEntityEffect + # prob: 1 + # effects: + # - !type:AdjustTemperature + # amount: -20000 - type: weather id: CP14SnowMedium @@ -101,12 +109,13 @@ params: loop: true volume: -18 - #effects: - #- !type:ApplyEntityEffect - # prob: 1 - # effects: - # - !type:AdjustTemperature - # amount: -40000 + #config: + #- effects: + #- !type:ApplyEntityEffect + # prob: 1 + # effects: + # - !type:AdjustTemperature + # amount: -40000 - type: weather id: CP14SnowHeavy @@ -118,12 +127,13 @@ params: loop: true volume: -6 - #effects: - #- !type:ApplyEntityEffect - # prob: 1 - # effects: - # - !type:AdjustTemperature - # amount: -60000 + #config: + #- effects: + #- !type:ApplyEntityEffect + # prob: 1 + # effects: + # - !type:AdjustTemperature + # amount: -60000 - type: weather id: CP14FireStorm @@ -136,14 +146,15 @@ params: loop: true volume: -6 - effects: - #- !type:ApplyEntityEffect - # prob: 1 - # effects: - # - !type:AdjustTemperature - # amount: 40000 - - !type:ApplyEntityEffect - effects: - - !type:FlammableReaction - multiplier: 1 - - !type:Ignite \ No newline at end of file + config: + - effects: + #- !type:ApplyEntityEffect + # prob: 1 + # effects: + # - !type:AdjustTemperature + # amount: 40000 + - !type:ApplyEntityEffect + effects: + - !type:FlammableReaction + multiplier: 1 + - !type:Ignite \ No newline at end of file