diff --git a/server/Battle.js b/server/Battle.js index 12ebea7..12d30bd 100644 --- a/server/Battle.js +++ b/server/Battle.js @@ -36,6 +36,7 @@ var Battle = (function(){ r._id = null; + r.events = null; r.init = function(){ PubSub.subscribe("update", this.update.bind(this)); @@ -134,6 +135,27 @@ var Battle = (function(){ }); } + r.runEvent = function(eventid, target){ + target = target || this; + this.events["on" + eventid].forEach(function(event) { + event.call(target); + }); + } + + r.on = function(eventid, cb){ + if(!this.events["on" + eventid]) { + this.events["on" + eventid] = []; + } + this.events["on" + eventid].push(cb); + } + + r.off = function(eventid) { + this.events["on" + eventid].forEach(function(event) { + event = null; + }); + delete this.events["on" + eventid]; + } + /*r._setUpChannel = function() { var self = this; this._abilityChannel.watch(function(d) {