diff --git a/Content.Client/Overlays/StencilOverlay.Weather.cs b/Content.Client/Overlays/StencilOverlay.Weather.cs index 29ed157a791213..bc514548036384 100644 --- a/Content.Client/Overlays/StencilOverlay.Weather.cs +++ b/Content.Client/Overlays/StencilOverlay.Weather.cs @@ -38,7 +38,7 @@ private void DrawWeather(in OverlayDrawArgs args, WeatherPrototype weatherProto, 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; } diff --git a/Content.Client/Weather/WeatherSystem.cs b/Content.Client/Weather/WeatherSystem.cs index b35483bba487d0..a0e8a44f40be63 100644 --- a/Content.Client/Weather/WeatherSystem.cs +++ b/Content.Client/Weather/WeatherSystem.cs @@ -2,16 +2,11 @@ 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; @@ -62,7 +57,7 @@ protected override void Run(EntityUid uid, WeatherData weather, WeatherPrototype if (TryComp(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(); frontier.Enqueue(seed); @@ -75,7 +70,7 @@ protected override void Run(EntityUid uid, WeatherData weather, WeatherPrototype 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 @@ -107,7 +102,7 @@ protected override void Run(EntityUid uid, WeatherData weather, WeatherPrototype 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); diff --git a/Content.Server/Weather/WeatherSystem.cs b/Content.Server/Weather/WeatherSystem.cs index bacdce2b347c57..c3af49944d99c5 100644 --- a/Content.Server/Weather/WeatherSystem.cs +++ b/Content.Server/Weather/WeatherSystem.cs @@ -1,17 +1,16 @@ -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() { @@ -30,7 +29,7 @@ private void OnWeatherGetState(EntityUid uid, WeatherComponent component, ref Co } [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) { @@ -60,7 +59,8 @@ private void WeatherTwo(IConsoleShell shell, string argstr, string[] args) var maxTime = TimeSpan.MaxValue; // If it's already running then just fade out with how much time we're into the weather. - if (TryComp(MapManager.GetMapEntityId(mapId), out var weatherComp) && + if (_mapSystem.TryGetMap(mapId, out var mapUid) && + TryComp(mapUid, out var weatherComp) && weatherComp.Weather.TryGetValue(args[1], out var existing)) { maxTime = curTime - existing.StartTime; diff --git a/Content.Shared/Weather/SharedWeatherSystem.cs b/Content.Shared/Weather/SharedWeatherSystem.cs index 19671bd77b0f2a..61419021247fad 100644 --- a/Content.Shared/Weather/SharedWeatherSystem.cs +++ b/Content.Shared/Weather/SharedWeatherSystem.cs @@ -1,9 +1,7 @@ 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; @@ -18,15 +16,14 @@ public abstract class SharedWeatherSystem : EntitySystem [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 _blockQuery; - private EntityQuery _physicsQuery; public override void Initialize() { base.Initialize(); _blockQuery = GetEntityQuery(); - _physicsQuery = GetEntityQuery(); SubscribeLocalEvent(OnWeatherUnpaused); } @@ -41,9 +38,7 @@ private void OnWeatherUnpaused(EntityUid uid, WeatherComponent component, ref En } } - public bool CanWeatherAffect( - MapGridComponent grid, - TileRef tileRef) + public bool CanWeatherAffect(EntityUid uid, MapGridComponent grid, TileRef tileRef) { if (tileRef.Tile.IsEmpty) return true; @@ -53,9 +48,9 @@ public bool CanWeatherAffect( 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; @@ -154,20 +149,22 @@ public override void Update(float frameTime) /// public void SetWeather(MapId mapId, WeatherPrototype? proto, TimeSpan? endTime) { - var mapUid = MapManager.GetMapEntityId(mapId); - var weatherComp = EnsureComp(mapUid); + if (!_mapSystem.TryGetMap(mapId, out var mapUid)) + return; + + var weatherComp = EnsureComp(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; } @@ -177,12 +174,12 @@ public void SetWeather(MapId mapId, WeatherPrototype? proto, TimeSpan? endTime) 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); } /// @@ -229,9 +226,9 @@ protected virtual bool SetState(EntityUid uid, WeatherState state, WeatherCompon [Serializable, NetSerializable] protected sealed class WeatherComponentState : ComponentState { - public Dictionary Weather; + public Dictionary, WeatherData> Weather; - public WeatherComponentState(Dictionary weather) + public WeatherComponentState(Dictionary, WeatherData> weather) { Weather = weather; } diff --git a/Content.Shared/Weather/WeatherComponent.cs b/Content.Shared/Weather/WeatherComponent.cs index df73109ac4949d..eaf901fb4245c9 100644 --- a/Content.Shared/Weather/WeatherComponent.cs +++ b/Content.Shared/Weather/WeatherComponent.cs @@ -1,8 +1,7 @@ -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; @@ -12,8 +11,8 @@ public sealed partial class WeatherComponent : Component /// /// Currently running weathers /// - [ViewVariables, DataField("weather", customTypeSerializer:typeof(PrototypeIdDictionarySerializer))] - public Dictionary Weather = new(); + [DataField] + public Dictionary, WeatherData> Weather = new(); public static readonly TimeSpan StartupTime = TimeSpan.FromSeconds(15); public static readonly TimeSpan ShutdownTime = TimeSpan.FromSeconds(15); @@ -29,19 +28,19 @@ public sealed partial class WeatherData /// /// When the weather started if relevant. /// - [ViewVariables, DataField("startTime", customTypeSerializer: typeof(TimeOffsetSerializer))] + [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] //TODO: Remove Custom serializer public TimeSpan StartTime = TimeSpan.Zero; /// /// When the applied weather will end. /// - [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; }