add fuel costs back to finishing welding (#27030)
* add fuel costs back to welding * ack * meh * eek!
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item.ItemToggle;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Tools.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -15,12 +19,15 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
|
||||
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] protected readonly SharedInteractionSystem InteractionSystem = default!;
|
||||
[Dependency] protected readonly SharedItemToggleSystem ItemToggle = default!;
|
||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] protected readonly SharedSolutionContainerSystem SolutionContainerSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly TileSystem _tiles = default!;
|
||||
[Dependency] private readonly TurfSystem _turfs = default!;
|
||||
@@ -29,6 +36,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
InitializeMultipleTool();
|
||||
InitializeTile();
|
||||
InitializeWelder();
|
||||
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
@@ -66,6 +74,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// <param name="toolQualitiesNeeded">The qualities needed for this tool to work.</param>
|
||||
/// <param name="doAfterEv">The event that will be raised when the tool has finished (including cancellation). Event
|
||||
/// will be directed at the tool target.</param>
|
||||
/// <param name="fuel">Amount of fuel that should be taken from the tool.</param>
|
||||
/// <param name="toolComponent">The tool component.</param>
|
||||
/// <returns>Returns true if any interaction takes place.</returns>
|
||||
public bool UseTool(
|
||||
@@ -75,6 +84,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
float doAfterDelay,
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
return UseTool(tool,
|
||||
@@ -84,6 +94,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
toolQualitiesNeeded,
|
||||
doAfterEv,
|
||||
out _,
|
||||
fuel,
|
||||
toolComponent);
|
||||
}
|
||||
|
||||
@@ -101,6 +112,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// will be directed at the tool target.</param>
|
||||
/// <param name="id">The id of the DoAfter that was created. This may be null even if the function returns true in
|
||||
/// the event that this tool-use cancelled an existing DoAfter</param>
|
||||
/// <param name="fuel">Amount of fuel that should be taken from the tool.</param>
|
||||
/// <param name="toolComponent">The tool component.</param>
|
||||
/// <returns>Returns true if any interaction takes place.</returns>
|
||||
public bool UseTool(
|
||||
@@ -111,31 +123,30 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
out DoAfterId? id,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
id = null;
|
||||
if (!Resolve(tool, ref toolComponent, false))
|
||||
return false;
|
||||
|
||||
if (!CanStartToolUse(tool, user, target, toolQualitiesNeeded, toolComponent))
|
||||
if (!CanStartToolUse(tool, user, target, fuel, toolQualitiesNeeded, toolComponent))
|
||||
return false;
|
||||
|
||||
var toolEvent = new ToolDoAfterEvent(doAfterEv, GetNetEntity(target));
|
||||
var toolEvent = new ToolDoAfterEvent(fuel, doAfterEv, GetNetEntity(target));
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, user, delay / toolComponent.SpeedModifier, toolEvent, tool, target: target, used: tool)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnMove = true,
|
||||
BreakOnWeightlessMove = false,
|
||||
NeedHand = tool != user,
|
||||
AttemptFrequency = IsWelder(tool) ? AttemptFrequency.EveryTick : AttemptFrequency.Never
|
||||
AttemptFrequency = fuel > 0 ? AttemptFrequency.EveryTick : AttemptFrequency.Never
|
||||
};
|
||||
|
||||
_doAfterSystem.TryStartDoAfter(doAfterArgs, out id);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract bool IsWelder(EntityUid uid);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to use a tool on some entity, which will start a DoAfter. Returns true if an interaction occurred.
|
||||
/// Note that this does not mean the interaction was successful, you need to listen for the DoAfter event.
|
||||
@@ -148,6 +159,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// <param name="toolQualityNeeded">The quality needed for this tool to work.</param>
|
||||
/// <param name="doAfterEv">The event that will be raised when the tool has finished (including cancellation). Event
|
||||
/// will be directed at the tool target.</param>
|
||||
/// <param name="fuel">Amount of fuel that should be taken from the tool.</param>
|
||||
/// <param name="toolComponent">The tool component.</param>
|
||||
/// <returns>Returns true if any interaction takes place.</returns>
|
||||
public bool UseTool(
|
||||
@@ -157,6 +169,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
float doAfterDelay,
|
||||
string toolQualityNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
return UseTool(tool,
|
||||
@@ -166,6 +179,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
new[] { toolQualityNeeded },
|
||||
doAfterEv,
|
||||
out _,
|
||||
fuel,
|
||||
toolComponent);
|
||||
}
|
||||
|
||||
@@ -180,12 +194,13 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Whether a tool entity has all specified qualities or not.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public bool HasAllQualities(EntityUid uid, IEnumerable<string> qualities, ToolComponent? tool = null)
|
||||
{
|
||||
return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities);
|
||||
}
|
||||
|
||||
private bool CanStartToolUse(EntityUid tool, EntityUid user, EntityUid? target, IEnumerable<string> toolQualitiesNeeded, ToolComponent? toolComponent = null)
|
||||
private bool CanStartToolUse(EntityUid tool, EntityUid user, EntityUid? target, float fuel, IEnumerable<string> toolQualitiesNeeded, ToolComponent? toolComponent = null)
|
||||
{
|
||||
if (!Resolve(tool, ref toolComponent))
|
||||
return false;
|
||||
@@ -220,6 +235,9 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed partial class ToolDoAfterEvent : DoAfterEvent
|
||||
{
|
||||
[DataField]
|
||||
public float Fuel;
|
||||
|
||||
/// <summary>
|
||||
/// Entity that the wrapped do after event will get directed at. If null, event will be broadcast.
|
||||
/// </summary>
|
||||
@@ -233,10 +251,11 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
}
|
||||
|
||||
public ToolDoAfterEvent(DoAfterEvent wrappedEvent, NetEntity? originalTarget)
|
||||
public ToolDoAfterEvent(float fuel, DoAfterEvent wrappedEvent, NetEntity? originalTarget)
|
||||
{
|
||||
DebugTools.Assert(wrappedEvent.GetType().HasCustomAttribute<NetSerializableAttribute>(), "Tool event is not serializable");
|
||||
|
||||
Fuel = fuel;
|
||||
WrappedEvent = wrappedEvent;
|
||||
OriginalTarget = originalTarget;
|
||||
}
|
||||
@@ -249,14 +268,14 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
if (evClone == WrappedEvent)
|
||||
return this;
|
||||
|
||||
return new ToolDoAfterEvent(evClone, OriginalTarget);
|
||||
return new ToolDoAfterEvent(Fuel, evClone, OriginalTarget);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed partial class LatticeCuttingCompleteEvent : DoAfterEvent
|
||||
{
|
||||
[DataField("coordinates", required:true)]
|
||||
[DataField(required:true)]
|
||||
public NetCoordinates Coordinates;
|
||||
|
||||
private LatticeCuttingCompleteEvent()
|
||||
@@ -273,9 +292,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class CableCuttingFinishedEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
public sealed partial class CableCuttingFinishedEvent : SimpleDoAfterEvent;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user