From 3e5c660d6d1a2ba81f10824aa04af7d7a507329b Mon Sep 17 00:00:00 2001 From: exane Date: Thu, 2 Jul 2015 19:21:24 +0200 Subject: [PATCH] fix monster ability bug --- client/js/client.js | 23 +++++++++---------- server/Battleside.js | 53 ++++++++++++++++++++++++-------------------- server/Field.js | 2 +- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/client/js/client.js b/client/js/client.js index ecc42ca..5b39ff1 100644 --- a/client/js/client.js +++ b/client/js/client.js @@ -263,18 +263,6 @@ let SideView = Backbone.View.extend({ }*/ }); -let calculateCardMargin = function($selector, totalWidth, cardWidth, n){ - let w = totalWidth, c = cardWidth; - let res; - if(n < 6) - res = 0; - else { - res = -((w - c) / (n - 1) - c) + 1 - } - - $selector.css("margin-left", -res); -} - let BattleView = Backbone.View.extend({ el: ".gwent-battle", template: require("../templates/battle.handlebars"), @@ -706,7 +694,7 @@ let ChooseSideModal = Modal.extend({ let User = Backbone.Model.extend({ defaults: { name: localStorage["userName"] || null, - deck: localStorage["userDeck"] || null, + deck: localStorage["userDeck"] || "random", serverOffline: true }, initialize: function(){ @@ -863,6 +851,7 @@ let Lobby = Backbone.View.extend({ this.app.receive("update:playerOnline", this.renderStatus.bind(this)); this.listenTo(this.app.user, "change:serverOffline", this.render); + this.listenTo(this.app.user, "change:name", this.setName); $(".gwent-battle").html(this.el); this.render(); }, @@ -893,6 +882,14 @@ let Lobby = Backbone.View.extend({ this.app.trigger("setDeck", val); this.$el.find("#deckChoice option[value='" + val + "']").attr("selected", "selected") }, + setName: function(){ + /*let val = $(e.target).val(); + this.app.trigger("setDeck", val); + this.$el.find("#deckChoice option[value='" + val + "']").attr("selected", "selected")*/ + localStorage["userName"] = this.app.user.get("name"); + /*this.render();*/ + this.$el.find(".name-input").val(this.app.user.get("name")); + }, changeName: function(e){ let name = $(e.target).val(); this.app.trigger("setName", name); diff --git a/server/Battleside.js b/server/Battleside.js index 79f1bd4..534492a 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -58,7 +58,7 @@ Battleside = (function(){ leaderCard.setDisabled(true); self.battle.sendNotification(self.getName() + " activated " + leaderCard.getName() + "! (leadercard)"); self.update(); - if(ability.waitResponse) { + if(ability.waitResponse){ return; } //self.runEvent("NextTurn", null, [self.foe]); @@ -219,7 +219,7 @@ Battleside = (function(){ return -1; } - r.getFieldCards = function() { + r.getFieldCards = function(){ var close, range, siege; close = this.field[Card.TYPE.CLOSE_COMBAT].get(); @@ -348,7 +348,7 @@ Battleside = (function(){ this.endTurn(); } - r.endTurn = function() { + r.endTurn = function(){ this.update(); this.runEvent("NextTurn", null, [this.foe]); @@ -473,22 +473,24 @@ Battleside = (function(){ }) } - r.setTightBond = function(card) { + r.setTightBond = function(card){ var field = this.field[card.getType()]; var pos = field.getPosition(card); var cards = field.get(); if(pos < 0) return; - if(pos >= 1 && cards[pos-1].getName() === cards[pos].getName()) { - cards[pos].setBoost(cards[pos].getID()+"|left", "tight_bond"); - } else { - cards[pos].setBoost(cards[pos].getID()+"|left", 0); + if(pos >= 1 && cards[pos - 1].getName() === cards[pos].getName()){ + cards[pos].setBoost(cards[pos].getID() + "|left", "tight_bond"); + } + else { + cards[pos].setBoost(cards[pos].getID() + "|left", 0); } - if(pos < cards.length-1 && cards[pos+1].getName() === cards[pos].getName()) { - cards[pos].setBoost(cards[pos].getID()+"|right", "tight_bond"); - } else { - cards[pos].setBoost(cards[pos].getID()+"|right", 0); + if(pos < cards.length - 1 && cards[pos + 1].getName() === cards[pos].getName()){ + cards[pos].setBoost(cards[pos].getID() + "|right", "tight_bond"); + } + else { + cards[pos].setBoost(cards[pos].getID() + "|right", 0); } } @@ -666,13 +668,13 @@ Battleside = (function(){ this.runEvent("WeatherChange"); } - r.scorchMelee = function(card) { + r.scorchMelee = function(card){ var side = this.foe; var field = side.field[Card.TYPE.CLOSE_COMBAT]; this.battle.sendNotification(this.getName() + " played " + card.getName()); - if(field.getScore() < 10) { + if(field.getScore() < 10){ this.battle.sendNotification("Scorch: Score is under 10! Nothing happens."); return; } @@ -682,7 +684,7 @@ Battleside = (function(){ var txt = "Scorch destroyed:"; - for (var i = 0; i < removeCards.length; i++) { + for(var i = 0; i < removeCards.length; i++) { var c = removeCards[i]; txt += "\n" + c.getName(); } @@ -716,9 +718,9 @@ Battleside = (function(){ if(card.getPower() === highest) res.push(card); }); - res.forEach(function(card) { + res.forEach(function(card){ var side = self; - if(self.foe.field[card.getType()].isOnField(card)) { + if(self.foe.field[card.getType()].isOnField(card)){ side = self.foe; } var removed = side.field[card.getType()].removeCard(card); @@ -726,7 +728,7 @@ Battleside = (function(){ }) var txt = "Scorch destroyed:"; - for (var i = 0; i < res.length; i++) { + for(var i = 0; i < res.length; i++) { var c = res[i]; txt += "\n" + c.getName(); } @@ -738,12 +740,11 @@ Battleside = (function(){ var rndCard = null; if(this.deck.getFaction() === Deck.FACTION.MONSTERS){ rndCard = this.getRandomCardOnField(); - if(rndCard) { + if(rndCard){ rndCard.__lock = true; - //console.log("Monsters faction ability triggered!"); - this.sendNotification(this.getName() + ": Monsters faction ability triggered! " + rndCard.getName()); - } else { + } + else { this.sendNotification(this.getName() + ": Monsters faction ability triggered! But no card found."); } } @@ -762,6 +763,10 @@ Battleside = (function(){ cards = [cards]; } cards.forEach(function(_card){ + if(_card.__lock){ + delete _card.__lock; + return; + } self._discard.push(_card); }); } @@ -837,7 +842,7 @@ Battleside = (function(){ } r.reDraw = function(n){ - var hand = this.hand.getCards(); + //var hand = this.hand.getCards(); var self = this; var left = n; var deferred = Promise.Deferred(); @@ -875,7 +880,7 @@ Battleside = (function(){ } - r.sendNotification = function(msg) { + r.sendNotification = function(msg){ this.battle.sendNotification(msg); } diff --git a/server/Field.js b/server/Field.js index a4ce2ec..5907893 100644 --- a/server/Field.js +++ b/server/Field.js @@ -97,7 +97,7 @@ var Field = (function(){ for(var i = 0; i < tmp.length; i++) { var card = tmp[i]; if(card.__lock){ - delete card.__lock; + //delete card.__lock; continue; } card.reset();