1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-08-30 05:57:30 +00:00

add notifications (kinda)

This commit is contained in:
exane
2015-06-29 19:57:51 +02:00
parent a89f3414ff
commit 70432e3530
9 changed files with 124 additions and 26 deletions

View File

@@ -121,7 +121,8 @@ var Battle = (function(){
}
r.startNextRound = function(){
var loser = this.checkRubies();
var lastRound = this.checkRubies();
var loser = lastRound.loser;
var winner = loser.foe;
if(this.checkIfIsOver()){
console.log("its over!");
@@ -134,10 +135,13 @@ var Battle = (function(){
this.p2.resetNewRound();
console.log("start new round!");
this.sendNotification("Start new round!");
if(winner.deck.getFaction() === Deck.FACTION.NORTHERN_REALM){
if(winner.deck.getFaction() === Deck.FACTION.NORTHERN_REALM && !lastRound.isTie){
winner.draw(1);
console.log(winner.getName() + " draws 1 extra card! (Northern ability)");
this.sendNotification(winner.getName() + " draws 1 extra card! (Northern ability)");
}
this.update();
@@ -158,6 +162,7 @@ var Battle = (function(){
r.waitForScoiatael = function(side){
var self = this;
self.sendNotification(side.getName() + " decides whos starts first");
side.send("request:chooseWhichSideBegins", null, true);
side.socket.once("response:chooseWhichSideBegins", function(data){
console.log("which side? ", data.side);
@@ -289,11 +294,17 @@ var Battle = (function(){
if(scoreP1 > scoreP2){
this.p2.removeRuby();
return this.p2;
return {
loser: this.p2,
isTie: false
}
}
if(scoreP2 > scoreP1){
this.p1.removeRuby();
return this.p1;
return {
loser: this.p1,
isTie: false
}
}
//tie
@@ -302,17 +313,28 @@ var Battle = (function(){
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;
self.sendNotification(this.p1.getName() + " wins the tie! (nilfgaardian ability)");
return {
loser: this.p2,
isTie: false
}
}
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;
self.sendNotification(this.p2.getName() + " wins the tie! (nilfgaardian ability)");
return {
loser: this.p1,
isTie: false
}
}
this.p1.removeRuby();
this.p2.removeRuby();
return Math.random() > 0.5 ? this.p1 : this.p2;
return {
loser: Math.random() > 0.5 ? this.p1 : this.p2,
isTie: true
}
}
r.userLeft = function(sideName){
@@ -326,6 +348,12 @@ var Battle = (function(){
this.channel = null;
}
r.sendNotification = function(msg){
this.send("notification", {
message: msg
})
}
return Battle;
})();

View File

@@ -176,6 +176,8 @@ Battleside = (function(){
var allCards = close.concat(range.concat(siege));
var rnd = (Math.random() * allCards.length) | 0 ;
if(allCards[rnd].getType === 4) return null;
return allCards[rnd];
}
@@ -332,6 +334,7 @@ Battleside = (function(){
if(!field){
field = obj.targetSide.field[card.getType()];
}
field.add(card);
}

View File

@@ -59,7 +59,7 @@ 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", foeSide: "p2"});
this._users[1].send("init:battle", {side: "p2", foeSide: "p2"});
this._users[1].send("init:battle", {side: "p2", foeSide: "p1"});
}
r.setReady = function(user, b){