Replaced Wieldable DoAfter with UseDelay (#18880)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
stopbreaking
2023-10-22 09:53:13 -04:00
committed by GitHub
parent ef0c079724
commit 988bfa5c09
13 changed files with 53 additions and 49 deletions

View File

@@ -30,9 +30,6 @@ public sealed partial class WieldableComponent : Component
public string? WieldedInhandPrefix = "wielded"; public string? WieldedInhandPrefix = "wielded";
public string? OldInhandPrefix = null; public string? OldInhandPrefix = null;
[DataField("wieldTime")]
public float WieldTime = 1.5f;
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -13,6 +13,7 @@ using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems; using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Wieldable.Components; using Content.Shared.Wieldable.Components;
using Robust.Shared.Player; using Robust.Shared.Player;
using Content.Shared.Timing;
namespace Content.Shared.Wieldable; namespace Content.Shared.Wieldable;
@@ -25,13 +26,13 @@ public sealed class WieldableSystem : EntitySystem
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UseDelaySystem _delay = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<WieldableComponent, UseInHandEvent>(OnUseInHand, before: new [] { typeof(SharedGunSystem) }); SubscribeLocalEvent<WieldableComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<WieldableComponent, WieldableDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<WieldableComponent, ItemUnwieldedEvent>(OnItemUnwielded); SubscribeLocalEvent<WieldableComponent, ItemUnwieldedEvent>(OnItemUnwielded);
SubscribeLocalEvent<WieldableComponent, GotUnequippedHandEvent>(OnItemLeaveHand); SubscribeLocalEvent<WieldableComponent, GotUnequippedHandEvent>(OnItemLeaveHand);
SubscribeLocalEvent<WieldableComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted); SubscribeLocalEvent<WieldableComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
@@ -76,7 +77,7 @@ public sealed class WieldableSystem : EntitySystem
gun.MinAngle -= component.MinAngle; gun.MinAngle -= component.MinAngle;
gun.MaxAngle -= component.MaxAngle; gun.MaxAngle -= component.MaxAngle;
Dirty(gun); Dirty(uid, gun);
} }
private void OnGunWielded(EntityUid uid, GunWieldBonusComponent component, ref ItemWieldedEvent args) private void OnGunWielded(EntityUid uid, GunWieldBonusComponent component, ref ItemWieldedEvent args)
@@ -86,7 +87,7 @@ public sealed class WieldableSystem : EntitySystem
gun.MinAngle += component.MinAngle; gun.MinAngle += component.MinAngle;
gun.MaxAngle += component.MaxAngle; gun.MaxAngle += component.MaxAngle;
Dirty(gun); Dirty(uid, gun);
} }
private void AddToggleWieldVerb(EntityUid uid, WieldableComponent component, GetVerbsEvent<InteractionVerb> args) private void AddToggleWieldVerb(EntityUid uid, WieldableComponent component, GetVerbsEvent<InteractionVerb> args)
@@ -157,7 +158,7 @@ public sealed class WieldableSystem : EntitySystem
} }
/// <summary> /// <summary>
/// Attempts to wield an item, creating a DoAfter.. /// Attempts to wield an item, starting a UseDelay after.
/// </summary> /// </summary>
/// <returns>True if the attempt wasn't blocked.</returns> /// <returns>True if the attempt wasn't blocked.</returns>
public bool TryWield(EntityUid used, WieldableComponent component, EntityUid user) public bool TryWield(EntityUid used, WieldableComponent component, EntityUid user)
@@ -171,13 +172,31 @@ public sealed class WieldableSystem : EntitySystem
if (ev.Cancelled) if (ev.Cancelled)
return false; return false;
var doargs = new DoAfterArgs(EntityManager, user, component.WieldTime, new WieldableDoAfterEvent(), used, used: used) if (TryComp<ItemComponent>(used, out var item))
{ {
BreakOnUserMove = false, component.OldInhandPrefix = item.HeldPrefix;
BreakOnDamage = true _itemSystem.SetHeldPrefix(used, component.WieldedInhandPrefix, item);
}; }
_doAfter.TryStartDoAfter(doargs); component.Wielded = true;
if (component.WieldSound != null)
_audioSystem.PlayPredicted(component.WieldSound, used, user);
for (var i = 0; i < component.FreeHandsRequired; i++)
{
_virtualItemSystem.TrySpawnVirtualItemInHand(used, user);
}
_delay.BeginDelay(used);
_popupSystem.PopupClient(Loc.GetString("wieldable-component-successful-wield", ("item", used)), user, user);
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield-other", ("user", user),("item", used)), user, Filter.PvsExcept(user), true);
var targEv = new ItemWieldedEvent();
RaiseLocalEvent(used, ref targEv);
Dirty(used, component);
return true; return true;
} }
@@ -199,38 +218,6 @@ public sealed class WieldableSystem : EntitySystem
return true; return true;
} }
private void OnDoAfter(EntityUid uid, WieldableComponent component, DoAfterEvent args)
{
if (args.Handled || args.Cancelled || !CanWield(uid, component, args.Args.User) || component.Wielded)
return;
if (TryComp<ItemComponent>(uid, out var item))
{
component.OldInhandPrefix = item.HeldPrefix;
_itemSystem.SetHeldPrefix(uid, component.WieldedInhandPrefix, item);
}
component.Wielded = true;
if (component.WieldSound != null)
_audioSystem.PlayPredicted(component.WieldSound, uid, args.User);
for (var i = 0; i < component.FreeHandsRequired; i++)
{
_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.Args.User);
}
_popupSystem.PopupClient(Loc.GetString("wieldable-component-successful-wield", ("item", uid)), args.Args.User, args.Args.User);
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield-other", ("user", args.Args.User),("item", uid)), args.Args.User, Filter.PvsExcept(args.Args.User), true);
var ev = new ItemWieldedEvent();
RaiseLocalEvent(uid, ref ev);
_appearance.SetData(uid, WieldableVisuals.Wielded, true);
Dirty(component);
args.Handled = true;
}
private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args) private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args)
{ {
if (args.User == null) if (args.User == null)
@@ -258,7 +245,7 @@ public sealed class WieldableSystem : EntitySystem
_appearance.SetData(uid, WieldableVisuals.Wielded, false); _appearance.SetData(uid, WieldableVisuals.Wielded, false);
Dirty(component); Dirty(uid, component);
_virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid); _virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid);
} }

