2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2022-11-15 12:30:59 +01:00
|
|
|
using Content.Shared.Fluids;
|
2023-04-10 15:37:03 +10:00
|
|
|
using Content.Shared.Fluids.Components;
|
2023-10-24 21:55:20 +11:00
|
|
|
using Robust.Server.Player;
|
2022-11-15 12:30:59 +01:00
|
|
|
using Robust.Shared.Map;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Robust.Shared.Map.Components;
|
2022-11-15 12:30:59 +01:00
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Fluids.EntitySystems;
|
|
|
|
|
|
|
|
|
|
public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
2023-01-12 16:41:40 +13:00
|
|
|
[Dependency] private readonly PuddleSystem _puddle = default!;
|
2022-11-15 12:30:59 +01:00
|
|
|
|
2023-10-24 21:55:20 +11:00
|
|
|
private readonly HashSet<IPlayerSession> _playerObservers = new();
|
2023-10-19 12:34:31 -07:00
|
|
|
private List<Entity<MapGridComponent>> _grids = new();
|
2022-11-15 12:30:59 +01:00
|
|
|
|
2023-10-24 21:55:20 +11:00
|
|
|
public bool ToggleObserver(IPlayerSession observer)
|
2022-11-15 12:30:59 +01:00
|
|
|
{
|
|
|
|
|
NextTick ??= _timing.CurTime + Cooldown;
|
|
|
|
|
|
|
|
|
|
if (_playerObservers.Contains(observer))
|
|
|
|
|
{
|
|
|
|
|
RemoveObserver(observer);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_playerObservers.Add(observer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 21:55:20 +11:00
|
|
|
private void RemoveObserver(IPlayerSession observer)
|
2022-11-15 12:30:59 +01:00
|
|
|
{
|
|
|
|
|
if (!_playerObservers.Remove(observer))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var message = new PuddleOverlayDisableMessage();
|
|
|
|
|
RaiseNetworkEvent(message, observer.ConnectedClient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
if (NextTick == null || _timing.CurTime < NextTick)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var session in _playerObservers)
|
|
|
|
|
{
|
|
|
|
|
if (session.AttachedEntity is not { Valid: true } entity)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var transform = EntityManager.GetComponent<TransformComponent>(entity);
|
|
|
|
|
|
2023-09-01 12:30:29 +10:00
|
|
|
var worldBounds = Box2.CenteredAround(transform.WorldPosition,
|
2022-11-15 12:30:59 +01:00
|
|
|
new Vector2(LocalViewRange, LocalViewRange));
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
_grids.Clear();
|
|
|
|
|
_mapManager.FindGridsIntersecting(transform.MapID, worldBounds, ref _grids);
|
2022-11-15 12:30:59 +01:00
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
foreach (var grid in _grids)
|
2022-11-15 12:30:59 +01:00
|
|
|
{
|
|
|
|
|
var data = new List<PuddleDebugOverlayData>();
|
2022-12-12 14:59:02 +11:00
|
|
|
var gridUid = grid.Owner;
|
2022-11-15 12:30:59 +01:00
|
|
|
|
|
|
|
|
if (!Exists(gridUid))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
foreach (var uid in grid.Comp.GetAnchoredEntities(worldBounds))
|
2022-11-15 12:30:59 +01:00
|
|
|
{
|
|
|
|
|
PuddleComponent? puddle = null;
|
|
|
|
|
TransformComponent? xform = null;
|
|
|
|
|
if (!Resolve(uid, ref puddle, ref xform, false))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager);
|
2023-01-12 16:41:40 +13:00
|
|
|
var vol = _puddle.CurrentVolume(uid, puddle);
|
|
|
|
|
data.Add(new PuddleDebugOverlayData(pos, vol));
|
2022-11-15 12:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
RaiseNetworkEvent(new PuddleOverlayDebugMessage(GetNetEntity(gridUid), data.ToArray()));
|
2022-11-15 12:30:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NextTick = _timing.CurTime + Cooldown;
|
|
|
|
|
}
|
|
|
|
|
}
|