Refactor a bunch of stuff.

This commit is contained in:
zumorica
2020-05-19 13:55:52 +02:00
parent 06c7030514
commit 06d2cc74ed
17 changed files with 153 additions and 347 deletions

View File

@@ -181,27 +181,27 @@ namespace Content.Client.Construction
break; break;
case ConstructionStepTool tool: case ConstructionStepTool tool:
switch (tool.Tool) switch (tool.ToolQuality)
{ {
case Tool.Wrench: case ToolQuality.Anchoring:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/wrench.png"); icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/wrench.png");
text = "Wrench"; text = "Wrench";
break; break;
case Tool.Crowbar: case ToolQuality.Prying:
icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/crowbar.png"); icon = ResourceCache.GetResource<TextureResource>("/Textures/Objects/Tools/crowbar.png");
text = "Crowbar"; text = "Crowbar";
break; break;
case Tool.Screwdriver: case ToolQuality.Screwing:
icon = ResourceCache.GetResource<TextureResource>( icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/screwdriver.png"); "/Textures/Objects/Tools/screwdriver.png");
text = "Screwdriver"; text = "Screwdriver";
break; break;
case Tool.Welder: case ToolQuality.Welding:
icon = ResourceCache.GetResource<RSIResource>("/Textures/Objects/tools.rsi") icon = ResourceCache.GetResource<RSIResource>("/Textures/Objects/tools.rsi")
.RSI["welder"].Frame0; .RSI["welder"].Frame0;
text = $"Welding tool ({tool.Amount} fuel)"; text = $"Welding tool ({tool.Amount} fuel)";
break; break;
case Tool.Wirecutter: case ToolQuality.Cutting:
icon = ResourceCache.GetResource<TextureResource>( icon = ResourceCache.GetResource<TextureResource>(
"/Textures/Objects/Tools/wirecutter.png"); "/Textures/Objects/Tools/wirecutter.png");
text = "Wirecutters"; text = "Wirecutters";

View File

@@ -1,6 +1,7 @@
using System; using System;
using Content.Client.UserInterface.Stylesheets; using Content.Client.UserInterface.Stylesheets;
using Content.Client.Utility; using Content.Client.Utility;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
@@ -13,26 +14,29 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable namespace Content.Client.GameObjects.Components.Interactable
{ {
[RegisterComponent] [RegisterComponent]
public class ToolComponent : SharedToolComponent, IItemStatus public class MultiToolComponent : Component, IItemStatus
{ {
private Tool _behavior; private ToolQuality _behavior;
private bool _statusShowBehavior; private bool _statusShowBehavior;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior; [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) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", false); serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", true);
} }
public override void HandleComponentState(ComponentState curState, ComponentState nextState) 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; _uiUpdateNeeded = true;
} }
@@ -41,10 +45,10 @@ namespace Content.Client.GameObjects.Components.Interactable
private sealed class StatusControl : Control private sealed class StatusControl : Control
{ {
private readonly ToolComponent _parent; private readonly MultiToolComponent _parent;
private readonly RichTextLabel _label; private readonly RichTextLabel _label;
public StatusControl(ToolComponent parent) public StatusControl(MultiToolComponent parent)
{ {
_parent = parent; _parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}}; _label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};

View File

@@ -14,18 +14,17 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable namespace Content.Client.GameObjects.Components.Interactable
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(ToolComponent))] public class WelderComponent : SharedToolComponent, IItemStatus
public class WelderComponent : ToolComponent, IItemStatus
{ {
public override string Name => "Welder"; public override string Name => "Welder";
public override uint? NetID => ContentNetIDs.WELDER; public override uint? NetID => ContentNetIDs.WELDER;
private Tool _behavior; private ToolQuality _behavior;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public float FuelCapacity { get; private set; } [ViewVariables] public float FuelCapacity { get; private set; }
[ViewVariables] public float Fuel { get; private set; } [ViewVariables] public float Fuel { get; private set; }
[ViewVariables] public bool Activated { 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) public override void ExposeData(ObjectSerializer serializer)
{ {
@@ -39,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Interactable
FuelCapacity = weld.FuelCapacity; FuelCapacity = weld.FuelCapacity;
Fuel = weld.Fuel; Fuel = weld.Fuel;
Activated = weld.Activated; Activated = weld.Activated;
_behavior = weld.Behavior; _behavior = weld.Quality;
_uiUpdateNeeded = true; _uiUpdateNeeded = true;
} }
@@ -70,14 +69,11 @@ namespace Content.Client.GameObjects.Components.Interactable
_parent._uiUpdateNeeded = false; _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]", _label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]",
fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap)); fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap));
}
} }
} }
} }

