From 65445711e01577cd52a7cd03f8edd20139a33290 Mon Sep 17 00:00:00 2001 From: Kara Date: Sat, 14 May 2022 19:10:34 -0700 Subject: [PATCH] Harmbaton rework + remove `MeleeInteractEvent` (#8157) --- Content.Server/Flash/FlashSystem.cs | 15 ----- Content.Server/Stunnable/StunbatonSystem.cs | 17 +---- .../Weapon/Melee/MeleeWeaponSystem.cs | 65 ------------------- .../Entities/Objects/Weapons/security.yml | 2 +- 4 files changed, 4 insertions(+), 95 deletions(-) diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index 227613f453..f52fab911a 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -30,7 +30,6 @@ namespace Content.Server.Flash { base.Initialize(); SubscribeLocalEvent(OnFlashMeleeHit); - SubscribeLocalEvent(OnFlashMeleeInteract); SubscribeLocalEvent(OnFlashUseInHand); SubscribeLocalEvent(OnFlashExamined); @@ -79,20 +78,6 @@ namespace Content.Server.Flash } } - private void OnFlashMeleeInteract(EntityUid uid, FlashComponent comp, MeleeInteractEvent args) - { - if (!UseFlash(comp, args.User)) - { - return; - } - - if (EntityManager.HasComponent(args.Entity)) - { - args.CanInteract = true; - Flash(args.Entity, args.User, uid, comp.FlashDuration, comp.SlowTo); - } - } - private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args) { if (!UseFlash(comp, args.User)) diff --git a/Content.Server/Stunnable/StunbatonSystem.cs b/Content.Server/Stunnable/StunbatonSystem.cs index 52b6ac106e..57c6913af2 100644 --- a/Content.Server/Stunnable/StunbatonSystem.cs +++ b/Content.Server/Stunnable/StunbatonSystem.cs @@ -34,7 +34,6 @@ namespace Content.Server.Stunnable base.Initialize(); SubscribeLocalEvent(OnMeleeHit); - SubscribeLocalEvent(OnMeleeInteract); SubscribeLocalEvent(OnUseInHand); SubscribeLocalEvent(OnThrowCollide); SubscribeLocalEvent(OnPowerCellChanged); @@ -43,7 +42,7 @@ namespace Content.Server.Stunnable private void OnMeleeHit(EntityUid uid, StunbatonComponent comp, MeleeHitEvent args) { - if (!comp.Activated || !args.HitEntities.Any()) + if (!comp.Activated || !args.HitEntities.Any() || args.Handled) return; if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse)) @@ -54,19 +53,9 @@ namespace Content.Server.Stunnable StunEntity(entity, comp); SendPowerPulse(entity, args.User, uid); } - } - private void OnMeleeInteract(EntityUid uid, StunbatonComponent comp, MeleeInteractEvent args) - { - if (!comp.Activated) - return; - - if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse)) - return; - - args.CanInteract = true; - StunEntity(args.Entity, comp); - SendPowerPulse(args.Entity, args.User, uid); + // No combat should occur if we successfully stunned. + args.Handled = true; } private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args) diff --git a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs index 4eb9345cbc..712a8212f8 100644 --- a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs @@ -38,7 +38,6 @@ namespace Content.Server.Weapon.Melee SubscribeLocalEvent(OnHandSelected); SubscribeLocalEvent(OnClickAttack); SubscribeLocalEvent(OnWideAttack); - SubscribeLocalEvent(OnAfterInteract); SubscribeLocalEvent(OnChemicalInjectorHit); } @@ -204,41 +203,6 @@ namespace Content.Server.Weapon.Melee RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); } - /// - /// Used for melee weapons that want some behavior on AfterInteract, - /// but also want the cooldown (stun batons, flashes) - /// - private void OnAfterInteract(EntityUid owner, MeleeWeaponComponent comp, AfterInteractEvent args) - { - if (args.Handled || !args.CanReach) - return; - - var curTime = _gameTiming.CurTime; - - if (curTime < comp.CooldownEnd) - { - return; - } - - if (!args.Target.HasValue) - return; - - var location = EntityManager.GetComponent(args.User).Coordinates; - var diff = args.ClickLocation.ToMapPos(EntityManager) - location.ToMapPos(EntityManager); - var angle = Angle.FromWorldVec(diff); - - var hitEvent = new MeleeInteractEvent(args.Target.Value, args.User); - RaiseLocalEvent(owner, hitEvent, false); - - if (!hitEvent.CanInteract) return; - SendAnimation(comp.ClickArc, angle, args.User, owner, new List() { args.Target.Value }, comp.ClickAttackEffect, false); - - comp.LastAttackTime = curTime; - comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime); - - RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); - } - private HashSet ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, EntityUid ignore) { var widthRad = Angle.FromDegrees(arcWidth); @@ -348,33 +312,4 @@ namespace Content.Server.Weapon.Melee User = user; } } - - /// - /// Raised directed on the melee weapon entity used to attack something in combat mode, - /// whether through a click attack or wide attack. - /// - public sealed class MeleeInteractEvent : EntityEventArgs - { - /// - /// The entity interacted with. - /// - public EntityUid Entity { get; } - - /// - /// The user who interacted using the melee weapon. - /// - public EntityUid User { get; } - - /// - /// Modified by the event handler to specify whether they could successfully interact with the entity. - /// Used to know whether to send the hit animation or not. - /// - public bool CanInteract { get; set; } = false; - - public MeleeInteractEvent(EntityUid entity, EntityUid user) - { - Entity = entity; - User = user; - } - } } diff --git a/Resources/Prototypes/Entities/Objects/Weapons/security.yml b/Resources/Prototypes/Entities/Objects/Weapons/security.yml index 7efdca8b5d..c31595ec92 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/security.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/security.yml @@ -11,7 +11,7 @@ - type: MeleeWeapon damage: types: - Blunt: 10 + Blunt: 5 range: 1.5 arcwidth: 60 arc: default