@@ -409,6 +409,13 @@ module.exports = { | |||||
return didCast || isCasting; | return didCast || isCasting; | ||||
}, | }, | ||||
//Callbacks to be called when this object is destroyed | |||||
registerDestroyCallback: function (callback) { | |||||
this.callbacks.push({ | |||||
cbOnSelfDestroyed: callback | |||||
}); | |||||
}, | |||||
registerCallback: function (sourceId, callback, time, destroyCallback, targetId, destroyOnRezone) { | registerCallback: function (sourceId, callback, time, destroyCallback, targetId, destroyOnRezone) { | ||||
let obj = { | let obj = { | ||||
sourceId: sourceId, | sourceId: sourceId, | ||||
@@ -508,8 +515,8 @@ module.exports = { | |||||
destroy: function () { | destroy: function () { | ||||
this.callbacks.forEach(c => { | this.callbacks.forEach(c => { | ||||
if (c.destroyCallback) | |||||
c.destroyCallback(); | |||||
if (c.cbOnSelfDestroyed) | |||||
c.cbOnSelfDestroyed(); | |||||
}); | }); | ||||
this.spells.forEach(s => { | this.spells.forEach(s => { | ||||
@@ -87,10 +87,12 @@ module.exports = { | |||||
this.queueCallback( | this.queueCallback( | ||||
this.reachDestination.bind(this, target, targetPos, targetEffect, selfEffect), | this.reachDestination.bind(this, target, targetPos, targetEffect, selfEffect), | ||||
ttl - 50, | |||||
this.destroyEffectOnTarget.bind(this, target, targetEffect) | |||||
ttl - 50 | |||||
); | ); | ||||
//To be called when the object is destroyed | |||||
this.obj.spellbook.registerDestroyCallback(this.destroyEffectOnTarget.bind(this, target, targetEffect)); | |||||
return true; | return true; | ||||
}, | }, | ||||
@@ -148,9 +148,12 @@ module.exports = { | |||||
this.queueCallback( | this.queueCallback( | ||||
this.endEffect.bind(this, m, targetPos, targetEffect), | this.endEffect.bind(this, m, targetPos, targetEffect), | ||||
ttl, | ttl, | ||||
this.destroyEffectOnTarget.bind(this, m, targetEffect), | |||||
null, | |||||
m | m | ||||
); | ); | ||||
//To be called when the object is destroyed | |||||
this.obj.spellbook.registerDestroyCallback(this.destroyEffectOnTarget.bind(this, m, targetEffect)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||