View File

@@ -10,7 +10,7 @@ using Robust.Shared.IoC;
namespace Content.Server.GameObjects.Components namespace Content.Server.GameObjects.Components
{ {
[RegisterComponent] [RegisterComponent]
public class AnchorableComponent : Component, IWrenchAct public class AnchorableComponent : Component, IAttackBy
{ {
public override string Name => "Anchorable"; public override string Name => "Anchorable";
@@ -20,15 +20,16 @@ namespace Content.Server.GameObjects.Components
Owner.EnsureComponent<PhysicsComponent>(); Owner.EnsureComponent<PhysicsComponent>();
} }
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; return false;
}
physics.Anchored = !physics.Anchored; physics.Anchored = !physics.Anchored;
eventArgs.ToolComponent.PlayUseSound();
return true; return true;
} }

View File

@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Construction
var stage = Prototype.Stages[Stage]; var stage = Prototype.Stages[Stage];
if (TryProcessStep(stage.Forward, eventArgs.AttackWith)) if (TryProcessStep(stage.Forward, eventArgs.AttackWith, eventArgs.User))
{ {
Stage++; Stage++;
if (Stage == Prototype.Stages.Count - 1) 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--; Stage--;
if (Stage == 0) 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) if (step == null)
{ {
@@ -144,10 +144,13 @@ namespace Content.Server.GameObjects.Components.Construction
case ConstructionStepTool toolStep: case ConstructionStepTool toolStep:
if (!slapped.TryGetComponent<ToolComponent>(out var tool)) if (!slapped.TryGetComponent<ToolComponent>(out var tool))
return false; return false;
if (toolStep.Tool != tool.Behavior) return false;
if (toolStep.Tool == Tool.Welder && !((WelderComponent)tool).TryWeld(toolStep.Amount)) return false; // Handle welder manually since tool steps specify fuel amount needed, for some reason.
tool.PlayUseSound(); if (toolStep.ToolQuality.HasFlag(ToolQuality.Welding))
return true; return slapped.TryGetComponent<WelderComponent>(out var welder)
&& welder.UseTool(user, Owner, toolStep.ToolQuality, toolStep.Amount);
return tool.UseTool(user, Owner, toolStep.ToolQuality);
default: default:
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -204,7 +204,7 @@ namespace Content.Server.GameObjects.Components.Doors
if (!eventArgs.AttackWith.TryGetComponent<ToolComponent>(out var tool)) if (!eventArgs.AttackWith.TryGetComponent<ToolComponent>(out var tool))
return false; return false;
if (tool.Behavior != Tool.Crowbar) return false; if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Prying)) return false;
if (IsPowered()) if (IsPowered())
{ {

View File

@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Power;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Shared.GameObjects.Components.Gravity; using Content.Shared.GameObjects.Components.Gravity;
using Content.Shared.GameObjects.Components.Interactable;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
@@ -19,7 +20,7 @@ using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Gravity namespace Content.Server.GameObjects.Components.Gravity
{ {
[RegisterComponent] [RegisterComponent]
public class GravityGeneratorComponent: SharedGravityGeneratorComponent, IWelderAct, IBreakAct, IAttackHand public class GravityGeneratorComponent: SharedGravityGeneratorComponent, IAttackBy, IBreakAct, IAttackHand
{ {
private BoundUserInterface _userInterface; private BoundUserInterface _userInterface;
@@ -98,10 +99,14 @@ namespace Content.Server.GameObjects.Components.Gravity
return true; return true;
} }
public bool WelderAct(WelderActEventArgs eventArgs) public bool AttackBy(AttackByEventArgs eventArgs)
{ {
var welder = eventArgs.WelderComponent; if (!eventArgs.AttackWith.TryGetComponent(out WelderComponent tool))
if (!welder.TryWeld(5.0f)) return false; return false;
if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Welding, 5f))
return false;
// Repair generator // Repair generator
var damageable = Owner.GetComponent<DamageableComponent>(); var damageable = Owner.GetComponent<DamageableComponent>();
var breakable = Owner.GetComponent<BreakableComponent>(); var breakable = Owner.GetComponent<BreakableComponent>();
@@ -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")); notifyManager.PopupMessage(Owner, eventArgs.User, Loc.GetString("You repair the gravity generator with the welder"));
return true; return true;
} }
public void OnBreak(BreakageEventArgs eventArgs) public void OnBreak(BreakageEventArgs eventArgs)

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.Components.Interactable;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
@@ -26,7 +27,7 @@ namespace Content.Server.GameObjects.Components.Interactable
private string _sprite; private string _sprite;
private string _changeSound; private string _changeSound;
public Tool Behavior { get; private set; } public ToolQuality Behavior { get; private set; }
public string State => _state; public string State => _state;
public string Texture => _texture; public string Texture => _texture;
public string Sprite => _sprite; public string Sprite => _sprite;
@@ -37,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Interactable
public void ExposeData(ObjectSerializer serializer) public void ExposeData(ObjectSerializer serializer)
{ {
if(serializer.Reading) if(serializer.Reading)
Behavior = (Tool)serializer.ReadStringEnumKey("behavior"); Behavior = (ToolQuality)serializer.ReadStringEnumKey("behavior");
serializer.DataField(ref _state, "state", string.Empty); serializer.DataField(ref _state, "state", string.Empty);
serializer.DataField(ref _sprite, "sprite", string.Empty); serializer.DataField(ref _sprite, "sprite", string.Empty);
serializer.DataField(ref _texture, "texture", string.Empty); serializer.DataField(ref _texture, "texture", string.Empty);
@@ -52,6 +53,7 @@ namespace Content.Server.GameObjects.Components.Interactable
#pragma warning restore 649 #pragma warning restore 649
public override string Name => "MultiTool"; public override string Name => "MultiTool";
public override uint? NetID => ContentNetIDs.MULTITOOLS;
private List<ToolEntry> _tools; private List<ToolEntry> _tools;
private int _currentTool = 0; private int _currentTool = 0;
@@ -87,7 +89,7 @@ namespace Content.Server.GameObjects.Components.Interactable
_tool.UseSound = current.Sound; _tool.UseSound = current.Sound;
_tool.UseSoundCollection = current.SoundCollection; _tool.UseSoundCollection = current.SoundCollection;
_tool.Behavior = current.Behavior; _tool.Qualities = current.Behavior;
if (_sprite == null) return; if (_sprite == null) return;
@@ -98,6 +100,8 @@ namespace Content.Server.GameObjects.Components.Interactable
_sprite.LayerSetState(0, current.State); _sprite.LayerSetState(0, current.State);
else else
_sprite.LayerSetTexture(0, current.Texture); _sprite.LayerSetTexture(0, current.Texture);
Dirty();
} }
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
@@ -111,5 +115,10 @@ namespace Content.Server.GameObjects.Components.Interactable
Cycle(); Cycle();
return true; return true;
} }
public override ComponentState GetComponentState()
{
return new MultiToolComponentState(_tool.Qualities);
}
} }
} }

