* Add test that puts all components on an entity and checks for no exceptions Also fix all the exceptions that happened because of this * Add comments to the test * Fix nullable errors * Fix more nullable errors * More nullable error fixes * Unignore basic actor component * Fix more nullable errors * NULLABLE ERROR * Add string interpolation * Merge if checks * Remove redundant pragma warning disable 649 * Address reviews * Remove null wrappers around TryGetComponent * Merge conflict fixes * APC battery component error fix * Fix power test * Fix atmos mapgrid usages
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using Content.Server.GameObjects.Components.Stack;
|
|
using Content.Server.Utility;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Content.Shared.Maps;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Content.Server.GameObjects.Components.Items
|
|
{
|
|
[RegisterComponent]
|
|
public class FloorTileItemComponent : Component, IAfterInteract
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
|
[Dependency] private readonly IMapManager _mapManager;
|
|
#pragma warning restore 649
|
|
|
|
public override string Name => "FloorTile";
|
|
private string _outputTile;
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _outputTile, "output", "floor_steel");
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
Owner.EnsureComponent<StackComponent>();
|
|
}
|
|
|
|
public void AfterInteract(AfterInteractEventArgs eventArgs)
|
|
{
|
|
if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return;
|
|
if (!Owner.TryGetComponent(out StackComponent stack)) return;
|
|
|
|
var attacked = eventArgs.Target;
|
|
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID);
|
|
var tile = mapGrid.GetTileRef(eventArgs.ClickLocation);
|
|
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
if (tileDef.IsSubFloor && attacked == null && stack.Use(1))
|
|
{
|
|
var desiredTile = _tileDefinitionManager[_outputTile];
|
|
mapGrid.SetTile(eventArgs.ClickLocation, new Tile(desiredTile.TileId));
|
|
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Items/genhit.ogg", eventArgs.ClickLocation);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|