Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Damage.js
Show First 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | 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); | ||||
// do the status change, eg. poisoning | |||||
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. | |||||
StanUnsubmitted 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… | |||||
let cmpStatus = Engine.QueryInterface(data.target, IID_Status); | |||||
if (cmpStatus) | |||||
cmpStatus.StartEffect(data.attacker); | |||||
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 }); | ||||
}; | }; | ||||
/** | /** | ||||
* 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. | ||||
Show All 38 Lines |
Wildfire Games · Phabricator
Might want to remove this as it's not adding anything :)