Harmbaton rework + remove MeleeInteractEvent (#8157)
This commit is contained in:
@@ -30,7 +30,6 @@ namespace Content.Server.Flash
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
|
||||
SubscribeLocalEvent<FlashComponent, MeleeInteractEvent>(OnFlashMeleeInteract);
|
||||
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand);
|
||||
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(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<FlashableComponent>(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))
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace Content.Server.Stunnable
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeInteractEvent>(OnMeleeInteract);
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(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)
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace Content.Server.Weapon.Melee
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnHandSelected);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, ClickAttackEvent>(OnClickAttack);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, WideAttackEvent>(OnWideAttack);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(OnChemicalInjectorHit);
|
||||
}
|
||||
|
||||
@@ -204,41 +203,6 @@ namespace Content.Server.Weapon.Melee
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used for melee weapons that want some behavior on AfterInteract,
|
||||
/// but also want the cooldown (stun batons, flashes)
|
||||
/// </summary>
|
||||
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<TransformComponent>(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<EntityUid>() { 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<EntityUid> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on the melee weapon entity used to attack something in combat mode,
|
||||
/// whether through a click attack or wide attack.
|
||||
/// </summary>
|
||||
public sealed class MeleeInteractEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity interacted with.
|
||||
/// </summary>
|
||||
public EntityUid Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user who interacted using the melee weapon.
|
||||
/// </summary>
|
||||
public EntityUid User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool CanInteract { get; set; } = false;
|
||||
|
||||
public MeleeInteractEvent(EntityUid entity, EntityUid user)
|
||||
{
|
||||
Entity = entity;
|
||||
User = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
- type: MeleeWeapon
|
||||
damage:
|
||||
types:
|
||||
Blunt: 10
|
||||
Blunt: 5
|
||||
range: 1.5
|
||||
arcwidth: 60
|
||||
arc: default
|
||||
|
||||
Reference in New Issue
Block a user