1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-12-11 18:23:07 +00:00

add faction ability

This commit is contained in:
exane
2015-06-28 16:10:25 +02:00
parent 187d6b21c2
commit 5b7190184b
9 changed files with 329 additions and 155 deletions

View File

@@ -1,5 +1,6 @@
var Battleside = require("./Battleside");
var Card = require("./Card");
var Deck = require("./Deck");
var shortid = require("shortid");
var Promise = require("jquery-deferred");
@@ -54,7 +55,6 @@ var Battle = (function(){
this.p1.setUpWeatherFieldWith(this.p2);
this.start();
}
@@ -63,26 +63,27 @@ var Battle = (function(){
this.p2.setLeadercard();
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.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"));
this.p1.hand.add(Card("biting_frost"));
this.p2.hand.add(Card("biting_frost"));
this.p1.hand.add(Card("torrential_rain"));
this.p2.hand.add(Card("torrential_rain"));
this.p1.hand.add(Card("clear_weather"));
this.p2.hand.add(Card("clear_weather"));
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"));
this.p1.hand.add(Card("biting_frost"));
this.p2.hand.add(Card("biting_frost"));
this.p1.hand.add(Card("torrential_rain"));
this.p2.hand.add(Card("torrential_rain"));
this.p1.hand.add(Card("clear_weather"));
this.p2.hand.add(Card("clear_weather"));
*/
this.update();
@@ -121,9 +122,10 @@ var Battle = (function(){
r.startNextRound = function(){
var loser = this.checkRubies();
var winner = loser.foe;
if(this.checkIfIsOver()){
console.log("its over!");
this.gameOver(loser.foe);
this.gameOver(winner);
this.update();
return;
}
@@ -133,11 +135,41 @@ var Battle = (function(){
console.log("start new round!");
if(winner.deck.getFaction() === Deck.FACTION.NORTHERN_REALM){
winner.draw(1);
console.log(winner.getName() + " draws 1 extra card! (Northern ability)");
}
this.update();
this.switchTurn(loser);
if(winner.deck.getFaction() === Deck.FACTION.SCOIATAEL){
this.waitForScoiatael(winner);
}
else if(this.p1.deck.getFaction() === Deck.FACTION.SCOIATAEL){
this.waitForScoiatael(this.p1);
}
else if(this.p2.deck.getFaction() === Deck.FACTION.SCOIATAEL){
this.waitForScoiatael(this.p2);
}
else {
this.switchTurn(loser);
}
}
r.gameOver = function(winner) {
r.waitForScoiatael = function(side){
var self = this;
side.send("request:chooseWhichSideBegins", null, true);
side.socket.once("response:chooseWhichSideBegins", function(data){
console.log("which side? ", data.side);
if(data.side !== "p1" && data.side !== "p2")
throw new Error("Unknown side property! - ", data.side);
self.switchTurn(self[data.side]);
})
}
r.gameOver = function(winner){
this.send("gameover", {
winner: winner.getName()
})
@@ -149,7 +181,7 @@ var Battle = (function(){
this._update(this.p2);
}
r.updateSelf = function(side) {
r.updateSelf = function(side){
this._update(side, true);
}
@@ -161,7 +193,7 @@ var Battle = (function(){
}, isPrivate)
p.send("update:hand", {
cards: JSON.stringify(p.hand.getCards())
},isPrivate);
}, isPrivate);
p.send("update:fields", {
close: p.field[Card.TYPE.CLOSE_COMBAT].getInfo(),
ranged: p.field[Card.TYPE.RANGED].getInfo(),
@@ -265,6 +297,19 @@ var Battle = (function(){
}
//tie
//check if is nilfgaardian faction ability
if(this.p1.deck.getFaction() === Deck.FACTION.NILFGAARDIAN_EMPIRE && this.p1.deck.getFaction() !== this.p2.deck.getFaction()){
this.p2.removeRuby();
console.log(this.p1.getName() + " wins the tie! (nilfgaardian ability)");
return this.p2;
}
if(this.p2.deck.getFaction() === Deck.FACTION.NILFGAARDIAN_EMPIRE && this.p1.deck.getFaction() !== this.p2.deck.getFaction()){
this.p1.removeRuby();
console.log(this.p2.getName() + " wins the tie! (nilfgaardian ability)");
return this.p1;
}
this.p1.removeRuby();
this.p2.removeRuby();
return Math.random() > 0.5 ? this.p1 : this.p2;

View File

@@ -166,6 +166,19 @@ Battleside = (function(){
return -1;
}
r.getRandomCardOnField = function() {
var close, range, siege;
close = this.field[Card.TYPE.CLOSE_COMBAT].get();
range = this.field[Card.TYPE.RANGED].get();
siege = this.field[Card.TYPE.SIEGE].get();
var allCards = close.concat(range.concat(siege));
var rnd = (Math.random() * allCards.length) | 0 ;
return allCards[rnd];
}
r.getCardFromDiscard = function(id){
for(var i = 0; i < this._discard.length; i++) {
var c = this._discard[i];
@@ -558,6 +571,10 @@ Battleside = (function(){
}
r.clearMainFields = function(){
var rndCard = null;
if(this.deck.getFaction() === Deck.FACTION.MONSTERS) {
rndCard = this.getRandomCardOnField();
}
var cards1 = this.field[Card.TYPE.CLOSE_COMBAT].removeAll();
var cards2 = this.field[Card.TYPE.RANGED].removeAll();
var cards3 = this.field[Card.TYPE.SIEGE].removeAll();
@@ -565,6 +582,12 @@ Battleside = (function(){
var cards = cards1.concat(cards2.concat(cards3.concat(cards4)));
this.addToDiscard(cards);
if(rndCard) {
this.removeFromDiscard(rndCard);
this.placeCard(rndCard, {disabled: true}); //disabled == no abilities get triggered
console.log("Monsters faction ability triggered!");
}
}
r.addToDiscard = function(cards){

View File

@@ -11,8 +11,11 @@ var Deck = (function(){
*/
this._deck = [];
if(typeof deck !== "object") throw new Error("Deck is not an object!");
this._originalDeck = [];
this.setDeck(deck);
this._faction = deck.faction;
this.setDeck(deck.data);
};
var r = Deck.prototype;
/**
@@ -23,6 +26,14 @@ var Deck = (function(){
r._deck = null;
r._owner = null;
r._originalDeck = null;
r._faction = null;
Deck.FACTION = {
NORTHERN_REALM: "northern",
SCOIATAEL: "scoiatael",
NILFGAARDIAN_EMPIRE: "nilfgaardian",
MONSTERS: "monster"
}
r.setDeck = function(deckData){
this._originalDeck = deckData.slice();
@@ -32,6 +43,10 @@ var Deck = (function(){
this.shuffle();
}
r.getFaction = function() {
return this._faction;
}
r.getLength = function(){
return this._deck.length;
}
@@ -99,7 +114,7 @@ var Deck = (function(){
}
}
r.add = function(card) {
r.add = function(card){
this._deck.push(card);
}

View File

@@ -58,8 +58,8 @@ var Room = (function(){
r.initBattle = function(){
this._battle = Battle(this._id, this._users[0], this._users[1], io);
this._users[0].send("init:battle", {side: "p1"});
this._users[1].send("init:battle", {side: "p2"});
this._users[0].send("init:battle", {side: "p1", foeSide: "p2"});
this._users[1].send("init:battle", {side: "p2", foeSide: "p2"});
}
r.setReady = function(user, b){