Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Health.js
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
Health.prototype.Kill = function() | Health.prototype.Kill = function() | ||||
{ | { | ||||
this.Reduce(this.hitpoints); | this.Reduce(this.hitpoints); | ||||
}; | }; | ||||
/** | /** | ||||
* Take damage according to the entity's resistance. | * @param {number} amount - The amount of damage to be taken. | ||||
* @param {Object} strengths - { "hack": number, "pierce": number, "crush": number } or something like that. | * @param {number} attacker - The entityID of the attacker. | ||||
* @param {number} bonusMultiplier - the damage multiplier. | * @param {number} attackerOwner - The playerID of the owner of the attacker. | ||||
* | |||||
* Returns object of the form { "killed": false, "change": -12 }. | * Returns object of the form { "killed": false, "change": -12 }. | ||||
bb: @returns {Object} - Object of the form { "healthChange": number }. | |||||
*/ | */ | ||||
Health.prototype.TakeDamage = function(effectData, attacker, attackerOwner, bonusMultiplier) | Health.prototype.TakeDamage = function(amount, attacker, attackerOwner) | ||||
{ | { | ||||
let cmpResistance = Engine.QueryInterface(this.entity, IID_Resistance); | let change = this.Reduce(amount); | ||||
if (cmpResistance && cmpResistance.IsInvulnerable()) | |||||
return { "killed": false }; | |||||
let total = Attacking.GetTotalAttackEffects(effectData, "Damage", cmpResistance) * bonusMultiplier; | |||||
// Reduce health | |||||
let change = this.Reduce(total); | |||||
let cmpLoot = Engine.QueryInterface(this.entity, IID_Loot); | let cmpLoot = Engine.QueryInterface(this.entity, IID_Loot); | ||||
if (cmpLoot && cmpLoot.GetXp() > 0 && change.HPchange < 0) | if (cmpLoot && cmpLoot.GetXp() > 0 && change.HPchange < 0) | ||||
change.xp = cmpLoot.GetXp() * -change.HPchange / this.GetMaxHitpoints(); | change.xp = cmpLoot.GetXp() * -change.HPchange / this.GetMaxHitpoints(); | ||||
return change; | return change; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
@returns {Object} - Object of the form { "healthChange": number }.