mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Remove Shared System IPrototypeManager instances * Remove RecipeManager IPrototypeManager instance * Fix ItemSystem IPrototypeManager refs, use TryComp * SharedItemSystem changes, EntWhitelist CompName * HasComponent->HasComp
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Shared.Tiles;
|
|
|
|
public sealed partial class ReplaceFloorOnSpawnSystem : EntitySystem
|
|
{
|
|
[Dependency] private ITileDefinitionManager _tile = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private SharedMapSystem _map = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<ReplaceFloorOnSpawnComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(Entity<ReplaceFloorOnSpawnComponent> ent, ref MapInitEvent args)
|
|
{
|
|
var xform = Transform(ent);
|
|
if (xform.GridUid is not { } grid || !TryComp<MapGridComponent>(grid, out var gridComp))
|
|
return;
|
|
|
|
if (ent.Comp.ReplaceableTiles != null && ent.Comp.ReplaceableTiles.Count == 0)
|
|
return;
|
|
|
|
var tileIndices = _map.LocalToTile(grid, gridComp, xform.Coordinates);
|
|
|
|
foreach (var offset in ent.Comp.Offsets)
|
|
{
|
|
var actualIndices = tileIndices + offset;
|
|
|
|
if (!_map.TryGetTileRef(grid, gridComp, actualIndices, out var tile))
|
|
continue;
|
|
|
|
if (ent.Comp.ReplaceableTiles != null &&
|
|
!tile.Tile.IsEmpty &&
|
|
!ent.Comp.ReplaceableTiles.Contains(_tile[tile.Tile.TypeId].ID))
|
|
continue;
|
|
|
|
var tileToSet = _random.Pick(ent.Comp.ReplacementTiles);
|
|
_map.SetTile(grid, gridComp, tile.GridIndices, new Tile(ProtoMan.Index(tileToSet).TileId));
|
|
}
|
|
}
|
|
}
|