Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror: StrippableSystem doafter overhaul #205

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
676 changes: 417 additions & 259 deletions Content.Server/Strip/StrippableSystem.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void StartDoAfter(EntityUid user, EntityUid item, EntityUid wearer, Togg
if (component.StripDelay == null)
return;

var (time, stealth) = _strippable.GetStripTimeModifiers(user, wearer, (float) component.StripDelay.Value.TotalSeconds);
var (time, stealth) = _strippable.GetStripTimeModifiers(user, wearer, component.StripDelay.Value);

var args = new DoAfterArgs(EntityManager, user, time, new ToggleClothingDoAfterEvent(), item, wearer, item)
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Inventory/InventoryTemplatePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed partial class SlotDefinition
[DataField("slotFlags")] public SlotFlags SlotFlags { get; private set; } = SlotFlags.PREVENTEQUIP;
[DataField("showInWindow")] public bool ShowInWindow { get; private set; } = true;
[DataField("slotGroup")] public string SlotGroup { get; private set; } = "Default";
[DataField("stripTime")] public float StripTime { get; private set; } = 4f;
[DataField("stripTime")] public TimeSpan StripTime { get; private set; } = TimeSpan.FromSeconds(4f);

[DataField("uiWindowPos", required: true)]
public Vector2i UIWindowPosition { get; private set; }
Expand Down
81 changes: 41 additions & 40 deletions Content.Shared/Strip/Components/StrippableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.DoAfter;
using Content.Shared.Inventory;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
Expand All @@ -8,10 +9,10 @@ namespace Content.Shared.Strip.Components
public sealed partial class StrippableComponent : Component
{
/// <summary>
/// The strip delay for hands.
/// The strip delay for hands.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("handDelay")]
public float HandStripDelay = 4f;
public TimeSpan HandStripDelay = TimeSpan.FromSeconds(4f);
}

[NetSerializable, Serializable]
Expand All @@ -21,63 +22,63 @@ public enum StrippingUiKey : byte
}

[NetSerializable, Serializable]
public sealed class StrippingSlotButtonPressed : BoundUserInterfaceMessage
public sealed class StrippingSlotButtonPressed(string slot, bool isHand) : BoundUserInterfaceMessage
{
public readonly string Slot;

public readonly bool IsHand;

public StrippingSlotButtonPressed(string slot, bool isHand)
{
Slot = slot;
IsHand = isHand;
}
public readonly string Slot = slot;
public readonly bool IsHand = isHand;
}

[NetSerializable, Serializable]
public sealed class StrippingEnsnareButtonPressed : BoundUserInterfaceMessage
{
public StrippingEnsnareButtonPressed()
{
}
}
public sealed class StrippingEnsnareButtonPressed : BoundUserInterfaceMessage;

public abstract class BaseBeforeStripEvent : EntityEventArgs, IInventoryRelayEvent
[ByRefEvent]
public abstract class BaseBeforeStripEvent(TimeSpan initialTime, bool stealth = false) : EntityEventArgs, IInventoryRelayEvent
{
public readonly float InitialTime;
public float Time => MathF.Max(InitialTime * Multiplier + Additive, 0f);
public float Additive = 0;
public float Multiplier = 1f;
public bool Stealth;
public readonly TimeSpan InitialTime = initialTime;
public TimeSpan Multiplier = TimeSpan.FromSeconds(1f);
public TimeSpan Additive = TimeSpan.Zero;
public bool Stealth = stealth;

public SlotFlags TargetSlots { get; } = SlotFlags.GLOVES;
public TimeSpan Time => TimeSpan.FromSeconds(MathF.Max(InitialTime.Seconds * Multiplier.Seconds + Additive.Seconds, 0f));

public BaseBeforeStripEvent(float initialTime, bool stealth = false)
{
InitialTime = initialTime;
Stealth = stealth;
}
public SlotFlags TargetSlots { get; } = SlotFlags.GLOVES;
}

/// <summary>
/// Used to modify strip times. Raised directed at the user.
/// Used to modify strip times. Raised directed at the user.
/// </summary>
/// <remarks>
/// This is also used by some stripping related interactions, i.e., interactions with items that are currently equipped by another player.
/// This is also used by some stripping related interactions, i.e., interactions with items that are currently equipped by another player.
/// </remarks>
public sealed class BeforeStripEvent : BaseBeforeStripEvent
{
public BeforeStripEvent(float initialTime, bool stealth = false) : base(initialTime, stealth) { }
}
[ByRefEvent]
public sealed class BeforeStripEvent(TimeSpan initialTime, bool stealth = false) : BaseBeforeStripEvent(initialTime, stealth);

/// <summary>
/// Used to modify strip times. Raised directed at the target.
/// Used to modify strip times. Raised directed at the target.
/// </summary>
/// <remarks>
/// This is also used by some stripping related interactions, i.e., interactions with items that are currently equipped by another player.
/// This is also used by some stripping related interactions, i.e., interactions with items that are currently equipped by another player.
/// </remarks>
public sealed class BeforeGettingStrippedEvent : BaseBeforeStripEvent
[ByRefEvent]
public sealed class BeforeGettingStrippedEvent(TimeSpan initialTime, bool stealth = false) : BaseBeforeStripEvent(initialTime, stealth);

/// <summary>
/// Organizes the behavior of DoAfters for <see cref="StrippableSystem">.
/// </summary>
[Serializable, NetSerializable]
public sealed partial class StrippableDoAfterEvent : DoAfterEvent
{
public BeforeGettingStrippedEvent(float initialTime, bool stealth = false) : base(initialTime, stealth) { }
public readonly bool InsertOrRemove;
public readonly bool InventoryOrHand;
public readonly string SlotOrHandName;

public StrippableDoAfterEvent(bool insertOrRemove, bool inventoryOrHand, string slotOrHandName)
{
InsertOrRemove = insertOrRemove;
InventoryOrHand = inventoryOrHand;
SlotOrHandName = slotOrHandName;
}

public override DoAfterEvent Clone() => this;
}
}
2 changes: 1 addition & 1 deletion Content.Shared/Strip/Components/ThievingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed partial class ThievingComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("stripTimeReduction")]
public float StripTimeReduction = 0.5f;
public TimeSpan StripTimeReduction = TimeSpan.FromSeconds(0.5f);

/// <summary>
/// Should it notify the user if they're stripping a pocket?
Expand Down
6 changes: 3 additions & 3 deletions Content.Shared/Strip/SharedStrippableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public override void Initialize()
SubscribeLocalEvent<StrippableComponent, DragDropDraggedEvent>(OnDragDrop);
}

public (float Time, bool Stealth) GetStripTimeModifiers(EntityUid user, EntityUid target, float initialTime)
public (TimeSpan Time, bool Stealth) GetStripTimeModifiers(EntityUid user, EntityUid target, TimeSpan initialTime)
{
var userEv = new BeforeStripEvent(initialTime);
RaiseLocalEvent(user, userEv);
RaiseLocalEvent(user, ref userEv);
var ev = new BeforeGettingStrippedEvent(userEv.Time, userEv.Stealth);
RaiseLocalEvent(target, ev);
RaiseLocalEvent(target, ref ev);
return (ev.Time, ev.Stealth);
}

Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Strip/ThievingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Inventory;
using Content.Shared.Strip;
using Content.Shared.Strip.Components;

namespace Content.Shared.Strip;
Expand Down