foreach (var tile in grid.Comp.GetTilesIntersecting(worldAABB))
{
// Ignored tiles for stencil
- if (_weather.CanWeatherAffect(grid, tile))
+ if (_weather.CanWeatherAffect(grid.Owner, grid, tile))
{
continue;
}
using Content.Shared.Weather;
using Robust.Client.Audio;
using Robust.Client.GameObjects;
-using Robust.Client.Graphics;
using Robust.Client.Player;
-using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
-using Robust.Shared.Physics;
-using Robust.Shared.Physics.Components;
-using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using AudioComponent = Robust.Shared.Audio.Components.AudioComponent;
if (TryComp<MapGridComponent>(entXform.GridUid, out var grid))
{
var gridId = entXform.GridUid.Value;
- // Floodfill to the nearest tile and use that for audio.
+ // FloodFill to the nearest tile and use that for audio.
var seed = _mapSystem.GetTileRef(gridId, grid, entXform.Coordinates);
var frontier = new Queue<TileRef>();
frontier.Enqueue(seed);
if (!visited.Add(node.GridIndices))
continue;
- if (!CanWeatherAffect(grid, node))
+ if (!CanWeatherAffect(entXform.GridUid.Value, grid, node))
{
// Add neighbors
// TODO: Ideally we pick some deterministically random direction and use that
if (nearestNode != null)
{
var entPos = _transform.GetMapCoordinates(entXform);
- var nodePosition = nearestNode.Value.ToMap(EntityManager, _transform).Position;
+ var nodePosition = _transform.ToMapCoordinates(nearestNode.Value).Position;
var delta = nodePosition - entPos.Position;
var distance = delta.Length();
occlusion = _audio.GetOcclusion(entPos, delta, distance);
-using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Weather;
using Robust.Shared.Console;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
-using Robust.Shared.Map.Components;
namespace Content.Server.Weather;
public sealed class WeatherSystem : SharedWeatherSystem
{
[Dependency] private readonly IConsoleHost _console = default!;
+ [Dependency] private readonly SharedMapSystem _mapSystem = default!;
public override void Initialize()
{
}
[AdminCommand(AdminFlags.Fun)]
- private void WeatherTwo(IConsoleShell shell, string argstr, string[] args)
+ private void WeatherTwo(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 2)
{
var maxTime = TimeSpan.MaxValue;
// If it's already running then just fade out with how much time we're into the weather.
- if (TryComp<WeatherComponent>(MapManager.GetMapEntityId(mapId), out var weatherComp) &&
+ if (_mapSystem.TryGetMap(mapId, out var mapUid) &&
+ TryComp<WeatherComponent>(mapUid, out var weatherComp) &&
weatherComp.Weather.TryGetValue(args[1], out var existing))
{
maxTime = curTime - existing.StartTime;
using Content.Shared.Maps;
-using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
-using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
+ [Dependency] private readonly SharedMapSystem _mapSystem = default!;
private EntityQuery<BlockWeatherComponent> _blockQuery;
- private EntityQuery<PhysicsComponent> _physicsQuery;
public override void Initialize()
{
base.Initialize();
_blockQuery = GetEntityQuery<BlockWeatherComponent>();
- _physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<WeatherComponent, EntityUnpausedEvent>(OnWeatherUnpaused);
}
}
}
- public bool CanWeatherAffect(
- MapGridComponent grid,
- TileRef tileRef)
+ public bool CanWeatherAffect(EntityUid uid, MapGridComponent grid, TileRef tileRef)
{
if (tileRef.Tile.IsEmpty)
return true;
if (!tileDef.Weather)
return false;
- var anchoredEnts = grid.GetAnchoredEntitiesEnumerator(tileRef.GridIndices);
+ var anchoredEntities = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, tileRef.GridIndices);
- while (anchoredEnts.MoveNext(out var ent))
+ while (anchoredEntities.MoveNext(out var ent))
{
if (_blockQuery.HasComponent(ent.Value))
return false;
/// </summary>
public void SetWeather(MapId mapId, WeatherPrototype? proto, TimeSpan? endTime)
{
- var mapUid = MapManager.GetMapEntityId(mapId);
- var weatherComp = EnsureComp<WeatherComponent>(mapUid);
+ if (!_mapSystem.TryGetMap(mapId, out var mapUid))
+ return;
+
+ var weatherComp = EnsureComp<WeatherComponent>(mapUid.Value);
foreach (var (eProto, weather) in weatherComp.Weather)
{
// Reset cooldown if it's an existing one.
- if (eProto == proto?.ID)
+ if (proto == null || eProto == proto.ID)
{
weather.EndTime = endTime;
if (weather.State == WeatherState.Ending)
weather.State = WeatherState.Running;
- Dirty(mapUid, weatherComp);
+ Dirty(mapUid.Value, weatherComp);
continue;
}
if (weather.EndTime == null || weather.EndTime > end)
{
weather.EndTime = end;
- Dirty(mapUid, weatherComp);
+ Dirty(mapUid.Value, weatherComp);
}
}
if (proto != null)
- StartWeather(mapUid, weatherComp, proto, endTime);
+ StartWeather(mapUid.Value, weatherComp, proto, endTime);
}
/// <summary>
[Serializable, NetSerializable]
protected sealed class WeatherComponentState : ComponentState
{
- public Dictionary<string, WeatherData> Weather;
+ public Dictionary<ProtoId<WeatherPrototype>, WeatherData> Weather;
- public WeatherComponentState(Dictionary<string, WeatherData> weather)
+ public WeatherComponentState(Dictionary<ProtoId<WeatherPrototype>, WeatherData> weather)
{
Weather = weather;
}
-using Robust.Shared.Audio;
using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Shared.Weather;
/// <summary>
/// Currently running weathers
/// </summary>
- [ViewVariables, DataField("weather", customTypeSerializer:typeof(PrototypeIdDictionarySerializer<WeatherData, WeatherPrototype>))]
- public Dictionary<string, WeatherData> Weather = new();
+ [DataField]
+ public Dictionary<ProtoId<WeatherPrototype>, WeatherData> Weather = new();
public static readonly TimeSpan StartupTime = TimeSpan.FromSeconds(15);
public static readonly TimeSpan ShutdownTime = TimeSpan.FromSeconds(15);
/// <summary>
/// When the weather started if relevant.
/// </summary>
- [ViewVariables, DataField("startTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] //TODO: Remove Custom serializer
public TimeSpan StartTime = TimeSpan.Zero;
/// <summary>
/// When the applied weather will end.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField("endTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] //TODO: Remove Custom serializer
public TimeSpan? EndTime;
[ViewVariables]
public TimeSpan Duration => EndTime == null ? TimeSpan.MaxValue : EndTime.Value - StartTime;
- [DataField("state")]
+ [DataField]
public WeatherState State = WeatherState.Invalid;
}