Index: binaries/data/mods/public/simulation/components/Attack.js
===================================================================
--- binaries/data/mods/public/simulation/components/Attack.js
+++ binaries/data/mods/public/simulation/components/Attack.js
@@ -533,22 +533,16 @@
}
let id = cmpProjectileManager.LaunchProjectileAtPoint(launchPoint, realTargetPosition, horizSpeed, gravity, actorName, impactActorName, impactAnimationLifetime);
-
- let attackImpactSound = "";
- let cmpSound = Engine.QueryInterface(this.entity, IID_Sound);
- if (cmpSound)
- attackImpactSound = cmpSound.GetSoundGroup("attack_impact_" + type.toLowerCase());
-
let data = {
"type": type,
"attackData": this.GetAttackEffectsData(type),
"target": target,
+ "source": this.entity,
"attacker": this.entity,
"attackerOwner": attackerOwner,
"position": realTargetPosition,
"direction": missileDirection,
"projectileId": id,
- "attackImpactSound": attackImpactSound,
"splash": this.GetSplashData(type),
"friendlyFire": this.template[type].Projectile.FriendlyFire == "true",
};
@@ -556,7 +550,12 @@
cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_DelayedDamage, "MissileHit", +this.template[type].Delay + timeToTarget * 1000, data);
}
else
+ {
Attacking.HandleAttackEffects(target, type, this.GetAttackEffectsData(type), this.entity, attackerOwner);
+ var impactSoundGroup = GetImpactSoundGroup(type, target, this.entity, false);
+ if (impactSoundGroup)
+ PlaySound(impactSoundGroup, this.entity);
+ }
};
Attack.prototype.OnValueModification = function(msg)
Index: binaries/data/mods/public/simulation/components/DelayedDamage.js
===================================================================
--- binaries/data/mods/public/simulation/components/DelayedDamage.js
+++ binaries/data/mods/public/simulation/components/DelayedDamage.js
@@ -39,9 +39,6 @@
if (!data.position)
return;
- let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager);
- if (cmpSoundManager && data.attackImpactSound)
- cmpSoundManager.PlaySoundGroupAtPosition(data.attackImpactSound, data.position);
// Do this first in case the direct hit kills the target.
if (data.splash)
@@ -65,10 +62,15 @@
if (cmpMirage)
target = cmpMirage.GetParent();
+ var hitTarget = PositionHelper.TestCollision(target, data.position, lateness) &&
+ Attacking.HandleAttackEffects(target, data.type, data.attackData, data.attacker, data.attackerOwner);
+
+ let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager);
+ if (cmpSoundManager)
+ cmpSoundManager.PlaySoundGroupAtPosition(GetImpactSoundGroup(data.type, target, data.attacker, !hitTarget), data.position);
// Deal direct damage if we hit the main target
// and we could handle the attack.
- if (PositionHelper.TestCollision(target, data.position, lateness) &&
- Attacking.HandleAttackEffects(target, data.type, data.attackData, data.attacker, data.attackerOwner))
+ if (hitTarget)
{
cmpProjectileManager.RemoveProjectile(data.projectileId);
return;
Index: binaries/data/mods/public/simulation/helpers/Sound.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Sound.js
+++ binaries/data/mods/public/simulation/helpers/Sound.js
@@ -10,4 +10,36 @@
cmpSound.PlaySoundGroup(name);
}
+/**
+ * Gets the matching impact sound group depending on the .
+ * @param {string} type - The type of damage.
+ * @param {number} target - The entity id of the target.
+ * @param {number} attacker - The entity id of the attacker.
+ * @param {boolean} missed - Whether the target was missed.
+ * @return {string} - The impact sound group.
+ */
+function GetImpactSoundGroup(type, target, attacker, missed)
+{
+ let cmpSound = Engine.QueryInterface(attacker, IID_Sound);
+ if (!cmpSound)
+ return "";
+
+ let attackImpactType = "attack_impact_" + type.toLowerCase();
+ let soundGroup = cmpSound.GetSoundGroup(attackImpactType);
+ let cmpIdentity = Engine.QueryInterface(target, IID_Identity);
+ if (!missed && cmpIdentity)
+ {
+ if(cmpIdentity.HasClass("Organic"))
+ soundGroup = cmpSound.GetSoundGroup(attackImpactType + "_flesh");
+ else if(cmpIdentity.HasClass("Structure"))
+ soundGroup = cmpSound.GetSoundGroup(attackImpactType + "_stone");
+ else if(cmpIdentity.HasClass("Ship"))
+ soundGroup = cmpSound.GetSoundGroup(attackImpactType + "_wood");
+ }
+
+ warn(`${attacker}:${target}:${soundGroup}:${attackImpactType}:${type}:${missed}`)
+ return soundGroup;
+};
+
+Engine.RegisterGlobal("GetImpactSoundGroup", GetImpactSoundGroup);
Engine.RegisterGlobal("PlaySound", PlaySound);
Index: binaries/data/mods/public/simulation/templates/template_unit.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit.xml
+++ binaries/data/mods/public/simulation/templates/template_unit.xml
@@ -112,6 +112,13 @@
interface/alarm/alarm_attackplayer.xml
interface/alarm/alarm_attacked_gaia.xml
attack/weapon/sword_attack.xml
+ attack/impact/shield_wooden.xml
+ attack/impact/shield_metal.xml
+ attack/impact/shield_wooden.xml
+ attack/impact/shield_wooden.xml
+ attack/impact/arrow_metal.xml
+ attack/impact/javelin_impact.xml
+ attack/impact/javelin_impact.xml