Fix punching (#4141)

This commit is contained in:
Vera Aguilera Puerto
2021-06-05 18:05:57 +02:00
committed by GitHub
parent 3af9c334ea
commit 62ce603858
4 changed files with 33 additions and 7 deletions

View File

@@ -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";

View File

@@ -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<ItemComponent>()) return;
if (EntityManager.TryGetEntity(targetUid, out var targetEnt) && targetEnt.HasComponent<ItemComponent>())
{
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);
}
}
}

View File

@@ -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)

View File

@@ -7,7 +7,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
/// <summary>
/// Raised directed on the used entity when a target entity is click attacked by a user.
/// </summary>
public class ClickAttackEvent : EntityEventArgs
public class ClickAttackEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity used to attack, for broadcast purposes.
@@ -49,7 +49,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
/// <summary>
/// Raised directed on the used entity when a target entity is wide attacked by a user.
/// </summary>
public class WideAttackEvent : EntityEventArgs
public class WideAttackEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity used to attack, for broadcast purposes.