From d8d0962a5f3e9c2f3f5c7a50ae44b10bda7bdfd1 Mon Sep 17 00:00:00 2001 From: exane Date: Fri, 26 Jun 2015 13:17:28 +0200 Subject: [PATCH] add scorch ability --- assets/data/abilities.js | 10 +++++++++- assets/data/cards.js | 16 ++++++++++++++++ server/Battle.js | 9 +++++++++ server/Battleside.js | 33 +++++++++++++++++++++++++++++++-- server/Field.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/assets/data/abilities.js b/assets/data/abilities.js index 7b3f52c..c5e5e29 100644 --- a/assets/data/abilities.js +++ b/assets/data/abilities.js @@ -231,9 +231,17 @@ module.exports = { description: "Decoy: Swap with a card on the battlefield to return it to your hand.", replaceWith: true }, + "scorch_card": { + name: "scorch", + description: "Scorch: Discard after playing. Kills the strongest card(s) in the battlefield.", + scorch: true, + removeImmediately: true, + nextTurn: true + }, "scorch": { name: "scorch", - description: "Scorch: Discard after playing. Kills the strongest card(s) in the battlefield." + description: "Scorch: Discard after playing. Kills the strongest card(s) in the battlefield.", + scorch: true }, "commanders_horn": { name: "commanders_horn", diff --git a/assets/data/cards.js b/assets/data/cards.js index a5c9f65..c2cee96 100644 --- a/assets/data/cards.js +++ b/assets/data/cards.js @@ -252,6 +252,14 @@ module.exports = { faction: null, type: 4 }, + "scorch": { + name: "Scorch", + power: -1, + ability: "scorch_card", + img: "scorch", + faction: null, + type: 4 + }, "commanders_horn": { name: "Commander's Horn", power: -1, @@ -311,6 +319,14 @@ module.exports = { faction: null, type: 0 }, + "villentretenmerth": { + name: "Villentretenmerth ", + power: 7, + ability: "scorch", + img: "villentretenmerth", + faction: null, + type: 0 + }, "francesca_pureblood_elf": { name: "Francesca, Pureblood Elf", diff --git a/server/Battle.js b/server/Battle.js index b07dcf6..1ae3c5a 100644 --- a/server/Battle.js +++ b/server/Battle.js @@ -64,6 +64,15 @@ var Battle = (function(){ this.p1.draw(10); this.p2.draw(10); + this.p1.placeCard("ves"); + this.p2.placeCard("ves"); + this.p1.placeCard("yarpen_zigrin"); + this.p2.placeCard("yarpen_zigrin"); + + this.p1.hand.add(Card("scorch")); + this.p2.hand.add(Card("scorch")); + this.p1.hand.add(Card("villentretenmerth")); + this.p2.hand.add(Card("villentretenmerth")); /* this.p1.hand.add(Card("impenetrable_fog")); this.p2.hand.add(Card("impenetrable_fog")); diff --git a/server/Battleside.js b/server/Battleside.js index 20abe46..7bc683f 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -301,6 +301,11 @@ Battleside = (function(){ this.checkAbilities(card, obj); if(obj._cancelPlacement && !obj.forceField) return 0; + if(obj._nextTurn && !obj.forceField) { + this.update(); + this.runEvent("NextTurn", null, [this.foe]); + return 0; + } var field = obj.forceField || null; @@ -424,6 +429,16 @@ Battleside = (function(){ if(ability.cancelPlacement && !obj.forcePlace){ obj._cancelPlacement = true; } + if(ability.nextTurn) { + obj._nextTurn = ability.nextTurn; + } + if(ability.scorch) { + this.scorch(card); + } + if(ability.removeImmediately) { + this.hand.remove(card); + this.addToDiscard(card); + } if(ability.waitResponse && !obj.forcePlace){ obj._waitResponse = true; } @@ -531,6 +546,17 @@ Battleside = (function(){ //this.update(); } + r.scorch = function(card) { + var side = this.foe; + var field = side.field[Card.TYPE.CLOSE_COMBAT]; + var cards = field.getHighestCards(); + var removeCards = field.removeCard(cards); + + side.addToDiscard(removeCards);/* + this.hand.remove(card); + this.addToDiscard(card);*/ + } + r.clearMainFields = function(){ var cards1 = this.field[Card.TYPE.CLOSE_COMBAT].removeAll(); var cards2 = this.field[Card.TYPE.RANGED].removeAll(); @@ -543,8 +569,11 @@ Battleside = (function(){ r.addToDiscard = function(cards){ var self = this; - cards.forEach(function(card){ - self._discard.push(card); + if(!Array.isArray(cards)) { + cards = [cards]; + } + cards.forEach(function(_card){ + self._discard.push(_card); }); } diff --git a/server/Field.js b/server/Field.js index e78f3db..eb3c4b9 100644 --- a/server/Field.js +++ b/server/Field.js @@ -105,6 +105,20 @@ var Field = (function(){ return tmp; } + r.removeCard = function(cards) { + var res = []; + var _cards = this.get(); + if(!Array.isArray(cards)) { + cards = [cards]; + } + var self = this; + cards.forEach(function(card) { + res.push(_cards.splice(self.getPosition(card), 1)[0]); + }) + + return res; + } + r.getInfo = function() { var self = this; return { @@ -124,6 +138,21 @@ var Field = (function(){ this._hornCard = card; } + r.getHighestCards = function() { + var res = []; + var highest = 0; + + this.get().forEach(function(card) { + highest = card.getPower() > highest ? card.getPower() : highest; + }) + + this.get().forEach(function(card) { + if(card.getPower() === highest) res.push(card); + }); + + return res; + } + return Field; })();