Weather backend start (#407)

* DayCycke StartWithRandomEntry

* add weather rule

* fix

* yep, its work

* finalize weather

* fix again

* weather resprite
This commit is contained in:
Ed
2024-09-01 17:22:16 +05:00
committed by GitHub
parent 37a4068334
commit 3b0af98a2e
15 changed files with 216 additions and 4 deletions

View File

@@ -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<CP14DayCycleComponent> 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)

View File

@@ -0,0 +1,23 @@
using Content.Shared._CP14.WeatherControl;
using Content.Shared.Destructible.Thresholds;
namespace Content.Server._CP14.WeatherControl;
/// <summary>
/// is the controller that hangs on the prototype map. It regulates which weather rules are run and where they are run.
/// </summary>
[RegisterComponent, AutoGenerateComponentPause, Access(typeof(CP14WeatherControllerSystem))]
public sealed partial class CP14WeatherControllerComponent : Component
{
/// <summary>
/// random time with no weather.
/// </summary>
[DataField]
public MinMax ClearDuration = new(60,600);
[DataField]
public HashSet<CP14WeatherData> Entries = new();
[DataField, AutoPausedField]
public TimeSpan NextWeatherTime = TimeSpan.Zero;
}

View File

@@ -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<CP14WeatherControllerComponent, RoundStartingEvent>(OnRoundStart);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CP14WeatherControllerComponent>();
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<CP14WeatherControllerComponent> ent, ref RoundStartingEvent args)
{
ent.Comp.NextWeatherTime = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.ClearDuration.Next(_random));
}
}

View File

@@ -1,3 +1,6 @@
namespace Content.Shared._CP14.DayCycle;
public abstract class CP14SharedDayCycleSystem : EntitySystem;
public abstract class CP14SharedDayCycleSystem : EntitySystem
{
}

View File

@@ -39,6 +39,9 @@ public sealed partial class CP14DayCycleComponent : Component
[DataField, ViewVariables, AutoNetworkedField]
public TimeSpan EntryEndTime;
[DataField]
public bool StartWithRandomEntry = true;
}
[DataDefinition, NetSerializable, Serializable]

View File

@@ -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<WeatherPrototype> Visuals { get; set; }
[DataField]
public MinMax Duration { get; set; } = new(30, 300);
}

View File

@@ -29,6 +29,10 @@ entities:
- type: CP14CloudShadows
- type: BecomesStation
id: Dev
- type: CP14WeatherController
entries:
- visuals: CP14Rain
- visuals: CP14Storm
- type: CP14DayCycle
timeEntries:
- duration: 80

View File

@@ -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:

View File

@@ -0,0 +1,7 @@
- type: entity
id: CP14BaseExpedition
parent:
- BaseStation
- BaseStationAllEventsEligible
- BaseStationJobsSpawning
- BaseStationAlertLevels #Checks fail without it

View File

@@ -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"

View File

@@ -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

View File

@@ -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
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB