Differential D2808 Diff 13649 binaries/data/mods/public/simulation/components/StatusEffectsReceiver.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/StatusEffectsReceiver.js
Show All 22 Lines | |||||
/** | /** | ||||
* Called by Attacking effects. Adds status effects for each entry in the effectData. | * Called by Attacking effects. Adds status effects for each entry in the effectData. | ||||
* | * | ||||
* @param {Object} effectData - An object containing the status effects to give to the entity. | * @param {Object} effectData - An object containing the status effects to give to the entity. | ||||
* @param {number} attacker - The entity ID of the attacker. | * @param {number} attacker - The entity ID of the attacker. | ||||
* @param {number} attackerOwner - The player ID of the attacker. | * @param {number} attackerOwner - The player ID of the attacker. | ||||
* @param {number} bonusMultiplier - A value to multiply the damage with (not implemented yet for SE). | * @param {number} bonusMultiplier - A value to multiply the damage with (not implemented yet for SE). | ||||
* | * | ||||
* @return {Object} - The names of the status effects which were processed. | * @return {Object} - The codes of the status effects which were processed. | ||||
*/ | */ | ||||
StatusEffectsReceiver.prototype.ApplyStatus = function(effectData, attacker, attackerOwner) | StatusEffectsReceiver.prototype.ApplyStatus = function(effectData, attacker, attackerOwner) | ||||
{ | { | ||||
let attackerData = { "entity": attacker, "owner": attackerOwner }; | let attackerData = { "entity": attacker, "owner": attackerOwner }; | ||||
for (let effect in effectData) | for (let effect in effectData) | ||||
Stan: Typo StatusEffectsReceiver here and below | |||||
this.AddStatus(effect, effectData[effect], attackerData); | this.AddStatus(effect, effectData[effect], attackerData); | ||||
// TODO: implement loot / resistance. | // TODO: implement loot? | ||||
Done Inline Actions-resistance Freagarach: -`resistance` | |||||
return { "inflictedStatuses": Object.keys(effectData) }; | return { "inflictedStatuses": Object.keys(effectData) }; | ||||
}; | }; | ||||
/** | /** | ||||
* Adds a status effect to the entity. | * Adds a status effect to the entity. | ||||
* | * | ||||
* @param {string} statusName - The name of the status effect. | * @param {string} statusCode - The code of the status effect. | ||||
Done Inline Actionsname -> code Freagarach: `name` -> `code` | |||||
* @param {Object} data - The various effects and timings. | * @param {Object} data - The various effects and timings. | ||||
* @param {Object} attackerData - The attacker and attackerOwner. | * @param {Object} attackerData - The attacker and attackerOwner. | ||||
*/ | */ | ||||
StatusEffectsReceiver.prototype.AddStatus = function(statusName, data, attackerData) | StatusEffectsReceiver.prototype.AddStatus = function(baseCode, data, attackerData) | ||||
{ | { | ||||
if (this.activeStatusEffects[statusName]) | let statusCode = baseCode; | ||||
if (this.activeStatusEffects[statusCode]) | |||||
{ | { | ||||
if (data.Stackability == "Ignore") | if (data.Stackability == "Ignore") | ||||
return; | return; | ||||
if (data.Stackability == "Extend") | if (data.Stackability == "Extend") | ||||
{ | { | ||||
this.activeStatusEffects[statusName].Duration += data.Duration; | this.activeStatusEffects[statusCode].Duration += data.Duration; | ||||
return; | return; | ||||
} | } | ||||
if (data.Stackability == "Replace") | if (data.Stackability == "Replace") | ||||
this.RemoveStatus(statusName); | this.RemoveStatus(statusCode); | ||||
else if (data.Stackability == "Stack") | else if (data.Stackability == "Stack") | ||||
{ | { | ||||
let i = 0; | let i = 0; | ||||
let temp; | let temp; | ||||
do | do | ||||
temp = statusName + "_" + i++; | temp = statusCode + "_" + i++; | ||||
while (!!this.activeStatusEffects[temp]); | while (!!this.activeStatusEffects[temp]); | ||||
statusName = temp; | statusCode = temp; | ||||
} | } | ||||
} | } | ||||
this.activeStatusEffects[statusName] = {}; | this.activeStatusEffects[statusCode] = { | ||||
let status = this.activeStatusEffects[statusName]; | "baseCode": baseCode | ||||
}; | |||||
let status = this.activeStatusEffects[statusCode]; | |||||
Object.assign(status, data); | Object.assign(status, data); | ||||
if (status.Modifiers) | if (status.Modifiers) | ||||
{ | { | ||||
let modifications = DeriveModificationsFromXMLTemplate(status.Modifiers); | let modifications = DeriveModificationsFromXMLTemplate(status.Modifiers); | ||||
let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); | let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); | ||||
cmpModifiersManager.AddModifiers(statusName, modifications, this.entity); | cmpModifiersManager.AddModifiers(statusCode, modifications, this.entity); | ||||
} | } | ||||
// With neither an interval nor a duration, there is no point in starting a timer. | // With neither an interval nor a duration, there is no point in starting a timer. | ||||
if (!status.Duration && !status.Interval) | if (!status.Duration && !status.Interval) | ||||
return; | return; | ||||
// We need this to prevent Status Effects from giving XP | // We need this to prevent Status Effects from giving XP | ||||
// to the entity that applied them. | // to the entity that applied them. | ||||
status.StatusEffect = true; | status.StatusEffect = true; | ||||
// We want an interval to update the GUI to show how much time of the status effect | // We want an interval to update the GUI to show how much time of the status effect | ||||
// is left even if the status effect itself has no interval. | // is left even if the status effect itself has no interval. | ||||
if (!status.Interval) | if (!status.Interval) | ||||
status._interval = this.DefaultInterval; | status._interval = this.DefaultInterval; | ||||
status._timeElapsed = 0; | status._timeElapsed = 0; | ||||
status._firstTime = true; | status._firstTime = true; | ||||
status.source = attackerData; | status.source = attackerData; | ||||
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 || status._interval), statusName); | status._timer = cmpTimer.SetInterval(this.entity, IID_StatusEffectsReceiver, "ExecuteEffect", 0, +(status.Interval || status._interval), statusCode); | ||||
}; | }; | ||||
/** | /** | ||||
* Removes a status effect from the entity. | * Removes a status effect from the entity. | ||||
* | * | ||||
* @param {string} statusName - The status effect to be removed. | * @param {string} statusCode - The status effect to be removed. | ||||
*/ | */ | ||||
StatusEffectsReceiver.prototype.RemoveStatus = function(statusName) | StatusEffectsReceiver.prototype.RemoveStatus = function(statusCode) | ||||
{ | { | ||||
let statusEffect = this.activeStatusEffects[statusName]; | let statusEffect = this.activeStatusEffects[statusCode]; | ||||
if (!statusEffect) | if (!statusEffect) | ||||
return; | return; | ||||
if (statusEffect.Modifiers) | if (statusEffect.Modifiers) | ||||
{ | { | ||||
let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); | let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); | ||||
cmpModifiersManager.RemoveAllModifiers(statusName, this.entity); | cmpModifiersManager.RemoveAllModifiers(statusCode, this.entity); | ||||
} | } | ||||
if (statusEffect._timer) | if (statusEffect._timer) | ||||
{ | { | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
cmpTimer.CancelTimer(statusEffect._timer); | cmpTimer.CancelTimer(statusEffect._timer); | ||||
} | } | ||||
delete this.activeStatusEffects[statusName]; | delete this.activeStatusEffects[statusCode]; | ||||
}; | }; | ||||
/** | /** | ||||
* Called by the timers. Executes a status effect. | * Called by the timers. Executes a status effect. | ||||
* | * | ||||
* @param {string} statusName - The name of the status effect to be executed. | * @param {string} statusCode - The status effect to be executed. | ||||
Done Inline Actionsname -> code Freagarach: `name` -> `code` | |||||
* @param {number} lateness - The delay between the calling of the function and the actual execution (turn time?). | * @param {number} lateness - The delay between the calling of the function and the actual execution (turn time?). | ||||
*/ | */ | ||||
StatusEffectsReceiver.prototype.ExecuteEffect = function(statusName, lateness) | StatusEffectsReceiver.prototype.ExecuteEffect = function(statusCode, lateness) | ||||
{ | { | ||||
let status = this.activeStatusEffects[statusName]; | let status = this.activeStatusEffects[statusCode]; | ||||
if (!status) | if (!status) | ||||
return; | return; | ||||
if (status.Damage || status.Capture) | if (status.Damage || status.Capture) | ||||
Attacking.HandleAttackEffects(this.entity, statusName, status, status.source.entity, status.source.owner); | Attacking.HandleAttackEffects(this.entity, statusCode, status, status.source.entity, status.source.owner); | ||||
if (!status.Duration) | if (!status.Duration) | ||||
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 || status._interval) + lateness; | status._timeElapsed += +(status.Interval || status._interval) + lateness; | ||||
if (status._timeElapsed >= +status.Duration) | if (status._timeElapsed >= +status.Duration) | ||||
this.RemoveStatus(statusName); | this.RemoveStatus(statusCode); | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); | Engine.RegisterComponentType(IID_StatusEffectsReceiver, "StatusEffectsReceiver", StatusEffectsReceiver); |
Wildfire Games · Phabricator
Typo StatusEffectsReceiver here and below