Compare commits

...

1 Commits

Author SHA1 Message Date
Ed
c8ce6d0141 weather is broken 2024-04-05 23:03:10 +03:00
6 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.CrystallPunk.MapEvents;
/// <summary>
///
/// </summary>
[RegisterComponent, Access(typeof(CPMapEventsSchedulerSystem))]
public sealed partial class CPMapEventsSchedulerComponent : Component
{
public MapId Map;
[DataField]
public float MinimumTimeUntilFirstEvent = 300f;
[DataField]
public float MinimumTimeBetweenEvents = 30f;
[DataField]
public float MaximumTimeBetweenEvents = 300f;
[DataField(required: true)]
public List<EntProtoId> WhitelistedEvents = new();
/// <summary>
/// How long until the next check for an event runs
/// </summary>
[DataField]
public TimeSpan NextEventTime;
}

View File

@@ -0,0 +1,47 @@
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.CrystallPunk.MapEvents;
public sealed class CPMapEventsSchedulerSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] public readonly GameTicker GameTicker = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CPMapEventsSchedulerComponent, MapInitEvent>(OnSchedulerInit);
}
private void OnSchedulerInit(Entity<CPMapEventsSchedulerComponent> scheduler, ref MapInitEvent args)
{
scheduler.Comp.NextEventTime = _timing.CurTime + TimeSpan.FromSeconds(scheduler.Comp.MinimumTimeUntilFirstEvent);
scheduler.Comp.Map = Transform(scheduler).MapID;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CPMapEventsSchedulerComponent>();
while (query.MoveNext(out var uid, out var scheduler))
{
if (_timing.CurTime < scheduler.NextEventTime)
continue;
var randomEvent = _random.Pick(scheduler.WhitelistedEvents);
//var ent = GameTicker.AddGameRule(randomEvent);
GameTicker.StartGameRule(randomEvent);
scheduler.NextEventTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(scheduler.MinimumTimeBetweenEvents, scheduler.MaximumTimeBetweenEvents));
}
}
}

View File

@@ -0,0 +1,21 @@
using Content.Shared.Weather;
using Robust.Shared.Prototypes;
namespace Content.Server.CrystallPunk.MapEvents;
/// <summary>
///
/// </summary>
[RegisterComponent, Access(typeof(CPWeatherRule))]
public sealed partial class CPWeatherRuleComponent : Component
{
[DataField(required: true)]
public ProtoId<WeatherPrototype> Weather = "Storm";
[DataField]
public float MinimumLength = 60f;
[DataField]
public float MaximumLength = 300f;
}

View File

@@ -0,0 +1,29 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Systems;
using Content.Server.StationEvents.Events;
using Content.Server.Weather;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.CrystallPunk.MapEvents;
public sealed class CPWeatherRule : StationEventSystem<CPWeatherRuleComponent>
{
[Dependency] private readonly WeatherSystem _weather = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
protected override void Started(EntityUid uid, CPWeatherRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
var mapId = GameTicker.DefaultMap;
var duration = _random.NextFloat(component.MinimumLength, component.MaximumLength);
_weather.SetWeather(mapId, _proto.Index(component.Weather), _timing.CurTime + TimeSpan.FromSeconds(duration));
}
}

View File

@@ -391,6 +391,14 @@ entities:
- type: GridTree - type: GridTree
- type: MovedGrids - type: MovedGrids
- type: MapLight - type: MapLight
- type: CPMapEventsScheduler
minimumTimeUntilFirstEvent: 5
minimumTimeBetweenEvents: 50
maximumTimeBetweenEvents: 120
whitelistedEvents:
- CPWeatherRain
- CPWeatherStorm
- CPWeatherAshfallHeavy
- type: DayCycle - type: DayCycle
timeEntries: timeEntries:
- startColor: "#754a4a" #Рассвет - startColor: "#754a4a" #Рассвет

View File

@@ -0,0 +1,29 @@
- type: entity
id: CPWeatherStorm
parent: BaseGameRule
noSpawn: true
components:
- type: CPWeatherRule
weather: Storm
minimumLength: 30
maximumLength: 120
- type: entity
id: CPWeatherRain
parent: BaseGameRule
noSpawn: true
components:
- type: CPWeatherRule
weather: Rain
minimumLength: 30
maximumLength: 120
- type: entity
id: CPWeatherAshfallHeavy
parent: BaseGameRule
noSpawn: true
components:
- type: CPWeatherRule
weather: AshfallHeavy
minimumLength: 30
maximumLength: 120