From f3d8f1c4a1e443fe88595f2231e49ab40d9b296a Mon Sep 17 00:00:00 2001 From: exane Date: Sun, 5 Jul 2015 10:55:27 +0200 Subject: [PATCH] revamp tight bond ability --- server/Battleside.js | 16 ++++++++++++---- server/Card.js | 7 +++++++ server/Field.js | 21 +++++++++++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/server/Battleside.js b/server/Battleside.js index 47c094c..acd897c 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -474,11 +474,19 @@ Battleside = (function(){ } r.setTightBond = function(card){ - var field = this.field[card.getType()]; - var pos = field.getPosition(card); + var field = this.field[card.getType()];/* + var pos = field.getPosition(card);*/ var cards = field.get(); - if(pos < 0) return; + card.resetTightBond(); + + cards.forEach(function(c) { + if(c.getID() === card.getID()) return; + if(c.getName() !== card.getName()) return; + card.setBoost(card.getID() + "|tight_bond|"+c.getID(), "tight_bond"); + }); + + /*if(pos < 0) return; if(pos >= 1 && cards[pos - 1].getName() === cards[pos].getName()){ cards[pos].setBoost(cards[pos].getID() + "|left", "tight_bond"); } @@ -491,7 +499,7 @@ Battleside = (function(){ } else { cards[pos].setBoost(cards[pos].getID() + "|right", 0); - } + }*/ } r.checkAbilities = function(card, obj, __flag){ diff --git a/server/Card.js b/server/Card.js index bd647c7..3ebe61a 100644 --- a/server/Card.js +++ b/server/Card.js @@ -137,6 +137,13 @@ var Card = (function(){ return this._id; } + r.resetTightBond = function() { + for(var key in this._boost) { + if(this._boost[key] !== "tight_bond") continue; + delete this._boost[key]; + } + } + r.getBoost = function(){ var res = 0; var doubles = 0; diff --git a/server/Field.js b/server/Field.js index f4b3b3d..300cac0 100644 --- a/server/Field.js +++ b/server/Field.js @@ -74,6 +74,9 @@ var Field = (function(){ var index = this.getPosition(oldCard); this._cards[index] = newCard; oldCard.reset(); + for(var event in oldCard._uidEvents) { + this.side.off(event, oldCard.getUidEvents(event)); + } return oldCard; } @@ -88,7 +91,7 @@ var Field = (function(){ r.removeAll = function(){ var tmp = this._cards.slice(); var self = this; - for(var i = 0; i < tmp.length; i++) { + /*for(var i = 0; i < tmp.length; i++) { var card = tmp[i]; card.reset(); if(card.__lock){ @@ -98,7 +101,17 @@ var Field = (function(){ self.side.off(event, card.getUidEvents(event)); } this._cards[i] = null; - } + }*/ + tmp.forEach(function(card, i) { + card.reset(); + if(card.__lock){ + return; + } + for(var event in card._uidEvents) { + this.side.off(event, card.getUidEvents(event)); + } + this._cards[i] = null; + }, this) this._cards = _.without(this._cards, null); @@ -122,6 +135,10 @@ var Field = (function(){ } var self = this; cards.forEach(function(card){ + card.reset(); + for(var event in card._uidEvents) { + this.side.off(event, card.getUidEvents(event)); + } res.push(_cards.splice(self.getPosition(card), 1)[0]); })