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:
@@ -107,28 +107,28 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
{
|
||||
coordinates = TransformSystem.ToCoordinates(_map.GetMap(mousePos.MapId), mousePos);
|
||||
}
|
||||
|
||||
|
||||
// If the gun has AltFireComponent, it can be used to attack.
|
||||
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
|
||||
{
|
||||
if (!TryComp<AltFireMeleeComponent>(weaponUid, out var altFireComponent) || altDown != BoundKeyState.Down)
|
||||
return;
|
||||
|
||||
|
||||
switch(altFireComponent.AttackType)
|
||||
{
|
||||
case AltFireAttackType.Light:
|
||||
ClientLightAttack(entity, mousePos, coordinates, weaponUid, weapon);
|
||||
break;
|
||||
|
||||
|
||||
case AltFireAttackType.Heavy:
|
||||
ClientHeavyAttack(entity, coordinates, weaponUid, weapon);
|
||||
break;
|
||||
|
||||
|
||||
case AltFireAttackType.Disarm:
|
||||
ClientDisarm(entity, mousePos, coordinates);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,35 +166,6 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
_color.RaiseEffect(Color.Red, targets, Filter.Local());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// They need to either have hands...
|
||||
if (!HasComp<HandsComponent>(target!.Value))
|
||||
{
|
||||
// or just be able to be shoved over.
|
||||
if (TryComp<StatusEffectsComponent>(target, out var status) && status.AllowedEffects.Contains("KnockedDown"))
|
||||
return true;
|
||||
|
||||
if (Timing.IsFirstTimePredicted && HasComp<MobStateComponent>(target.Value))
|
||||
PopupSystem.PopupEntity(Loc.GetString("disarm-action-disarmable", ("targetName", target.Value)), target.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises a heavy attack event with the relevant attacked entities.
|
||||
/// This is to avoid lag effecting the client's perspective too much.
|
||||
@@ -222,7 +193,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
var entities = GetNetEntityList(ArcRayCast(userPos, direction.ToWorldAngle(), component.Angle, distance, userXform.MapID, user).ToList());
|
||||
RaisePredictiveEvent(new HeavyAttackEvent(GetNetEntity(meleeUid), entities.GetRange(0, Math.Min(MaxTargets, entities.Count)), GetNetCoordinates(coordinates)));
|
||||
}
|
||||
|
||||
|
||||
private void ClientDisarm(EntityUid attacker, MapCoordinates mousePos, EntityCoordinates coordinates)
|
||||
{
|
||||
EntityUid? target = null;
|
||||
@@ -232,7 +203,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
|
||||
RaisePredictiveEvent(new DisarmAttackEvent(GetNetEntity(target), GetNetCoordinates(coordinates)));
|
||||
}
|
||||
|
||||
|
||||
private void ClientLightAttack(EntityUid attacker, MapCoordinates mousePos, EntityCoordinates coordinates, EntityUid weaponUid, MeleeWeaponComponent meleeComponent)
|
||||
{
|
||||
var attackerPos = TransformSystem.GetMapCoordinates(attacker);
|
||||
|
||||
Reference in New Issue
Block a user