Compare commits
1 Commits
LocalHelpe
...
ed_worldev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8ce6d0141 |
@@ -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;
|
||||||
|
}
|
||||||
47
Content.Server/_CP14/MapEvents/CPMapEventsSchedulerSystem.cs
Normal file
47
Content.Server/_CP14/MapEvents/CPMapEventsSchedulerSystem.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
29
Content.Server/_CP14/MapEvents/Events/CPWeatherRule.cs
Normal file
29
Content.Server/_CP14/MapEvents/Events/CPWeatherRule.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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" #Рассвет
|
||||||
|
|||||||
29
Resources/Prototypes/_CP14/Entities/GameRules/weather.yml
Normal file
29
Resources/Prototypes/_CP14/Entities/GameRules/weather.yml
Normal 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
|
||||||
Reference in New Issue
Block a user