Make melee damage not go through MeleeHitEvent.cs (#16881)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user