Skip to content

Commit

Permalink
Play tap.ogg when no damage is being done (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Jul 7, 2022
1 parent 94a9569 commit 3135dfb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public sealed class MeleeWeaponComponent : Component
[DataField("hitSound")]
public SoundSpecifier? HitSound;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("noDamageSound")]
public SoundSpecifier NoDamageSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/tap.ogg");

[ViewVariables(VVAccess.ReadWrite)]
[DataField("missSound")]
public SoundSpecifier MissSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
Expand Down
50 changes: 30 additions & 20 deletions Content.Server/Weapon/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,26 @@ private void OnClickAttack(EntityUid owner, MeleeWeaponComponent comp, ClickAtta
var modifiedDamage = DamageSpecifier.ApplyModifierSets(comp.Damage + hitEvent.BonusDamage, hitEvent.ModifiersList);
var damageResult = _damageableSystem.TryChangeDamage(target, modifiedDamage);

if (damageResult != null)
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
{
if (args.Used == args.User)
_adminLogger.Add(LogType.MeleeHit,
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using their hands and dealt {damageResult.Total:damage} damage");
else
_adminLogger.Add(LogType.MeleeHit,
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
}

PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, comp.HitSound);
PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, comp.HitSound);
}
else
{
SoundSystem.Play(comp.NoDamageSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
}
}
}
else
{
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), args.User);
return;
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
}

comp.LastAttackTime = curTime;
Expand Down Expand Up @@ -176,27 +179,18 @@ private void OnWideAttack(EntityUid owner, MeleeWeaponComponent comp, WideAttack
if (!hitEvent.Handled)
{
var modifiedDamage = DamageSpecifier.ApplyModifierSets(comp.Damage + hitEvent.BonusDamage, hitEvent.ModifiersList);

if (entities.Count != 0)
{
var target = entities.First();
TryComp<MeleeWeaponComponent>(target, out var meleeWeapon);

PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, meleeWeapon?.HitSound);
}
else
{
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner), Transform(args.User).Coordinates);
}
var appliedDamage = new DamageSpecifier();

foreach (var entity in hitEntities)
{
RaiseLocalEvent(entity, new AttackedEvent(args.Used, args.User, args.ClickLocation), true);

var damageResult = _damageableSystem.TryChangeDamage(entity, modifiedDamage);

if (damageResult != null)
if (damageResult != null && damageResult.Total > FixedPoint2.Zero)
{
appliedDamage += damageResult;

if (args.Used == args.User)
_adminLogger.Add(LogType.MeleeHit,
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(entity):target} using their hands and dealt {damageResult.Total:damage} damage");
Expand All @@ -205,12 +199,28 @@ private void OnWideAttack(EntityUid owner, MeleeWeaponComponent comp, WideAttack
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(entity):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
}
}

if (entities.Count != 0)
{
if (appliedDamage.Total > FixedPoint2.Zero)
{
var target = entities.First();
PlayHitSound(target, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, comp.HitSound);
}
else
{
SoundSystem.Play(comp.NoDamageSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
}
}
else
{
SoundSystem.Play(comp.MissSound.GetSound(), Filter.Pvs(owner, entityManager: EntityManager), owner);
}
}

comp.LastAttackTime = curTime;
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.ArcCooldownTime);

RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd));
}

public static string? GetHighestDamageSound(DamageSpecifier modifiedDamage, IPrototypeManager protoManager)
Expand Down

0 comments on commit 3135dfb

Please sign in to comment.