View File

@@ -2,6 +2,7 @@
// ReSharper disable once RedundantUsingDirective // ReSharper disable once RedundantUsingDirective
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
@@ -46,18 +47,18 @@ namespace Content.Server.GameObjects.Components.Interactable
private InteractionSystem _interactionSystem; private InteractionSystem _interactionSystem;
private SpriteComponent _spriteComponent; private SpriteComponent _spriteComponent;
protected Tool _behavior = Tool.Wrench; protected ToolQuality _qualities = ToolQuality.Anchoring;
private string _useSound; private string _useSound;
private string _useSoundCollection; private string _useSoundCollection;
private float _speedModifier = 1; private float _speedModifier = 1;
[ViewVariables] [ViewVariables]
public override Tool Behavior public override ToolQuality Qualities
{ {
get => _behavior; get => _qualities;
set set
{ {
_behavior = value; _qualities = value;
Dirty(); Dirty();
} }
} }
@@ -84,6 +85,23 @@ namespace Content.Server.GameObjects.Components.Interactable
set => _useSoundCollection = value; 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -99,13 +117,10 @@ namespace Content.Server.GameObjects.Components.Interactable
if (serializer.Reading) if (serializer.Reading)
{ {
try var qualities = serializer.ReadDataField("qualities", new List<ToolQuality>());
foreach (var quality in qualities)
{ {
_behavior = (Tool)serializer.ReadStringEnumKey("behavior"); AddQuality(quality);
}
catch
{
// ignored
} }
} }
serializer.DataField(ref _speedModifier, "speed", 1); serializer.DataField(ref _speedModifier, "speed", 1);
@@ -113,22 +128,11 @@ namespace Content.Server.GameObjects.Components.Interactable
serializer.DataField(ref _useSoundCollection, "useSoundCollection", string.Empty); serializer.DataField(ref _useSoundCollection, "useSoundCollection", string.Empty);
} }
/// <summary> public virtual bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded)
/// Status modifier which determines whether or not we can act as a tool at this time
/// </summary>
public virtual bool CanUse(float resource)
{ {
return true; PlayUseSound();
}
/// <summary> return ActionBlockerSystem.CanInteract(user) && HasQuality(toolQualityNeeded);
/// Method which will try to use the current tool and consume resources/power if applicable.
/// </summary>
/// <param name="resource">The amount of resource</param>
/// <returns>Whether the tool could be used or not.</returns>
public virtual bool TryUse(float resource = 0f)
{
return true;
} }
protected void PlaySoundCollection(string name, float volume=-5f) protected void PlaySoundCollection(string name, float volume=-5f)
@@ -147,17 +151,9 @@ namespace Content.Server.GameObjects.Components.Interactable
PlaySoundCollection(UseSoundCollection, 0f); PlaySoundCollection(UseSoundCollection, 0f);
} }
public override ComponentState GetComponentState()
{
return new ToolComponentState(Behavior);
}
public void AfterAttack(AfterAttackEventArgs eventArgs) public void AfterAttack(AfterAttackEventArgs eventArgs)
{ {
if (eventArgs.Attacked != null && RaiseToolAct(eventArgs)) if (Qualities != ToolQuality.Prying)
return;
if (Behavior != Tool.Crowbar)
return; return;
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); 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); var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates);
tileItem.Transform.WorldPosition += (0.2f, 0.2f); 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<IWrenchAct>().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<ICrowbarAct>().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<IScrewdriverAct>().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<IWirecutterAct>().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<IWelderAct>().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<IMultitoolAct>().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;
}
} }
} }

