Start refactoring tools
This commit is contained in:
@@ -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<AudioSystem>();
|
||||
_interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For tool interactions that have a delay before action this will modify the rate, time to wait is divided by this value
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SpeedModifier
|
||||
{
|
||||
get => _speedModifier;
|
||||
set => _speedModifier = value;
|
||||
}
|
||||
private float _speedModifier = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Status modifier which determines whether or not we can act as a tool at this time
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual bool CanUse()
|
||||
{
|
||||
if (_behavior != Tool.Welder)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default Cost of using the welder fuel for an action
|
||||
/// </summary>
|
||||
public const float DefaultFuelCost = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Rate at which we expunge fuel from ourselves when activated
|
||||
/// </summary>
|
||||
public const float FuelLossRate = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// Status of welder, whether it is ignited
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// For tool interactions that have a delay before action this will modify the rate, time to wait is divided by this value
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Status modifier which determines whether or not we can act as a tool at this time
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual bool CanUse()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
@@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used for interfacing/hacking into configurable computers
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class MultitoolComponent : ToolComponent
|
||||
{
|
||||
public override string Name => "Multitool";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ScrewdriverComponent : ToolComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool that interacts with technical components that need to be screwed in
|
||||
/// </summary>
|
||||
public override string Name => "Screwdriver";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool that can be used for some cutting interactions such as wires or hacking
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class WirecutterComponent : ToolComponent
|
||||
{
|
||||
public override string Name => "Wirecutter";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrenches bolts, and interacts with things that have been bolted
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class WrenchComponent : ToolComponent
|
||||
{
|
||||
public override string Name => "Wrench";
|
||||
}
|
||||
}
|
||||
21
Content.Server/GameObjects/EntitySystems/ToolSystem.cs
Normal file
21
Content.Server/GameObjects/EntitySystems/ToolSystem.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Despite the name, it's only really used for the welder logic in tools. Go figure.
|
||||
/// </summary>
|
||||
public class ToolSystem : EntitySystem
|
||||
{
|
||||
private readonly HashSet<ToolComponent> _activeWelders = new HashSet<ToolComponent>();
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var tool in _activeWelders) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<WelderComponent>();
|
||||
comp.OnUpdate(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- type: sound_collection
|
||||
- type: soundCollection
|
||||
id: dice
|
||||
files:
|
||||
- /Audio/items/dice/dice1.ogg
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- type: sound_collection
|
||||
- type: soundCollection
|
||||
id: glassbreak
|
||||
files:
|
||||
- /Audio/effects/glassbreak1.ogg
|
||||
|
||||
@@ -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
|
||||
|
||||
10
Resources/Prototypes/SoundCollections/tools.yml
Normal file
10
Resources/Prototypes/SoundCollections/tools.yml
Normal file
@@ -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
|
||||
@@ -55,4 +55,5 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=prefs/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Soundfont/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=soundfonts/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=swsl/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=swsl/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=underplating/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
|
||||
Reference in New Issue
Block a user