Fire MeleeHitEvent on misses. (#12867)
* Fire MeleeHitEvent when there are no targets. * Prevent certain weapons from activating if they had no hit entities on hit. * Prevent miss events from firing when target is yourself or was deleted. * Use .Value as Target is already known not to be null. * uid changes --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Flash.Components;
|
||||
using Content.Server.Light.EntitySystems;
|
||||
using Content.Server.Stunnable;
|
||||
@@ -43,11 +44,12 @@ namespace Content.Server.Flash
|
||||
|
||||
private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!args.IsHit)
|
||||
return;
|
||||
|
||||
if (!UseFlash(comp, args.User))
|
||||
if (!args.IsHit ||
|
||||
!args.HitEntities.Any() ||
|
||||
!UseFlash(comp, args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
foreach (var e in args.HitEntities)
|
||||
|
||||
@@ -95,17 +95,19 @@ public sealed partial class NPCCombatSystem
|
||||
|
||||
foreach (var (comp, _) in EntityQuery<NPCMeleeCombatComponent, ActiveNPCComponent>())
|
||||
{
|
||||
if (!combatQuery.TryGetComponent(comp.Owner, out var combat) || !combat.IsInCombatMode)
|
||||
var uid = comp.Owner;
|
||||
|
||||
if (!combatQuery.TryGetComponent(uid, out var combat) || !combat.IsInCombatMode)
|
||||
{
|
||||
RemComp<NPCMeleeCombatComponent>(comp.Owner);
|
||||
RemComp<NPCMeleeCombatComponent>(uid);
|
||||
continue;
|
||||
}
|
||||
|
||||
Attack(comp, curTime, physicsQuery, xformQuery);
|
||||
Attack(uid, comp, curTime, physicsQuery, xformQuery);
|
||||
}
|
||||
}
|
||||
|
||||
private void Attack(NPCMeleeCombatComponent component, TimeSpan curTime, EntityQuery<PhysicsComponent> physicsQuery, EntityQuery<TransformComponent> xformQuery)
|
||||
private void Attack(EntityUid uid, NPCMeleeCombatComponent component, TimeSpan curTime, EntityQuery<PhysicsComponent> physicsQuery, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
component.Status = CombatStatus.Normal;
|
||||
|
||||
@@ -115,7 +117,7 @@ public sealed partial class NPCCombatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (!xformQuery.TryGetComponent(component.Owner, out var xform) ||
|
||||
if (!xformQuery.TryGetComponent(uid, out var xform) ||
|
||||
!xformQuery.TryGetComponent(component.Target, out var targetXform))
|
||||
{
|
||||
component.Status = CombatStatus.TargetUnreachable;
|
||||
@@ -134,7 +136,7 @@ public sealed partial class NPCCombatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<NPCSteeringComponent>(component.Owner, out var steering) &&
|
||||
if (TryComp<NPCSteeringComponent>(uid, out var steering) &&
|
||||
steering.Status == SteeringStatus.NoPath)
|
||||
{
|
||||
component.Status = CombatStatus.TargetUnreachable;
|
||||
@@ -147,11 +149,11 @@ public sealed partial class NPCCombatSystem
|
||||
return;
|
||||
}
|
||||
|
||||
steering = EnsureComp<NPCSteeringComponent>(component.Owner);
|
||||
steering = EnsureComp<NPCSteeringComponent>(uid);
|
||||
steering.Range = MathF.Max(0.2f, weapon.Range - 0.4f);
|
||||
|
||||
// Gets unregistered on component shutdown.
|
||||
_steering.TryRegister(component.Owner, new EntityCoordinates(component.Target, Vector2.Zero), steering);
|
||||
_steering.TryRegister(uid, new EntityCoordinates(component.Target, Vector2.Zero), steering);
|
||||
|
||||
if (weapon.NextAttack > curTime || !Enabled)
|
||||
return;
|
||||
@@ -160,11 +162,11 @@ public sealed partial class NPCCombatSystem
|
||||
physicsQuery.TryGetComponent(component.Target, out var targetPhysics) &&
|
||||
targetPhysics.LinearVelocity.LengthSquared != 0f)
|
||||
{
|
||||
_melee.AttemptLightAttackMiss(component.Owner, weapon, targetXform.Coordinates.Offset(_random.NextVector2(0.5f)));
|
||||
_melee.AttemptLightAttackMiss(uid, component.Weapon, weapon, targetXform.Coordinates.Offset(_random.NextVector2(0.5f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_melee.AttemptLightAttack(component.Owner, weapon, component.Target);
|
||||
_melee.AttemptLightAttack(uid, component.Weapon, weapon, component.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public sealed partial class NPCSteeringSystem
|
||||
// TODO: Validate we can damage it
|
||||
if (destructibleQuery.HasComponent(ent))
|
||||
{
|
||||
_melee.AttemptLightAttack(component.Owner, meleeWeapon, ent);
|
||||
_melee.AttemptLightAttack(component.Owner, component.Owner, meleeWeapon, ent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return;
|
||||
|
||||
if (user == null)
|
||||
PopupSystem.PopupEntity(message, uid.Value);
|
||||
PopupSystem.PopupEntity(message, uid.Value);
|
||||
else
|
||||
PopupSystem.PopupEntity(message, uid.Value, Filter.PvsExcept(user.Value, entityManager: EntityManager), true);
|
||||
}
|
||||
|
||||
protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, MeleeWeaponComponent component, ICommonSession? session)
|
||||
protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
||||
{
|
||||
if (!base.DoDisarm(user, ev, component, session))
|
||||
if (!base.DoDisarm(user, ev, meleeUid, component, session))
|
||||
return false;
|
||||
|
||||
if (!TryComp<CombatModeComponent>(user, out var combatMode) ||
|
||||
@@ -228,11 +228,12 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
|
||||
private void OnChemicalInjectorHit(EntityUid owner, MeleeChemicalInjectorComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!args.IsHit)
|
||||
return;
|
||||
|
||||
if (!_solutions.TryGetSolution(owner, comp.Solution, out var solutionContainer))
|
||||
if (!args.IsHit ||
|
||||
!args.HitEntities.Any() ||
|
||||
!_solutions.TryGetSolution(owner, comp.Solution, out var solutionContainer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var hitBloodstreams = new List<BloodstreamComponent>();
|
||||
var bloodQuery = GetEntityQuery<BloodstreamComponent>();
|
||||
|
||||
Reference in New Issue
Block a user