View File

@@ -21,7 +21,6 @@ namespace Content.Server.GameObjects.Components.Interactable
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private IEntitySystemManager _entitySystemManager; [Dependency] private IEntitySystemManager _entitySystemManager;
[Dependency] private readonly IRobustRandom _robustRandom;
#pragma warning restore 649 #pragma warning restore 649
public override string Name => "Welder"; public override string Name => "Welder";
@@ -38,7 +37,6 @@ namespace Content.Server.GameObjects.Components.Interactable
public const float FuelLossRate = 0.5f; public const float FuelLossRate = 0.5f;
private bool _welderLit = false; private bool _welderLit = false;
private WelderSystem _welderSystem; private WelderSystem _welderSystem;
private SpriteComponent _spriteComponent; private SpriteComponent _spriteComponent;
private SolutionComponent _solutionComponent; private SolutionComponent _solutionComponent;
@@ -67,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Interactable
{ {
base.Initialize(); base.Initialize();
_behavior = Tool.Welder; AddQuality(ToolQuality.Welding);
_welderSystem = _entitySystemManager.GetEntitySystem<WelderSystem>(); _welderSystem = _entitySystemManager.GetEntitySystem<WelderSystem>();
@@ -80,41 +78,40 @@ namespace Content.Server.GameObjects.Components.Interactable
return new WelderComponentState(FuelCapacity, Fuel, WelderLit); 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) if (!WelderLit || !CanWeld(value) || _solutionComponent == null)
{
return false; return false;
}
return _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(value)); 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;
} }
/// <summary> /// <summary>
/// Deactivates welding tool if active, activates welding tool if possible /// Deactivates welding tool if active, activates welding tool if possible
/// </summary> /// </summary>
/// <returns></returns> private bool ToggleWelderStatus()
public bool ToggleWelderStatus()
{ {
if (WelderLit) if (WelderLit)
{ {
@@ -157,17 +154,13 @@ namespace Content.Server.GameObjects.Components.Interactable
public void OnUpdate(float frameTime) public void OnUpdate(float frameTime)
{ {
if (Behavior != Tool.Welder || !WelderLit) if (!HasQuality(ToolQuality.Welding) || !WelderLit)
{
return; return;
}
_solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime));
if (Fuel == 0) if (Fuel == 0)
{
ToggleWelderStatus(); ToggleWelderStatus();
}
Dirty(); Dirty();
} }

View File

@@ -142,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Power
public bool AttackBy(AttackByEventArgs eventArgs) public bool AttackBy(AttackByEventArgs eventArgs)
{ {
if (!eventArgs.AttackWith.TryGetComponent(out ToolComponent tool)) return false; 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(); Owner.Delete();
var droppedEnt = Owner.EntityManager.SpawnEntity("CableStack", eventArgs.ClickLocation); var droppedEnt = Owner.EntityManager.SpawnEntity("CableStack", eventArgs.ClickLocation);

View File

@@ -248,7 +248,7 @@ namespace Content.Server.GameObjects.Components
switch (msg.Action) switch (msg.Action)
{ {
case WiresAction.Cut: 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!")); _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a wirecutter in your hand!"));
return; return;
@@ -258,7 +258,7 @@ namespace Content.Server.GameObjects.Components
UpdateUserInterface(); UpdateUserInterface();
break; break;
case WiresAction.Mend: 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!")); _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a wirecutter in your hand!"));
return; return;
@@ -268,7 +268,7 @@ namespace Content.Server.GameObjects.Components
UpdateUserInterface(); UpdateUserInterface();
break; break;
case WiresAction.Pulse: 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!")); _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You need to hold a multitool in your hand!"));
return; return;
@@ -300,13 +300,13 @@ namespace Content.Server.GameObjects.Components
{ {
if (!eventArgs.AttackWith.TryGetComponent<ToolComponent>(out var tool)) if (!eventArgs.AttackWith.TryGetComponent<ToolComponent>(out var tool))
return false; return false;
if (tool.Behavior != Tool.Screwdriver) if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Screwing))
return false; return false;
IsPanelOpen = !IsPanelOpen; IsPanelOpen = !IsPanelOpen;
IoCManager.Resolve<IEntitySystemManager>() IoCManager.Resolve<IEntitySystemManager>()
.GetEntitySystem<AudioSystem>() .GetEntitySystem<AudioSystem>()
.Play(IsPanelOpen ? "/Audio/machines/screwdriveropen.ogg" : "/Audio/machines/screwdriverclose.ogg"); .Play(IsPanelOpen ? "/Audio/machines/screwdriveropen.ogg" : "/Audio/machines/screwdriverclose.ogg", Owner);
return true; return true;
} }

