Tearable Deliveries V2 (#36815)
* Add new fields to DeliveryComponent for #36636 * Setting the baseSpesoPenalty for currently available deliveries * Small fixes * Basic delivery penalization * Penalty and reward multiplier calculation in place Also fixes an issue in SharedCargoSystem when opening a delivery in dev server due to trying to allocate cargo twice. * Calling penalty no longer happens on opening * Extract multiplier getting * Removing unused include * Changing method description. \n\n Not actually sure what I meant by the first one * Localising default delivery messages * Unused include removal * init or smth * minor tweaks * I KEEP MERGE CONFLICTING MYSELF * comments * no icon * slight increase * slarti changes * forgot * stuffs * yippee * Locn't * doc * partial review * message * review * pain * stuff --------- Co-authored-by: Lmorgan89 <billsmith116@gmail.com>
This commit is contained in:
47
Content.Shared/Tools/Components/SimpleToolUsageComponent.cs
Normal file
47
Content.Shared/Tools/Components/SimpleToolUsageComponent.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Tools.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Component responsible for simple tool interactions.
|
||||
/// Using a tool with the correct quality on an entity with this component will start a doAfter and raise events.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SimpleToolUsageSystem))]
|
||||
public sealed partial class SimpleToolUsageComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool quality required to use a tool on this.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<ToolQualityPrototype> Quality = "Slicing";
|
||||
|
||||
/// <summary>
|
||||
/// The duration using a tool on this entity will take in seconds.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float DoAfter = 5;
|
||||
|
||||
/// <summary>
|
||||
/// What verb should display to allow you to use a tool on this entity.
|
||||
/// If null, no verb will be shown.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId? UsageVerb;
|
||||
|
||||
/// <summary>
|
||||
/// The message to show when the verb is disabled.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId BlockedMessage = "simple-tool-usage-blocked-message";
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct AttemptSimpleToolUseEvent(EntityUid User, bool Cancelled = false);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class SimpleToolDoAfterEvent : SimpleDoAfterEvent;
|
||||
79
Content.Shared/Tools/Systems/SimpleToolUsageSystem.cs
Normal file
79
Content.Shared/Tools/Systems/SimpleToolUsageSystem.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Tools.Systems;
|
||||
|
||||
public sealed partial class SimpleToolUsageSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly SharedToolSystem _tools = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SimpleToolUsageComponent, AfterInteractUsingEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<SimpleToolUsageComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
|
||||
}
|
||||
|
||||
private void OnAfterInteract(Entity<SimpleToolUsageComponent> ent, ref AfterInteractUsingEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Handled)
|
||||
return;
|
||||
|
||||
if (!_tools.HasQuality(args.Used, ent.Comp.Quality))
|
||||
return;
|
||||
|
||||
AttemptToolUsage(ent, args.User, args.Used);
|
||||
}
|
||||
|
||||
public void OnGetInteractionVerbs(Entity<SimpleToolUsageComponent> ent, ref GetVerbsEvent<InteractionVerb> args)
|
||||
{
|
||||
if (ent.Comp.UsageVerb == null)
|
||||
return;
|
||||
|
||||
if (!args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
var disabled = args.Using == null || !_tools.HasQuality(args.Using.Value, ent.Comp.Quality);
|
||||
|
||||
var used = args.Using;
|
||||
var user = args.User;
|
||||
|
||||
InteractionVerb verb = new()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
if (used != null)
|
||||
AttemptToolUsage(ent, user, used.Value);
|
||||
},
|
||||
Disabled = disabled,
|
||||
Message = disabled ? Loc.GetString(ent.Comp.BlockedMessage, ("quality", ent.Comp.Quality)) : null,
|
||||
Text = Loc.GetString(ent.Comp.UsageVerb),
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AttemptToolUsage(Entity<SimpleToolUsageComponent> ent, EntityUid user, EntityUid tool)
|
||||
{
|
||||
var attemptEv = new AttemptSimpleToolUseEvent(user);
|
||||
RaiseLocalEvent(ent, ref attemptEv);
|
||||
|
||||
if (attemptEv.Cancelled)
|
||||
return;
|
||||
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, user, ent.Comp.DoAfter, new SimpleToolDoAfterEvent(), ent, tool)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnDropItem = true,
|
||||
BreakOnMove = true,
|
||||
BreakOnHandChange = true,
|
||||
};
|
||||
|
||||
_doAfterSystem.TryStartDoAfter(doAfterArgs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user