diff --git a/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs new file mode 100644 index 0000000000..cc8a8d674a --- /dev/null +++ b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs @@ -0,0 +1,68 @@ +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.GameObjects.Components.Interactable; +using Content.Shared.Maps; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.Interfaces.Random; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization; + +namespace Content.Server.GameObjects.Components.Interactable +{ + [RegisterComponent] + public class TilePryingComponent : Component, IAfterAttack + { +#pragma warning disable 649 + [Dependency] private IEntitySystemManager _entitySystemManager; + [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; + [Dependency] private readonly IMapManager _mapManager; + [Dependency] private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IRobustRandom _robustRandom; +#pragma warning restore 649 + + public override string Name => "TilePrying"; + private bool _toolComponentNeeded = true; + + public void AfterAttack(AfterAttackEventArgs eventArgs) + { + TryPryTile(eventArgs.User, eventArgs.ClickLocation); + } + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + serializer.DataField(ref _toolComponentNeeded, "toolComponentNeeded", true); + } + + public void TryPryTile(IEntity user, GridCoordinates clickLocation) + { + if (!Owner.TryGetComponent(out var tool) && _toolComponentNeeded) + return; + + var mapGrid = _mapManager.GetGrid(clickLocation.GridID); + var tile = mapGrid.GetTileRef(clickLocation); + + var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); + + if (!_entitySystemManager.GetEntitySystem().InRangeUnobstructed(user.Transform.MapPosition, coordinates.ToMapPos(_mapManager), ignoredEnt:user)) + return; + + var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; + + if (!tileDef.CanCrowbar) return; + + if (_toolComponentNeeded && !tool.UseTool(user, null, ToolQuality.Prying)) + return; + + var underplating = _tileDefinitionManager["underplating"]; + mapGrid.SetTile(clickLocation, new Tile(underplating.TileId)); + + //Actually spawn the relevant tile item at the right position and give it some offset to the corner. + var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates); + tileItem.Transform.WorldPosition += (0.2f, 0.2f); + } + } +} diff --git a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs index 408b100466..817aa3f9e1 100644 --- a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs @@ -33,7 +33,7 @@ using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Interactable { [RegisterComponent] - public class ToolComponent : SharedToolComponent, IAfterAttack + public class ToolComponent : SharedToolComponent { #pragma warning disable 649 [Dependency] private IEntitySystemManager _entitySystemManager; @@ -140,47 +140,15 @@ namespace Content.Server.GameObjects.Components.Interactable var soundCollection = _prototypeManager.Index(name); var file = _robustRandom.Pick(soundCollection.PickFiles); _entitySystemManager.GetEntitySystem() - .Play(file, Owner, AudioParams.Default.WithVolume(volume)); + .Play(file, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume)); } - public void PlayUseSound() + public void PlayUseSound(float volume=-5f) { if(string.IsNullOrEmpty(UseSoundCollection)) - _audioSystem.Play(UseSound, Owner); + _audioSystem.Play(UseSound, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume)); else - PlaySoundCollection(UseSoundCollection, 0f); - } - - public void AfterAttack(AfterAttackEventArgs eventArgs) - { - TryPryTile(eventArgs.User, eventArgs.ClickLocation); - } - - public bool TryPryTile(IEntity user, GridCoordinates clickLocation) - { - if (!HasQuality(ToolQuality.Prying)) - return false; - - var mapGrid = _mapManager.GetGrid(clickLocation.GridID); - var tile = mapGrid.GetTileRef(clickLocation); - - var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); - - if (!_interactionSystem.InRangeUnobstructed(user.Transform.MapPosition, coordinates.ToMapPos(_mapManager), ignoredEnt:user)) - return false; - - var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; - - if (!tileDef.CanCrowbar) return false; - - var underplating = _tileDefinitionManager["underplating"]; - mapGrid.SetTile(clickLocation, new Tile(underplating.TileId)); - PlayUseSound(); - - //Actually spawn the relevant tile item at the right position and give it some offset to the corner. - var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates); - tileItem.Transform.WorldPosition += (0.2f, 0.2f); - return true; + PlaySoundCollection(UseSoundCollection, volume); } } } diff --git a/Resources/Prototypes/Entities/Items/tools.yml b/Resources/Prototypes/Entities/Items/tools.yml index 025d4f573a..89795b07e7 100644 --- a/Resources/Prototypes/Entities/Items/tools.yml +++ b/Resources/Prototypes/Entities/Items/tools.yml @@ -98,6 +98,7 @@ qualities: - Prying useSound: /Audio/items/crowbar.ogg + - type: TilePrying - type: entity name: Multitool @@ -131,6 +132,7 @@ state: jaws_pry - type: Item sprite: Objects/Tools/jaws_of_life.rsi + - type: TilePrying - type: Tool qualities: - Prying