View File

@@ -46,119 +46,6 @@ namespace Content.Server.GameObjects.EntitySystems
public IEntity AttackWith { get; set; } 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<ToolComponent>();
public virtual Tool Behavior { get; }
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a wrench in their hand
/// </summary>
public interface IWrenchAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
bool WrenchAct(WrenchActEventArgs eventArgs);
}
public class WrenchActEventArgs : ToolActEventArgs
{
public override Tool Behavior => Tool.Wrench;
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a crowbar in their hand
/// </summary>
public interface ICrowbarAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
bool CrowbarAct(CrowbarActEventArgs eventArgs);
}
public class CrowbarActEventArgs : ToolActEventArgs
{
public override Tool Behavior => Tool.Crowbar;
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a screwdriver in their hand
/// </summary>
public interface IScrewdriverAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
bool ScrewdriverAct(ScrewdriverActEventArgs eventArgs);
}
public class ScrewdriverActEventArgs : ToolActEventArgs
{
public override Tool Behavior => Tool.Screwdriver;
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a wirecutter in their hand
/// </summary>
public interface IWirecutterAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
bool WirecutterAct(WirecutterActEventArgs eventArgs);
}
public class WirecutterActEventArgs : ToolActEventArgs
{
public override Tool Behavior => Tool.Wirecutter;
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a welder in their hand
/// </summary>
public interface IWelderAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
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; }
}
/// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with a multitool in their hand
/// </summary>
public interface IMultitoolAct
{
/// <summary>
/// Called when using a wrench on an entity
/// </summary>
bool MultitoolAct(MultitoolActEventArgs eventArgs);
}
public class MultitoolActEventArgs : ToolActEventArgs
{
public override Tool Behavior => Tool.Multitool;
}
#endregion
/// <summary> /// <summary>
/// This interface gives components behavior when being clicked on or "attacked" by a user with an empty hand /// This interface gives components behavior when being clicked on or "attacked" by a user with an empty hand
/// </summary> /// </summary>

