Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Health.js
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | Health.prototype.GetHitpoints = function() | ||||
return this.hitpoints; | return this.hitpoints; | ||||
}; | }; | ||||
Health.prototype.GetMaxHitpoints = function() | Health.prototype.GetMaxHitpoints = function() | ||||
{ | { | ||||
return this.maxHitpoints; | return this.maxHitpoints; | ||||
}; | }; | ||||
// TODO get rid of this | |||||
Health.prototype.GetMax = Health.prototype.GetMaxHitpoints; | |||||
/** | /** | ||||
* @return {boolean} Whether the units are injured. Dead units are not considered injured. | * @return {boolean} Whether the units are injured. Dead units are not considered injured. | ||||
*/ | */ | ||||
Health.prototype.IsInjured = function() | Health.prototype.IsInjured = function() | ||||
{ | { | ||||
return this.hitpoints > 0 && this.hitpoints < this.GetMaxHitpoints(); | return this.hitpoints > 0 && this.hitpoints < this.GetMaxHitpoints(); | ||||
}; | }; | ||||
Show All 13 Lines | Health.prototype.SetHitpoints = function(value) | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
if (cmpRangeManager) | if (cmpRangeManager) | ||||
cmpRangeManager.SetEntityFlag(this.entity, "injured", this.IsInjured()); | cmpRangeManager.SetEntityFlag(this.entity, "injured", this.IsInjured()); | ||||
this.RegisterHealthChanged(old); | this.RegisterHealthChanged(old); | ||||
}; | }; | ||||
Health.prototype.CanAttack = function(playerID) | |||||
{ | |||||
let cmpIdentity = QueryMiragedInterface(this.entity, IID_Identity); | |||||
let cmpPlayerEntity = QueryOwnerInterface(this.entity); | |||||
let cmpPlayerSource = QueryPlayerIDInterface(playerID); | |||||
if (!cmpIdentity || !cmpPlayerEntity || !cmpPlayerSource) | |||||
return false; | |||||
return this.hitpoints > 0 && (cmpPlayerSource.IsEnemy(cmpPlayerEntity.GetPlayerID()) || cmpIdentity.GetClassesList().indexOf("Domestic") != -1); | |||||
}; | |||||
Health.prototype.IsRepairable = function() | Health.prototype.IsRepairable = function() | ||||
{ | { | ||||
return Engine.QueryInterface(this.entity, IID_Repairable) != null; | return Engine.QueryInterface(this.entity, IID_Repairable) != null; | ||||
}; | }; | ||||
bb: nuke | |||||
Health.prototype.IsUnhealable = function() | Health.prototype.IsUnhealable = function() | ||||
{ | { | ||||
return this.template.Unhealable == "true" || | return this.template.Unhealable == "true" || | ||||
this.hitpoints <= 0 || !this.IsInjured(); | this.hitpoints <= 0 || !this.IsInjured(); | ||||
}; | }; | ||||
Health.prototype.GetIdleRegenRate = function() | Health.prototype.GetIdleRegenRate = function() | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
Health.prototype.Reduce = function(amount) | Health.prototype.Reduce = function(amount) | ||||
{ | { | ||||
// If we are dead, do not do anything | // If we are dead, do not do anything | ||||
// (The entity will exist a little while after calling DestroyEntity so this | // (The entity will exist a little while after calling DestroyEntity so this | ||||
// might get called multiple times) | // might get called multiple times) | ||||
// Likewise if the amount is 0. | // Likewise if the amount is 0. | ||||
if (!amount || !this.hitpoints) | if (!amount || !this.hitpoints) | ||||
return { "killed": false, "change": 0 }; | return { "killed": false, "healthChange": 0 }; | ||||
// Before changing the value, activate Fogging if necessary to hide changes | // Before changing the value, activate Fogging if necessary to hide changes | ||||
let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); | let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); | ||||
if (cmpFogging) | if (cmpFogging) | ||||
cmpFogging.Activate(); | cmpFogging.Activate(); | ||||
let oldHitpoints = this.hitpoints; | let oldHitpoints = this.hitpoints; | ||||
// If we reached 0, then die. | // If we reached 0, then die. | ||||
if (amount >= this.hitpoints) | if (amount >= this.hitpoints) | ||||
{ | { | ||||
this.hitpoints = 0; | this.hitpoints = 0; | ||||
this.RegisterHealthChanged(oldHitpoints); | this.RegisterHealthChanged(oldHitpoints); | ||||
this.HandleDeath(); | this.HandleDeath(); | ||||
return { "killed": true, "change": -oldHitpoints }; | return { "killed": true, "healthChange": -oldHitpoints }; | ||||
} | } | ||||
// If we are not marked as injured, do it now | // If we are not marked as injured, do it now | ||||
if (!this.IsInjured()) | if (!this.IsInjured()) | ||||
{ | { | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
if (cmpRangeManager) | if (cmpRangeManager) | ||||
cmpRangeManager.SetEntityFlag(this.entity, "injured", true); | cmpRangeManager.SetEntityFlag(this.entity, "injured", true); | ||||
} | } | ||||
this.hitpoints -= amount; | this.hitpoints -= amount; | ||||
this.RegisterHealthChanged(oldHitpoints); | this.RegisterHealthChanged(oldHitpoints); | ||||
return { "killed": false, "change": this.hitpoints - oldHitpoints }; | return { "killed": false, "healthChange": this.hitpoints - oldHitpoints }; | ||||
}; | }; | ||||
/** | /** | ||||
* Handle what happens when the entity dies. | * Handle what happens when the entity dies. | ||||
*/ | */ | ||||
Health.prototype.HandleDeath = function() | Health.prototype.HandleDeath = function() | ||||
{ | { | ||||
let cmpDeathDamage = Engine.QueryInterface(this.entity, IID_DeathDamage); | let cmpDeathDamage = Engine.QueryInterface(this.entity, IID_DeathDamage); | ||||
▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
nuke