mirror of
https://github.com/exane/not-gwent-online
synced 2024-10-31 10:36:53 +00:00
more improvements. now with gameplay
This commit is contained in:
parent
f0cbb9de5d
commit
dbf1b07c1f
@ -13,6 +13,7 @@ module.exports = {
|
|||||||
|
|
||||||
cards.forEach(function(_card) {
|
cards.forEach(function(_card) {
|
||||||
if(_card.getID() == card.getID()) return;
|
if(_card.getID() == card.getID()) return;
|
||||||
|
if(_card.getRawPower() === -1) return;
|
||||||
_card.boost(1);
|
_card.boost(1);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -50,7 +51,8 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"weather_fog": {
|
"weather_fog": {
|
||||||
onEachTurn: function(card) {
|
onEachTurn: function(args) {
|
||||||
|
card = args[0]
|
||||||
var targetRow = card.constructor.TYPE.RANGED;
|
var targetRow = card.constructor.TYPE.RANGED;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
@ -64,6 +66,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onEachCardPlace: function(card) {
|
onEachCardPlace: function(card) {
|
||||||
|
card = args[0]
|
||||||
var targetRow = card.constructor.TYPE.RANGED;
|
var targetRow = card.constructor.TYPE.RANGED;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
|
@ -181,7 +181,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"foltest_king_of_temeria": {
|
"foltest_king_of_temeria": {
|
||||||
name: "Foltest: King of Temeria",
|
name: "Foltest: King of Temeria",
|
||||||
power: 0,
|
power: -1,
|
||||||
ability: "foltest_leader1",
|
ability: "foltest_leader1",
|
||||||
img: "foltest_king",
|
img: "foltest_king",
|
||||||
faction: "Northern Realm",
|
faction: "Northern Realm",
|
||||||
@ -189,7 +189,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"decoy": {
|
"decoy": {
|
||||||
name: "Decoy",
|
name: "Decoy",
|
||||||
power: 0,
|
power: -1,
|
||||||
ability: "decoy",
|
ability: "decoy",
|
||||||
img: "decoy",
|
img: "decoy",
|
||||||
faction: null,
|
faction: null,
|
||||||
@ -197,7 +197,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"impenetrable_fog": {
|
"impenetrable_fog": {
|
||||||
name: "Impenetrable Fog",
|
name: "Impenetrable Fog",
|
||||||
power: 0,
|
power: -1,
|
||||||
ability: "weather_fog",
|
ability: "weather_fog",
|
||||||
img: "fog",
|
img: "fog",
|
||||||
faction: null,
|
faction: null,
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "gulpfile.js",
|
"main": "gulpfile.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"socket.io": "^1.3.5"
|
"socketcluster": "2.2.x",
|
||||||
|
"socketcluster-client": "2.2.x"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babelify": "^6.1.2",
|
"babelify": "^6.1.2",
|
||||||
@ -15,14 +16,11 @@
|
|||||||
"handlebars": "^3.0.3",
|
"handlebars": "^3.0.3",
|
||||||
"jquery": "^2.1.4",
|
"jquery": "^2.1.4",
|
||||||
"promise": "^7.0.1",
|
"promise": "^7.0.1",
|
||||||
"pubsub-js": "^1.5.2",
|
|
||||||
"shortid": "^2.2.2",
|
"shortid": "^2.2.2",
|
||||||
"connect": "3.0.1",
|
"connect": "3.0.1",
|
||||||
"express": "4.12.3",
|
"express": "4.12.3",
|
||||||
"minimist": "1.1.0",
|
"minimist": "1.1.0",
|
||||||
"serve-static": "1.8.0",
|
"serve-static": "1.8.0",
|
||||||
"socketcluster": "2.2.x",
|
|
||||||
"socketcluster-client": "2.2.x",
|
|
||||||
"vinyl-source-stream": "^1.1.0"
|
"vinyl-source-stream": "^1.1.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -432,6 +432,10 @@ var User = Backbone.Model.extend({
|
|||||||
var waiting = data.waiting;
|
var waiting = data.waiting;
|
||||||
self.set("waiting", waiting);
|
self.set("waiting", waiting);
|
||||||
})
|
})
|
||||||
|
app.receive("set:passing", function(data){
|
||||||
|
var passing = data.passing;
|
||||||
|
self.set("passing", passing);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
app.on("createRoom", this.createRoom, this);
|
app.on("createRoom", this.createRoom, this);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
var Battleside = require("./Battleside");
|
var Battleside = require("./Battleside");
|
||||||
//var PubSub = require("pubsub-js");
|
|
||||||
var Card = require("./Card");
|
var Card = require("./Card");
|
||||||
|
|
||||||
/*var io = global.io;*/
|
|
||||||
|
|
||||||
var Battle = (function(){
|
var Battle = (function(){
|
||||||
var Battle = function(id, p1, p2, socket){
|
var Battle = function(id, p1, p2, socket){
|
||||||
@ -72,31 +70,21 @@ var Battle = (function(){
|
|||||||
/*PubSub.subscribe("nextTurn", this.switchTurn.bind(this));*/
|
/*PubSub.subscribe("nextTurn", this.switchTurn.bind(this));*/
|
||||||
this.on("NextTurn", this.switchTurn);
|
this.on("NextTurn", this.switchTurn);
|
||||||
|
|
||||||
this.switchTurn();
|
this.switchTurn(Math.random() > .5 ? this.p1 : this.p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
r.switchTurn = function(__flag){
|
r.switchTurn = function(side, __flag){
|
||||||
/*this.playerManager.renderInfos();
|
|
||||||
if(this.playerManager.bothPassed() && !this._roundCheck) {
|
|
||||||
//start new round
|
|
||||||
this._roundCheck = true;
|
|
||||||
this.checkRound();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.playerManager.bothPassed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var entity = this.playerManager.getNextPlayer();
|
|
||||||
|
|
||||||
this.playerManager.renderInfos();*/
|
|
||||||
__flag = typeof __flag == "undefined" ? 0 : 1;
|
__flag = typeof __flag == "undefined" ? 0 : 1;
|
||||||
var side = this.turn++ % 2 ? this.p1 : this.p2;
|
//var side = this.turn++ % 2 ? this.p1 : this.p2;
|
||||||
|
|
||||||
|
/*if(__flag instanceof Battleside) {
|
||||||
|
side = __flag;
|
||||||
|
}*/
|
||||||
if(side.isPassing()){
|
if(side.isPassing()){
|
||||||
if(__flag){
|
if(__flag){
|
||||||
return this.startNextRound();
|
return this.startNextRound();
|
||||||
}
|
}
|
||||||
return this.switchTurn(1);
|
return this.switchTurn(side.foe, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*PubSub.publish("onEachTurn");*/
|
/*PubSub.publish("onEachTurn");*/
|
||||||
@ -109,7 +97,19 @@ var Battle = (function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.startNextRound = function(){
|
r.startNextRound = function(){
|
||||||
|
var loser = this.checkRubies();
|
||||||
|
if(this.checkIfIsOver()){
|
||||||
|
console.log("its over!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.p1.resetNewRound();
|
||||||
|
this.p2.resetNewRound();
|
||||||
|
|
||||||
|
console.log("start new round!");
|
||||||
|
|
||||||
|
this.update();
|
||||||
|
this.switchTurn(loser);
|
||||||
}
|
}
|
||||||
|
|
||||||
r.update = function(){
|
r.update = function(){
|
||||||
@ -140,17 +140,18 @@ var Battle = (function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
r.runEvent = function(eventid, target, args){
|
r.runEvent = function(eventid, ctx, args){
|
||||||
target = target || this;
|
ctx = ctx || this;
|
||||||
args = args || [];
|
args = args || [];
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
|
|
||||||
if(!this.events["on" + eventid]){
|
if(!this.events[event]){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.events[event].forEach(function(e){
|
this.events[event].forEach(function(e){
|
||||||
e.apply(target, args);
|
e.apply(ctx, args);
|
||||||
});
|
});
|
||||||
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
r.on = function(eventid, cb, ctx, args){
|
r.on = function(eventid, cb, ctx, args){
|
||||||
@ -160,9 +161,9 @@ var Battle = (function(){
|
|||||||
if(!(event in this.events)){
|
if(!(event in this.events)){
|
||||||
this.events[event] = [];
|
this.events[event] = [];
|
||||||
}
|
}
|
||||||
/*if(!this.events[event]) {
|
if(typeof cb !== "function"){
|
||||||
this.events[event] = [];
|
throw new Error("cb not a function");
|
||||||
}*/
|
}
|
||||||
if(args){
|
if(args){
|
||||||
this.events[event].push(cb.bind(ctx, args));
|
this.events[event].push(cb.bind(ctx, args));
|
||||||
}
|
}
|
||||||
@ -179,6 +180,30 @@ var Battle = (function(){
|
|||||||
delete this.events[event];
|
delete this.events[event];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.checkIfIsOver = function(){
|
||||||
|
return !(this.p1.getRubies() && this.p2.getRubies());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
r.checkRubies = function(){
|
||||||
|
var scoreP1 = this.p1.getScore();
|
||||||
|
var scoreP2 = this.p2.getScore();
|
||||||
|
|
||||||
|
if(scoreP1 > scoreP2){
|
||||||
|
this.p2.removeRuby();
|
||||||
|
return this.p2;
|
||||||
|
}
|
||||||
|
if(scoreP2 > scoreP1){
|
||||||
|
this.p1.removeRuby();
|
||||||
|
return this.p1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//tie
|
||||||
|
this.p1.removeRuby();
|
||||||
|
this.p2.removeRuby();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return Battle;
|
return Battle;
|
||||||
})();
|
})();
|
||||||
|
@ -30,6 +30,7 @@ Battleside = (function(){
|
|||||||
this.battle = battle;
|
this.battle = battle;
|
||||||
this.hand = Hand();
|
this.hand = Hand();
|
||||||
this.deck = Deck(DeckData["test"]);
|
this.deck = Deck(DeckData["test"]);
|
||||||
|
this._discard = [];
|
||||||
|
|
||||||
this.runEvent = this.battle.runEvent.bind(this.battle);
|
this.runEvent = this.battle.runEvent.bind(this.battle);
|
||||||
this.on = this.battle.on.bind(this.battle);
|
this.on = this.battle.on.bind(this.battle);
|
||||||
@ -48,14 +49,13 @@ Battleside = (function(){
|
|||||||
if(self._isWaiting) return;
|
if(self._isWaiting) return;
|
||||||
var card = self.findCardOnFieldByID(data.cardID);
|
var card = self.findCardOnFieldByID(data.cardID);
|
||||||
if(card === -1) throw new Error("decoy:replace | unknown card");
|
if(card === -1) throw new Error("decoy:replace | unknown card");
|
||||||
/*PubSub.publish("decoy:replaceWith", card);*/
|
|
||||||
self.runEvent("Decoy:replaceWith", self, [card]);
|
self.runEvent("Decoy:replaceWith", self, [card]);
|
||||||
})
|
})
|
||||||
this.receive("set:passing", function() {
|
this.receive("set:passing", function() {
|
||||||
self.setPassing(true);
|
self.setPassing(true);
|
||||||
self.update();/*
|
self.update();/*
|
||||||
PubSub.publish("nextTurn");*/
|
PubSub.publish("nextTurn");*/
|
||||||
self.runEvent("NextTurn");
|
self.runEvent("NextTurn", null, [self.foe]);
|
||||||
})
|
})
|
||||||
|
|
||||||
/*PubSub.subscribe("turn/" + this.getID(), this.onTurnStart.bind(this));*/
|
/*PubSub.subscribe("turn/" + this.getID(), this.onTurnStart.bind(this));*/
|
||||||
@ -74,7 +74,7 @@ Battleside = (function(){
|
|||||||
r._range = null;
|
r._range = null;
|
||||||
r._siege = null;
|
r._siege = null;
|
||||||
r._field = null;*/
|
r._field = null;*/
|
||||||
r._lives = 2;
|
r._rubies = 2;
|
||||||
r._score = 0;
|
r._score = 0;
|
||||||
r._isWaiting = null;
|
r._isWaiting = null;
|
||||||
r._passing = null;
|
r._passing = null;
|
||||||
@ -108,6 +108,7 @@ Battleside = (function(){
|
|||||||
|
|
||||||
r.setPassing = function(b) {
|
r.setPassing = function(b) {
|
||||||
this._passing = b;
|
this._passing = b;
|
||||||
|
this.send("set:passing", {passing: this._passing}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
r.wait = function(){
|
r.wait = function(){
|
||||||
@ -154,13 +155,25 @@ Battleside = (function(){
|
|||||||
r.getInfo = function(){
|
r.getInfo = function(){
|
||||||
return {
|
return {
|
||||||
name: this.getName(),
|
name: this.getName(),
|
||||||
lives: this._lives,
|
lives: this._rubies,
|
||||||
score: this.calcScore(),
|
score: this.calcScore(),
|
||||||
hand: this.hand.length(),
|
hand: this.hand.length(),
|
||||||
passing: this._passing
|
passing: this._passing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.getRubies = function() {
|
||||||
|
return this._rubies;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.getScore = function() {
|
||||||
|
return +this.calcScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
r.removeRuby = function() {
|
||||||
|
this._rubies--;
|
||||||
|
}
|
||||||
|
|
||||||
r.getName = function(){
|
r.getName = function(){
|
||||||
return this._name;
|
return this._name;
|
||||||
}
|
}
|
||||||
@ -203,8 +216,8 @@ Battleside = (function(){
|
|||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
|
|
||||||
//PubSub.publish("nextTurn");
|
|
||||||
this.runEvent("NextTurn");
|
this.runEvent("NextTurn", this, [this.foe]);
|
||||||
}
|
}
|
||||||
|
|
||||||
r.placeCard = function(card){
|
r.placeCard = function(card){
|
||||||
@ -221,6 +234,8 @@ Battleside = (function(){
|
|||||||
|
|
||||||
this.checkAbilityOnAfterPlace(card);
|
this.checkAbilityOnAfterPlace(card);
|
||||||
|
|
||||||
|
this.update();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,29 +251,26 @@ Battleside = (function(){
|
|||||||
if(ability.replaceWith){
|
if(ability.replaceWith){
|
||||||
obj._canclePlacement = true;
|
obj._canclePlacement = true;
|
||||||
|
|
||||||
//var decoy = PubSub.subscribe("decoy:replaceWith", function(event, replaceCard){
|
|
||||||
this.on("Decoy:replaceWith", function(replaceCard) {
|
this.on("Decoy:replaceWith", function(replaceCard) {
|
||||||
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
||||||
replaceCard.getType() == Card.TYPE.WEATHER ||
|
replaceCard.getType() == Card.TYPE.WEATHER ||
|
||||||
replaceCard.getType() == Card.TYPE.SPECIAL){
|
replaceCard.getType() == Card.TYPE.SPECIAL){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*PubSub.unsubscribe(decoy);*/
|
if(replaceCard.getName() === card.getName()) return;
|
||||||
self.off("Decoy:replaceWith");
|
self.off("Decoy:replaceWith");
|
||||||
var field = self.field[replaceCard.getType()];
|
var field = self.field[replaceCard.getType()];
|
||||||
|
|
||||||
field.replaceWith(replaceCard, card);
|
field.replaceWith(replaceCard, card);
|
||||||
|
|
||||||
self.hand.add(replaceCard);
|
self.hand.add(replaceCard);
|
||||||
|
/*
|
||||||
|
self.update();*/
|
||||||
|
|
||||||
self.update();
|
self.runEvent("NextTurn", null, [self.foe]);
|
||||||
|
|
||||||
/*PubSub.publish("nextTurn");*/
|
|
||||||
self.runEvent("NextTurn");
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if(ability.onEachTurn){
|
if(ability.onEachTurn){
|
||||||
//PubSub.subscribe("onEachTurn", ability.onEachTurn.bind(this, card));
|
|
||||||
this.on("EachTurn", ability.onEachTurn, this, [card])
|
this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
}
|
}
|
||||||
if(ability.onEachCardPlace){
|
if(ability.onEachCardPlace){
|
||||||
@ -278,6 +290,26 @@ Battleside = (function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.clearMainFields = function() {
|
||||||
|
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();
|
||||||
|
|
||||||
|
var cards = cards1.concat(cards2.concat(cards3));
|
||||||
|
this.addToDiscard(cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
r.addToDiscard = function(cards) {
|
||||||
|
var self = this;
|
||||||
|
cards.forEach(function(card) {
|
||||||
|
self._discard.push(card);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
r.resetNewRound = function() {
|
||||||
|
this.clearMainFields();
|
||||||
|
this.setPassing(false);
|
||||||
|
}
|
||||||
|
|
||||||
return Battleside;
|
return Battleside;
|
||||||
})();
|
})();
|
||||||
|
@ -50,11 +50,22 @@ var Card = (function(){
|
|||||||
return this._data.name;
|
return this._data.name;
|
||||||
}
|
}
|
||||||
r.getPower = function(){
|
r.getPower = function(){
|
||||||
|
if(this._data.power === -1) return 0;
|
||||||
if(this._forcedPower > -1){
|
if(this._forcedPower > -1){
|
||||||
return this._forcedPower + this._boost;
|
return this._forcedPower + this._boost;
|
||||||
}
|
}
|
||||||
return this._data.power + this._boost;
|
return this._data.power + this._boost;
|
||||||
}
|
}
|
||||||
|
r.getRawPower = function() {
|
||||||
|
return this._data.power;
|
||||||
|
}
|
||||||
|
r.calculateBoost = function() {
|
||||||
|
this._boost = 0;
|
||||||
|
for (var key in this._boosts) {
|
||||||
|
var boost = this._boosts[key];
|
||||||
|
this.boost(boost.getPower());
|
||||||
|
}
|
||||||
|
}
|
||||||
r.setForcedPower = function(nr){
|
r.setForcedPower = function(nr){
|
||||||
this._forcedPower = nr;
|
this._forcedPower = nr;
|
||||||
}
|
}
|
||||||
@ -82,7 +93,7 @@ var Card = (function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.boost = function(nr){
|
r.boost = function(nr){
|
||||||
this.getPower(); //to recalculate this._power;
|
/*this.getPower(); //to recalculate this._power;*/
|
||||||
this._boost += nr;
|
this._boost += nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,11 @@ var Field = (function(){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.removeAll = function() {
|
||||||
|
var tmp = this._cards.slice();
|
||||||
|
this._cards = [];
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return Field;
|
return Field;
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user