Make melee damage not go through MeleeHitEvent.cs (#16881)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Power.NodeGroups;
|
||||
using Content.Server.Weapons.Melee;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Database;
|
||||
@@ -37,6 +38,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
|
||||
[Dependency] private readonly SharedJitteringSystem _jittering = default!;
|
||||
[Dependency] private readonly MeleeWeaponSystem _meleeWeapon = default!;
|
||||
[Dependency] private readonly SharedStunSystem _stun = default!;
|
||||
[Dependency] private readonly SharedStutteringSystem _stuttering = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
@@ -161,12 +163,8 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
||||
if (!electrified.OnAttacked)
|
||||
return;
|
||||
|
||||
//Dont shock if the attacker used a toy
|
||||
if (EntityManager.TryGetComponent<MeleeWeaponComponent>(args.Used, out var meleeWeaponComponent))
|
||||
{
|
||||
if (meleeWeaponComponent.Damage.Total == 0)
|
||||
if (_meleeWeapon.GetDamage(args.Used).Total == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
TryDoElectrifiedAct(uid, args.User, 1, electrified);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.Power.Events;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Events;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction.Events;
|
||||
@@ -27,15 +28,16 @@ namespace Content.Server.Stunnable.Systems
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<StunbatonComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, StunbatonComponent component, MeleeHitEvent args)
|
||||
private void OnGetMeleeDamage(EntityUid uid, StunbatonComponent component, ref GetMeleeDamageEvent args)
|
||||
{
|
||||
if (!component.Activated) return;
|
||||
if (!component.Activated)
|
||||
return;
|
||||
|
||||
// Don't apply damage if it's activated; just do stamina damage.
|
||||
args.BonusDamage -= args.BaseDamage;
|
||||
args.Damage = new DamageSpecifier();
|
||||
}
|
||||
|
||||
private void OnStaminaHitAttempt(EntityUid uid, StunbatonComponent component, ref StaminaDamageOnHitAttemptEvent args)
|
||||
|
||||
@@ -44,13 +44,13 @@ namespace Content.Server.Tools
|
||||
SubscribeLocalEvent<WelderComponent, ToolDoAfterEvent>(OnWelderDoAfter);
|
||||
SubscribeLocalEvent<WelderComponent, ComponentShutdown>(OnWelderShutdown);
|
||||
SubscribeLocalEvent<WelderComponent, ComponentGetState>(OnWelderGetState);
|
||||
SubscribeLocalEvent<WelderComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<WelderComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, WelderComponent component, MeleeHitEvent args)
|
||||
private void OnGetMeleeDamage(EntityUid uid, WelderComponent component, ref GetMeleeDamageEvent args)
|
||||
{
|
||||
if (!args.Handled && component.Lit)
|
||||
args.BonusDamage += component.LitMeleeDamageBonus;
|
||||
if (component.Lit)
|
||||
args.Damage += component.LitMeleeDamageBonus;
|
||||
}
|
||||
|
||||
public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed class EnergySwordSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
|
||||
SubscribeLocalEvent<EnergySwordComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<EnergySwordComponent, IsHotEvent>(OnIsHotEvent);
|
||||
@@ -42,13 +42,13 @@ public sealed class EnergySwordSystem : EntitySystem
|
||||
comp.BladeColor = _random.Pick(comp.ColorOptions);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, EnergySwordComponent comp, MeleeHitEvent args)
|
||||
private void OnGetMeleeDamage(EntityUid uid, EnergySwordComponent comp, ref GetMeleeDamageEvent args)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
// Overrides basic blunt damage with burn+slash as set in yaml
|
||||
args.BonusDamage = comp.LitDamageBonus;
|
||||
args.Damage = comp.LitDamageBonus;
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, EnergySwordComponent comp, UseInHandEvent args)
|
||||
|
||||
@@ -62,16 +62,7 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
if (!args.CanInteract || !args.CanAccess || component.HideFromExamine)
|
||||
return;
|
||||
|
||||
var getDamage = new MeleeHitEvent(new List<EntityUid>(), args.User, uid, component.Damage);
|
||||
getDamage.IsHit = false;
|
||||
RaiseLocalEvent(uid, getDamage);
|
||||
|
||||
var damageSpec = GetDamage(component);
|
||||
|
||||
if (damageSpec == null)
|
||||
damageSpec = new DamageSpecifier();
|
||||
|
||||
damageSpec += getDamage.BonusDamage;
|
||||
var damageSpec = GetDamage(uid, component);
|
||||
|
||||
if (damageSpec.Total == FixedPoint2.Zero)
|
||||
return;
|
||||
@@ -115,10 +106,6 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
private DamageSpecifier? GetDamage(MeleeWeaponComponent component)
|
||||
{
|
||||
return component.Damage.Total > FixedPoint2.Zero ? component.Damage : null;
|
||||
}
|
||||
|
||||
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.Damage;
|
||||
|
||||
namespace Content.Shared.Weapons.Melee.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for adding in bonus damage via <see cref="GetMeleeWeaponEvent"/>
|
||||
/// This exists only for event relays and doing entity shenanigans.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class BonusMeleeDamageComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The damage that will be applied.
|
||||
/// </summary>
|
||||
[DataField("bonusDamage", required: true)]
|
||||
public DamageSpecifier BonusDamage = default!;
|
||||
}
|
||||
@@ -66,3 +66,10 @@ public sealed class MeleeHitEvent : HandledEntityEventArgs
|
||||
BaseDamage = baseDamage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a melee weapon to calculate potential damage bonuses or decreases.
|
||||
/// </summary>
|
||||
/// <param name="Damage"></param>
|
||||
[ByRefEvent]
|
||||
public record struct GetMeleeDamageEvent(DamageSpecifier Damage);
|
||||
|
||||
@@ -73,6 +73,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, HandDeselectedEvent>(OnMeleeDropped);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnMeleeSelected);
|
||||
SubscribeLocalEvent<MeleeWeaponComponent, GunShotEvent>(OnMeleeShot);
|
||||
SubscribeLocalEvent<BonusMeleeDamageComponent, GetMeleeDamageEvent>(OnGetBonusMeleeDamage);
|
||||
|
||||
SubscribeAllEvent<HeavyAttackEvent>(OnHeavyAttack);
|
||||
SubscribeAllEvent<LightAttackEvent>(OnLightAttack);
|
||||
@@ -140,6 +141,11 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private void OnGetBonusMeleeDamage(EntityUid uid, BonusMeleeDamageComponent component, ref GetMeleeDamageEvent args)
|
||||
{
|
||||
args.Damage += component.BonusDamage;
|
||||
}
|
||||
|
||||
private void OnStopAttack(StopAttackEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
var user = args.SenderSession.AttachedEntity;
|
||||
@@ -270,6 +276,17 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
component.Range = state.Range;
|
||||
}
|
||||
|
||||
public DamageSpecifier GetDamage(EntityUid uid, MeleeWeaponComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return new DamageSpecifier();
|
||||
|
||||
var ev = new GetMeleeDamageEvent(new (component.Damage));
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
|
||||
return ev.Damage;
|
||||
}
|
||||
|
||||
public bool TryGetWeapon(EntityUid entity, out EntityUid weaponUid, [NotNullWhen(true)] out MeleeWeaponComponent? melee)
|
||||
{
|
||||
weaponUid = default;
|
||||
@@ -469,7 +486,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
|
||||
protected virtual void DoLightAttack(EntityUid user, LightAttackEvent ev, EntityUid meleeUid, MeleeWeaponComponent component, ICommonSession? session)
|
||||
{
|
||||
var damage = component.Damage * GetModifier(component, true);
|
||||
var damage = GetDamage(meleeUid, component) * GetModifier(component, true);
|
||||
|
||||
// For consistency with wide attacks stuff needs damageable.
|
||||
if (Deleted(ev.Target) ||
|
||||
@@ -543,7 +560,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
{
|
||||
Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user);
|
||||
}
|
||||
else if (component.Damage.Total.Equals(FixedPoint2.Zero) && component.HitSound != null)
|
||||
else if (GetDamage(meleeUid, component).Total.Equals(FixedPoint2.Zero) && component.HitSound != null)
|
||||
{
|
||||
Audio.PlayPredicted(component.HitSound, meleeUid, user);
|
||||
}
|
||||
@@ -576,7 +593,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
||||
var direction = targetMap.Position - userPos;
|
||||
var distance = Math.Min(component.Range, direction.Length);
|
||||
|
||||
var damage = component.Damage * GetModifier(component, false);
|
||||
var damage = GetDamage(meleeUid, component) * GetModifier(component, false);
|
||||
var entities = ev.Entities;
|
||||
|
||||
if (entities.Count == 0)
|
||||
|
||||
@@ -40,7 +40,7 @@ public sealed class WieldableSystem : EntitySystem
|
||||
SubscribeLocalEvent<MeleeRequiresWieldComponent, AttemptMeleeEvent>(OnMeleeAttempt);
|
||||
SubscribeLocalEvent<GunRequiresWieldComponent, AttemptShootEvent>(OnShootAttempt);
|
||||
|
||||
SubscribeLocalEvent<IncreaseDamageOnWieldComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<IncreaseDamageOnWieldComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
|
||||
}
|
||||
|
||||
private void OnMeleeAttempt(EntityUid uid, MeleeRequiresWieldComponent component, ref AttemptMeleeEvent args)
|
||||
@@ -243,16 +243,13 @@ public sealed class WieldableSystem : EntitySystem
|
||||
AttemptUnwield(args.BlockingEntity, component, args.User);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, IncreaseDamageOnWieldComponent component, MeleeHitEvent args)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<WieldableComponent>(uid, out var wield))
|
||||
private void OnGetMeleeDamage(EntityUid uid, IncreaseDamageOnWieldComponent component, ref GetMeleeDamageEvent args)
|
||||
{
|
||||
if (!TryComp<WieldableComponent>(uid, out var wield))
|
||||
return;
|
||||
if (!wield.Wielded)
|
||||
return;
|
||||
}
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.BonusDamage += component.BonusDamage;
|
||||
args.Damage += component.BonusDamage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user