Differential D2218 Diff 9753 binaries/data/mods/public/simulation/components/StatusEffectsReceiver.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/StatusEffectsReceiver.js
function StatusEffectsReceiver() {} | function StatusEffectsReceiver() {} | ||||
StatusEffectsReceiver.prototype.Init = function() | StatusEffectsReceiver.prototype.Init = function() | ||||
{ | { | ||||
this.activeStatusEffects = {}; | this.activeStatusEffects = {}; | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.GetActiveStatuses = function() | |||||
Freagarach: `GetActiveEffects`? | |||||
Done Inline ActionsI think GetActiveStatuses is more accurate, I guess I could just go with GetActiveStatusEffects. Your 'status' is 'burning', not your effect. wraitii: I think `GetActiveStatuses` is more accurate, I guess I could just go with… | |||||
{ | |||||
return this.activeStatusEffects; | |||||
}; | |||||
// Called by attacking effects. | // Called by attacking effects. | ||||
StatusEffectsReceiver.prototype.GiveStatus = function(effectData, attacker, attackerOwner, bonusMultiplier) | StatusEffectsReceiver.prototype.GiveStatus = function(effectData, attacker, attackerOwner, bonusMultiplier) | ||||
{ | { | ||||
for (let effect in effectData) | for (let effect in effectData) | ||||
this.AddStatus(effect, effectData[effect]); | this.AddStatus(effect, effectData[effect]); | ||||
// TODO: implement loot / resistance. | // TODO: implement loot / resistance. | ||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.AddStatus = function(statusName, data) | StatusEffectsReceiver.prototype.AddStatus = function(statusName, data) | ||||
{ | { | ||||
if (this.activeStatusEffects[statusName]) | if (this.activeStatusEffects[statusName]) | ||||
return; | return; | ||||
this.activeStatusEffects[statusName] = {}; | this.activeStatusEffects[statusName] = {}; | ||||
let status = this.activeStatusEffects[statusName]; | let status = this.activeStatusEffects[statusName]; | ||||
status.duration = +data.Duration; | Object.assign(status, data); | ||||
Not Done Inline Actionswhy capital letter for damage? Silier: why capital letter for damage? | |||||
Done Inline ActionsBecause it's much easier if this follows the template (because the GUI code can be somewhat more agnostic). In fact I should move everything to use capitals. wraitii: Because it's much easier if this follows the template (because the GUI code can be somewhat… | |||||
status.interval = +data.Interval; | status.Duration = +data.Duration; | ||||
FreagarachUnsubmitted Done Inline ActionsDuration is not strictly necessary, one could have a permanent SE, which gradually decreases HPs of an entity until it dies or gets healed by some method. I've changed it in v2, but you might as well change it here? Freagarach: Duration is not strictly necessary, one could have a permanent SE, which gradually decreases… | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsIndeed. wraitii: Indeed. | |||||
status.damage = +data.Damage; | status.Interval = +data.Interval; | ||||
status.timeElapsed = 0; | status.TimeElapsed = 0; | ||||
status.firstTime = true; | status.FirstTime = true; | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
status.timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +status.interval, statusName); | status.Timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +status.Interval, statusName); | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.RemoveStatus = function(statusName) { | StatusEffectsReceiver.prototype.RemoveStatus = function(statusName) | ||||
{ | |||||
Not Done Inline Actions\n Freagarach: `\n` | |||||
if (!this.activeStatusEffects[statusName]) | if (!this.activeStatusEffects[statusName]) | ||||
return; | return; | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
cmpTimer.CancelTimer(this.activeStatusEffects[statusName].timer); | cmpTimer.CancelTimer(this.activeStatusEffects[statusName].Timer); | ||||
this.activeStatusEffects[statusName] = undefined; | delete this.activeStatusEffects[statusName]; | ||||
}; | }; | ||||
StatusEffectsReceiver.prototype.ExecuteEffect = function(statusName, lateness) | StatusEffectsReceiver.prototype.ExecuteEffect = function(statusName, lateness) | ||||
{ | { | ||||
let status = this.activeStatusEffects[statusName]; | let status = this.activeStatusEffects[statusName]; | ||||
if (!status) | if (!status) | ||||
return; | return; | ||||
if (status.firstTime) | if (status.FirstTime) | ||||
{ | { | ||||
status.firstTime = false; | status.FirstTime = false; | ||||
status.timeElapsed += lateness; | status.TimeElapsed += lateness; | ||||
} | } | ||||
else | else | ||||
status.timeElapsed += status.interval + lateness; | status.TimeElapsed += status.Interval + lateness; | ||||
Attacking.HandleAttackEffects(statusName, { "Damage": { [statusName]: status.damage } }, this.entity, -1, -1); | Attacking.HandleAttackEffects(statusName, status, this.entity, -1, -1); | ||||
if (status.timeElapsed >= status.duration) | if (status.TimeElapsed >= status.Duration) | ||||
this.RemoveStatus(statusName); | this.RemoveStatus(statusName); | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); | Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); |
Wildfire Games · Phabricator
GetActiveEffects?