Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Health.js
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
//// Interface functions //// | //// Interface functions //// | ||||
/** | /** | ||||
* Returns the current hitpoint value. | * Returns the current hitpoint value. | ||||
* This is 0 if (and only if) the unit is dead. | * This is 0 if (and only if) the unit is dead. | ||||
*/ | */ | ||||
Health.prototype.GetHitpoints = function() | Health.prototype.GetHitpoints = function() | ||||
{ | { | ||||
return this.hitpoints; | return this.hitpoints; | ||||
fatherbushido: no | |||||
}; | }; | ||||
Health.prototype.GetMaxHitpoints = function() | Health.prototype.GetMaxHitpoints = function() | ||||
{ | { | ||||
return this.maxHitpoints; | return this.maxHitpoints; | ||||
Not Done Inline Actionsno fatherbushido: no | |||||
}; | }; | ||||
Health.prototype.SetHitpoints = function(value) | Health.prototype.SetHitpoints = function(value) | ||||
{ | { | ||||
// If we're already dead, don't allow resurrection | // If we're already dead, don't allow resurrection | ||||
if (this.hitpoints == 0) | if (this.hitpoints == 0) | ||||
return; | return; | ||||
// 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(); | ||||
var old = this.hitpoints; | var old = this.hitpoints; | ||||
this.hitpoints = Math.max(1, Math.min(this.GetMaxHitpoints(), value)); | this.hitpoints = Math.floor(Math.max(1, Math.min(this.GetMaxHitpoints(), value))); | ||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
if (cmpRangeManager) | if (cmpRangeManager) | ||||
{ | { | ||||
if (this.hitpoints < this.GetMaxHitpoints()) | if (this.hitpoints < this.GetMaxHitpoints()) | ||||
cmpRangeManager.SetEntityFlag(this.entity, "injured", true); | cmpRangeManager.SetEntityFlag(this.entity, "injured", true); | ||||
else | else | ||||
cmpRangeManager.SetEntityFlag(this.entity, "injured", false); | cmpRangeManager.SetEntityFlag(this.entity, "injured", false); | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
Health.prototype.OnValueModification = function(msg) | Health.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
if (msg.component != "Health") | if (msg.component != "Health") | ||||
return; | return; | ||||
let oldMaxHitpoints = this.GetMaxHitpoints(); | let oldMaxHitpoints = this.GetMaxHitpoints(); | ||||
let newMaxHitpoints = ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity); | let newMaxHitpoints = Math.floor(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity)); | ||||
if (oldMaxHitpoints != newMaxHitpoints) | if (oldMaxHitpoints != newMaxHitpoints) | ||||
{ | { | ||||
let newHitpoints = this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints; | let newHitpoints = this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints; | ||||
this.maxHitpoints = newMaxHitpoints; | this.maxHitpoints = newMaxHitpoints; | ||||
this.SetHitpoints(newHitpoints); | this.SetHitpoints(newHitpoints); | ||||
} | } | ||||
let oldRegenRate = this.regenRate; | let oldRegenRate = this.regenRate; | ||||
Show All 17 Lines |
Wildfire Games · Phabricator
no