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

You can no longer disarm wielded weapons #7983

Merged
merged 7 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion Content.Server/Actions/Events/DisarmAttemptEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ public sealed class DisarmAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid TargetUid;
public readonly EntityUid DisarmerUid;
public DisarmAttemptEvent(EntityUid targetUid, EntityUid disarmerUid)
public readonly EntityUid? TargetItemInHandUid;

public DisarmAttemptEvent(EntityUid targetUid, EntityUid disarmerUid, EntityUid? targetItemInHandUid = null)
{
TargetUid = targetUid;
DisarmerUid = disarmerUid;
TargetItemInHandUid = targetItemInHandUid;
}
}
}
22 changes: 21 additions & 1 deletion Content.Server/CombatMode/CombatModeSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Diagnostics;
using Content.Server.Act;
using Content.Server.Actions.Events;
using Content.Server.Administration.Logs;
using Content.Server.Hands.Components;
using Content.Server.Popups;
using Content.Server.Weapon.Melee;
using Content.Shared.ActionBlocker;
Expand All @@ -9,6 +11,10 @@
using Content.Shared.Database;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Random;

Expand Down Expand Up @@ -38,7 +44,21 @@ private void OnEntityActionPerform(EntityUid uid, SharedCombatModeComponent comp
if (!_actionBlockerSystem.CanAttack(args.Performer))
return;

var attemptEvent = new DisarmAttemptEvent(args.Target, args.Performer);
EntityUid? inTargetHand = null;

if (EntityManager.TryGetComponent<HandsComponent>(args.Target, out HandsComponent targetHandsComponent)
&& targetHandsComponent.ActiveHand != null
&& !targetHandsComponent.ActiveHand.IsEmpty)
{
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
}

var attemptEvent = new DisarmAttemptEvent(args.Target, args.Performer,inTargetHand);

if (inTargetHand != null)
{
RaiseLocalEvent(inTargetHand.Value, attemptEvent);
}
RaiseLocalEvent(args.Target, attemptEvent);
if (attemptEvent.Cancelled)
return;
Expand Down
10 changes: 9 additions & 1 deletion Content.Server/Wieldable/WieldableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using System.Linq;
using Content.Server.Actions.Events;


namespace Content.Server.Wieldable
{
Expand All @@ -32,10 +33,17 @@ public override void Initialize()
SubscribeLocalEvent<WieldableComponent, GotUnequippedHandEvent>(OnItemLeaveHand);
SubscribeLocalEvent<WieldableComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
SubscribeLocalEvent<WieldableComponent, GetVerbsEvent<InteractionVerb>>(AddToggleWieldVerb);
SubscribeLocalEvent<WieldableComponent, DisarmAttemptEvent>(OnDisarmAttemptEvent);

SubscribeLocalEvent<IncreaseDamageOnWieldComponent, MeleeHitEvent>(OnMeleeHit);
}

private void OnDisarmAttemptEvent(EntityUid uid, WieldableComponent component, DisarmAttemptEvent args)
{
if (component.Wielded)
args.Cancel();
}

private void AddToggleWieldVerb(EntityUid uid, WieldableComponent component, GetVerbsEvent<InteractionVerb> args)
{
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
Expand Down