Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
* @param {number} data.target - the entity id of the target. | * @param {number} data.target - the entity id of the target. | ||||
* @param {Vector2D} data.origin - the origin of the projectile hit. | * @param {Vector2D} data.origin - the origin of the projectile hit. | ||||
* @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. | |||||
* ***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.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; | ||||
// 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, | ||||
"strengths": data.splashStrengths, | "strengths": data.splashStrengths, | ||||
"splashBonus": data.splashBonus, | |||||
"direction": data.direction, | "direction": data.direction, | ||||
"playersToDamage": this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire), | "playersToDamage": this.GetPlayersToDamage(data.attackerOwner, data.friendlyFire), | ||||
"type": data.type, | "type": data.type, | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
} | } | ||||
let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | ||||
// Deal direct damage if we hit the main target | // Deal direct damage if we hit the main target | ||||
// and if the target has DamageReceiver (not the case for a mirage for example) | // and if the target has DamageReceiver (not the case for a mirage for example) | ||||
let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | ||||
if (cmpDamageReceiver && this.TestCollision(data.target, data.position, lateness)) | if (cmpDamageReceiver && this.TestCollision(data.target, data.position, lateness)) | ||||
{ | { | ||||
data.multiplier = GetDamageBonus(data.target, data.bonus); | |||||
this.CauseDamage(data); | this.CauseDamage(data); | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
return; | return; | ||||
} | } | ||||
let targetPosition = this.InterpolatedLocation(data.target, lateness); | let targetPosition = this.InterpolatedLocation(data.target, lateness); | ||||
if (!targetPosition) | if (!targetPosition) | ||||
return; | return; | ||||
// If we didn't hit the main target look for nearby units | // If we didn't hit the main target look for nearby units | ||||
let cmpPlayer = QueryPlayerIDInterface(data.attackerOwner); | let cmpPlayer = QueryPlayerIDInterface(data.attackerOwner); | ||||
let ents = this.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, cmpPlayer.GetEnemies()); | let ents = this.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, cmpPlayer.GetEnemies()); | ||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
if (!this.TestCollision(ent, data.position, lateness)) | if (!this.TestCollision(ent, data.position, lateness)) | ||||
continue; | continue; | ||||
this.CauseDamage({ | this.CauseDamage({ | ||||
"strengths": data.strengths, | "strengths": data.strengths, | ||||
"target": ent, | "target": ent, | ||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||
"multiplier": data.multiplier, | "multiplier": GetDamageBonus(ent, data.bonus), | ||||
"type": data.type, | "type": data.type, | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
break; | break; | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Damages units around a given origin. | * Damages units around a given origin. | ||||
* @param {Object} data - the data sent by the caller. | * @param {Object} data - the data sent by the caller. | ||||
* @param {number} data.attacker - the entity id of the attacker. | * @param {number} data.attacker - the entity id of the attacker. | ||||
* @param {Vector2D} data.origin - the origin of the projectile hit. | * @param {Vector2D} data.origin - the origin of the projectile hit. | ||||
* @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 radius. | * @param {string} data.shape - the shape of the radius. | ||||
* @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 attacker. | * @param {number} data.attackerOwner - the player id of the attacker. | ||||
* @param {Vector3D} [data.direction] - the unit vector defining the direction. | * @param {Vector3D} [data.direction] - the unit vector defining the direction. Needed for linear splash damage. | ||||
* @param {Object} data.splashBonus - the attack bonus template from the attacker. | |||||
* @param {number[]} data.playersToDamage - the array of player id's to damage. | * @param {number[]} data.playersToDamage - the array of player id's to damage. | ||||
*/ | */ | ||||
Damage.prototype.CauseSplashDamage = function(data) | Damage.prototype.CauseSplashDamage = function(data) | ||||
{ | { | ||||
// Get nearby entities and define variables | // Get nearby entities and define variables | ||||
let nearEnts = this.EntitiesNearPoint(data.origin, data.radius, data.playersToDamage); | let nearEnts = this.EntitiesNearPoint(data.origin, data.radius, data.playersToDamage); | ||||
let damageMultiplier = 1; | let damageMultiplier = 1; | ||||
Show All 23 Lines | else if (data.shape == 'Linear') // linear effect with quadratic falloff in two directions (only used for certain missiles) | ||||
(1 - perpPos * perpPos / (width * width)); | (1 - perpPos * perpPos / (width * width)); | ||||
else | else | ||||
damageMultiplier = 0; | damageMultiplier = 0; | ||||
} | } | ||||
else // In case someone calls this function with an invalid shape. | else // In case someone calls this function with an invalid shape. | ||||
{ | { | ||||
warn("The " + data.shape + " splash damage shape is not implemented!"); | warn("The " + data.shape + " splash damage shape is not implemented!"); | ||||
} | } | ||||
if (data.splashBonus) | |||||
damageMultiplier *= GetDamageBonus(ent, data.splashBonus); | |||||
// Call CauseDamage which reduces the hitpoints, posts network command, plays sounds.... | // Call CauseDamage which reduces the hitpoints, posts network command, plays sounds.... | ||||
this.CauseDamage({ | this.CauseDamage({ | ||||
"strengths": data.strengths, | "strengths": data.strengths, | ||||
"target": ent, | "target": ent, | ||||
"attacker": data.attacker, | "attacker": data.attacker, | ||||
"multiplier": damageMultiplier, | "multiplier": damageMultiplier, | ||||
"type": data.type + ".Splash", | "type": data.type + ".Splash", | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator