Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Resistance.js
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | "<choice>" + | ||||
Resistance.prototype.BuildResistanceSchema() + | Resistance.prototype.BuildResistanceSchema() + | ||||
"</element>" + | "</element>" + | ||||
"</choice>" + | "</choice>" + | ||||
"</zeroOrMore>"; | "</zeroOrMore>"; | ||||
Resistance.prototype.Init = function() | Resistance.prototype.Init = function() | ||||
{ | { | ||||
this.invulnerable = false; | this.invulnerable = false; | ||||
this.attackers = new Set(); | |||||
}; | }; | ||||
Resistance.prototype.IsInvulnerable = function() | Resistance.prototype.IsInvulnerable = function() | ||||
{ | { | ||||
return this.invulnerable; | return this.invulnerable; | ||||
}; | }; | ||||
/** | |||||
* @param {number} attacker - The entity ID of the attacker to add. | |||||
* @return {boolean} - Whether the attacker was added sucessfully. | |||||
*/ | |||||
Resistance.prototype.AddAttacker = function(attacker) | |||||
{ | |||||
if (this.attackers.has(attacker)) | |||||
return false; | |||||
this.attackers.add(attacker); | |||||
return true; | |||||
}; | |||||
/** | |||||
* @param {number} attacker - The entity ID of the attacker to remove. | |||||
* @return {boolean} - Whether the attacker was attacking us previously. | |||||
*/ | |||||
Resistance.prototype.RemoveAttacker = function(attacker) | |||||
{ | |||||
return this.attackers.delete(attacker); | |||||
}; | |||||
Resistance.prototype.SetInvulnerability = function(invulnerability) | Resistance.prototype.SetInvulnerability = function(invulnerability) | ||||
{ | { | ||||
this.invulnerable = invulnerability; | this.invulnerable = invulnerability; | ||||
Engine.PostMessage(this.entity, MT_InvulnerabilityChanged, { "entity": this.entity, "invulnerability": invulnerability }); | Engine.PostMessage(this.entity, MT_InvulnerabilityChanged, { "entity": this.entity, "invulnerability": invulnerability }); | ||||
}; | }; | ||||
/** | /** | ||||
* Calculate the effective resistance of an entity to a particular effect. | * Calculate the effective resistance of an entity to a particular effect. | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | for (let effect in template.ApplyStatus) | ||||
"duration": ApplyValueModificationsToEntity("Resistance/" + entityForm + "/ApplyStatus/" + effect + "/Duration", +(template.ApplyStatus[effect].Duration || 1), this.entity), | "duration": ApplyValueModificationsToEntity("Resistance/" + entityForm + "/ApplyStatus/" + effect + "/Duration", +(template.ApplyStatus[effect].Duration || 1), this.entity), | ||||
"blockChance": ApplyValueModificationsToEntity("Resistance/" + entityForm + "/ApplyStatus/" + effect + "/BlockChance", +(template.ApplyStatus[effect].BlockChance || 0), this.entity) | "blockChance": ApplyValueModificationsToEntity("Resistance/" + entityForm + "/ApplyStatus/" + effect + "/BlockChance", +(template.ApplyStatus[effect].BlockChance || 0), this.entity) | ||||
}; | }; | ||||
} | } | ||||
return ret; | return ret; | ||||
}; | }; | ||||
Resistance.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
if (msg.to === INVALID_PLAYER) | |||||
for (let attacker of this.attackers) | |||||
Engine.QueryInterface(attacker, IID_Attack)?.StopAttacking("TargetInvalidated"); | |||||
}; | |||||
Engine.RegisterComponentType(IID_Resistance, "Resistance", Resistance); | Engine.RegisterComponentType(IID_Resistance, "Resistance", Resistance); |
Wildfire Games · Phabricator