View File

@@ -45,3 +45,5 @@
slots: slots:
- suitStorage - suitStorage
- Belt - Belt
- type: UseDelay
delay: 1

View File

@@ -14,9 +14,10 @@
slots: slots:
- Back - Back
- type: Wieldable - type: Wieldable
wieldTime: 0.5
wieldSound: wieldSound:
path: /Audio/Items/bow_pull.ogg path: /Audio/Items/bow_pull.ogg
- type: UseDelay
delay: 1
- type: GunRequiresWield - type: GunRequiresWield
- type: Gun - type: Gun
minAngle: 0 minAngle: 0

View File

@@ -58,6 +58,8 @@
gun_chamber: !type:ContainerSlot gun_chamber: !type:ContainerSlot
- type: StaticPrice - type: StaticPrice
price: 500 price: 500
- type: UseDelay
delay: 1
- type: entity - type: entity
name: L6 SAW name: L6 SAW

View File

@@ -30,6 +30,8 @@
- type: Construction - type: Construction
graph: WoodenBat graph: WoodenBat
node: bat node: bat
- type: UseDelay
delay: 1
- type: Tag - type: Tag
tags: tags:
- BaseballBat - BaseballBat

View File

@@ -5,7 +5,6 @@
description: A very large chainsaw. Usually you use this for cutting down trees... usually. description: A very large chainsaw. Usually you use this for cutting down trees... usually.
components: components:
- type: Wieldable - type: Wieldable
wieldTime: 1
wieldSound: !type:SoundPathSpecifier wieldSound: !type:SoundPathSpecifier
path: /Audio/Weapons/chainsawwield.ogg path: /Audio/Weapons/chainsawwield.ogg
params: params:
@@ -44,3 +43,5 @@
- ReagentId: WeldingFuel - ReagentId: WeldingFuel
Quantity: 300 Quantity: 300
maxVol: 300 maxVol: 300
- type: UseDelay
delay: 1

View File

@@ -81,3 +81,5 @@
quickEquip: false quickEquip: false
slots: slots:
- back - back
- type: UseDelay
delay: 1

View File

@@ -171,7 +171,6 @@
description: Syndicate Command Interns thought that having one blade on the energy sword was not enough. This can be stored in pockets. description: Syndicate Command Interns thought that having one blade on the energy sword was not enough. This can be stored in pockets.
components: components:
- type: Wieldable - type: Wieldable
wieldTime: 0
- type: EnergySword - type: EnergySword
litDamageBonus: litDamageBonus:
types: types:
@@ -205,3 +204,5 @@
enabled: true enabled: true
reflectProb: .75 reflectProb: .75
spread: 75 spread: 75
- type: UseDelay
delay: 1

View File

@@ -41,6 +41,8 @@
- type: TilePrying - type: TilePrying
advanced: true advanced: true
- type: Prying - type: Prying
- type: UseDelay
delay: 1
- type: entity - type: entity
id: FireAxeFlaming id: FireAxeFlaming

View File

@@ -28,6 +28,8 @@
- type: Item - type: Item
size: 80 size: 80
sprite: Objects/Weapons/Melee/pickaxe.rsi sprite: Objects/Weapons/Melee/pickaxe.rsi
- type: UseDelay
delay: 1
- type: entity - type: entity
name: mining drill name: mining drill

View File

@@ -104,6 +104,8 @@
damage: damage:
types: types:
Blunt: 5 Blunt: 5
- type: UseDelay
delay: 1
- type: Appearance - type: Appearance
- type: SolutionContainerVisuals - type: SolutionContainerVisuals
maxFillLevels: 1 maxFillLevels: 1

View File

@@ -22,3 +22,6 @@
damage: damage:
types: types:
Blunt: 3 Blunt: 3
- type: UseDelay
delay: 1