mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
This implements a status effects receiver component (in a similar fashion to the damage receiver component). The plan is to further extend this component notably to handle graphical indication of status effects, and a variety of other effects. Currently implemented: ranged attacks can inflict status effects that reduce HP over time. This can be resisted by armour. No units currently utilise this in-game but with proper graphics support that could be changed. Patch By: Mate-86 Reviewed By: wraitii References #1912 Differential Revision: https://code.wildfiregames.com/D1252 This was SVN commit r22304.
69 lines
1.9 KiB
JavaScript
Executable file
69 lines
1.9 KiB
JavaScript
Executable file
function StatusEffectsReceiver() {}
|
|
|
|
StatusEffectsReceiver.prototype.Init = function()
|
|
{
|
|
this.activeStatusEffects = {};
|
|
};
|
|
|
|
StatusEffectsReceiver.prototype.InflictEffects = function(statusEffects)
|
|
{
|
|
for (let effect in statusEffects)
|
|
this.InflictEffect(effect, statusEffects[effect]);
|
|
};
|
|
|
|
StatusEffectsReceiver.prototype.InflictEffect = function(statusName, data)
|
|
{
|
|
if (this.activeStatusEffects[statusName])
|
|
return;
|
|
|
|
this.activeStatusEffects[statusName] = {};
|
|
let status = this.activeStatusEffects[statusName];
|
|
status.duration = +data.Duration;
|
|
status.interval = +data.Interval;
|
|
status.damage = +data.Damage;
|
|
status.timeElapsed = 0;
|
|
status.firstTime = true;
|
|
|
|
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
|
status.timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +status.interval, statusName);
|
|
};
|
|
|
|
StatusEffectsReceiver.prototype.RemoveEffect = function(statusName) {
|
|
if (!this.activeStatusEffects[statusName])
|
|
return;
|
|
|
|
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
|
cmpTimer.CancelTimer(this.activeStatusEffects[statusName].timer);
|
|
this.activeStatusEffects[statusName] = undefined;
|
|
};
|
|
|
|
StatusEffectsReceiver.prototype.ExecuteEffect = function(statusName, lateness)
|
|
{
|
|
let status = this.activeStatusEffects[statusName];
|
|
if (!status)
|
|
return;
|
|
|
|
if (status.firstTime)
|
|
{
|
|
status.firstTime = false;
|
|
status.timeElapsed += lateness;
|
|
}
|
|
else
|
|
status.timeElapsed += status.interval + lateness;
|
|
|
|
let cmpDamage = Engine.QueryInterface(SYSTEM_ENTITY, IID_Damage);
|
|
|
|
cmpDamage.CauseDamage({
|
|
"strengths": { [statusName]: status.damage },
|
|
"target": this.entity,
|
|
"attacker": -1,
|
|
"multiplier": 1,
|
|
"type": statusName,
|
|
"attackerOwner": -1
|
|
});
|
|
|
|
if (status.timeElapsed >= status.duration)
|
|
this.RemoveEffect(statusName);
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver);
|