Predict tile-prying (#21167)
This commit is contained in:
@@ -5,6 +5,7 @@ using Content.Shared.Tools;
|
|||||||
using Content.Shared.Tools.Components;
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Client.Tools
|
namespace Content.Client.Tools
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public sealed class VariantizeCommand : IConsoleCommand
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||||
|
|
||||||
public string Command => "variantize";
|
public string Command => "variantize";
|
||||||
|
|
||||||
@@ -39,11 +40,14 @@ public sealed class VariantizeCommand : IConsoleCommand
|
|||||||
return;
|
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 def = tile.GetContentTileDefinition(_tileDefManager);
|
||||||
var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, def.PickVariant(_random));
|
var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, tileSystem.PickVariant(def));
|
||||||
gridComp.SetTile(tile.GridIndices, newTile);
|
mapsSystem.SetTile(euid.Value, gridComp, tile.GridIndices, newTile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Server.Body.Systems;
|
|||||||
using Content.Server.Maps;
|
using Content.Server.Maps;
|
||||||
using Content.Server.NodeContainer.EntitySystems;
|
using Content.Server.NodeContainer.EntitySystems;
|
||||||
using Content.Shared.Atmos.EntitySystems;
|
using Content.Shared.Atmos.EntitySystems;
|
||||||
|
using Content.Shared.Maps;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using JetBrains.Annotations;
|
|||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Construction
|
namespace Content.Server.Construction
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Stacks;
|
using Content.Shared.Stacks;
|
||||||
using Content.Shared.Tools;
|
using Content.Shared.Tools;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Construction
|
namespace Content.Server.Construction
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -305,10 +305,10 @@ namespace Content.Server.Decals
|
|||||||
return true;
|
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);
|
=> 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 decalIds = new HashSet<(uint, Decal)>();
|
||||||
var chunkCollection = ChunkCollection(gridId);
|
var chunkCollection = ChunkCollection(gridId);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Examine;
|
|||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Tools;
|
using Content.Shared.Tools;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
using SignalReceivedEvent = Content.Server.DeviceLinking.Events.SignalReceivedEvent;
|
using SignalReceivedEvent = Content.Server.DeviceLinking.Events.SignalReceivedEvent;
|
||||||
|
|
||||||
namespace Content.Server.DeviceLinking.Systems;
|
namespace Content.Server.DeviceLinking.Systems;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Content.Server.Administration;
|
|||||||
using Content.Server.Tools.Components;
|
using Content.Server.Tools.Components;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
@@ -10,7 +11,7 @@ using Robust.Shared.Map;
|
|||||||
namespace Content.Server.Interaction
|
namespace Content.Server.Interaction
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="TilePryingComponent.TryPryTile"/>
|
/// <see cref="Shared.Tools.Components.TilePryingComponent.TryPryTile"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AdminCommand(AdminFlags.Debug)]
|
[AdminCommand(AdminFlags.Debug)]
|
||||||
sealed class TilePryCommand : IConsoleCommand
|
sealed class TilePryCommand : IConsoleCommand
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ using Content.Shared.Tools;
|
|||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Medical;
|
namespace Content.Server.Medical;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Tools;
|
using Content.Shared.Tools;
|
||||||
using Content.Shared.Tools.Components;
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using CableCuttingFinishedEvent = Content.Shared.Tools.Systems.CableCuttingFinishedEvent;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Power.EntitySystems;
|
namespace Content.Server.Power.EntitySystems;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Repairable;
|
using Content.Shared.Repairable;
|
||||||
using Content.Shared.Tools;
|
using Content.Shared.Tools;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Repairable
|
namespace Content.Server.Repairable
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ using Content.Shared.DoAfter;
|
|||||||
using Content.Shared.Emag.Systems;
|
using Content.Shared.Emag.Systems;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Humanoid;
|
using Content.Shared.Humanoid;
|
||||||
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Mobs;
|
using Content.Shared.Mobs;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Mobs.Components;
|
||||||
using Content.Shared.Mobs.Systems;
|
using Content.Shared.Mobs.Systems;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using Content.Shared.Verbs;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Toilet
|
namespace Content.Server.Toilet
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -62,14 +62,14 @@ public sealed partial class ToolSystem
|
|||||||
|
|
||||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
||||||
|
|
||||||
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_tileDefinitionManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|
if (_tileDefinitionManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|
||||||
|| !tileDef.CanWirecutter
|
|| !tileDef.CanWirecutter
|
||||||
|| string.IsNullOrEmpty(tileDef.BaseTurf)
|
|| string.IsNullOrEmpty(tileDef.BaseTurf)
|
||||||
|| _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition newDef
|
|| _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition ||
|
||||||
|| tile.IsBlockedTurf(true))
|
tile.IsBlockedTurf(true))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Content.Shared.Maps;
|
|||||||
using Content.Shared.Tools;
|
using Content.Shared.Tools;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Tools
|
namespace Content.Server.Tools
|
||||||
{
|
{
|
||||||
@@ -21,13 +22,11 @@ namespace Content.Server.Tools
|
|||||||
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
||||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||||
[Dependency] private readonly TurfSystem _turf = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
InitializeTilePrying();
|
|
||||||
InitializeLatticeCutting();
|
InitializeLatticeCutting();
|
||||||
InitializeWelders();
|
InitializeWelders();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Server.Wires;
|
namespace Content.Server.Wires;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinition = default!;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinition = default!;
|
||||||
|
[Dependency] private readonly TileSystem _tiles = default!;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -30,6 +31,8 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
|
|||||||
private void PlaceFloorplanTiles(BlobFloorPlanBuilderComponent comp, MapGridComponent grid)
|
private void PlaceFloorplanTiles(BlobFloorPlanBuilderComponent comp, MapGridComponent grid)
|
||||||
{
|
{
|
||||||
// NO MORE THAN TWO ALLOCATIONS THANK YOU VERY MUCH.
|
// 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 spawnPoints = new HashSet<Vector2i>(comp.FloorPlacements * 6);
|
||||||
var taken = new Dictionary<Vector2i, Tile>(comp.FloorPlacements * 5);
|
var taken = new Dictionary<Vector2i, Tile>(comp.FloorPlacements * 5);
|
||||||
|
|
||||||
@@ -56,7 +59,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
|
|||||||
spawnPoints.Add(west);
|
spawnPoints.Add(west);
|
||||||
|
|
||||||
var tileDef = _tileDefinition[_random.Pick(comp.FloorTileset)];
|
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);
|
PlaceTile(Vector2i.Zero);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
|
|||||||
return; // Redundant logic, prolly needs it's own handler for your custom system.
|
return; // Redundant logic, prolly needs it's own handler for your custom system.
|
||||||
|
|
||||||
var placer = Comp<DebrisFeaturePlacerControllerComponent>(component.OwningController);
|
var placer = Comp<DebrisFeaturePlacerControllerComponent>(component.OwningController);
|
||||||
var xform = Transform(uid);
|
var xform = args.Component;
|
||||||
var ownerXform = Transform(component.OwningController);
|
var ownerXform = Transform(component.OwningController);
|
||||||
if (xform.MapUid is null || ownerXform.MapUid is null)
|
if (xform.MapUid is null || ownerXform.MapUid is null)
|
||||||
return; // not our problem
|
return; // not our problem
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using Content.Shared.Tag;
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Shared.Construction.EntitySystems;
|
namespace Content.Shared.Construction.EntitySystems;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
@@ -107,6 +108,18 @@ namespace Content.Shared.Decals
|
|||||||
{
|
{
|
||||||
// used by client-side overlay code
|
// 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
|
// TODO: Pretty sure paul was moving this somewhere but just so people know
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Server.Decals;
|
|
||||||
using Content.Shared.Coordinates.Helpers;
|
using Content.Shared.Coordinates.Helpers;
|
||||||
using Content.Shared.Decals;
|
using Content.Shared.Decals;
|
||||||
using Content.Shared.Maps;
|
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Maps;
|
namespace Content.Shared.Maps;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles server-side tile manipulation like prying/deconstructing tiles.
|
/// Handles server-side tile manipulation like prying/deconstructing tiles.
|
||||||
@@ -15,15 +15,39 @@ namespace Content.Server.Maps;
|
|||||||
public sealed class TileSystem : EntitySystem
|
public sealed class TileSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = 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!;
|
[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)
|
public bool PryTile(Vector2i indices, EntityUid gridId)
|
||||||
{
|
{
|
||||||
var grid = _mapManager.GetGrid(gridId);
|
var grid = Comp<MapGridComponent>(gridId);
|
||||||
var tileRef = grid.GetTileRef(indices);
|
var tileRef = _maps.GetTileRef(gridId, grid, indices);
|
||||||
return PryTile(tileRef);
|
return PryTile(tileRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,16 +95,20 @@ public sealed class TileSystem : EntitySystem
|
|||||||
|
|
||||||
public bool ReplaceTile(TileRef tileref, ContentTileDefinition replacementTile, EntityUid grid, MapGridComponent? component = null)
|
public bool ReplaceTile(TileRef tileref, ContentTileDefinition replacementTile, EntityUid grid, MapGridComponent? component = null)
|
||||||
{
|
{
|
||||||
|
DebugTools.Assert(tileref.GridUid == grid);
|
||||||
|
|
||||||
if (!Resolve(grid, ref component))
|
if (!Resolve(grid, ref component))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var variant = replacementTile.PickVariant();
|
|
||||||
|
var variant = PickVariant(replacementTile);
|
||||||
var decals = _decal.GetDecalsInRange(tileref.GridUid, _turf.GetTileCenter(tileref).Position, 0.5f);
|
var decals = _decal.GetDecalsInRange(tileref.GridUid, _turf.GetTileCenter(tileref).Position, 0.5f);
|
||||||
foreach (var (id, _) in decals)
|
foreach (var (id, _) in decals)
|
||||||
{
|
{
|
||||||
_decal.RemoveDecal(tileref.GridUid, id);
|
_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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +122,13 @@ public sealed class TileSystem : EntitySystem
|
|||||||
if (string.IsNullOrEmpty(tileDef.BaseTurf))
|
if (string.IsNullOrEmpty(tileDef.BaseTurf))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var mapGrid = _mapManager.GetGrid(tileRef.GridUid);
|
var gridUid = tileRef.GridUid;
|
||||||
|
var mapGrid = Comp<MapGridComponent>(gridUid);
|
||||||
|
|
||||||
const float margin = 0.1f;
|
const float margin = 0.1f;
|
||||||
var bounds = mapGrid.TileSize - margin * 2;
|
var bounds = mapGrid.TileSize - margin * 2;
|
||||||
var indices = tileRef.GridIndices;
|
var indices = tileRef.GridIndices;
|
||||||
var coordinates = mapGrid.GridTileToLocal(indices)
|
var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, indices)
|
||||||
.Offset(new Vector2(
|
.Offset(new Vector2(
|
||||||
(_robustRandom.NextFloat() - 0.5f) * bounds,
|
(_robustRandom.NextFloat() - 0.5f) * bounds,
|
||||||
(_robustRandom.NextFloat() - 0.5f) * bounds));
|
(_robustRandom.NextFloat() - 0.5f) * bounds));
|
||||||
@@ -109,15 +138,14 @@ public sealed class TileSystem : EntitySystem
|
|||||||
Transform(tileItem).LocalRotation = _robustRandom.NextDouble() * Math.Tau;
|
Transform(tileItem).LocalRotation = _robustRandom.NextDouble() * Math.Tau;
|
||||||
|
|
||||||
// Destroy any decals on the tile
|
// 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)
|
foreach (var (id, _) in decals)
|
||||||
{
|
{
|
||||||
_decal.RemoveDecal(tileRef.GridUid, id);
|
_decal.RemoveDecal(tileRef.GridUid, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
var plating = _tileDefinitionManager[tileDef.BaseTurf];
|
var plating = _tileDefinitionManager[tileDef.BaseTurf];
|
||||||
|
_maps.SetTile(gridUid, mapGrid, tileRef.GridIndices, new Tile(plating.TileId));
|
||||||
mapGrid.SetTile(tileRef.GridIndices, new Tile(plating.TileId));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -86,30 +86,6 @@ namespace Content.Shared.Maps
|
|||||||
return tile.Tile.IsSpace(tileDefinitionManager);
|
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>
|
/// <summary>
|
||||||
/// Helper that returns all entities in a turf.
|
/// Helper that returns all entities in a turf.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using Robust.Shared.Network;
|
|||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||||
|
|
||||||
namespace Content.Shared.Radio.EntitySystems;
|
namespace Content.Shared.Radio.EntitySystems;
|
||||||
|
|
||||||
|
|||||||
26
Content.Shared/Tools/Components/TilePryingComponent.cs
Normal file
26
Content.Shared/Tools/Components/TilePryingComponent.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Tools.Components;
|
|
||||||
using Content.Shared.Prying.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
|
public abstract partial class SharedToolSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
using Content.Server.Tools.Components;
|
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Fluids.Components;
|
using Content.Shared.Fluids.Components;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Tools.Components;
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Shared.Map;
|
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()
|
private void InitializeTilePrying()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
|
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
|
||||||
@@ -20,7 +18,8 @@ public sealed partial class ToolSystem
|
|||||||
|
|
||||||
private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
|
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))
|
if (TryPryTile(uid, args.User, component, args.ClickLocation))
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
@@ -33,26 +32,28 @@ public sealed partial class ToolSystem
|
|||||||
|
|
||||||
var coords = GetCoordinates(args.Coordinates);
|
var coords = GetCoordinates(args.Coordinates);
|
||||||
var gridUid = coords.GetGridUid(EntityManager);
|
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?");
|
Log.Error("Attempted to pry from a non-existent grid?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tile = grid.GetTileRef(coords);
|
var tile = _maps.GetTileRef(gridUid.Value, grid, coords);
|
||||||
var center = _turf.GetTileCenter(tile);
|
var center = _turfs.GetTileCenter(tile);
|
||||||
|
|
||||||
if (args.Used != null)
|
if (args.Used != null)
|
||||||
{
|
{
|
||||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
_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
|
else
|
||||||
{
|
{
|
||||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
_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)
|
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
|
||||||
@@ -60,17 +61,16 @@ public sealed partial class ToolSystem
|
|||||||
if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
|
if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
var tile = mapGrid.GetTileRef(clickLocation);
|
var tile = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
|
||||||
|
var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tile.GridIndices);
|
||||||
|
|
||||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||||
|
|
||||||
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
var tileDef = (ContentTileDefinition) _tileDefManager[tile.Tile.TypeId];
|
||||||
|
|
||||||
if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
|
if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
|
||||||
return false;
|
return false;
|
||||||
@@ -1,22 +1,35 @@
|
|||||||
|
using Content.Shared.Administration.Logs;
|
||||||
using Content.Shared.DoAfter;
|
using Content.Shared.DoAfter;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Tools.Components;
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Tools;
|
namespace Content.Shared.Tools.Systems;
|
||||||
|
|
||||||
public abstract partial class SharedToolSystem : EntitySystem
|
public abstract partial class SharedToolSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
[Dependency] private readonly INetManager _netManager = default!;
|
||||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = 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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
InitializeMultipleTool();
|
InitializeMultipleTool();
|
||||||
|
InitializeTilePrying();
|
||||||
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
|
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user