diff --git a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs new file mode 100644 index 0000000000..fa1b3357a8 --- /dev/null +++ b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs @@ -0,0 +1,144 @@ +// Only unused on .NET Core due to KeyValuePair.Deconstruct +// ReSharper disable once RedundantUsingDirective + +using Content.Server.GameObjects.Components.Chemistry; +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.Maps; +using Robust.Server.GameObjects.EntitySystems; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Serialization; +using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; + +namespace Content.Server.GameObjects.Components.Interactable +{ + public enum Tool : byte + { + Wrench, + Crowbar, + Screwdriver, + Wirecutters, + Welder, + Multitool, + } + + public abstract class ToolComponent : Component, IExamine, IAfterAttack + { +#pragma warning disable 649 + [Dependency] private IEntitySystemManager _entitySystemManager; + [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; + [Dependency] private readonly IMapManager _mapManager; +#pragma warning restore 649 + + private AudioSystem _audioSystem; + private InteractionSystem _interactionSystem; + private SolutionComponent + + private Tool _behavior; + private bool _activated = false; + + public override string Name => "Tool"; + + public Tool Behavior + { + get => _behavior; + set => _behavior = value; + } + + public override void Initialize() + { + base.Initialize(); + + _audioSystem = _entitySystemManager.GetEntitySystem(); + _interactionSystem = _entitySystemManager.GetEntitySystem(); + } + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + + serializer.DataField(ref _behavior, "behavior", Tool.Wrench); + serializer.DataField(ref _speedModifier, "Speed", 1); + } + + public void Examine(FormattedMessage message) + { + throw new System.NotImplementedException(); + } + + /// + /// For tool interactions that have a delay before action this will modify the rate, time to wait is divided by this value + /// + [ViewVariables(VVAccess.ReadWrite)] + public float SpeedModifier + { + get => _speedModifier; + set => _speedModifier = value; + } + private float _speedModifier = 1; + + /// + /// Status modifier which determines whether or not we can act as a tool at this time + /// + /// + public virtual bool CanUse() + { + if (_behavior != Tool.Welder) + return true; + } + + /// + /// Default Cost of using the welder fuel for an action + /// + public const float DefaultFuelCost = 5; + + /// + /// Rate at which we expunge fuel from ourselves when activated + /// + public const float FuelLossRate = 0.2f; + + /// + /// Status of welder, whether it is ignited + /// + [ViewVariables] + public bool Activated + { + get => _activated; + private set + { + _activated = value; + Dirty(); + } + } + + public void AfterAttack(AfterAttackEventArgs eventArgs) + { + if (Behavior != Tool.Crowbar) + return; + + var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); + var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); + + var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); + + if (!_interactionSystem.InRangeUnobstructed(eventArgs.User.Transform.MapPosition, coordinates.ToMapPos(_mapManager), ignoredEnt:eventArgs.User)) + return; + + var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; + + if (!tileDef.CanCrowbar) return; + + var underplating = _tileDefinitionManager["underplating"]; + mapGrid.SetTile(eventArgs.ClickLocation, new Tile(underplating.TileId)); + _audioSystem.Play("/Audio/items/crowbar.ogg", Owner); + + //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/Tools/BaseTool.cs b/Content.Server/GameObjects/Components/Interactable/Tools/BaseTool.cs deleted file mode 100644 index b95e91a537..0000000000 --- a/Content.Server/GameObjects/Components/Interactable/Tools/BaseTool.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Only unused on .NET Core due to KeyValuePair.Deconstruct -// ReSharper disable once RedundantUsingDirective -using Robust.Shared.Utility; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; -using Robust.Shared.ViewVariables; - -namespace Content.Server.GameObjects.Components.Interactable.Tools -{ - public abstract class ToolComponent : Component - { - /// - /// For tool interactions that have a delay before action this will modify the rate, time to wait is divided by this value - /// - [ViewVariables(VVAccess.ReadWrite)] - public float SpeedModifier - { - get => _speedModifier; - set => _speedModifier = value; - } - private float _speedModifier = 1; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _speedModifier, "Speed", 1); - } - - /// - /// Status modifier which determines whether or not we can act as a tool at this time - /// - /// - public virtual bool CanUse() - { - return true; - } - } -} diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs index 8d052c9680..593759413a 100644 --- a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs @@ -13,9 +13,7 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools public class CrowbarComponent : ToolComponent, IAfterAttack { #pragma warning disable 649 - [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; - [Dependency] private readonly IEntitySystemManager _entitySystemManager; - [Dependency] private readonly IMapManager _mapManager; + #pragma warning restore 649 /// @@ -25,27 +23,7 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools public void AfterAttack(AfterAttackEventArgs eventArgs) { - var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); - var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); - var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); - float distance = coordinates.Distance(_mapManager, Owner.Transform.GridPosition); - - if (distance > InteractionSystem.InteractionRange) - { - return; - } - - var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; - if (tileDef.CanCrowbar) - { - var underplating = _tileDefinitionManager["underplating"]; - mapGrid.SetTile(eventArgs.ClickLocation, new Tile(underplating.TileId)); - _entitySystemManager.GetEntitySystem().Play("/Audio/items/crowbar.ogg", Owner); - //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/Tools/MultitoolComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/MultitoolComponent.cs deleted file mode 100644 index 7493374f57..0000000000 --- a/Content.Server/GameObjects/Components/Interactable/Tools/MultitoolComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Server.GameObjects.Components.Interactable.Tools -{ - /// - /// Tool used for interfacing/hacking into configurable computers - /// - [RegisterComponent] - public class MultitoolComponent : ToolComponent - { - public override string Name => "Multitool"; - } -} diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/ScrewdriverComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/ScrewdriverComponent.cs deleted file mode 100644 index 8f69c1b2c7..0000000000 --- a/Content.Server/GameObjects/Components/Interactable/Tools/ScrewdriverComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Server.GameObjects.Components.Interactable.Tools -{ - [RegisterComponent] - public class ScrewdriverComponent : ToolComponent - { - /// - /// Tool that interacts with technical components that need to be screwed in - /// - public override string Name => "Screwdriver"; - } -} diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/WirecutterComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/WirecutterComponent.cs deleted file mode 100644 index bc7568c381..0000000000 --- a/Content.Server/GameObjects/Components/Interactable/Tools/WirecutterComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Server.GameObjects.Components.Interactable.Tools -{ - /// - /// Tool that can be used for some cutting interactions such as wires or hacking - /// - [RegisterComponent] - public class WirecutterComponent : ToolComponent - { - public override string Name => "Wirecutter"; - } -} diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/WrenchComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/WrenchComponent.cs deleted file mode 100644 index 8bb24680d9..0000000000 --- a/Content.Server/GameObjects/Components/Interactable/Tools/WrenchComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Robust.Shared.GameObjects; - -namespace Content.Server.GameObjects.Components.Interactable.Tools -{ - /// - /// Wrenches bolts, and interacts with things that have been bolted - /// - [RegisterComponent] - public class WrenchComponent : ToolComponent - { - public override string Name => "Wrench"; - } -} diff --git a/Content.Server/GameObjects/EntitySystems/ToolSystem.cs b/Content.Server/GameObjects/EntitySystems/ToolSystem.cs new file mode 100644 index 0000000000..6d46fd5155 --- /dev/null +++ b/Content.Server/GameObjects/EntitySystems/ToolSystem.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using Content.Server.GameObjects.Components.Interactable; +using Content.Server.GameObjects.Components.Interactable.Tools; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; + +namespace Content.Server.GameObjects.EntitySystems +{ + /// + /// Despite the name, it's only really used for the welder logic in tools. Go figure. + /// + public class ToolSystem : EntitySystem + { + private readonly HashSet _activeWelders = new HashSet(); + + public override void Update(float frameTime) + { + foreach (var tool in _activeWelders) ; + } + } +} diff --git a/Content.Server/GameObjects/EntitySystems/WelderSystem.cs b/Content.Server/GameObjects/EntitySystems/WelderSystem.cs deleted file mode 100644 index fa1c54c7fa..0000000000 --- a/Content.Server/GameObjects/EntitySystems/WelderSystem.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Content.Server.GameObjects.Components.Interactable.Tools; -using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Systems; - -namespace Content.Server.GameObjects.EntitySystems -{ - class WelderSystem : EntitySystem - { - public override void Initialize() - { - EntityQuery = new TypeEntityQuery(typeof(WelderComponent)); - } - - public override void Update(float frameTime) - { - foreach (var entity in RelevantEntities) - { - var comp = entity.GetComponent(); - comp.OnUpdate(frameTime); - } - } - } -} diff --git a/Content.Shared/Audio/SoundCollectionPrototype.cs b/Content.Shared/Audio/SoundCollectionPrototype.cs index 9a0c79e77c..e4918bf518 100644 --- a/Content.Shared/Audio/SoundCollectionPrototype.cs +++ b/Content.Shared/Audio/SoundCollectionPrototype.cs @@ -5,7 +5,7 @@ using YamlDotNet.RepresentationModel; namespace Content.Shared.Audio { - [Prototype("sound_collection")] + [Prototype("soundCollection")] public sealed class SoundCollectionPrototype : IPrototype, IIndexedPrototype { public string ID { get; private set; } diff --git a/Resources/Prototypes/Entities/Items/tools.yml b/Resources/Prototypes/Entities/Items/tools.yml index 78726f8f28..a057ee819a 100644 --- a/Resources/Prototypes/Entities/Items/tools.yml +++ b/Resources/Prototypes/Entities/Items/tools.yml @@ -4,13 +4,14 @@ id: Wirecutter description: This kills the wire. components: - - type: Wirecutter - type: Sprite texture: Objects/Tools/wirecutter.png - type: Icon texture: Objects/Tools/wirecutter.png - type: ItemCooldown - type: MeleeWeapon + - type: Tool + behavior: enum.Tool.Wirecutter - type: entity name: Screwdriver @@ -18,20 +19,18 @@ id: Screwdriver description: Industrial grade torque in a small screwdriving package components: - - type: Screwdriver - type: Sprite sprite: Objects/Tools/screwdriver.rsi state: screwdriver - - type: Icon sprite: Objects/Tools/screwdriver.rsi state: screwdriver - - type: Item sprite: Objects/Tools/screwdriver.rsi - - type: ItemCooldown - type: MeleeWeapon + - type: Tool + behavior: enum.Tool.Screwdriver - type: entity name: Welding Tool @@ -39,7 +38,6 @@ id: Welder description: Melts anything as long as it's fueled, don't forget your eye protection! components: - - type: Welder - type: Sprite sprite: Objects/Tools/welder.rsi layers: @@ -47,13 +45,14 @@ - state: welder_flame shader: unshaded visible: false - - type: Icon sprite: Objects/Tools/welder.rsi state: welder - type: ItemCooldown - type: MeleeWeapon - type: ItemStatus + - type: Tool + behavior: enum.Tool.Screwdriver - type: entity name: Wrench @@ -61,24 +60,14 @@ id: Wrench description: A common tool for assembly and disassembly, righty tighty lefty loosey components: - - type: Wrench - type: Sprite texture: Objects/Tools/wrench.png - type: Icon texture: Objects/Tools/wrench.png - type: ItemCooldown - type: MeleeWeapon - -- type: sound_collection - id: welder_on - files: - - /Audio/items/lighter1.ogg - - /Audio/items/lighter2.ogg - -- type: sound_collection - id: welder_off - files: - - /Audio/effects/zzzt.ogg + - type: Tool + behavior: enum.Tool.Wrench - type: entity name: Crowbar @@ -86,13 +75,14 @@ id: Crowbar description: A multipurpose tool to pry open doors and fight interdimensional invaders components: - - type: Crowbar - type: Sprite texture: Objects/Tools/crowbar.png - type: Icon texture: Objects/Tools/crowbar.png - type: ItemCooldown - type: MeleeWeapon + - type: Tool + behavior: enum.Tool.Crowbar - type: entity name: Multitool @@ -100,14 +90,13 @@ id: Multitool description: An advanced tool to copy, store, and send electrical pulses and signals through wires and machines components: - - type: Multitool - type: Sprite sprite: Objects/Tools/multitool.rsi state: multitool - - type: Icon sprite: Objects/Tools/multitool.rsi state: multitool - - type: Item sprite: Objects/Tools/multitool.rsi + - type: Tool + behavior: enum.Tool.Multitool diff --git a/Resources/Prototypes/SoundCollections/dice.yml b/Resources/Prototypes/SoundCollections/dice.yml index 7e2527c08a..d4e195b413 100644 --- a/Resources/Prototypes/SoundCollections/dice.yml +++ b/Resources/Prototypes/SoundCollections/dice.yml @@ -1,4 +1,4 @@ -- type: sound_collection +- type: soundCollection id: dice files: - /Audio/items/dice/dice1.ogg @@ -7,4 +7,4 @@ - /Audio/items/dice/dice4.ogg - /Audio/items/dice/dice5.ogg - /Audio/items/dice/dice6.ogg - - /Audio/items/dice/dice7.ogg \ No newline at end of file + - /Audio/items/dice/dice7.ogg diff --git a/Resources/Prototypes/SoundCollections/footsteps.yml b/Resources/Prototypes/SoundCollections/footsteps.yml index d84481345c..2bd9e15045 100644 --- a/Resources/Prototypes/SoundCollections/footsteps.yml +++ b/Resources/Prototypes/SoundCollections/footsteps.yml @@ -1,4 +1,4 @@ -- type: sound_collection +- type: soundCollection id: footstep_carpet files: - /Audio/effects/footsteps/carpet1.ogg @@ -7,7 +7,7 @@ - /Audio/effects/footsteps/carpet4.ogg - /Audio/effects/footsteps/carpet5.ogg -- type: sound_collection +- type: soundCollection id: footstep_wood files: - /Audio/effects/footsteps/wood1.ogg @@ -16,7 +16,7 @@ - /Audio/effects/footsteps/wood4.ogg - /Audio/effects/footsteps/wood5.ogg -- type: sound_collection +- type: soundCollection id: footstep_catwalk files: - /Audio/effects/footsteps/catwalk1.ogg @@ -25,7 +25,7 @@ - /Audio/effects/footsteps/catwalk4.ogg - /Audio/effects/footsteps/catwalk5.ogg -- type: sound_collection +- type: soundCollection id: footstep_floor files: - /Audio/effects/footsteps/floor1.ogg @@ -34,7 +34,7 @@ - /Audio/effects/footsteps/floor4.ogg - /Audio/effects/footsteps/floor5.ogg -- type: sound_collection +- type: soundCollection id: footstep_hull files: - /Audio/effects/footsteps/hull1.ogg @@ -43,7 +43,7 @@ - /Audio/effects/footsteps/hull4.ogg - /Audio/effects/footsteps/hull5.ogg -- type: sound_collection +- type: soundCollection id: footstep_plating files: - /Audio/effects/footsteps/plating1.ogg @@ -52,7 +52,7 @@ - /Audio/effects/footsteps/plating4.ogg - /Audio/effects/footsteps/plating5.ogg -- type: sound_collection +- type: soundCollection id: footstep_tile files: - /Audio/effects/footsteps/tile1.ogg @@ -61,19 +61,19 @@ - /Audio/effects/footsteps/tile4.ogg - /Audio/effects/footsteps/tile5.ogg -- type: sound_collection +- type: soundCollection id: footstep_clown files: - /Audio/effects/footsteps/clownstep1.ogg - /Audio/effects/footsteps/clownstep2.ogg -- type: sound_collection +- type: soundCollection id: footstep_heavy files: - /Audio/effects/footsteps/suitstep1.ogg - /Audio/effects/footsteps/suitstep2.ogg -- type: sound_collection +- type: soundCollection id: footstep_asteroid files: - /Audio/effects/footsteps/asteroid1.ogg diff --git a/Resources/Prototypes/SoundCollections/glassbreak.yml b/Resources/Prototypes/SoundCollections/glassbreak.yml index ee3d9278bb..30bf2928e3 100644 --- a/Resources/Prototypes/SoundCollections/glassbreak.yml +++ b/Resources/Prototypes/SoundCollections/glassbreak.yml @@ -1,4 +1,4 @@ -- type: sound_collection +- type: soundCollection id: glassbreak files: - /Audio/effects/glassbreak1.ogg diff --git a/Resources/Prototypes/SoundCollections/keyboard.yml b/Resources/Prototypes/SoundCollections/keyboard.yml index 30a0c7712d..ec26a28eb9 100644 --- a/Resources/Prototypes/SoundCollections/keyboard.yml +++ b/Resources/Prototypes/SoundCollections/keyboard.yml @@ -1,8 +1,7 @@ -- type: sound_collection +- type: soundCollection id: keyboard files: - /Audio/machines/keyboard/keyboard1.ogg - /Audio/machines/keyboard/keyboard2.ogg - /Audio/machines/keyboard/keyboard3.ogg - /Audio/machines/keyboard/keyboard4.ogg - \ No newline at end of file diff --git a/Resources/Prototypes/SoundCollections/tools.yml b/Resources/Prototypes/SoundCollections/tools.yml new file mode 100644 index 0000000000..5be73b3aed --- /dev/null +++ b/Resources/Prototypes/SoundCollections/tools.yml @@ -0,0 +1,10 @@ +- type: soundCollection + id: WelderOn + files: + - /Audio/items/lighter1.ogg + - /Audio/items/lighter2.ogg + +- type: soundCollection + id: WelderOff + files: + - /Audio/effects/zzzt.ogg diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index 7853887435..3497a17c82 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -55,4 +55,5 @@ True True True - True + True + True