Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
* @param {Object} data.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | * @param {Object} data.strengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | ||||
* @param {string} data.type - the type of damage. | * @param {string} data.type - the type of damage. | ||||
* @param {number} data.attackerOwner - the player id of the owner of the attacker. | * @param {number} data.attackerOwner - the player id of the owner of the attacker. | ||||
* @param {boolean} data.isSplash - a flag indicating if it's splash damage. | * @param {boolean} data.isSplash - a flag indicating if it's splash damage. | ||||
* @param {Vector3D} data.position - the expected position of the target. | * @param {Vector3D} data.position - the expected position of the target. | ||||
* @param {number} data.projectileId - the id of the projectile. | * @param {number} data.projectileId - the id of the projectile. | ||||
* @param {Vector3D} data.direction - the unit vector defining the direction. | * @param {Vector3D} data.direction - the unit vector defining the direction. | ||||
* @param {Object} data.bonus - the attack bonus template from the attacker. | * @param {Object} data.bonus - the attack bonus template from the attacker. | ||||
* @param {string} data.attackImpactSound - the name of the sound emited on impact. | |||||
* ***When splash damage*** | * ***When splash damage*** | ||||
* @param {boolean} data.friendlyFire - a flag indicating if allied entities are also damaged. | * @param {boolean} data.friendlyFire - a flag indicating if allied entities are also damaged. | ||||
* @param {number} data.radius - the radius of the splash damage. | * @param {number} data.radius - the radius of the splash damage. | ||||
* @param {string} data.shape - the shape of the splash range. | * @param {string} data.shape - the shape of the splash range. | ||||
* @param {Object} data.splashBonus - the attack bonus template from the attacker. | * @param {Object} data.splashBonus - the attack bonus template from the attacker. | ||||
* @param {Object} data.splashStrengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | * @param {Object} data.splashStrengths - data of the form { 'hack': number, 'pierce': number, 'crush': number }. | ||||
*/ | */ | ||||
Damage.prototype.MissileHit = function(data, lateness) | Damage.prototype.MissileHit = function(data, lateness) | ||||
{ | { | ||||
if (!data.position) | if (!data.position) | ||||
return; | 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 | // Do this first in case the direct hit kills the target | ||||
if (data.isSplash) | if (data.isSplash) | ||||
{ | { | ||||
this.CauseSplashDamage({ | this.CauseSplashDamage({ | ||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||
"origin": Vector2D.from3D(data.position), | "origin": Vector2D.from3D(data.position), | ||||
"radius": data.radius, | "radius": data.radius, | ||||
"shape": data.shape, | "shape": data.shape, | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | Damage.prototype.CauseDamage = function(data) | ||||
let cmpHealth = Engine.QueryInterface(data.target, IID_Health); | let cmpHealth = Engine.QueryInterface(data.target, IID_Health); | ||||
if (cmpPromotion && cmpLoot && cmpLoot.GetXp() > 0) | if (cmpPromotion && cmpLoot && cmpLoot.GetXp() > 0) | ||||
cmpPromotion.IncreaseXp(cmpLoot.GetXp() * -targetState.change / cmpHealth.GetMaxHitpoints()); | cmpPromotion.IncreaseXp(cmpLoot.GetXp() * -targetState.change / cmpHealth.GetMaxHitpoints()); | ||||
if (targetState.killed) | if (targetState.killed) | ||||
this.TargetKilled(data.attacker, data.target, data.attackerOwner); | this.TargetKilled(data.attacker, data.target, data.attackerOwner); | ||||
Engine.PostMessage(data.target, MT_Attacked, { "attacker": data.attacker, "target": data.target, "type": data.type, "damage": -targetState.change, "attackerOwner": data.attackerOwner }); | Engine.PostMessage(data.target, MT_Attacked, { "attacker": data.attacker, "target": data.target, "type": data.type, "damage": -targetState.change, "attackerOwner": data.attackerOwner }); | ||||
PlaySound("attack_impact", data.attacker); | |||||
}; | }; | ||||
/** | /** | ||||
* Gets entities near a give point for given players. | * Gets entities near a give point for given players. | ||||
* @param {Vector2D} origin - the point to check around. | * @param {Vector2D} origin - the point to check around. | ||||
* @param {number} radius - the radius around the point to check. | * @param {number} radius - the radius around the point to check. | ||||
* @param {number[]} players - the players of which we need to check entities. | * @param {number[]} players - the players of which we need to check entities. | ||||
* @return {number[]} - the id's of the entities in range of the given point. | * @return {number[]} - the id's of the entities in range of the given point. | ||||
Show All 37 Lines |
Wildfire Games · Phabricator