Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
* @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. | |||||
* ***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) | ||||
Show All 27 Lines | Damage.prototype.MissileHit = function(data, lateness) | ||||
// 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); | data.multiplier = GetDamageBonus(data.target, data.bonus); | ||||
this.CauseDamage(data); | this.CauseDamage(data); | ||||
cmpProjectileManager.RemoveProjectile(data.projectileId); | cmpProjectileManager.RemoveProjectile(data.projectileId); | ||||
// Do the status change, eg. poisoning, burning etc. | |||||
let cmpStatus = Engine.QueryInterface(data.target, IID_Status); | |||||
if (cmpStatus && data.statusEffects) | |||||
cmpStatus.StartEffects(data.statusEffects); | |||||
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": GetDamageBonus(ent, data.bonus), | "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; | ||||
Stan: Might want to remove this as it's not adding anything :) | |||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* 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. | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | Damage.prototype.CauseSplashDamage = function(data) | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* 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 }. | ||||
* @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 og 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. | ||||
*/ | */ | ||||
Damage.prototype.CauseDamage = function(data) | Damage.prototype.CauseDamage = function(data) | ||||
{ | { | ||||
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.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); | ||||
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) | ||||
Done Inline Actionsthis exists just in case of ranged attack, test for existence or add everywhere as parameter Silier: this exists just in case of ranged attack, test for existence or add everywhere as parameter | |||||
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 }); | ||||
Done Inline ActionsSetTimeout(SYSTEM_ENTITY -> this.entity Silier: SetTimeout(SYSTEM_ENTITY -> this.entity
cache timer as variable of Damage component, delete… | |||||
Done Inline ActionsJust realised Damage is only system component so comment above is invalid. Silier: Just realised Damage is only system component so comment above is invalid. | |||||
Done Inline ActionsComments start with Capitals as per the coding conventions. Might want to turn poisoning into burning as it is more common. Stan: Comments start with Capitals as per the coding conventions. Might want to turn poisoning into… | |||||
}; | }; | ||||
/** | /** | ||||
* 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
Might want to remove this as it's not adding anything :)