Refactor disarms (#36546)
* Refactor disarms - Move client stuff to shared - Cleanup a bunch of stuff - Ref events - Fix the swing sound mispredict (I noticed it on target dummies). * Revert this change * minor review * Rebiew --------- Co-authored-by: Milon <milonpl.git@proton.me>
This commit is contained in:
@@ -1,26 +1,13 @@
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Movement.Systems;
|
||||
using Content.Shared.Actions.Events;
|
||||
using Content.Shared.Administration.Components;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Damage.Events;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Effects;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Speech.Components;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
@@ -28,12 +15,9 @@ namespace Content.Server.Weapons.Melee;
|
||||
|
||||
public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
|
||||
[Dependency] private readonly LagCompensationSystem _lag = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -85,106 +69,6 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
||||
{
|
||||
if (!base.DoDisarm(user, ev, meleeUid, component, session))
|
||||
return false;
|
||||
|
||||
if (!TryComp<CombatModeComponent>(user, out var combatMode) ||
|
||||
combatMode.CanDisarm != true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var target = GetEntity(ev.Target!.Value);
|
||||
|
||||
if (_mobState.IsIncapacitated(target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryComp<HandsComponent>(target, out var targetHandsComponent))
|
||||
{
|
||||
if (!TryComp<StatusEffectsComponent>(target, out var status) || !status.AllowedEffects.Contains("KnockedDown"))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!InRange(user, target, component.Range, session))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUid? inTargetHand = null;
|
||||
|
||||
if (targetHandsComponent?.ActiveHand is { IsEmpty: false })
|
||||
{
|
||||
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
|
||||
}
|
||||
|
||||
Interaction.DoContactInteraction(user, target);
|
||||
|
||||
var attemptEvent = new DisarmAttemptEvent(target, user, inTargetHand);
|
||||
|
||||
if (inTargetHand != null)
|
||||
{
|
||||
RaiseLocalEvent(inTargetHand.Value, attemptEvent);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(target, attemptEvent);
|
||||
|
||||
if (attemptEvent.Cancelled)
|
||||
return false;
|
||||
|
||||
var chance = CalculateDisarmChance(user, target, inTargetHand, combatMode);
|
||||
|
||||
if (_random.Prob(chance))
|
||||
{
|
||||
// Yknow something tells me this comment is hilariously out of date...
|
||||
// Don't play a sound as the swing is already predicted.
|
||||
// Also don't play popups because most disarms will miss.
|
||||
return false;
|
||||
}
|
||||
|
||||
AdminLogger.Add(LogType.DisarmedAction, $"{ToPrettyString(user):user} used disarm on {ToPrettyString(target):target}");
|
||||
|
||||
var eventArgs = new DisarmedEvent { Target = target, Source = user, PushProbability = 1 - chance };
|
||||
RaiseLocalEvent(target, eventArgs);
|
||||
|
||||
if (!eventArgs.Handled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_audio.PlayPvs(combatMode.DisarmSuccessSound, user, AudioParams.Default.WithVariation(0.025f).WithVolume(5f));
|
||||
AdminLogger.Add(LogType.DisarmedAction, $"{ToPrettyString(user):user} used disarm on {ToPrettyString(target):target}");
|
||||
|
||||
var targetEnt = Identity.Entity(target, EntityManager);
|
||||
var userEnt = Identity.Entity(user, EntityManager);
|
||||
|
||||
var msgOther = Loc.GetString(
|
||||
eventArgs.PopupPrefix + "popup-message-other-clients",
|
||||
("performerName", userEnt),
|
||||
("targetName", targetEnt));
|
||||
|
||||
var msgUser = Loc.GetString(eventArgs.PopupPrefix + "popup-message-cursor", ("targetName", targetEnt));
|
||||
|
||||
var filterOther = Filter.PvsExcept(user, entityManager: EntityManager);
|
||||
|
||||
PopupSystem.PopupEntity(msgOther, user, filterOther, true);
|
||||
PopupSystem.PopupEntity(msgUser, target, user);
|
||||
|
||||
if (eventArgs.IsStunned)
|
||||
{
|
||||
|
||||
PopupSystem.PopupEntity(Loc.GetString("stunned-component-disarm-success-others", ("source", userEnt), ("target", targetEnt)), targetEnt, Filter.PvsExcept(user), true, PopupType.LargeCaution);
|
||||
PopupSystem.PopupCursor(Loc.GetString("stunned-component-disarm-success", ("target", targetEnt)), user, PopupType.Large);
|
||||
|
||||
AdminLogger.Add(LogType.DisarmedKnockdown, LogImpact.Medium, $"{ToPrettyString(user):user} knocked down {ToPrettyString(target):target}");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool InRange(EntityUid user, EntityUid target, float range, ICommonSession? session)
|
||||
{
|
||||
EntityCoordinates targetCoordinates;
|
||||
@@ -205,24 +89,6 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
_color.RaiseEffect(Color.Red, targets, filter);
|
||||
}
|
||||
|
||||
private float CalculateDisarmChance(EntityUid disarmer, EntityUid disarmed, EntityUid? inTargetHand, CombatModeComponent disarmerComp)
|
||||
{
|
||||
if (HasComp<DisarmProneComponent>(disarmer))
|
||||
return 1.0f;
|
||||
|
||||
if (HasComp<DisarmProneComponent>(disarmed))
|
||||
return 0.0f;
|
||||
|
||||
var chance = disarmerComp.BaseDisarmFailChance;
|
||||
|
||||
if (inTargetHand != null && TryComp<DisarmMalusComponent>(inTargetHand, out var malus))
|
||||
{
|
||||
chance += malus.Malus;
|
||||
}
|
||||
|
||||
return Math.Clamp(chance, 0f, 1f);
|
||||
}
|
||||
|
||||
public override void DoLunge(EntityUid user, EntityUid weapon, Angle angle, Vector2 localPos, string? animation, bool predicted = true)
|
||||
{
|
||||
Filter filter;
|
||||
|
||||
Reference in New Issue
Block a user