welder stuff (#17476)
This commit is contained in:
@@ -54,7 +54,6 @@ 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(
|
||||
@@ -64,7 +63,6 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
float doAfterDelay,
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0f,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
return UseTool(tool,
|
||||
@@ -74,7 +72,6 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
toolQualitiesNeeded,
|
||||
doAfterEv,
|
||||
out _,
|
||||
fuel,
|
||||
toolComponent);
|
||||
}
|
||||
|
||||
@@ -92,7 +89,6 @@ 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(
|
||||
@@ -103,30 +99,31 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
out DoAfterId? id,
|
||||
float fuel = 0f,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
id = null;
|
||||
if (!Resolve(tool, ref toolComponent, false))
|
||||
return false;
|
||||
|
||||
if (!CanStartToolUse(tool, user, target, fuel, toolQualitiesNeeded, toolComponent))
|
||||
if (!CanStartToolUse(tool, user, target, toolQualitiesNeeded, toolComponent))
|
||||
return false;
|
||||
|
||||
var toolEvent = new ToolDoAfterEvent(fuel, doAfterEv, target);
|
||||
var toolEvent = new ToolDoAfterEvent(doAfterEv, target);
|
||||
var doAfterArgs = new DoAfterArgs(user, delay / toolComponent.SpeedModifier, toolEvent, tool, target: target, used: tool)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = tool != user,
|
||||
AttemptFrequency = fuel <= 0 ? AttemptFrequency.Never : AttemptFrequency.EveryTick
|
||||
AttemptFrequency = IsWelder(tool) ? AttemptFrequency.Never : AttemptFrequency.EveryTick
|
||||
};
|
||||
|
||||
_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.
|
||||
@@ -141,7 +138,6 @@ 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(
|
||||
@@ -151,7 +147,6 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
float doAfterDelay,
|
||||
string toolQualityNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
{
|
||||
return UseTool(tool,
|
||||
@@ -161,7 +156,6 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
new[] { toolQualityNeeded },
|
||||
doAfterEv,
|
||||
out _,
|
||||
fuel,
|
||||
toolComponent);
|
||||
}
|
||||
|
||||
@@ -181,7 +175,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities);
|
||||
}
|
||||
|
||||
private bool CanStartToolUse(EntityUid tool, EntityUid user, EntityUid? target, float fuel, IEnumerable<string> toolQualitiesNeeded, ToolComponent? toolComponent = null)
|
||||
private bool CanStartToolUse(EntityUid tool, EntityUid user, EntityUid? target, IEnumerable<string> toolQualitiesNeeded, ToolComponent? toolComponent = null)
|
||||
{
|
||||
if (!Resolve(tool, ref toolComponent))
|
||||
return false;
|
||||
@@ -194,7 +188,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
if (!toolComponent.Qualities.ContainsAll(toolQualitiesNeeded))
|
||||
return false;
|
||||
|
||||
var beforeAttempt = new ToolUseAttemptEvent(fuel, user);
|
||||
var beforeAttempt = new ToolUseAttemptEvent(user);
|
||||
RaiseLocalEvent(tool, beforeAttempt, false);
|
||||
|
||||
return !beforeAttempt.Cancelled;
|
||||
@@ -205,9 +199,6 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class ToolDoAfterEvent : DoAfterEvent
|
||||
{
|
||||
[DataField("fuel")]
|
||||
public readonly float Fuel;
|
||||
|
||||
/// <summary>
|
||||
/// Entity that the wrapped do after event will get directed at. If null, event will be broadcast.
|
||||
/// </summary>
|
||||
@@ -221,11 +212,10 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
}
|
||||
|
||||
public ToolDoAfterEvent(float fuel, DoAfterEvent wrappedEvent, EntityUid? originalTarget)
|
||||
public ToolDoAfterEvent(DoAfterEvent wrappedEvent, EntityUid? originalTarget)
|
||||
{
|
||||
DebugTools.Assert(wrappedEvent.GetType().HasCustomAttribute<NetSerializableAttribute>(), "Tool event is not serializable");
|
||||
|
||||
Fuel = fuel;
|
||||
WrappedEvent = wrappedEvent;
|
||||
OriginalTarget = originalTarget;
|
||||
}
|
||||
@@ -238,7 +228,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
if (evClone == WrappedEvent)
|
||||
return this;
|
||||
|
||||
return new ToolDoAfterEvent(Fuel, evClone, OriginalTarget);
|
||||
return new ToolDoAfterEvent(evClone, OriginalTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user