diff --git a/client/js/client.js b/client/js/client.js index 17fea44..621de28 100644 --- a/client/js/client.js +++ b/client/js/client.js @@ -380,7 +380,7 @@ var BattleView = Backbone.View.extend({ calculateCardMargin(this.$el.find(".field-hand .card"), 538, 70, this.handCards.length); } - if(this.user.get("isReDrawing")) { + if(this.user.get("isReDrawing")){ this.user.set("handCards", this.handCards); var modal = new ReDrawModal({model: this.user}); this.$el.prepend(modal.render().el); @@ -584,11 +584,11 @@ var User = Backbone.Model.extend({ self.set("setHorn", data.cardID); }) - app.receive("redraw:cards", function() { + app.receive("redraw:cards", function(){ self.set("isReDrawing", true); }) - app.receive("redraw:close", function() { + app.receive("redraw:close", function(){ self.set("isReDrawing", false); }) diff --git a/server/Battle.js b/server/Battle.js index 5883230..56bca98 100644 --- a/server/Battle.js +++ b/server/Battle.js @@ -67,25 +67,16 @@ var Battle = (function(){ Promise.when(this.p1.reDraw(2), this.p2.reDraw(2)) - .then(function() { + .then(function(){ this.on("NextTurn", this.switchTurn); this.switchTurn(Math.random() > .5 ? this.p1 : this.p2); }.bind(this)); - - - - /* - this.on("NextTurn", this.switchTurn); - - this.switchTurn(Math.random() > .5 ? this.p1 : this.p2);*/ } r.switchTurn = function(side, __flag){ __flag = typeof __flag == "undefined" ? 0 : 1; - /*side.foe.wait();*/ - if(!(side instanceof Battleside)){ console.trace("side is not a battleside!"); @@ -98,13 +89,12 @@ var Battle = (function(){ return this.switchTurn(side.foe, 1); } + this.runEvent("EachTurn"); - //setTimeout(function() { this.runEvent("Turn" + side.getID()); - //}.bind(this), 1000); - console.log("current Turn: ", side.getName()); + console.log("current Turn: ", side.getName()); } r.startNextRound = function(){ @@ -175,7 +165,7 @@ var Battle = (function(){ obj.cb.apply(ctx, obj.onArgs.concat(args)); } } - this.update(); + //this.update(); } r.on = function(eventid, cb, ctx, args){ diff --git a/server/Battleside.js b/server/Battleside.js index 4d07cc9..8da5e5d 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -78,7 +78,7 @@ Battleside = (function(){ }) this.receive("set:passing", function(){ self.setPassing(true); - self.update(); + //self.update(); self.runEvent("NextTurn", null, [self.foe]); }) this.receive("medic:chooseCardFromDiscard", function(data){ @@ -210,10 +210,6 @@ Battleside = (function(){ var card = this.deck.draw(); this.hand.add(card); } - - console.log("update:hand fired"); - - /*this.update();*/ } r.calcScore = function(){ @@ -266,9 +262,9 @@ Battleside = (function(){ this.socket.on(event, cb); } - r.update = function(){ - //PubSub.publish("update"); - this.runEvent("Update"); + r.update = function(self){ + self = self || false; + this.runEvent("Update", null, [self]); } r.onTurnStart = function(){ @@ -325,7 +321,6 @@ Battleside = (function(){ this.checkAbilityOnAfterPlace(card, obj); - this.update(); if(obj._waitResponse){ this.hand.remove(card); @@ -333,6 +328,8 @@ Battleside = (function(){ return 0; } + this.update(); + return 1; } @@ -409,7 +406,7 @@ Battleside = (function(){ } if(ability && ability.name === obj.suppress){ - this.update(); + //this.update(); } if(ability && !Array.isArray(ability)){ @@ -454,7 +451,6 @@ Battleside = (function(){ self.hand.add(replaceCard); self.hand.remove(card); - self.update(); self.runEvent("NextTurn", null, [self.foe]); }) @@ -472,7 +468,7 @@ Battleside = (function(){ card._uidEvents["WeatherChange"] = uid; } - this.update(); + //this.update(); } } @@ -480,7 +476,7 @@ Battleside = (function(){ var ability = card.getAbility(); if(ability){ if(ability.name && ability.name === obj.suppress){ - this.update(); + //this.update(); return; } if(ability.onAfterPlace){ @@ -529,7 +525,7 @@ Battleside = (function(){ _card.setForcedPower(forcedPower); }); this.runEvent("WeatherChange"); - this.update(); + //this.update(); } r.clearMainFields = function(){ @@ -624,7 +620,7 @@ Battleside = (function(){ this.send("redraw:cards", null, true); - this.receive("redraw:reDrawCard", function(data){ + var h1 = this.receive("redraw:reDrawCard", function(data){ var id = data.cardID; if(!left) return; left--; @@ -633,17 +629,19 @@ Battleside = (function(){ self.deck.add(card); self.deck.shuffle(); self.draw(1); - self.update(); if(!left) { self.send("redraw:close", null, true); console.log("redraw finished"); deferred.resolve("done"); + self.socket.off("redraw:reDrawCard", h1); } + self.update(self); }) - this.receive("redraw:close_client", function() { + var h2 = this.receive("redraw:close_client", function() { console.log("redraw finished!"); deferred.resolve("done"); + self.socket.off("redraw:close_client", h2); }) return deferred;