Dynamic demiplane weather + farming hotfix (#1131)
* dynamic demiplane weather * add skeleton sprite * hotfix farming * Update wheat.yml
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Weather;
|
||||
using Content.Shared._CP14.WeatherControl;
|
||||
using Content.Shared.Weather;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -12,13 +15,6 @@ public sealed class CP14WeatherControllerSystem : EntitySystem
|
||||
[Dependency] private readonly WeatherSystem _weather = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14WeatherControllerComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -32,22 +28,52 @@ public sealed class CP14WeatherControllerSystem : EntitySystem
|
||||
if (!weather.Enabled)
|
||||
continue;
|
||||
|
||||
var weatherData = _random.Pick(weather.Entries);
|
||||
var weatherData = PickWeatherDataByWeight(uid, 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;
|
||||
{
|
||||
var weatherDuration = TimeSpan.FromSeconds(weatherData.Duration.Next(_random));
|
||||
_weather.SetWeather(Transform(uid).MapID, null, null);
|
||||
weather.NextWeatherTime = _timing.CurTime + weatherDuration;
|
||||
}
|
||||
else
|
||||
{
|
||||
var weatherDuration = TimeSpan.FromSeconds(weatherData.Duration.Next(_random));
|
||||
_weather.SetWeather(Transform(uid).MapID, weatherVisualsIndexed, null);
|
||||
weather.NextWeatherTime = _timing.CurTime + weatherDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<CP14WeatherControllerComponent> ent, ref MapInitEvent args)
|
||||
private CP14WeatherData PickWeatherDataByWeight(EntityUid map, HashSet<CP14WeatherData> entries)
|
||||
{
|
||||
ent.Comp.NextWeatherTime = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.ClearDuration.Next(_random));
|
||||
var filteredEntries = new HashSet<CP14WeatherData>(entries);
|
||||
|
||||
if (TryComp<WeatherComponent>(map, out var currentWeather))
|
||||
{
|
||||
foreach (var (weatherProto, data) in currentWeather.Weather)
|
||||
{
|
||||
if (!_proto.TryIndex(weatherProto, out var weatherPrototype))
|
||||
continue;
|
||||
|
||||
filteredEntries.RemoveWhere(entry => entry.Visuals == weatherPrototype);
|
||||
}
|
||||
}
|
||||
|
||||
var totalWeight = filteredEntries.Sum(entry => entry.Weight);
|
||||
var randomWeight = _random.NextFloat() * totalWeight;
|
||||
var currentWeight = 0f;
|
||||
|
||||
foreach (var entry in filteredEntries)
|
||||
{
|
||||
currentWeight += entry.Weight;
|
||||
if (randomWeight < currentWeight)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback in case of rounding errors
|
||||
return filteredEntries.Last();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user