Harmbaton rework + remove MeleeInteractEvent (#8157)

This commit is contained in:
Kara
2022-05-14 19:10:34 -07:00
committed by GitHub
parent c3f0f4625b
commit 65445711e0
4 changed files with 4 additions and 95 deletions

View File

@@ -30,7 +30,6 @@ namespace Content.Server.Flash
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit); SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
SubscribeLocalEvent<FlashComponent, MeleeInteractEvent>(OnFlashMeleeInteract);
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand); SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand);
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnFlashExamined); 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) private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
{ {
if (!UseFlash(comp, args.User)) if (!UseFlash(comp, args.User))

View File

@@ -34,7 +34,6 @@ namespace Content.Server.Stunnable
base.Initialize(); base.Initialize();
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit); SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<StunbatonComponent, MeleeInteractEvent>(OnMeleeInteract);
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand); SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide); SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged); SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged);
@@ -43,7 +42,7 @@ namespace Content.Server.Stunnable
private void OnMeleeHit(EntityUid uid, StunbatonComponent comp, MeleeHitEvent args) private void OnMeleeHit(EntityUid uid, StunbatonComponent comp, MeleeHitEvent args)
{ {
if (!comp.Activated || !args.HitEntities.Any()) if (!comp.Activated || !args.HitEntities.Any() || args.Handled)
return; return;
if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse)) if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse))
@@ -54,19 +53,9 @@ namespace Content.Server.Stunnable
StunEntity(entity, comp); StunEntity(entity, comp);
SendPowerPulse(entity, args.User, uid); SendPowerPulse(entity, args.User, uid);
} }
}
private void OnMeleeInteract(EntityUid uid, StunbatonComponent comp, MeleeInteractEvent args) // No combat should occur if we successfully stunned.
{ args.Handled = true;
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);
} }
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args) private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)

View File

@@ -38,7 +38,6 @@ namespace Content.Server.Weapon.Melee
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnHandSelected); SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnHandSelected);
SubscribeLocalEvent<MeleeWeaponComponent, ClickAttackEvent>(OnClickAttack); SubscribeLocalEvent<MeleeWeaponComponent, ClickAttackEvent>(OnClickAttack);
SubscribeLocalEvent<MeleeWeaponComponent, WideAttackEvent>(OnWideAttack); SubscribeLocalEvent<MeleeWeaponComponent, WideAttackEvent>(OnWideAttack);
SubscribeLocalEvent<MeleeWeaponComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(OnChemicalInjectorHit); SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(OnChemicalInjectorHit);
} }
@@ -204,41 +203,6 @@ namespace Content.Server.Weapon.Melee
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); 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) private HashSet<EntityUid> ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, EntityUid ignore)
{ {
var widthRad = Angle.FromDegrees(arcWidth); var widthRad = Angle.FromDegrees(arcWidth);
@@ -348,33 +312,4 @@ namespace Content.Server.Weapon.Melee
User = user; 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;
}
}
} }

View File

@@ -11,7 +11,7 @@
- type: MeleeWeapon - type: MeleeWeapon
damage: damage:
types: types:
Blunt: 10 Blunt: 5
range: 1.5 range: 1.5
arcwidth: 60 arcwidth: 60
arc: default arc: default