View File

@@ -139,7 +139,7 @@ namespace Content.Shared.Construction
if (step.TryGetNode("tool", out node)) if (step.TryGetNode("tool", out node))
{ {
return new ConstructionStepTool( return new ConstructionStepTool(
node.AsEnum<Tool>(), node.AsEnum<ToolQuality>(),
amount amount
); );
} }
@@ -191,11 +191,11 @@ namespace Content.Shared.Construction
public class ConstructionStepTool : ConstructionStep 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;
} }
} }

View File

@@ -4,32 +4,33 @@ using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Interactable namespace Content.Shared.GameObjects.Components.Interactable
{ {
public enum Tool : byte [Flags]
public enum ToolQuality : byte
{ {
Wrench, None = 0,
Crowbar, Anchoring = 1,
Screwdriver, Prying = 1 << 1,
Wirecutter, Screwing = 1 << 2,
Welder, Cutting = 1 << 3,
Multitool, Welding = 1 << 4,
Multitool = 1 << 5,
} }
public class SharedToolComponent : Component public class SharedToolComponent : Component
{ {
public override string Name => "Tool"; 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] [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 FuelCapacity { get; }
public float Fuel { get; } public float Fuel { get; }
public bool Activated { get; } public bool Activated { get; }
public Tool Behavior { get; } public ToolQuality Quality { get; }
public WelderComponentState(float fuelCapacity, float fuel, bool activated) : base(ContentNetIDs.WELDER) public WelderComponentState(float fuelCapacity, float fuel, bool activated) : base(ContentNetIDs.WELDER)
{ {
FuelCapacity = fuelCapacity; FuelCapacity = fuelCapacity;
Fuel = fuel; Fuel = fuel;
Activated = activated; Activated = activated;
Behavior = Tool.Welder; Quality = ToolQuality.Welding;
} }
} }
} }

View File

@@ -45,5 +45,6 @@
public const uint GHOST = 1040; public const uint GHOST = 1040;
public const uint MICROWAVE = 1041; public const uint MICROWAVE = 1041;
public const uint GRAVITY_GENERATOR = 1042; public const uint GRAVITY_GENERATOR = 1042;
public const uint MULTITOOLS = 1043;
} }
} }

