Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/** | /** | ||||
* Handles hit logic after the projectile travel time has passed. | * Handles hit logic after the projectile travel time has passed. | ||||
* @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 {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, 'capture': 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. | * @param {string} data.attackImpactSound - The name of the sound emited on impact. | ||||
* @param {Object} data.statusEffects - Status effects eg. poisoning, burning etc. | * @param {Object} data.statusEffects - Status effects eg. poisoning, burning etc. | ||||
* ***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, 'capture': 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); | let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | ||||
if (cmpSoundManager && data.attackImpactSound) | if (cmpSoundManager && data.attackImpactSound) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* 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, 'capture': 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. Needed for linear splash damage. | * @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 {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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | this.CauseDamage({ | ||||
"type": data.type + ".Splash", | "type": data.type + ".Splash", | ||||
"attackerOwner": data.attackerOwner | "attackerOwner": data.attackerOwner | ||||
}); | }); | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Causes damage on a given unit. | * Causes damage on a given unit. | ||||
* @param {Object} data - The data passed by the caller. | * @param {Object} data - the data passed by the caller. | ||||
* @param {Object} data.strengths - Data in the form of { 'hack': number, 'pierce': number, 'crush': number }. | * @param {Object} data.strengths - data in the form of { 'hack': number, 'pierce': number, 'crush': number, 'capture': number }. | ||||
* @param {number} data.target - The entity id of the target. | * @param {number} data.target - the entity id of the target. | ||||
* @param {number} data.attacker - The entity id of the attacker. | * @param {number} data.attacker - the entity id of the attacker. | ||||
* @param {number} data.multiplier - The damage multiplier. | * @param {number} data.multiplier - the damage multiplier. | ||||
* @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 {boolean} data.isSplash - a flag indicating if it's splash damage. | |||||
* ***When splash damage*** | |||||
* @param {boolean} data.friendlyFire - a flag indicating if allied entities are also damaged. | |||||
* @param {number} data.radius - the radius of the splash damage. | |||||
* @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, 'capture': number }. | |||||
* @param {Vector3D} data.position - the position of the target. | |||||
* @param {Vector3D} data.direction - The unit vector defining the direction | |||||
*/ | */ | ||||
bb: statuseffect missing | |||||
Damage.prototype.CauseDamage = function(data) | Damage.prototype.CauseDamage = function(data) | ||||
{ | { | ||||
// Do splash first in case the direct hit kills or captures the target | |||||
if (data.isSplash) | |||||
this.CauseSplashDamage({ | |||||
"attacker": data.attacker, | |||||
"origin": Vector2D.from3D(data.position), | |||||
"radius": data.radius, | |||||
"shape": data.shape, | |||||
"strengths": data.splashStrengths, | |||||
"splashBonus": data.splashBonus, | |||||
"direction": data.direction, | |||||
"playersToDamage": data.friendlyFire ? | |||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetAllPlayers() : | |||||
QueryPlayerIDInterface(data.attackerOwner).GetEnemies(), | |||||
"type": data.type, | |||||
"attackerOwner": data.attackerOwner | |||||
}); | |||||
let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | let cmpDamageReceiver = Engine.QueryInterface(data.target, IID_DamageReceiver); | ||||
if (!cmpDamageReceiver) | if (!cmpDamageReceiver) | ||||
return; | return; | ||||
let targetState = cmpDamageReceiver.TakeDamage(data.strengths, data.multiplier); | let targetState = cmpDamageReceiver.TakeDamage(data.attackerOwner, data.strengths, data.multiplier); | ||||
let cmpPromotion = Engine.QueryInterface(data.attacker, IID_Promotion); | let cmpPromotion = Engine.QueryInterface(data.attacker, IID_Promotion); | ||||
let cmpLoot = Engine.QueryInterface(data.target, IID_Loot); | let cmpLoot = Engine.QueryInterface(data.target, IID_Loot); | ||||
let cmpHealth = Engine.QueryInterface(data.target, IID_Health); | let cmpHealth = Engine.QueryInterface(data.target, IID_Health); | ||||
//TODO capture? | |||||
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.healthChange / 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.healthChange || 0) + (targetState.captureChange || 0), "attackerOwner": data.attackerOwner }); | ||||
}; | }; | ||||
/** | /** | ||||
* 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
statuseffect missing