From 62ce603858bba4acf50f21eaa838a5c1f9df705e Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Date: Sat, 5 Jun 2021 18:05:57 +0200 Subject: [PATCH] Fix punching (#4141) --- .../Weapon/Melee/UnarmedCombatComponent.cs | 2 ++ .../EntitySystems/Click/InteractionSystem.cs | 32 ++++++++++++++++--- .../Weapon/Melee/MeleeWeaponSystem.cs | 2 ++ .../Components/Interaction/AttackEvent.cs | 4 +-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/UnarmedCombatComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/UnarmedCombatComponent.cs index 9841f283a0..c17b580ac3 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/UnarmedCombatComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/UnarmedCombatComponent.cs @@ -2,7 +2,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee { + // TODO: Remove this, just use MeleeWeapon... [RegisterComponent] + [ComponentReference(typeof(MeleeWeaponComponent))] public class UnarmedCombatComponent : MeleeWeaponComponent { public override string Name => "UnarmedCombat"; diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index eec7f55549..676adbad9e 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -838,18 +838,40 @@ namespace Content.Server.GameObjects.EntitySystems.Click if (item != null) { - if(wideAttack) - RaiseLocalEvent(item.Uid, new WideAttackEvent(item, player, coordinates), false); + if (wideAttack) + { + var ev = new WideAttackEvent(item, player, coordinates); + RaiseLocalEvent(item.Uid, ev, false); + + if(ev.Handled) + return; + } else - RaiseLocalEvent(item.Uid, new ClickAttackEvent(item, player, coordinates, targetUid), false); + { + var ev = new ClickAttackEvent(item, player, coordinates, targetUid); + RaiseLocalEvent(item.Uid, ev, false); + + if(ev.Handled) + return; + } } else { // We pick up items if our hand is empty, even if we're in combat mode. - if (!EntityManager.TryGetEntity(targetUid, out var targetEnt) || !targetEnt.HasComponent()) return; - Interaction(player, targetEnt); + if (EntityManager.TryGetEntity(targetUid, out var targetEnt) && targetEnt.HasComponent()) + { + Interaction(player, targetEnt); + return; + } } } + + // TODO: Make this saner? + // Attempt to do unarmed combat. We don't check for handled just because at this point it doesn't matter. + if(wideAttack) + RaiseLocalEvent(player.Uid, new WideAttackEvent(player, player, coordinates), false); + else + RaiseLocalEvent(player.Uid, new ClickAttackEvent(player, player, coordinates, targetUid), false); } } } diff --git a/Content.Server/GameObjects/EntitySystems/Weapon/Melee/MeleeWeaponSystem.cs b/Content.Server/GameObjects/EntitySystems/Weapon/Melee/MeleeWeaponSystem.cs index d84f484acd..a62661c7af 100644 --- a/Content.Server/GameObjects/EntitySystems/Weapon/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Weapon/Melee/MeleeWeaponSystem.cs @@ -60,6 +60,7 @@ namespace Content.Server.GameObjects.EntitySystems.Weapon.Melee private void OnClickAttack(EntityUid uid, MeleeWeaponComponent comp, ClickAttackEvent args) { + args.Handled = true; var curTime = _gameTiming.CurTime; if (curTime < comp.CooldownEnd || !args.Target.IsValid()) @@ -105,6 +106,7 @@ namespace Content.Server.GameObjects.EntitySystems.Weapon.Melee private void OnWideAttack(EntityUid uid, MeleeWeaponComponent comp, WideAttackEvent args) { + args.Handled = true; var curTime = _gameTiming.CurTime; if (curTime < comp.CooldownEnd) diff --git a/Content.Shared/Interfaces/GameObjects/Components/Interaction/AttackEvent.cs b/Content.Shared/Interfaces/GameObjects/Components/Interaction/AttackEvent.cs index e917e4c639..239300c70c 100644 --- a/Content.Shared/Interfaces/GameObjects/Components/Interaction/AttackEvent.cs +++ b/Content.Shared/Interfaces/GameObjects/Components/Interaction/AttackEvent.cs @@ -7,7 +7,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components /// /// Raised directed on the used entity when a target entity is click attacked by a user. /// - public class ClickAttackEvent : EntityEventArgs + public class ClickAttackEvent : HandledEntityEventArgs { /// /// Entity used to attack, for broadcast purposes. @@ -49,7 +49,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components /// /// Raised directed on the used entity when a target entity is wide attacked by a user. /// - public class WideAttackEvent : EntityEventArgs + public class WideAttackEvent : HandledEntityEventArgs { /// /// Entity used to attack, for broadcast purposes.