View File

@@ -11,7 +11,8 @@
- type: ItemCooldown - type: ItemCooldown
- type: MeleeWeapon - type: MeleeWeapon
- type: Tool - type: Tool
behavior: enum.Tool.Wirecutter qualities:
- Cutting
useSound: /Audio/items/wirecutter.ogg useSound: /Audio/items/wirecutter.ogg
- type: entity - type: entity
@@ -31,7 +32,8 @@
- type: ItemCooldown - type: ItemCooldown
- type: MeleeWeapon - type: MeleeWeapon
- type: Tool - type: Tool
behavior: enum.Tool.Screwdriver qualities:
- Screwing
useSoundCollection: Screwdriver useSoundCollection: Screwdriver
- type: entity - type: entity
@@ -76,7 +78,8 @@
- type: ItemCooldown - type: ItemCooldown
- type: MeleeWeapon - type: MeleeWeapon
- type: Tool - type: Tool
behavior: enum.Tool.Wrench qualities:
- Anchoring
useSound: /Audio/items/ratchet.ogg useSound: /Audio/items/ratchet.ogg
- type: entity - type: entity
@@ -92,7 +95,8 @@
- type: ItemCooldown - type: ItemCooldown
- type: MeleeWeapon - type: MeleeWeapon
- type: Tool - type: Tool
behavior: enum.Tool.Crowbar qualities:
- Prying
useSound: /Audio/items/crowbar.ogg useSound: /Audio/items/crowbar.ogg
- type: entity - type: entity
@@ -110,7 +114,8 @@
- type: Item - type: Item
sprite: Objects/Tools/multitool.rsi sprite: Objects/Tools/multitool.rsi
- type: Tool - type: Tool
behavior: enum.Tool.Multitool qualities:
- Multitool
- type: entity - type: entity
name: Jaws of life name: Jaws of life
@@ -127,15 +132,16 @@
- type: Item - type: Item
sprite: Objects/Tools/jaws_of_life.rsi sprite: Objects/Tools/jaws_of_life.rsi
- type: Tool - type: Tool
behavior: enum.Tool.Crowbar qualities:
- Prying
statusShowBehavior: true statusShowBehavior: true
- type: MultiTool - type: MultiTool
tools: tools:
- behavior: enum.Tool.Crowbar - behavior: enum.ToolQuality.Prying
state: jaws_pry state: jaws_pry
useSound: /Audio/items/jaws_pry.ogg useSound: /Audio/items/jaws_pry.ogg
changeSound: /Audio/items/change_jaws.ogg changeSound: /Audio/items/change_jaws.ogg
- behavior: enum.Tool.Wirecutter - behavior: enum.ToolQuality.Cutting
state: jaws_cutter state: jaws_cutter
useSound: /Audio/items/jaws_cut.ogg useSound: /Audio/items/jaws_cut.ogg
changeSound: /Audio/items/change_jaws.ogg changeSound: /Audio/items/change_jaws.ogg
@@ -155,15 +161,16 @@
- type: Item - type: Item
sprite: Objects/Tools/drill.rsi sprite: Objects/Tools/drill.rsi
- type: Tool - type: Tool
behavior: enum.Tool.Screwdriver qualities:
- Screwing
statusShowBehavior: true statusShowBehavior: true
- type: MultiTool - type: MultiTool
tools: tools:
- behavior: enum.Tool.Screwdriver - behavior: enum.ToolQuality.Screwing
state: drill_screw state: drill_screw
useSound: /Audio/items/drill_use.ogg useSound: /Audio/items/drill_use.ogg
changeSound: /Audio/items/change_drill.ogg changeSound: /Audio/items/change_drill.ogg
- behavior: enum.Tool.Wrench - behavior: enum.ToolQuality.Anchoring
state: drill_bolt state: drill_bolt
useSound: /Audio/items/drill_use.ogg useSound: /Audio/items/drill_use.ogg
changeSound: /Audio/items/change_drill.ogg changeSound: /Audio/items/change_drill.ogg