Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Health.js
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
Health.prototype.GetMaxHitpoints = function() | Health.prototype.GetMaxHitpoints = function() | ||||
{ | { | ||||
return this.maxHitpoints; | return this.maxHitpoints; | ||||
}; | }; | ||||
/** | /** | ||||
* @param {Object} effectData - The effects calculate the effect for. | |||||
* @param {string} effectType - The type of effect to apply (e.g. Damage, Capture or ApplyStatus). | |||||
* @param {number} bonusMultiplier - The factor to multiply the total effect with. | |||||
* @param {number} attackerOwner - The player id of the attacker. | |||||
* @return {number} - The fraction of the damage when this attack is done with maxHitpoints. | |||||
*/ | |||||
Health.prototype.GetRelativeDamage = function(effectData, effectType, bonusMultiplier, attackerOwner) | |||||
{ | |||||
const cmpResistance = QueryMiragedInterface(this.entity, IID_Resistance); | |||||
if (cmpResistance && cmpResistance.IsInvulnerable()) | |||||
return 0; | |||||
const cmpIdentity = QueryMiragedInterface(this.entity, IID_Identity); | |||||
const cmpPlayerEntity = QueryOwnerInterface(this.entity); | |||||
const cmpPlayerSource = QueryPlayerIDInterface(attackerOwner); | |||||
if (!cmpIdentity || !cmpPlayerEntity || !cmpPlayerSource) | |||||
return 0; | |||||
if (this.hitpoints <= 0 || (!cmpPlayerSource.IsEnemy(cmpPlayerEntity.GetPlayerID()) && !cmpIdentity.GetClassesList().includes("Domestic"))) | |||||
return 0; | |||||
return AttackHelper.GetTotalAttackEffects( | |||||
this.entity, | |||||
effectData, | |||||
effectType, | |||||
bonusMultiplier, | |||||
QueryMiragedInterface(this.entity, IID_Resistance) | |||||
) / this.maxHitpoints; | |||||
}; | |||||
/** | |||||
* @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(); | ||||
}; | }; | ||||
Health.prototype.SetHitpoints = function(value) | Health.prototype.SetHitpoints = function(value) | ||||
Show All 12 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.IsRepairable = function() | Health.prototype.IsRepairable = function() | ||||
{ | { | ||||
let cmpRepairable = Engine.QueryInterface(this.entity, IID_Repairable); | let cmpRepairable = Engine.QueryInterface(this.entity, IID_Repairable); | ||||
return cmpRepairable && cmpRepairable.IsRepairable(); | return cmpRepairable && cmpRepairable.IsRepairable(); | ||||
}; | }; | ||||
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() | ||||
{ | { | ||||
return this.idleRegenRate; | return this.idleRegenRate; | ||||
bb: nuke | |||||
}; | }; | ||||
Health.prototype.GetRegenRate = function() | Health.prototype.GetRegenRate = function() | ||||
{ | { | ||||
return this.regenRate; | return this.regenRate; | ||||
}; | }; | ||||
Health.prototype.ExecuteRegeneration = function() | Health.prototype.ExecuteRegeneration = function() | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | |||||
Health.prototype.RegisterHealthChanged = function(from) | Health.prototype.RegisterHealthChanged = function(from) | ||||
{ | { | ||||
this.CheckRegenTimer(); | this.CheckRegenTimer(); | ||||
this.UpdateActor(); | this.UpdateActor(); | ||||
Engine.PostMessage(this.entity, MT_HealthChanged, { "from": from, "to": this.hitpoints }); | Engine.PostMessage(this.entity, MT_HealthChanged, { "from": from, "to": this.hitpoints }); | ||||
}; | }; | ||||
function HealthMirage() {} | function HealthMirage() {} | ||||
HealthMirage.prototype.Init = function(cmpHealth) | HealthMirage.prototype.Init = function(cmpHealth, miragedEnt) | ||||
{ | { | ||||
this.entity = miragedEnt; | |||||
this.maxHitpoints = cmpHealth.GetMaxHitpoints(); | this.maxHitpoints = cmpHealth.GetMaxHitpoints(); | ||||
this.hitpoints = cmpHealth.GetHitpoints(); | this.hitpoints = cmpHealth.GetHitpoints(); | ||||
this.repairable = cmpHealth.IsRepairable(); | this.repairable = cmpHealth.IsRepairable(); | ||||
this.injured = cmpHealth.IsInjured(); | this.injured = cmpHealth.IsInjured(); | ||||
this.unhealable = cmpHealth.IsUnhealable(); | this.unhealable = cmpHealth.IsUnhealable(); | ||||
}; | }; | ||||
HealthMirage.prototype.GetMaxHitpoints = function() { return this.maxHitpoints; }; | |||||
HealthMirage.prototype.GetHitpoints = function() { return this.hitpoints; }; | HealthMirage.prototype.GetHitpoints = function() { return this.hitpoints; }; | ||||
HealthMirage.prototype.GetMaxHitpoints = function() { return this.maxHitpoints; }; | |||||
HealthMirage.prototype.GetRelativeDamage = Health.prototype.GetRelativeDamage; | |||||
HealthMirage.prototype.IsRepairable = function() { return this.repairable; }; | HealthMirage.prototype.IsRepairable = function() { return this.repairable; }; | ||||
HealthMirage.prototype.IsInjured = function() { return this.injured; }; | HealthMirage.prototype.IsInjured = function() { return this.injured; }; | ||||
HealthMirage.prototype.IsUnhealable = function() { return this.unhealable; }; | HealthMirage.prototype.IsUnhealable = function() { return this.unhealable; }; | ||||
Engine.RegisterGlobal("HealthMirage", HealthMirage); | Engine.RegisterGlobal("HealthMirage", HealthMirage); | ||||
Health.prototype.Mirage = function() | Health.prototype.Mirage = function(miragedEnt) | ||||
{ | { | ||||
let mirage = new HealthMirage(); | let mirage = new HealthMirage(); | ||||
mirage.Init(this); | mirage.Init(this, miragedEnt); | ||||
return mirage; | return mirage; | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_Health, "Health", Health); | Engine.RegisterComponentType(IID_Health, "Health", Health); |
Wildfire Games · Phabricator
nuke