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 0000000000..09d74bad9a Binary files /dev/null and b/Resources/Textures/_CP14/Effects/weather.rsi/rain.png differ diff --git a/Resources/Textures/_CP14/Effects/weather.rsi/storm.png b/Resources/Textures/_CP14/Effects/weather.rsi/storm.png new file mode 100644 index 0000000000..e42f8a7061 Binary files /dev/null and b/Resources/Textures/_CP14/Effects/weather.rsi/storm.png differ