Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/DelayedDamage.js
function DelayedDamage() {} | function DelayedDamage() {} | ||||
DelayedDamage.prototype.Schema = | DelayedDamage.prototype.Schema = | ||||
"<a:component type='system'/><empty/>"; | "<a:component type='system'/><empty/>"; | ||||
DelayedDamage.prototype.Init = function() | DelayedDamage.prototype.Init = function() | ||||
{ | { | ||||
}; | }; | ||||
/** | /** | ||||
* 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 {string} data.type - The type of damage. | * @param {string} data.type - The type of damage. | ||||
* @param {Object} data.attackData - Data of the form { 'effectType': { ...opaque effect data... }, 'Bonuses': {...} }. | * @param {Object} data.attackData - Data of the form { 'effectType': { ...opaque effect data... }, 'Bonuses': {...} }. | ||||
* @param {number} data.target - The entity id of the target. | * @param {number | Vector3D} data.target - Either the target entity ID, or a Vector3D of a position to attack. | ||||
* @param {number} data.attacker - The entity id of the attacker. | * @param {number} data.attacker - The entity id of the attacker. | ||||
* @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 {Vector2D} data.origin - The origin of the projectile hit. | * @param {Vector2D} data.origin - The origin of the projectile hit. | ||||
* @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 {string} data.attackImpactSound - The name of the sound emited on impact. | * @param {string} data.attackImpactSound - The name of the sound emited on impact. | ||||
* ***When splash damage*** | * ***When splash damage*** | ||||
Show All 24 Lines | Attacking.CauseDamageOverArea({ | ||||
"shape": data.splash.shape, | "shape": data.splash.shape, | ||||
"direction": data.direction, | "direction": data.direction, | ||||
"friendlyFire": data.splash.friendlyFire | "friendlyFire": data.splash.friendlyFire | ||||
}); | }); | ||||
} | } | ||||
let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); | ||||
let targetPosition; | |||||
if (typeof data.target == "number") | |||||
{ | |||||
// Deal direct damage if we hit the main target | // Deal direct damage if we hit the main target | ||||
wraitii: cf above | |||||
// and if the target has Resistance (not the case for a mirage for example) | // and if the target has Resistance (not the case for a mirage for example) | ||||
if (Attacking.TestCollision(data.target, data.position, lateness)) | if (Attacking.TestCollision(data.target, data.position, lateness)) | ||||
{ | { | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attacker, data.attackerOwner); | Attacking.HandleAttackEffects(data.type, data.attackData, data.target, data.attacker, data.attackerOwner); | ||||
return; | return; | ||||
} | } | ||||
targetPosition = Attacking.InterpolatedLocation(data.target, lateness); | |||||
} | |||||
else | |||||
targetPosition = data.target; | |||||
let targetPosition = Attacking.InterpolatedLocation(data.target, lateness); | |||||
if (!targetPosition) | if (!targetPosition) | ||||
return; | return; | ||||
// If we didn't hit the main target look for nearby units | // Look for nearby units. | ||||
let cmpPlayer = QueryPlayerIDInterface(data.attackerOwner); | let cmpPlayer = QueryPlayerIDInterface(data.attackerOwner); | ||||
let ents = Attacking.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, cmpPlayer.GetEnemies()); | let ents = Attacking.EntitiesNearPoint(Vector2D.from3D(data.position), targetPosition.horizDistanceTo(data.position) * 2, cmpPlayer.GetEnemies()); | ||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
if (!Attacking.TestCollision(ent, data.position, lateness)) | if (!Attacking.TestCollision(ent, data.position, lateness)) | ||||
continue; | continue; | ||||
Attacking.HandleAttackEffects(data.type, data.attackData, ent, data.attacker, data.attackerOwner); | Attacking.HandleAttackEffects(data.type, data.attackData, ent, data.attacker, data.attackerOwner); | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
break; | break; | ||||
} | } | ||||
}; | }; | ||||
Engine.RegisterSystemComponentType(IID_DelayedDamage, "DelayedDamage", DelayedDamage); | Engine.RegisterSystemComponentType(IID_DelayedDamage, "DelayedDamage", DelayedDamage); |
Wildfire Games · Phabricator
cf above