mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Revert "Support for melee weapon user overrides" (#43106)
Revert "Support for melee weapon user overrides (#39633)"
This reverts commit 18149dbb3b.
This commit is contained in:
parent
012ffe5abd
commit
38cd873fc3
5 changed files with 17 additions and 102 deletions
|
|
@ -2,7 +2,6 @@ using System.Numerics;
|
|||
using Content.Client.Animations;
|
||||
using Content.Client.Weapons.Melee.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Animations;
|
||||
|
|
@ -36,25 +35,7 @@ public sealed partial class MeleeWeaponSystem
|
|||
if (!_xformQuery.TryGetComponent(user, out var userXform) || userXform.MapID == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
// Allow systems to override how visuals are spawned/tracked.
|
||||
var prepare = new PrepareMeleeLungeEvent(user, weapon, angle, localPos, animation)
|
||||
{
|
||||
SpawnAtMap = false,
|
||||
DisableTracking = false
|
||||
};
|
||||
RaiseLocalEvent(user, ref prepare);
|
||||
|
||||
EntityUid animationUid;
|
||||
var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform);
|
||||
if (prepare.SpawnAtMap)
|
||||
{
|
||||
var spawnCoords = new MapCoordinates(mapPos, userXform.MapID);
|
||||
animationUid = Spawn(animation, spawnCoords);
|
||||
}
|
||||
else
|
||||
{
|
||||
animationUid = Spawn(animation, userXform.Coordinates);
|
||||
}
|
||||
var animationUid = Spawn(animation, userXform.Coordinates);
|
||||
|
||||
if (!TryComp<SpriteComponent>(animationUid, out var sprite)
|
||||
|| !TryComp<WeaponArcVisualsComponent>(animationUid, out var arcComponent))
|
||||
|
|
@ -81,8 +62,7 @@ public sealed partial class MeleeWeaponSystem
|
|||
length = (1 / meleeWeaponComponent.AttackRate) * 0.6f;
|
||||
offset = meleeWeaponComponent.AnimationOffset;
|
||||
}
|
||||
var baseVec = prepare.SpawnAtMap ? (mapRot - userXform.LocalRotation).RotateVec(localPos) : localPos;
|
||||
_sprite.SetRotation((animationUid, sprite), baseVec.ToWorldAngle());
|
||||
_sprite.SetRotation((animationUid, sprite), localPos.ToWorldAngle());
|
||||
|
||||
var xform = _xformQuery.GetComponent(animationUid);
|
||||
TrackUserComponent track;
|
||||
|
|
@ -90,27 +70,21 @@ public sealed partial class MeleeWeaponSystem
|
|||
switch (arcComponent.Animation)
|
||||
{
|
||||
case WeaponArcAnimation.Slash:
|
||||
if (!prepare.DisableTracking)
|
||||
{
|
||||
track = EnsureComp<TrackUserComponent>(animationUid);
|
||||
track.User = user;
|
||||
}
|
||||
track = EnsureComp<TrackUserComponent>(animationUid);
|
||||
track.User = user;
|
||||
_animation.Play(animationUid, GetSlashAnimation((animationUid, sprite), angle, spriteRotation, length, offset), SlashAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, length * 0.5f, length + 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.Thrust:
|
||||
if (!prepare.DisableTracking)
|
||||
{
|
||||
track = EnsureComp<TrackUserComponent>(animationUid);
|
||||
track.User = user;
|
||||
}
|
||||
track = EnsureComp<TrackUserComponent>(animationUid);
|
||||
track.User = user;
|
||||
_animation.Play(animationUid, GetThrustAnimation((animationUid, sprite), offset, spriteRotation, length), ThrustAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, length * 0.5f, length + 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.None:
|
||||
(mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform);
|
||||
var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform);
|
||||
var worldPos = mapPos + (mapRot - userXform.LocalRotation).RotateVec(localPos);
|
||||
var newLocalPos = Vector2.Transform(worldPos, TransformSystem.GetInvWorldMatrix(xform.ParentUid));
|
||||
TransformSystem.SetLocalPositionNoLerp(animationUid, newLocalPos, xform);
|
||||
|
|
|
|||
|
|
@ -183,26 +183,18 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
|||
return;
|
||||
}
|
||||
|
||||
// Resolve attacker and use its transform for ray origin and ignore.
|
||||
var attacker = user;
|
||||
var getAttackerEv = new GetMeleeAttackerEntityEvent();
|
||||
RaiseLocalEvent(user, ref getAttackerEv);
|
||||
if (getAttackerEv.Handled && getAttackerEv.Attacker != null)
|
||||
attacker = getAttackerEv.Attacker.Value;
|
||||
|
||||
var targetMap = TransformSystem.ToMapCoordinates(coordinates);
|
||||
var attackerXform = _xformQuery.TryGetComponent(attacker, out var aXform) ? aXform : userXform;
|
||||
|
||||
if (targetMap.MapId != attackerXform.MapID)
|
||||
if (targetMap.MapId != userXform.MapID)
|
||||
return;
|
||||
|
||||
var attackerPos = TransformSystem.GetWorldPosition(attackerXform);
|
||||
var direction = targetMap.Position - attackerPos;
|
||||
var userPos = TransformSystem.GetWorldPosition(userXform);
|
||||
var direction = targetMap.Position - userPos;
|
||||
var distance = MathF.Min(component.Range, direction.Length());
|
||||
|
||||
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
|
||||
// Server will validate it with InRangeUnobstructed.
|
||||
var entities = GetNetEntityList(ArcRayCast(attackerPos, direction.ToWorldAngle(), component.Angle, distance, attackerXform.MapID, attacker).ToList());
|
||||
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)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Weapons.Melee.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised to get the effective melee attacker entity (for range/origin/animation),
|
||||
/// which may differ from the controlling user.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public struct GetMeleeAttackerEntityEvent
|
||||
{
|
||||
public EntityUid? Attacker;
|
||||
public bool Handled;
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Shared.Weapons.Melee.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the attacker before spawning melee lunge visuals on the client.
|
||||
/// Systems may adjust the visual behavior by setting the flags below.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct PrepareMeleeLungeEvent(
|
||||
EntityUid User,
|
||||
EntityUid Weapon,
|
||||
Angle Angle,
|
||||
Vector2 LocalPos,
|
||||
string? Animation)
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, spawns the visual at world MapCoordinates (based on the user's current world position)
|
||||
/// instead of at the user's local coordinates. Use this to avoid inheriting user rotation.
|
||||
/// </summary>
|
||||
public bool SpawnAtMap;
|
||||
|
||||
/// <summary>
|
||||
/// If true, disables tracking the visual to the user (i.e., removes the TrackUser behavior).
|
||||
/// </summary>
|
||||
public bool DisableTracking;
|
||||
}
|
||||
|
|
@ -408,13 +408,6 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||
break;
|
||||
}
|
||||
|
||||
// Resolve effective melee attacker.
|
||||
var attacker = user;
|
||||
var getAttackerEv = new GetMeleeAttackerEntityEvent();
|
||||
RaiseLocalEvent(user, ref getAttackerEv);
|
||||
if (getAttackerEv.Handled && getAttackerEv.Attacker != null)
|
||||
attacker = getAttackerEv.Attacker.Value;
|
||||
|
||||
// Windup time checked elsewhere.
|
||||
var fireRate = TimeSpan.FromSeconds(1f / GetAttackRate(weaponUid, user, weapon));
|
||||
var swings = 0;
|
||||
|
|
@ -459,17 +452,17 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||
switch (attack)
|
||||
{
|
||||
case LightAttackEvent light:
|
||||
DoLightAttack(attacker, light, weaponUid, weapon, session);
|
||||
DoLightAttack(user, light, weaponUid, weapon, session);
|
||||
animation = weapon.Animation;
|
||||
break;
|
||||
case DisarmAttackEvent disarm:
|
||||
if (!DoDisarm(attacker, disarm, weaponUid, weapon, session))
|
||||
if (!DoDisarm(user, disarm, weaponUid, weapon, session))
|
||||
return false;
|
||||
|
||||
animation = weapon.Animation;
|
||||
break;
|
||||
case HeavyAttackEvent heavy:
|
||||
if (!DoHeavyAttack(attacker, heavy, weaponUid, weapon, session))
|
||||
if (!DoHeavyAttack(user, heavy, weaponUid, weapon, session))
|
||||
return false;
|
||||
|
||||
animation = weapon.WideAnimation;
|
||||
|
|
@ -478,7 +471,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
DoLungeAnimation(attacker, weaponUid, weapon.Angle, TransformSystem.ToMapCoordinates(GetCoordinates(attack.Coordinates)), weapon.Range, animation);
|
||||
DoLungeAnimation(user, weaponUid, weapon.Angle, TransformSystem.ToMapCoordinates(GetCoordinates(attack.Coordinates)), weapon.Range, animation);
|
||||
}
|
||||
|
||||
var attackEv = new MeleeAttackEvent(weaponUid);
|
||||
|
|
@ -600,7 +593,6 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||
if (targetMap.MapId != userXform.MapID)
|
||||
return false;
|
||||
|
||||
// Use the resolved attacker for positional calculations if available
|
||||
var userPos = TransformSystem.GetWorldPosition(userXform);
|
||||
var direction = targetMap.Position - userPos;
|
||||
var distance = Math.Min(component.Range, direction.Length());
|
||||
|
|
@ -744,9 +736,9 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||
_meleeSound.PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component);
|
||||
}
|
||||
|
||||
if (appliedDamage.GetTotal() > FixedPoint2.Zero && TryComp(targets[0], out TransformComponent? targetXform))
|
||||
if (appliedDamage.GetTotal() > FixedPoint2.Zero)
|
||||
{
|
||||
DoDamageEffect(targets, user, targetXform);
|
||||
DoDamageEffect(targets, user, Transform(targets[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue