using Content.Shared.Tools.Components;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Client.Tools
{
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
+ [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
public string Command => "variantize";
return;
}
- foreach (var tile in gridComp.GetAllTiles())
+ var mapsSystem = _entManager.System<SharedMapSystem>();
+ var tileSystem = _entManager.System<TileSystem>();
+
+ foreach (var tile in mapsSystem.GetAllTiles(euid.Value, gridComp))
{
- var def = tile.GetContentTileDefinition();
- var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, def.PickVariant(_random));
- gridComp.SetTile(tile.GridIndices, newTile);
+ var def = tile.GetContentTileDefinition(_tileDefManager);
+ var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, tileSystem.PickVariant(def));
+ mapsSystem.SetTile(euid.Value, gridComp, tile.GridIndices, newTile);
}
}
}
using Content.Server.Maps;
using Content.Server.NodeContainer.EntitySystems;
using Content.Shared.Atmos.EntitySystems;
+using Content.Shared.Maps;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Server.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Construction
{
using Content.Shared.Stacks;
using Content.Shared.Tools;
using Robust.Shared.Serialization;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Construction
{
return true;
}
- public bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
+ public override bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
=> RemoveDecalInternal(gridId, decalId, out _, component);
- public HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
+ public override HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
{
var decalIds = new HashSet<(uint, Decal)>();
var chunkCollection = ChunkCollection(gridId);
using Content.Shared.Interaction;
using Content.Shared.Tools;
using Content.Shared.Popups;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
using SignalReceivedEvent = Content.Server.DeviceLinking.Events.SignalReceivedEvent;
namespace Content.Server.DeviceLinking.Systems;
using Content.Server.Tools.Components;
using Content.Shared.Administration;
using Content.Shared.Maps;
+using Content.Shared.Tools.Components;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Map;
namespace Content.Server.Interaction
{
/// <summary>
- /// <see cref="TilePryingComponent.TryPryTile"/>
+ /// <see cref="Shared.Tools.Components.TilePryingComponent.TryPryTile"/>
/// </summary>
[AdminCommand(AdminFlags.Debug)]
sealed class TilePryCommand : IConsoleCommand
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Medical;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Robust.Shared.Map;
+using CableCuttingFinishedEvent = Content.Shared.Tools.Systems.CableCuttingFinishedEvent;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Power.EntitySystems;
using Content.Shared.Popups;
using Content.Shared.Repairable;
using Content.Shared.Tools;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Repairable
{
using Content.Shared.Emag.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
+using Content.Shared.Maps;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Toilet
{
+++ /dev/null
-using System.Threading;
-using Content.Shared.Tools;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-
-namespace Content.Server.Tools.Components
-{
- [RegisterComponent]
- public sealed partial class TilePryingComponent : Component
- {
- [DataField("toolComponentNeeded")]
- public bool ToolComponentNeeded = true;
-
- [DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
- public string QualityNeeded = "Prying";
-
- /// <summary>
- /// Whether this tool can pry tiles with CanAxe.
- /// </summary>
- [DataField("advanced")]
- public bool Advanced = false;
-
- [DataField("delay")]
- public float Delay = 1f;
- }
-}
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
- if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
+ if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
return false;
if (_tileDefinitionManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|| !tileDef.CanWirecutter
|| string.IsNullOrEmpty(tileDef.BaseTurf)
- || _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition newDef
- || tile.IsBlockedTurf(true))
+ || _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition ||
+ tile.IsBlockedTurf(true))
{
return false;
}
using Content.Shared.Tools;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Tools
{
[Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
- [Dependency] private readonly TurfSystem _turf = default!;
public override void Initialize()
{
base.Initialize();
- InitializeTilePrying();
InitializeLatticeCutting();
InitializeWelders();
}
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Wires;
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinition = default!;
+ [Dependency] private readonly TileSystem _tiles = default!;
/// <inheritdoc />
public override void Initialize()
private void PlaceFloorplanTiles(BlobFloorPlanBuilderComponent comp, MapGridComponent grid)
{
// NO MORE THAN TWO ALLOCATIONS THANK YOU VERY MUCH.
+ // TODO: Just put these on a field instead then?
+ // Also the end of the method has a big LINQ which is gonna blow this out the water.
var spawnPoints = new HashSet<Vector2i>(comp.FloorPlacements * 6);
var taken = new Dictionary<Vector2i, Tile>(comp.FloorPlacements * 5);
spawnPoints.Add(west);
var tileDef = _tileDefinition[_random.Pick(comp.FloorTileset)];
- taken.Add(point, new Tile(tileDef.TileId, 0, ((ContentTileDefinition)tileDef).PickVariant(_random)));
+ taken.Add(point, new Tile(tileDef.TileId, 0, _tiles.PickVariant((ContentTileDefinition) tileDef)));
}
PlaceTile(Vector2i.Zero);
return; // Redundant logic, prolly needs it's own handler for your custom system.
var placer = Comp<DebrisFeaturePlacerControllerComponent>(component.OwningController);
- var xform = Transform(uid);
+ var xform = args.Component;
var ownerXform = Transform(component.OwningController);
if (xform.MapUid is null || ownerXform.MapUid is null)
return; // not our problem
using Robust.Shared.Player;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Shared.Construction.EntitySystems;
+using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Robust.Shared.GameStates;
{
// used by client-side overlay code
}
+
+ public virtual HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
+ {
+ // NOOP on client atm.
+ return new HashSet<(uint Index, Decal Decal)>();
+ }
+
+ public virtual bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
+ {
+ // NOOP on client atm.
+ return true;
+ }
}
// TODO: Pretty sure paul was moving this somewhere but just so people know
+using System.Linq;
using System.Numerics;
-using Content.Server.Decals;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Decals;
-using Content.Shared.Maps;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;
+using Robust.Shared.Utility;
-namespace Content.Server.Maps;
+namespace Content.Shared.Maps;
/// <summary>
/// Handles server-side tile manipulation like prying/deconstructing tiles.
public sealed class TileSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
- [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
- [Dependency] private readonly DecalSystem _decal = default!;
+ [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
+ [Dependency] private readonly SharedDecalSystem _decal = default!;
+ [Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly TurfSystem _turf = default!;
+ /// <summary>
+ /// Returns a weighted pick of a tile variant.
+ /// </summary>
+ public byte PickVariant(ContentTileDefinition tile)
+ {
+ var variants = tile.PlacementVariants;
+
+ var sum = variants.Sum();
+ var accumulated = 0f;
+ var rand = _robustRandom.NextFloat() * sum;
+
+ for (byte i = 0; i < variants.Length; ++i)
+ {
+ accumulated += variants[i];
+
+ if (accumulated >= rand)
+ return i;
+ }
+
+ // Shouldn't happen
+ throw new InvalidOperationException($"Invalid weighted variantize tile pick for {tile.ID}!");
+ }
+
public bool PryTile(Vector2i indices, EntityUid gridId)
{
- var grid = _mapManager.GetGrid(gridId);
- var tileRef = grid.GetTileRef(indices);
+ var grid = Comp<MapGridComponent>(gridId);
+ var tileRef = _maps.GetTileRef(gridId, grid, indices);
return PryTile(tileRef);
}
public bool ReplaceTile(TileRef tileref, ContentTileDefinition replacementTile, EntityUid grid, MapGridComponent? component = null)
{
+ DebugTools.Assert(tileref.GridUid == grid);
+
if (!Resolve(grid, ref component))
return false;
- var variant = replacementTile.PickVariant();
+
+ var variant = PickVariant(replacementTile);
var decals = _decal.GetDecalsInRange(tileref.GridUid, _turf.GetTileCenter(tileref).Position, 0.5f);
foreach (var (id, _) in decals)
{
_decal.RemoveDecal(tileref.GridUid, id);
}
- component.SetTile(tileref.GridIndices, new Tile(replacementTile.TileId, 0, variant));
+
+ _maps.SetTile(grid, component, tileref.GridIndices, new Tile(replacementTile.TileId, 0, variant));
return true;
}
if (string.IsNullOrEmpty(tileDef.BaseTurf))
return false;
- var mapGrid = _mapManager.GetGrid(tileRef.GridUid);
+ var gridUid = tileRef.GridUid;
+ var mapGrid = Comp<MapGridComponent>(gridUid);
const float margin = 0.1f;
var bounds = mapGrid.TileSize - margin * 2;
var indices = tileRef.GridIndices;
- var coordinates = mapGrid.GridTileToLocal(indices)
+ var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, indices)
.Offset(new Vector2(
(_robustRandom.NextFloat() - 0.5f) * bounds,
(_robustRandom.NextFloat() - 0.5f) * bounds));
Transform(tileItem).LocalRotation = _robustRandom.NextDouble() * Math.Tau;
// Destroy any decals on the tile
- var decals = _decal.GetDecalsInRange(tileRef.GridUid, coordinates.SnapToGrid(EntityManager, _mapManager).Position, 0.5f);
+ var decals = _decal.GetDecalsInRange(gridUid, coordinates.SnapToGrid(EntityManager, _mapManager).Position, 0.5f);
foreach (var (id, _) in decals)
{
_decal.RemoveDecal(tileRef.GridUid, id);
}
var plating = _tileDefinitionManager[tileDef.BaseTurf];
-
- mapGrid.SetTile(tileRef.GridIndices, new Tile(plating.TileId));
+ _maps.SetTile(gridUid, mapGrid, tileRef.GridIndices, new Tile(plating.TileId));
return true;
}
return tile.Tile.IsSpace(tileDefinitionManager);
}
- /// <summary>
- /// Returns a weighted pick of a tile variant.
- /// </summary>
- public static byte PickVariant(this ContentTileDefinition tile, IRobustRandom? random = null)
- {
- IoCManager.Resolve(ref random);
- var variants = tile.PlacementVariants;
-
- var sum = variants.Sum();
- var accumulated = 0f;
- var rand = random.NextFloat() * sum;
-
- for (byte i = 0; i < variants.Length; ++i)
- {
- accumulated += variants[i];
-
- if (accumulated >= rand)
- return i;
- }
-
- // Shouldn't happen
- throw new InvalidOperationException($"Invalid weighted variantize tile pick for {tile.ID}!");
- }
-
/// <summary>
/// Helper that returns all entities in a turf.
/// </summary>
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Shared.Radio.EntitySystems;
--- /dev/null
+using Robust.Shared.GameStates;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
+
+namespace Content.Shared.Tools.Components;
+
+/// <summary>
+/// Allows prying tiles up on a grid.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TilePryingComponent : Component
+{
+ [DataField("toolComponentNeeded"), AutoNetworkedField]
+ public bool ToolComponentNeeded = true;
+
+ [DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>)), AutoNetworkedField]
+ public string QualityNeeded = "Prying";
+
+ /// <summary>
+ /// Whether this tool can pry tiles with CanAxe.
+ /// </summary>
+ [DataField("advanced"), AutoNetworkedField]
+ public bool Advanced = false;
+
+ [DataField("delay"), AutoNetworkedField]
+ public float Delay = 1f;
+}
using System.Linq;
using Content.Shared.Interaction;
-using Content.Shared.Tools.Components;
using Content.Shared.Prying.Components;
+using Content.Shared.Tools.Components;
-namespace Content.Shared.Tools;
+namespace Content.Shared.Tools.Systems;
public abstract partial class SharedToolSystem : EntitySystem
{
-using Content.Server.Tools.Components;
using Content.Shared.Database;
using Content.Shared.Fluids.Components;
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Tools.Components;
using Robust.Shared.Map;
+using Robust.Shared.Map.Components;
-namespace Content.Server.Tools;
+namespace Content.Shared.Tools.Systems;
-public sealed partial class ToolSystem
+public abstract partial class SharedToolSystem
{
- [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
-
private void InitializeTilePrying()
{
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
{
- if (args.Handled || !args.CanReach || (args.Target != null && !HasComp<PuddleComponent>(args.Target))) return;
+ if (args.Handled || !args.CanReach || args.Target != null && !HasComp<PuddleComponent>(args.Target))
+ return;
if (TryPryTile(uid, args.User, component, args.ClickLocation))
args.Handled = true;
var coords = GetCoordinates(args.Coordinates);
var gridUid = coords.GetGridUid(EntityManager);
- if (!_mapManager.TryGetGrid(gridUid, out var grid))
+ if (!TryComp(gridUid, out MapGridComponent? grid))
{
Log.Error("Attempted to pry from a non-existent grid?");
return;
}
- var tile = grid.GetTileRef(coords);
- var center = _turf.GetTileCenter(tile);
+ var tile = _maps.GetTileRef(gridUid.Value, grid, coords);
+ var center = _turfs.GetTileCenter(tile);
+
if (args.Used != null)
{
_adminLogger.Add(LogType.Tile, LogImpact.Low,
- $"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
+ $"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
}
else
{
_adminLogger.Add(LogType.Tile, LogImpact.Low,
- $"{ToPrettyString(args.User):actor} pried {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
+ $"{ToPrettyString(args.User):actor} pried {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
}
- _tile.PryTile(tile, component.Advanced);
+ if (_netManager.IsServer)
+ _tiles.PryTile(tile, component.Advanced);
}
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
return false;
- if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out _, out var mapGrid))
+ if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out var gridUid, out var mapGrid))
return false;
- var tile = mapGrid.GetTileRef(clickLocation);
-
- var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
+ var tile = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
+ var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tile.GridIndices);
- if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
+ if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
return false;
- var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
+ var tileDef = (ContentTileDefinition) _tileDefManager[tile.Tile.TypeId];
if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
return false;
+using Content.Shared.Administration.Logs;
using Content.Shared.DoAfter;
+using Content.Shared.Interaction;
+using Content.Shared.Maps;
using Content.Shared.Tools.Components;
using Robust.Shared.Map;
+using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
-using Robust.Shared.Timing;
using Robust.Shared.Utility;
-namespace Content.Shared.Tools;
+namespace Content.Shared.Tools.Systems;
public abstract partial class SharedToolSystem : EntitySystem
{
- [Dependency] private readonly IPrototypeManager _protoMan = default!;
- [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
- [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
+ [Dependency] private readonly IMapManager _mapManager = default!;
+ [Dependency] private readonly INetManager _netManager = default!;
+ [Dependency] private readonly IPrototypeManager _protoMan = default!;
+ [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+ [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
+ [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+ [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
+ [Dependency] protected readonly SharedInteractionSystem InteractionSystem = default!;
+ [Dependency] private readonly SharedMapSystem _maps = default!;
+ [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
+ [Dependency] private readonly TileSystem _tiles = default!;
+ [Dependency] private readonly TurfSystem _turfs = default!;
public override void Initialize()
{
InitializeMultipleTool();
+ InitializeTilePrying();
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
}