From 3b0af98a2e66d381d05d57cbc5384cac26f91f42 Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:22:16 +0500 Subject: [PATCH] Weather backend start (#407) * DayCycke StartWithRandomEntry * add weather rule * fix * yep, its work * finalize weather * fix again * weather resprite --- .../_CP14/DayCycle/CP14DayCycleSystem.cs | 5 ++ .../CP14WeatherControllerComponent.cs | 23 ++++++++ .../CP14WeatherControllerSystem.cs | 53 ++++++++++++++++++ .../DayCycle/CP14SharedDayCycleSystem.cs | 5 +- .../Components/CP14DayCycleComponent.cs | 3 + .../_CP14/WeatherControl/CP14WeatherData.cs | 15 +++++ Resources/Maps/_CP14/dev_map.yml | 4 ++ Resources/Maps/_CP14/expedition_test.yml | 29 ++++++++++ .../_CP14/Entities/Stations/expedition.yml | 7 +++ .../Prototypes/_CP14/GameRules/events.yml | 0 Resources/Prototypes/_CP14/Maps/arenas.yml | 6 +- Resources/Prototypes/_CP14/weather.yml | 21 +++++++ .../_CP14/Effects/weather.rsi/meta.json | 49 ++++++++++++++++ .../_CP14/Effects/weather.rsi/rain.png | Bin 0 -> 1620 bytes .../_CP14/Effects/weather.rsi/storm.png | Bin 0 -> 2859 bytes 15 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs create mode 100644 Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs create mode 100644 Content.Shared/_CP14/WeatherControl/CP14WeatherData.cs create mode 100644 Resources/Prototypes/_CP14/Entities/Stations/expedition.yml create mode 100644 Resources/Prototypes/_CP14/GameRules/events.yml create mode 100644 Resources/Prototypes/_CP14/weather.yml create mode 100644 Resources/Textures/_CP14/Effects/weather.rsi/meta.json create mode 100644 Resources/Textures/_CP14/Effects/weather.rsi/rain.png create mode 100644 Resources/Textures/_CP14/Effects/weather.rsi/storm.png diff --git a/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs b/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs index 0f2df41ec1..4798ae37bc 100644 --- a/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs +++ b/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs @@ -4,6 +4,7 @@ using Content.Shared.Maps; using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Prototypes; +using Robust.Shared.Random; using Robust.Shared.Timing; namespace Content.Server._CP14.DayCycle; @@ -18,6 +19,7 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly SharedMapSystem _maps = default!; [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; + [Dependency] private readonly IRobustRandom _random = default!; public override void Initialize() { @@ -30,6 +32,9 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem private void OnMapInitDayCycle(Entity dayCycle, ref MapInitEvent args) { Init(dayCycle); + + if (dayCycle.Comp.StartWithRandomEntry && dayCycle.Comp.TimeEntries.Count > 1) + SetTimeEntry(dayCycle, _random.Next(dayCycle.Comp.TimeEntries.Count)); } public override void Update(float frameTime) diff --git a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs new file mode 100644 index 0000000000..705338fd0a --- /dev/null +++ b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerComponent.cs @@ -0,0 +1,23 @@ +using Content.Shared._CP14.WeatherControl; +using Content.Shared.Destructible.Thresholds; + +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))] +public sealed partial class CP14WeatherControllerComponent : Component +{ + /// + /// random time with no weather. + /// + [DataField] + public MinMax ClearDuration = new(60,600); + + [DataField] + public HashSet Entries = new(); + + [DataField, AutoPausedField] + public TimeSpan NextWeatherTime = TimeSpan.Zero; +} diff --git a/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs new file mode 100644 index 0000000000..ac3c8cac98 --- /dev/null +++ b/Content.Server/_CP14/WeatherControl/CP14WeatherControllerSystem.cs @@ -0,0 +1,53 @@ +using Content.Server.GameTicking; +using Content.Server.GameTicking.Events; +using Content.Server.Weather; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; +using Robust.Shared.Timing; + +namespace Content.Server._CP14.WeatherControl; + +public sealed class CP14WeatherControllerSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly GameTicker _gameTicker = default!; + [Dependency] private readonly WeatherSystem _weather = default!; + [Dependency] private readonly IPrototypeManager _proto = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnRoundStart); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var weather)) + { + if (_timing.CurTime <= weather.NextWeatherTime) + continue; + + var weatherData = _random.Pick(weather.Entries); + + if (!_proto.TryIndex(weatherData.Visuals, out var weatherVisualsIndexed)) + continue; + + var weatherDuration = TimeSpan.FromSeconds(weatherData.Duration.Next(_random)); + _weather.SetWeather(Transform(uid).MapID, weatherVisualsIndexed, _timing.CurTime + weatherDuration); + + var clearDuration = TimeSpan.FromSeconds(weather.ClearDuration.Next(_random)); + weather.NextWeatherTime = _timing.CurTime + weatherDuration + clearDuration; + } + } + + private void OnRoundStart(Entity ent, ref RoundStartingEvent args) + { + ent.Comp.NextWeatherTime = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.ClearDuration.Next(_random)); + } +} + diff --git a/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs b/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs index 90049abce1..1c67a48162 100644 --- a/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs +++ b/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs @@ -1,3 +1,6 @@ namespace Content.Shared._CP14.DayCycle; -public abstract class CP14SharedDayCycleSystem : EntitySystem; +public abstract class CP14SharedDayCycleSystem : EntitySystem +{ + +} diff --git a/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs b/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs index 556259e16e..5924b49617 100644 --- a/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs +++ b/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs @@ -39,6 +39,9 @@ public sealed partial class CP14DayCycleComponent : Component [DataField, ViewVariables, AutoNetworkedField] public TimeSpan EntryEndTime; + + [DataField] + public bool StartWithRandomEntry = true; } [DataDefinition, NetSerializable, Serializable] diff --git a/Content.Shared/_CP14/WeatherControl/CP14WeatherData.cs b/Content.Shared/_CP14/WeatherControl/CP14WeatherData.cs new file mode 100644 index 0000000000..7de114bd05 --- /dev/null +++ b/Content.Shared/_CP14/WeatherControl/CP14WeatherData.cs @@ -0,0 +1,15 @@ +using Content.Shared.Destructible.Thresholds; +using Content.Shared.Weather; +using Robust.Shared.Prototypes; + +namespace Content.Shared._CP14.WeatherControl; + +[DataRecord, Serializable] +public sealed class CP14WeatherData +{ + [DataField(required: true)] + public ProtoId Visuals { get; set; } + + [DataField] + public MinMax Duration { get; set; } = new(30, 300); +} diff --git a/Resources/Maps/_CP14/dev_map.yml b/Resources/Maps/_CP14/dev_map.yml index 3aa7244587..15f3a5d920 100644 --- a/Resources/Maps/_CP14/dev_map.yml +++ b/Resources/Maps/_CP14/dev_map.yml @@ -29,6 +29,10 @@ entities: - type: CP14CloudShadows - type: BecomesStation id: Dev + - type: CP14WeatherController + entries: + - visuals: CP14Rain + - visuals: CP14Storm - type: CP14DayCycle timeEntries: - duration: 80 diff --git a/Resources/Maps/_CP14/expedition_test.yml b/Resources/Maps/_CP14/expedition_test.yml index be16e3a8c6..0d804f1d8b 100644 --- a/Resources/Maps/_CP14/expedition_test.yml +++ b/Resources/Maps/_CP14/expedition_test.yml @@ -35,6 +35,35 @@ entities: id: ExpeditionTest - type: Broadphase - type: OccluderTree + - type: CP14WeatherController + clearDuration: + min: 60 + max: 600 + entries: + - visuals: Rains + - visuals: Storm + - type: CP14DayCycle + timeEntries: + - duration: 80 + color: '#754A4AFF' + - duration: 80 + color: '#E0BA87FF' + - duration: 80 + color: '#BFEEFFFF' + - period: Night + duration: 80 + color: '#385163FF' + - period: Night + duration: 80 + color: '#060D12FF' + - period: Night + duration: 80 + color: '#000000FF' + - period: Night + duration: 80 + color: '#000000FF' + - duration: 80 + color: '#120906FF' - type: MapGrid chunks: -4,-1: diff --git a/Resources/Prototypes/_CP14/Entities/Stations/expedition.yml b/Resources/Prototypes/_CP14/Entities/Stations/expedition.yml new file mode 100644 index 0000000000..958d0586e1 --- /dev/null +++ b/Resources/Prototypes/_CP14/Entities/Stations/expedition.yml @@ -0,0 +1,7 @@ +- type: entity + id: CP14BaseExpedition + parent: + - BaseStation + - BaseStationAllEventsEligible + - BaseStationJobsSpawning + - BaseStationAlertLevels #Checks fail without it \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/GameRules/events.yml b/Resources/Prototypes/_CP14/GameRules/events.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Resources/Prototypes/_CP14/Maps/arenas.yml b/Resources/Prototypes/_CP14/Maps/arenas.yml index 116e4c069e..4b2440abbf 100644 --- a/Resources/Prototypes/_CP14/Maps/arenas.yml +++ b/Resources/Prototypes/_CP14/Maps/arenas.yml @@ -22,7 +22,7 @@ minPlayers: 0 stations: AlchemyTest: - stationProto: StandardStationArena + stationProto: CP14BaseExpedition components: - type: CP14StationZLevels defaultMapLevel: 0 @@ -46,7 +46,7 @@ minPlayers: 0 stations: BattleRoyale: - stationProto: StandardStationArena + stationProto: CP14BaseExpedition components: - type: StationNameSetup mapNameTemplate: "Battle royale" @@ -67,7 +67,7 @@ minPlayers: 0 stations: ExpeditionTest: - stationProto: StandardStationArena + stationProto: CP14BaseExpedition components: - type: StationNameSetup mapNameTemplate: "Expedition test" diff --git a/Resources/Prototypes/_CP14/weather.yml b/Resources/Prototypes/_CP14/weather.yml new file mode 100644 index 0000000000..72def46aef --- /dev/null +++ b/Resources/Prototypes/_CP14/weather.yml @@ -0,0 +1,21 @@ +- type: weather + id: CP14Rain + sprite: + sprite: /Textures/_CP14/Effects/weather.rsi + state: rain + sound: + collection: Rain + params: + loop: true + volume: -6 + +- type: weather + id: CP14Storm + sprite: + sprite: /Textures/_CP14/Effects/weather.rsi + state: storm + sound: + path: /Audio/Effects/Weather/rain_heavy.ogg + params: + loop: true + volume: -6 diff --git a/Resources/Textures/_CP14/Effects/weather.rsi/meta.json b/Resources/Textures/_CP14/Effects/weather.rsi/meta.json new file mode 100644 index 0000000000..8485314955 --- /dev/null +++ b/Resources/Textures/_CP14/Effects/weather.rsi/meta.json @@ -0,0 +1,49 @@ +{ + "version": 1, + "copyright": "Taken from https://github.com/Citadel-Station-13/Citadel-Station-13-RP/tree/5781addfa1193c2811408f64d15176139395d670 and edited by vladimir.s (Discord)", + "license": "CC-BY-SA-3.0", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "rain", + "delays": [ + [ + 0.02, + 0.02, + 0.02, + 0.02, + 0.02, + 0.02, + 0.02, + 0.02 + ] + ] + }, + { + "name": "storm", + "delays": [ + [ + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03, + 0.03 + ] + ] + } + ] +} \ No newline at end of file diff --git a/Resources/Textures/_CP14/Effects/weather.rsi/rain.png b/Resources/Textures/_CP14/Effects/weather.rsi/rain.png new file mode 100644 index 0000000000000000000000000000000000000000..09d74bad9a8ccfcbc6f5c979f53f44a7200a829e GIT binary patch literal 1620 zcmV-a2CMm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