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
@@ -575,12 +575,6 @@
}
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),
@@ -590,7 +584,6 @@
"position": realTargetPosition,
"direction": missileDirection,
"projectileId": id,
- "attackImpactSound": attackImpactSound,
"splash": this.GetSplashData(type),
"friendlyFire": this.template[type].Projectile.FriendlyFire == "true",
};
@@ -598,7 +591,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);
+ let 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,19 @@
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)
+ {
+ let soundGroup = GetImpactSoundGroup(data.type, target, data.attacker, hitTarget);
+ if(soundGroup)
+ cmpSoundManager.PlaySoundGroupAtPosition(soundGroup, 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/components/Identity.js
===================================================================
--- binaries/data/mods/public/simulation/components/Identity.js
+++ binaries/data/mods/public/simulation/components/Identity.js
@@ -28,6 +28,11 @@
"" +
"" +
"" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"" +
"" +
"" +
@@ -186,6 +191,11 @@
return this.template.GenericName;
};
+Identity.prototype.GetMaterial = function()
+{
+ return this.template.Material || "";
+};
+
Identity.prototype.IsUndeletable = function()
{
return this.template.Undeletable == "true";
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,42 @@
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} hitTarget - Whether the target was hit.
+ * @return {string} - The impact sound group.
+ */
+function GetImpactSoundGroup(type, target, attacker, hitTarget)
+{
+ let cmpSound = Engine.QueryInterface(attacker, IID_Sound);
+ if (!cmpSound)
+ return null;
+
+ let attackImpactType = "attack_impact_" + type.toLowerCase();
+ if (!hitTarget)
+ {
+ let soundGroup = cmpSound.GetSoundGroup(attackImpactType + "_missed");
+ if (soundGroup)
+ return soundGroup;
+ }
+
+ let cmpIdentity = Engine.QueryInterface(target, IID_Identity);
+ if (cmpIdentity)
+ {
+ let material = cmpIdentity.GetMaterial();
+ if(material)
+ {
+ let soundGroup = cmpSound.GetSoundGroup(attackImpactType + "_" + cmpIdentity.GetMaterial());
+ if (soundGroup)
+ return soundGroup;
+ }
+ }
+
+ return cmpSound.GetSoundGroup(attackImpactType);
+}
+
+Engine.RegisterGlobal("GetImpactSoundGroup", GetImpactSoundGroup);
Engine.RegisterGlobal("PlaySound", PlaySound);
Index: binaries/data/mods/public/simulation/templates/template_structure.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure.xml
+++ binaries/data/mods/public/simulation/templates/template_structure.xml
@@ -44,6 +44,7 @@
gaia
+ stone
Structure
Structure
false
@@ -138,6 +139,14 @@
interface/alarm/alarm_attacked_gaia.xml
interface/alarm/alarm_attackplayer.xml
interface/alarm/alarm_attacked_gaia.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
+ attack/impact/arrow_impact.xml
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
@@ -36,6 +36,7 @@
gaia
Unit Organic ConquestCritical
Unit
+ flesh
special/formations/null
special/formations/box
@@ -112,6 +113,14 @@
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/shield_wooden.xml
+ attack/impact/javelin_impact.xml
+ attack/impact/arrow_impact.xml
Index: binaries/data/mods/public/simulation/templates/template_unit_ship.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship.xml
@@ -25,6 +25,7 @@
Ship
+ wood
-Organic
Ship