diff --git a/Content.Client/Weapons/Melee/MeleeWeaponSystem.Effects.cs b/Content.Client/Weapons/Melee/MeleeWeaponSystem.Effects.cs index 0de2e7eae6..0bccd5b1b3 100644 --- a/Content.Client/Weapons/Melee/MeleeWeaponSystem.Effects.cs +++ b/Content.Client/Weapons/Melee/MeleeWeaponSystem.Effects.cs @@ -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(animationUid, out var sprite) || !TryComp(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(animationUid); - track.User = user; - } + track = EnsureComp(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(animationUid); - track.User = user; - } + track = EnsureComp(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); diff --git a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs index 8c17b049b7..420e18748f 100644 --- a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs @@ -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))); } diff --git a/Content.Shared/Weapons/Melee/Events/GetMeleeAttackerEntityEvent.cs b/Content.Shared/Weapons/Melee/Events/GetMeleeAttackerEntityEvent.cs deleted file mode 100644 index 9559a14421..0000000000 --- a/Content.Shared/Weapons/Melee/Events/GetMeleeAttackerEntityEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Weapons.Melee.Events; - -/// -/// Raised to get the effective melee attacker entity (for range/origin/animation), -/// which may differ from the controlling user. -/// -[ByRefEvent] -public struct GetMeleeAttackerEntityEvent -{ - public EntityUid? Attacker; - public bool Handled; -} diff --git a/Content.Shared/Weapons/Melee/Events/PrepareMeleeLungeEvent.cs b/Content.Shared/Weapons/Melee/Events/PrepareMeleeLungeEvent.cs deleted file mode 100644 index e70b1223d1..0000000000 --- a/Content.Shared/Weapons/Melee/Events/PrepareMeleeLungeEvent.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Numerics; -using Robust.Shared.GameObjects; -using Robust.Shared.Maths; - -namespace Content.Shared.Weapons.Melee.Events; - -/// -/// Raised on the attacker before spawning melee lunge visuals on the client. -/// Systems may adjust the visual behavior by setting the flags below. -/// -[ByRefEvent] -public record struct PrepareMeleeLungeEvent( - EntityUid User, - EntityUid Weapon, - Angle Angle, - Vector2 LocalPos, - string? Animation) -{ - /// - /// 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. - /// - public bool SpawnAtMap; - - /// - /// If true, disables tracking the visual to the user (i.e., removes the TrackUser behavior). - /// - public bool DisableTracking; -} diff --git a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs index 14d8d9162b..6f4b078fe2 100644 --- a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs +++ b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs @@ -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;