diff --git a/Content.Client/Construction/ConstructionMenu.cs b/Content.Client/Construction/ConstructionMenu.cs index af374ca281..d8c6a87b91 100644 --- a/Content.Client/Construction/ConstructionMenu.cs +++ b/Content.Client/Construction/ConstructionMenu.cs @@ -181,27 +181,27 @@ namespace Content.Client.Construction break; case ConstructionStepTool tool: - switch (tool.Tool) + switch (tool.ToolQuality) { - case Tool.Wrench: + case ToolQuality.Anchoring: icon = ResourceCache.GetResource("/Textures/Objects/Tools/wrench.png"); text = "Wrench"; break; - case Tool.Crowbar: + case ToolQuality.Prying: icon = ResourceCache.GetResource("/Textures/Objects/Tools/crowbar.png"); text = "Crowbar"; break; - case Tool.Screwdriver: + case ToolQuality.Screwing: icon = ResourceCache.GetResource( "/Textures/Objects/Tools/screwdriver.png"); text = "Screwdriver"; break; - case Tool.Welder: + case ToolQuality.Welding: icon = ResourceCache.GetResource("/Textures/Objects/tools.rsi") .RSI["welder"].Frame0; text = $"Welding tool ({tool.Amount} fuel)"; break; - case Tool.Wirecutter: + case ToolQuality.Cutting: icon = ResourceCache.GetResource( "/Textures/Objects/Tools/wirecutter.png"); text = "Wirecutters"; diff --git a/Content.Client/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs similarity index 77% rename from Content.Client/GameObjects/Components/Interactable/ToolComponent.cs rename to Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs index b213644d49..5eb67e8113 100644 --- a/Content.Client/GameObjects/Components/Interactable/ToolComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs @@ -1,6 +1,7 @@ using System; using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; +using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Interactable; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -13,26 +14,29 @@ using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Interactable { [RegisterComponent] - public class ToolComponent : SharedToolComponent, IItemStatus + public class MultiToolComponent : Component, IItemStatus { - private Tool _behavior; + private ToolQuality _behavior; private bool _statusShowBehavior; [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables] public bool StatusShowBehavior => _statusShowBehavior; - [ViewVariables] public override Tool Behavior => _behavior; + [ViewVariables] public ToolQuality Behavior => _behavior; + + public override string Name => "MultiTool"; + public override uint? NetID => ContentNetIDs.MULTITOOLS; public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); - serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", false); + serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", true); } public override void HandleComponentState(ComponentState curState, ComponentState nextState) { - if (!(curState is ToolComponentState tool)) return; + if (!(curState is MultiToolComponentState tool)) return; - _behavior = tool.Behavior; + _behavior = tool.Quality; _uiUpdateNeeded = true; } @@ -41,10 +45,10 @@ namespace Content.Client.GameObjects.Components.Interactable private sealed class StatusControl : Control { - private readonly ToolComponent _parent; + private readonly MultiToolComponent _parent; private readonly RichTextLabel _label; - public StatusControl(ToolComponent parent) + public StatusControl(MultiToolComponent parent) { _parent = parent; _label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}}; diff --git a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs index 98dceeb6b8..5852469bc6 100644 --- a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs @@ -14,18 +14,17 @@ using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Interactable { [RegisterComponent] - [ComponentReference(typeof(ToolComponent))] - public class WelderComponent : ToolComponent, IItemStatus + public class WelderComponent : SharedToolComponent, IItemStatus { public override string Name => "Welder"; public override uint? NetID => ContentNetIDs.WELDER; - private Tool _behavior; + private ToolQuality _behavior; [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables] public float FuelCapacity { get; private set; } [ViewVariables] public float Fuel { get; private set; } [ViewVariables] public bool Activated { get; private set; } - [ViewVariables] public override Tool Behavior => _behavior; + [ViewVariables] public override ToolQuality Qualities => _behavior; public override void ExposeData(ObjectSerializer serializer) { @@ -39,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Interactable FuelCapacity = weld.FuelCapacity; Fuel = weld.Fuel; Activated = weld.Activated; - _behavior = weld.Behavior; + _behavior = weld.Quality; _uiUpdateNeeded = true; } @@ -70,14 +69,11 @@ namespace Content.Client.GameObjects.Components.Interactable _parent._uiUpdateNeeded = false; - if (_parent.Behavior == Tool.Welder) - { - var fuelCap = _parent.FuelCapacity; - var fuel = _parent.Fuel; + var fuelCap = _parent.FuelCapacity; + var fuel = _parent.Fuel; - _label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]", - fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap)); - } + _label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]", + fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap)); } } } diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs index 5afa2fbfd9..114284fbe5 100644 --- a/Content.Server/GameObjects/Components/AnchorableComponent.cs +++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs @@ -10,7 +10,7 @@ using Robust.Shared.IoC; namespace Content.Server.GameObjects.Components { [RegisterComponent] - public class AnchorableComponent : Component, IWrenchAct + public class AnchorableComponent : Component, IAttackBy { public override string Name => "Anchorable"; @@ -20,15 +20,16 @@ namespace Content.Server.GameObjects.Components Owner.EnsureComponent(); } - public bool WrenchAct(WrenchActEventArgs eventArgs) + public bool AttackBy(AttackByEventArgs eventArgs) { - if (!Owner.TryGetComponent(out PhysicsComponent physics)) - { + if (!Owner.TryGetComponent(out PhysicsComponent physics) + || !eventArgs.AttackWith.TryGetComponent(out ToolComponent tool)) + return false; + + if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Anchoring)) return false; - } physics.Anchored = !physics.Anchored; - eventArgs.ToolComponent.PlayUseSound(); return true; } diff --git a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs index 605e37322a..9b07e95258 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Construction var stage = Prototype.Stages[Stage]; - if (TryProcessStep(stage.Forward, eventArgs.AttackWith)) + if (TryProcessStep(stage.Forward, eventArgs.AttackWith, eventArgs.User)) { Stage++; if (Stage == Prototype.Stages.Count - 1) @@ -83,7 +83,7 @@ namespace Content.Server.GameObjects.Components.Construction } } - else if (TryProcessStep(stage.Backward, eventArgs.AttackWith)) + else if (TryProcessStep(stage.Backward, eventArgs.AttackWith, eventArgs.User)) { Stage--; if (Stage == 0) @@ -119,7 +119,7 @@ namespace Content.Server.GameObjects.Components.Construction } - bool TryProcessStep(ConstructionStep step, IEntity slapped) + bool TryProcessStep(ConstructionStep step, IEntity slapped, IEntity user) { if (step == null) { @@ -144,10 +144,13 @@ namespace Content.Server.GameObjects.Components.Construction case ConstructionStepTool toolStep: if (!slapped.TryGetComponent(out var tool)) return false; - if (toolStep.Tool != tool.Behavior) return false; - if (toolStep.Tool == Tool.Welder && !((WelderComponent)tool).TryWeld(toolStep.Amount)) return false; - tool.PlayUseSound(); - return true; + + // Handle welder manually since tool steps specify fuel amount needed, for some reason. + if (toolStep.ToolQuality.HasFlag(ToolQuality.Welding)) + return slapped.TryGetComponent(out var welder) + && welder.UseTool(user, Owner, toolStep.ToolQuality, toolStep.Amount); + + return tool.UseTool(user, Owner, toolStep.ToolQuality); default: throw new NotImplementedException(); diff --git a/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs b/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs index 3e650fd339..59b8b76a7f 100644 --- a/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs +++ b/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs @@ -204,7 +204,7 @@ namespace Content.Server.GameObjects.Components.Doors if (!eventArgs.AttackWith.TryGetComponent(out var tool)) return false; - if (tool.Behavior != Tool.Crowbar) return false; + if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Prying)) return false; if (IsPowered()) { diff --git a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs index 239931435b..b2fcc7b47a 100644 --- a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs @@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Shared.GameObjects.Components.Gravity; +using Content.Shared.GameObjects.Components.Interactable; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; @@ -19,7 +20,7 @@ using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Gravity { [RegisterComponent] - public class GravityGeneratorComponent: SharedGravityGeneratorComponent, IWelderAct, IBreakAct, IAttackHand + public class GravityGeneratorComponent: SharedGravityGeneratorComponent, IAttackBy, IBreakAct, IAttackHand { private BoundUserInterface _userInterface; @@ -98,10 +99,14 @@ namespace Content.Server.GameObjects.Components.Gravity return true; } - public bool WelderAct(WelderActEventArgs eventArgs) + public bool AttackBy(AttackByEventArgs eventArgs) { - var welder = eventArgs.WelderComponent; - if (!welder.TryWeld(5.0f)) return false; + if (!eventArgs.AttackWith.TryGetComponent(out WelderComponent tool)) + return false; + + if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Welding, 5f)) + return false; + // Repair generator var damageable = Owner.GetComponent(); var breakable = Owner.GetComponent(); @@ -116,7 +121,6 @@ namespace Content.Server.GameObjects.Components.Gravity notifyManager.PopupMessage(Owner, eventArgs.User, Loc.GetString("You repair the gravity generator with the welder")); return true; - } public void OnBreak(BreakageEventArgs eventArgs) diff --git a/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs b/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs index 4c9d0c8abd..48d6958997 100644 --- a/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; +using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Interactable; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; @@ -26,7 +27,7 @@ namespace Content.Server.GameObjects.Components.Interactable private string _sprite; private string _changeSound; - public Tool Behavior { get; private set; } + public ToolQuality Behavior { get; private set; } public string State => _state; public string Texture => _texture; public string Sprite => _sprite; @@ -37,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Interactable public void ExposeData(ObjectSerializer serializer) { if(serializer.Reading) - Behavior = (Tool)serializer.ReadStringEnumKey("behavior"); + Behavior = (ToolQuality)serializer.ReadStringEnumKey("behavior"); serializer.DataField(ref _state, "state", string.Empty); serializer.DataField(ref _sprite, "sprite", string.Empty); serializer.DataField(ref _texture, "texture", string.Empty); @@ -52,6 +53,7 @@ namespace Content.Server.GameObjects.Components.Interactable #pragma warning restore 649 public override string Name => "MultiTool"; + public override uint? NetID => ContentNetIDs.MULTITOOLS; private List _tools; private int _currentTool = 0; @@ -87,7 +89,7 @@ namespace Content.Server.GameObjects.Components.Interactable _tool.UseSound = current.Sound; _tool.UseSoundCollection = current.SoundCollection; - _tool.Behavior = current.Behavior; + _tool.Qualities = current.Behavior; if (_sprite == null) return; @@ -98,6 +100,8 @@ namespace Content.Server.GameObjects.Components.Interactable _sprite.LayerSetState(0, current.State); else _sprite.LayerSetTexture(0, current.Texture); + + Dirty(); } public override void ExposeData(ObjectSerializer serializer) @@ -111,5 +115,10 @@ namespace Content.Server.GameObjects.Components.Interactable Cycle(); return true; } + + public override ComponentState GetComponentState() + { + return new MultiToolComponentState(_tool.Qualities); + } } } diff --git a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs index 66f2fb7ca9..b7b9f0db9a 100644 --- a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs @@ -2,6 +2,7 @@ // ReSharper disable once RedundantUsingDirective using System; +using System.Collections.Generic; using System.Linq; using System.Reflection.Metadata.Ecma335; using Content.Server.GameObjects.Components.Chemistry; @@ -46,18 +47,18 @@ namespace Content.Server.GameObjects.Components.Interactable private InteractionSystem _interactionSystem; private SpriteComponent _spriteComponent; - protected Tool _behavior = Tool.Wrench; + protected ToolQuality _qualities = ToolQuality.Anchoring; private string _useSound; private string _useSoundCollection; private float _speedModifier = 1; [ViewVariables] - public override Tool Behavior + public override ToolQuality Qualities { - get => _behavior; + get => _qualities; set { - _behavior = value; + _qualities = value; Dirty(); } } @@ -84,6 +85,23 @@ namespace Content.Server.GameObjects.Components.Interactable set => _useSoundCollection = value; } + public void AddQuality(ToolQuality quality) + { + _qualities |= quality; + Dirty(); + } + + public void RemoveQuality(ToolQuality quality) + { + _qualities &= ~quality; + Dirty(); + } + + public bool HasQuality(ToolQuality quality) + { + return _qualities.HasFlag(quality); + } + public override void Initialize() { base.Initialize(); @@ -99,13 +117,10 @@ namespace Content.Server.GameObjects.Components.Interactable if (serializer.Reading) { - try + var qualities = serializer.ReadDataField("qualities", new List()); + foreach (var quality in qualities) { - _behavior = (Tool)serializer.ReadStringEnumKey("behavior"); - } - catch - { - // ignored + AddQuality(quality); } } serializer.DataField(ref _speedModifier, "speed", 1); @@ -113,22 +128,11 @@ namespace Content.Server.GameObjects.Components.Interactable serializer.DataField(ref _useSoundCollection, "useSoundCollection", string.Empty); } - /// - /// Status modifier which determines whether or not we can act as a tool at this time - /// - public virtual bool CanUse(float resource) + public virtual bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded) { - return true; - } + PlayUseSound(); - /// - /// Method which will try to use the current tool and consume resources/power if applicable. - /// - /// The amount of resource - /// Whether the tool could be used or not. - public virtual bool TryUse(float resource = 0f) - { - return true; + return ActionBlockerSystem.CanInteract(user) && HasQuality(toolQualityNeeded); } protected void PlaySoundCollection(string name, float volume=-5f) @@ -147,17 +151,9 @@ namespace Content.Server.GameObjects.Components.Interactable PlaySoundCollection(UseSoundCollection, 0f); } - public override ComponentState GetComponentState() - { - return new ToolComponentState(Behavior); - } - public void AfterAttack(AfterAttackEventArgs eventArgs) { - if (eventArgs.Attacked != null && RaiseToolAct(eventArgs)) - return; - - if (Behavior != Tool.Crowbar) + if (Qualities != ToolQuality.Prying) return; var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); @@ -180,101 +176,5 @@ namespace Content.Server.GameObjects.Components.Interactable var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates); tileItem.Transform.WorldPosition += (0.2f, 0.2f); } - - private bool RaiseToolAct(AfterAttackEventArgs eventArgs) - { - var attacked = eventArgs.Attacked; - var clickLocation = eventArgs.ClickLocation; - var user = eventArgs.User; - - switch (Behavior) - { - case Tool.Wrench: - var wrenchList = attacked.GetAllComponents().ToList(); - var wrenchAttackBy = new WrenchActEventArgs() - { User = user, ClickLocation = clickLocation, AttackWith = Owner }; - - foreach (var comp in wrenchList) - { - if (comp.WrenchAct(wrenchAttackBy)) - return true; - } - - break; - - case Tool.Crowbar: - var crowbarList = attacked.GetAllComponents().ToList(); - var crowbarAttackBy = new CrowbarActEventArgs() - { User = user, ClickLocation = clickLocation, AttackWith = Owner }; - - foreach (var comp in crowbarList) - { - if (comp.CrowbarAct(crowbarAttackBy)) - return true; - } - - break; - - case Tool.Screwdriver: - var screwdriverList = attacked.GetAllComponents().ToList(); - var screwdriverAttackBy = new ScrewdriverActEventArgs() - { User = user, ClickLocation = clickLocation, AttackWith = Owner }; - - foreach (var comp in screwdriverList) - { - if (comp.ScrewdriverAct(screwdriverAttackBy)) - return true; - } - - break; - - case Tool.Wirecutter: - var wirecutterList = attacked.GetAllComponents().ToList(); - var wirecutterAttackBy = new WirecutterActEventArgs() - { User = user, ClickLocation = clickLocation, AttackWith = Owner }; - - foreach (var comp in wirecutterList) - { - if (comp.WirecutterAct(wirecutterAttackBy)) - return true; - } - break; - - case Tool.Welder: - var welderList = attacked.GetAllComponents().ToList(); - var welder = (WelderComponent) this; - var welderAttackBy = new WelderActEventArgs() - { - User = user, ClickLocation = clickLocation, AttackWith = Owner, - Fuel = welder.Fuel, FuelCapacity = welder.FuelCapacity - }; - - foreach (var comp in welderList) - { - if (comp.WelderAct(welderAttackBy)) - return true; - } - - break; - - case Tool.Multitool: - var multitoolList = attacked.GetAllComponents().ToList(); - var multitoolAttackBy = new MultitoolActEventArgs() - { User = user, ClickLocation = clickLocation, AttackWith = Owner }; - - foreach (var comp in multitoolList) - { - if (comp.MultitoolAct(multitoolAttackBy)) - return true; - } - - break; - - default: - throw new ArgumentOutOfRangeException(); - } - - return false; - } } } diff --git a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs index fa3e4c56b9..561b65917e 100644 --- a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs @@ -21,7 +21,6 @@ namespace Content.Server.GameObjects.Components.Interactable { #pragma warning disable 649 [Dependency] private IEntitySystemManager _entitySystemManager; - [Dependency] private readonly IRobustRandom _robustRandom; #pragma warning restore 649 public override string Name => "Welder"; @@ -38,7 +37,6 @@ namespace Content.Server.GameObjects.Components.Interactable public const float FuelLossRate = 0.5f; private bool _welderLit = false; - private WelderSystem _welderSystem; private SpriteComponent _spriteComponent; private SolutionComponent _solutionComponent; @@ -67,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Interactable { base.Initialize(); - _behavior = Tool.Welder; + AddQuality(ToolQuality.Welding); _welderSystem = _entitySystemManager.GetEntitySystem(); @@ -80,41 +78,40 @@ namespace Content.Server.GameObjects.Components.Interactable return new WelderComponentState(FuelCapacity, Fuel, WelderLit); } - public bool CanUse() + public override bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded) { - return CanWeld(DefaultFuelCost); + var canUse = base.UseTool(user, target, toolQualityNeeded); + + return toolQualityNeeded.HasFlag(ToolQuality.Welding) ? canUse && TryWeld(DefaultFuelCost) : canUse; } - public bool TryUse() + public bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded, float fuelConsumed) { - return TryWeld(DefaultFuelCost); + return base.UseTool(user, target, toolQualityNeeded) && TryWeld(fuelConsumed); } - public bool TryWeld(float value) + private bool TryWeld(float value) { if (!WelderLit || !CanWeld(value) || _solutionComponent == null) - { return false; - } return _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(value)); } - public bool CanWeld(float value) + private bool CanWeld(float value) { - return Fuel > value || Behavior != Tool.Welder; + return Fuel > value || Qualities != ToolQuality.Welding; } - public bool CanLitWelder() + private bool CanLitWelder() { - return Fuel > 0 || Behavior != Tool.Welder; + return Fuel > 0 || Qualities != ToolQuality.Welding; } /// /// Deactivates welding tool if active, activates welding tool if possible /// - /// - public bool ToggleWelderStatus() + private bool ToggleWelderStatus() { if (WelderLit) { @@ -157,17 +154,13 @@ namespace Content.Server.GameObjects.Components.Interactable public void OnUpdate(float frameTime) { - if (Behavior != Tool.Welder || !WelderLit) - { + if (!HasQuality(ToolQuality.Welding) || !WelderLit) return; - } _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); if (Fuel == 0) - { ToggleWelderStatus(); - } Dirty(); } diff --git a/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs b/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs index 9bafecbb2e..8a460c0b30 100644 --- a/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs @@ -142,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Power public bool AttackBy(AttackByEventArgs eventArgs) { if (!eventArgs.AttackWith.TryGetComponent(out ToolComponent tool)) return false; - if (tool.Behavior != Tool.Wirecutter) return false; + if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Cutting)) return false; Owner.Delete(); var droppedEnt = Owner.EntityManager.SpawnEntity("CableStack", eventArgs.ClickLocation); diff --git a/Content.Server/GameObjects/Components/WiresComponent.cs b/Content.Server/GameObjects/Components/WiresComponent.cs index 2495669d73..02ea339b92 100644 --- a/Content.Server/GameObjects/Components/WiresComponent.cs +++ b/Content.Server/GameObjects/Components/WiresComponent.cs @@ -248,7 +248,7 @@ namespace Content.Server.GameObjects.Components switch (msg.Action) { case WiresAction.Cut: - if (tool == null || tool.Behavior != Tool.Wirecutter) + if (tool == null || !tool.HasQuality(ToolQuality.Cutting)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a wirecutter in your hand!")); return; @@ -258,7 +258,7 @@ namespace Content.Server.GameObjects.Components UpdateUserInterface(); break; case WiresAction.Mend: - if (tool == null || tool.Behavior != Tool.Wirecutter) + if (tool == null || !tool.HasQuality(ToolQuality.Cutting)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a wirecutter in your hand!")); return; @@ -268,7 +268,7 @@ namespace Content.Server.GameObjects.Components UpdateUserInterface(); break; case WiresAction.Pulse: - if (tool == null || tool.Behavior != Tool.Multitool) + if (tool == null || !tool.HasQuality(ToolQuality.Multitool)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a multitool in your hand!")); return; @@ -300,13 +300,13 @@ namespace Content.Server.GameObjects.Components { if (!eventArgs.AttackWith.TryGetComponent(out var tool)) return false; - if (tool.Behavior != Tool.Screwdriver) + if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Screwing)) return false; IsPanelOpen = !IsPanelOpen; IoCManager.Resolve() .GetEntitySystem() - .Play(IsPanelOpen ? "/Audio/machines/screwdriveropen.ogg" : "/Audio/machines/screwdriverclose.ogg"); + .Play(IsPanelOpen ? "/Audio/machines/screwdriveropen.ogg" : "/Audio/machines/screwdriverclose.ogg", Owner); return true; } diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 0669575a74..cab0f56f11 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -46,119 +46,6 @@ namespace Content.Server.GameObjects.EntitySystems public IEntity AttackWith { get; set; } } - #region Tools - - public class ToolActEventArgs : EventArgs - { - public IEntity User { get; set; } - public GridCoordinates ClickLocation { get; set; } - public IEntity AttackWith { get; set; } - public ToolComponent ToolComponent => AttackWith.GetComponent(); - public virtual Tool Behavior { get; } - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a wrench in their hand - /// - public interface IWrenchAct - { - /// - /// Called when using a wrench on an entity - /// - bool WrenchAct(WrenchActEventArgs eventArgs); - } - - public class WrenchActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Wrench; - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a crowbar in their hand - /// - public interface ICrowbarAct - { - /// - /// Called when using a wrench on an entity - /// - bool CrowbarAct(CrowbarActEventArgs eventArgs); - } - - public class CrowbarActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Crowbar; - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a screwdriver in their hand - /// - public interface IScrewdriverAct - { - /// - /// Called when using a wrench on an entity - /// - bool ScrewdriverAct(ScrewdriverActEventArgs eventArgs); - } - - public class ScrewdriverActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Screwdriver; - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a wirecutter in their hand - /// - public interface IWirecutterAct - { - /// - /// Called when using a wrench on an entity - /// - bool WirecutterAct(WirecutterActEventArgs eventArgs); - } - - public class WirecutterActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Wirecutter; - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a welder in their hand - /// - public interface IWelderAct - { - /// - /// Called when using a wrench on an entity - /// - bool WelderAct(WelderActEventArgs eventArgs); - } - - public class WelderActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Welder; - public WelderComponent WelderComponent => (WelderComponent)ToolComponent; - public bool Lit { get; set; } - public float Fuel { get; set; } - public float FuelCapacity { get; set; } - } - - /// - /// This interface gives components behavior when being clicked on or "attacked" by a user with a multitool in their hand - /// - public interface IMultitoolAct - { - /// - /// Called when using a wrench on an entity - /// - bool MultitoolAct(MultitoolActEventArgs eventArgs); - } - - public class MultitoolActEventArgs : ToolActEventArgs - { - public override Tool Behavior => Tool.Multitool; - } - - #endregion - /// /// This interface gives components behavior when being clicked on or "attacked" by a user with an empty hand /// diff --git a/Content.Shared/Construction/ConstructionPrototype.cs b/Content.Shared/Construction/ConstructionPrototype.cs index be9f6c1ef3..6b7a83bb25 100644 --- a/Content.Shared/Construction/ConstructionPrototype.cs +++ b/Content.Shared/Construction/ConstructionPrototype.cs @@ -139,7 +139,7 @@ namespace Content.Shared.Construction if (step.TryGetNode("tool", out node)) { return new ConstructionStepTool( - node.AsEnum(), + node.AsEnum(), amount ); } @@ -191,11 +191,11 @@ namespace Content.Shared.Construction public class ConstructionStepTool : ConstructionStep { - public readonly Tool Tool; + public readonly ToolQuality ToolQuality; - public ConstructionStepTool(Tool tool, int amount) : base(amount) + public ConstructionStepTool(ToolQuality toolQuality, int amount) : base(amount) { - Tool = tool; + ToolQuality = toolQuality; } } diff --git a/Content.Shared/GameObjects/Components/Interactable/SharedToolComponent.cs b/Content.Shared/GameObjects/Components/Interactable/SharedToolComponent.cs index c46b1bcba8..a99f4e029f 100644 --- a/Content.Shared/GameObjects/Components/Interactable/SharedToolComponent.cs +++ b/Content.Shared/GameObjects/Components/Interactable/SharedToolComponent.cs @@ -4,32 +4,33 @@ using Robust.Shared.Serialization; namespace Content.Shared.GameObjects.Components.Interactable { - public enum Tool : byte + [Flags] + public enum ToolQuality : byte { - Wrench, - Crowbar, - Screwdriver, - Wirecutter, - Welder, - Multitool, + None = 0, + Anchoring = 1, + Prying = 1 << 1, + Screwing = 1 << 2, + Cutting = 1 << 3, + Welding = 1 << 4, + Multitool = 1 << 5, } public class SharedToolComponent : Component { public override string Name => "Tool"; - public override uint? NetID => ContentNetIDs.TOOL; - public virtual Tool Behavior { get; set; } + public virtual ToolQuality Qualities { get; set; } } [NetSerializable, Serializable] - public class ToolComponentState : ComponentState + public class MultiToolComponentState : ComponentState { - public Tool Behavior { get; } + public ToolQuality Quality { get; } - public ToolComponentState(Tool behavior) : base(ContentNetIDs.TOOL) + public MultiToolComponentState(ToolQuality quality) : base(ContentNetIDs.MULTITOOLS) { - Behavior = behavior; + Quality = quality; } } @@ -39,14 +40,14 @@ namespace Content.Shared.GameObjects.Components.Interactable public float FuelCapacity { get; } public float Fuel { get; } public bool Activated { get; } - public Tool Behavior { get; } + public ToolQuality Quality { get; } public WelderComponentState(float fuelCapacity, float fuel, bool activated) : base(ContentNetIDs.WELDER) { FuelCapacity = fuelCapacity; Fuel = fuel; Activated = activated; - Behavior = Tool.Welder; + Quality = ToolQuality.Welding; } } } diff --git a/Content.Shared/GameObjects/ContentNetIDs.cs b/Content.Shared/GameObjects/ContentNetIDs.cs index acf73f7d74..e72f56d26a 100644 --- a/Content.Shared/GameObjects/ContentNetIDs.cs +++ b/Content.Shared/GameObjects/ContentNetIDs.cs @@ -45,5 +45,6 @@ public const uint GHOST = 1040; public const uint MICROWAVE = 1041; public const uint GRAVITY_GENERATOR = 1042; + public const uint MULTITOOLS = 1043; } } diff --git a/Resources/Prototypes/Entities/Items/tools.yml b/Resources/Prototypes/Entities/Items/tools.yml index a40d8305c0..025d4f573a 100644 --- a/Resources/Prototypes/Entities/Items/tools.yml +++ b/Resources/Prototypes/Entities/Items/tools.yml @@ -11,7 +11,8 @@ - type: ItemCooldown - type: MeleeWeapon - type: Tool - behavior: enum.Tool.Wirecutter + qualities: + - Cutting useSound: /Audio/items/wirecutter.ogg - type: entity @@ -31,7 +32,8 @@ - type: ItemCooldown - type: MeleeWeapon - type: Tool - behavior: enum.Tool.Screwdriver + qualities: + - Screwing useSoundCollection: Screwdriver - type: entity @@ -76,7 +78,8 @@ - type: ItemCooldown - type: MeleeWeapon - type: Tool - behavior: enum.Tool.Wrench + qualities: + - Anchoring useSound: /Audio/items/ratchet.ogg - type: entity @@ -92,7 +95,8 @@ - type: ItemCooldown - type: MeleeWeapon - type: Tool - behavior: enum.Tool.Crowbar + qualities: + - Prying useSound: /Audio/items/crowbar.ogg - type: entity @@ -110,7 +114,8 @@ - type: Item sprite: Objects/Tools/multitool.rsi - type: Tool - behavior: enum.Tool.Multitool + qualities: + - Multitool - type: entity name: Jaws of life @@ -127,15 +132,16 @@ - type: Item sprite: Objects/Tools/jaws_of_life.rsi - type: Tool - behavior: enum.Tool.Crowbar + qualities: + - Prying statusShowBehavior: true - type: MultiTool tools: - - behavior: enum.Tool.Crowbar + - behavior: enum.ToolQuality.Prying state: jaws_pry useSound: /Audio/items/jaws_pry.ogg changeSound: /Audio/items/change_jaws.ogg - - behavior: enum.Tool.Wirecutter + - behavior: enum.ToolQuality.Cutting state: jaws_cutter useSound: /Audio/items/jaws_cut.ogg changeSound: /Audio/items/change_jaws.ogg @@ -155,15 +161,16 @@ - type: Item sprite: Objects/Tools/drill.rsi - type: Tool - behavior: enum.Tool.Screwdriver + qualities: + - Screwing statusShowBehavior: true - type: MultiTool tools: - - behavior: enum.Tool.Screwdriver + - behavior: enum.ToolQuality.Screwing state: drill_screw useSound: /Audio/items/drill_use.ogg changeSound: /Audio/items/change_drill.ogg - - behavior: enum.Tool.Wrench + - behavior: enum.ToolQuality.Anchoring state: drill_bolt useSound: /Audio/items/drill_use.ogg changeSound: /Audio/items/change_drill.ogg