1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-09-22 14:49:06 +00:00

much stuff

This commit is contained in:
exane
2015-06-18 15:06:13 +02:00
parent ef7d9aacf9
commit 6667db814c
17 changed files with 522 additions and 152 deletions

View File

@@ -80,6 +80,10 @@ var Battle = (function(){
/*if(__flag instanceof Battleside) {
side = __flag;
}*/
if(!(side instanceof Battleside)){
console.trace("side is not a battleside!");
return
}
if(side.isPassing()){
if(__flag){
return this.startNextRound();
@@ -87,10 +91,7 @@ var Battle = (function(){
return this.switchTurn(side.foe, 1);
}
/*PubSub.publish("onEachTurn");*/
this.runEvent("EachTurn");
/*
PubSub.publish("turn/" + side.getID());*/
this.runEvent("Turn" + side.getID());
console.log("current Turn: ", side.getName());
@@ -100,6 +101,7 @@ var Battle = (function(){
var loser = this.checkRubies();
if(this.checkIfIsOver()){
console.log("its over!");
this.update();
return;
}
@@ -153,6 +155,7 @@ var Battle = (function(){
obj.cb = obj.cb.bind(ctx)
obj.cb.apply(ctx, obj.onArgs.concat(args));
});
this.update();
}
r.on = function(eventid, cb, ctx, args){
@@ -161,9 +164,10 @@ var Battle = (function(){
var event = "on" + eventid;
var obj = {};
if(!ctx) {
if(!ctx){
obj.cb = cb;
} else {
}
else {
obj.cb = cb.bind(ctx);
}
obj.onArgs = args;
@@ -187,6 +191,7 @@ var Battle = (function(){
r.off = function(eventid){
var event = "on" + eventid;
if(!this.events[event]) return;
this.events[event].forEach(function(e){
e = null;
});
@@ -215,7 +220,7 @@ var Battle = (function(){
//tie
this.p1.removeRuby();
this.p2.removeRuby();
return 0;
return Math.random() > 0.5 ? this.p1 : this.p2;
}

View File

@@ -4,7 +4,6 @@ var Deck = require("./Deck");
var Hand = require("./Hand");
var Card = require("./Card");
var Field = require("./Field");
//var PubSub = require("pubsub-js");
var Battleside;
@@ -37,6 +36,22 @@ Battleside = (function(){
this.off = this.battle.off.bind(this.battle);
this.receive("activate:leader", function(){
if(self._isWaiting) return;
if(self.isPassing()) return;
console.log("leader activated");
var leaderCard = self.getLeader();
if(leaderCard.isDisabled()) return;
var ability = leaderCard.getAbility();
ability.onActivate.apply(self);
leaderCard.setDisabled(true);
self.update();
})
this.receive("play:cardFromHand", function(data){
if(self._isWaiting) return;
if(self.isPassing()) return;
@@ -51,14 +66,15 @@ Battleside = (function(){
if(card === -1) throw new Error("decoy:replace | unknown card");
self.runEvent("Decoy:replaceWith", self, [card]);
})
this.receive("set:passing", function() {
this.receive("cancel:decoy", function(){
self.off("Decoy:replaceWith");
})
this.receive("set:passing", function(){
self.setPassing(true);
self.update();/*
PubSub.publish("nextTurn");*/
self.update();
self.runEvent("NextTurn", null, [self.foe]);
})
/*PubSub.subscribe("turn/" + this.getID(), this.onTurnStart.bind(this));*/
this.on("Turn" + this.getID(), this.onTurnStart, this);
};
var r = Battleside.prototype;
@@ -69,11 +85,7 @@ Battleside = (function(){
*/
r._name = null;
r._discard = null;
/*r.leaderField = null;
r.closeField = null;
r._range = null;
r._siege = null;
r._field = null;*/
r._rubies = 2;
r._score = 0;
r._isWaiting = null;
@@ -89,7 +101,7 @@ Battleside = (function(){
r.battle = null;
r.deck = null;
r.isPassing = function() {
r.isPassing = function(){
return this._passing;
}
@@ -97,7 +109,7 @@ Battleside = (function(){
this.field[Card.TYPE.WEATHER] = p2.field[Card.TYPE.WEATHER] = Field(Card.TYPE.WEATHER);
}
r.findCardOnFieldByID = function(id) {
r.findCardOnFieldByID = function(id){
for(var key in this.field) {
var field = this.field[key];
var card = field.getCard(id);
@@ -106,7 +118,7 @@ Battleside = (function(){
return -1;
}
r.setPassing = function(b) {
r.setPassing = function(b){
this._passing = b;
this.send("set:passing", {passing: this._passing}, true);
}
@@ -129,6 +141,10 @@ Battleside = (function(){
this.field[Card.TYPE.LEADER].add(leaderCard[0]);
}
r.getLeader = function(){
return this.field[Card.TYPE.LEADER].get()[0];
}
r.getID = function(){
return this.n;
}
@@ -158,19 +174,20 @@ Battleside = (function(){
lives: this._rubies,
score: this.calcScore(),
hand: this.hand.length(),
discard: this.getDiscard(true),
passing: this._passing
}
}
r.getRubies = function() {
r.getRubies = function(){
return this._rubies;
}
r.getScore = function() {
r.getScore = function(){
return +this.calcScore();
}
r.removeRuby = function() {
r.removeRuby = function(){
this._rubies--;
}
@@ -210,14 +227,14 @@ Battleside = (function(){
r.playCard = function(card){
if(card === null || card === -1) return;
this.hand.remove(card);
if(!this.placeCard(card)) return;
this.hand.remove(card);
this.update();
this.runEvent("NextTurn", this, [this.foe]);
this.runEvent("NextTurn", null, [this.foe]);
}
r.placeCard = function(card){
@@ -251,7 +268,7 @@ Battleside = (function(){
if(ability.replaceWith){
obj._canclePlacement = true;
this.on("Decoy:replaceWith", function(replaceCard) {
this.on("Decoy:replaceWith", function(replaceCard){
if(replaceCard.getType() == Card.TYPE.LEADER ||
replaceCard.getType() == Card.TYPE.WEATHER ||
replaceCard.getType() == Card.TYPE.SPECIAL){
@@ -261,11 +278,12 @@ Battleside = (function(){
self.off("Decoy:replaceWith");
var field = self.field[replaceCard.getType()];
field.replaceWith(replaceCard, card);
self.hand.add(replaceCard);
/*
self.update();*/
self.hand.remove(card);
self.update();
self.runEvent("NextTurn", null, [self.foe]);
})
@@ -278,6 +296,7 @@ Battleside = (function(){
this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
}
this.update();
}
}
@@ -290,7 +309,7 @@ Battleside = (function(){
}
}
r.clearMainFields = 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();
@@ -299,14 +318,21 @@ Battleside = (function(){
this.addToDiscard(cards);
}
r.addToDiscard = function(cards) {
r.addToDiscard = function(cards){
var self = this;
cards.forEach(function(card) {
cards.forEach(function(card){
self._discard.push(card);
});
}
r.resetNewRound = function() {
r.getDiscard = function(json){
if(json){
return JSON.stringify(this._discard);
}
return this._discard;
}
r.resetNewRound = function(){
this.clearMainFields();
this.setPassing(false);
}

View File

@@ -9,9 +9,11 @@ var Card = (function(){
/**
* constructor here
*/
this.setDisabled(false);
this.channel = {};
this._key = key;
this._data = CardData[key];
this._data.key = key;
this._boost = 0;
this._forcedPower = -1;
this._init();
@@ -29,6 +31,7 @@ var Card = (function(){
r._owner = null;
r._boost = null;
r._forcedPower = null;
r._disabled = null;
Card.__id = 0;
Card.TYPE = {
CLOSE_COMBAT: 0,
@@ -97,6 +100,14 @@ var Card = (function(){
this._boost += nr;
}
r.isDisabled = function() {
return this._disabled;
}
r.setDisabled = function(b) {
this._disabled = b;
}
r.getProperty = function(prop){
return this._data[prop];
}

View File

@@ -44,19 +44,12 @@ var Deck = (function(){
return this._deck;
}
r.draw = function(times){
r.draw = function(){
if(!this._deck.length) return 0;
var card = this.pop();
return card;
}
/*
r._loadCards = function(){
var n = this._originalDeck.length;
for(var i = 0; i < n; i++) {
this._deck.push(CardManager().add(this._originalDeck[i], this._owner));
}
}*/
r._loadCards = function(){
this._deck = this.getDeck().map(function(cardkey){
@@ -77,7 +70,6 @@ var Deck = (function(){
if(card.getProperty(key) == val){
res.push(card);
}
});
return res;
}
@@ -93,7 +85,7 @@ var Deck = (function(){
}*/
var c = this.getDeck()[i];
if(c.getID() === card.getID()){
return this.getDeck().splice(i, 1);
return this.getDeck().splice(i, 1)[0];
}
}
return -1;

View File

@@ -42,6 +42,7 @@ var Hand = (function(){
r.remove = function(id){
var n = this.length();
//console.trace(id);
id = id instanceof Card ? id.getID() : id;
for(var i = 0; i < n; i++) {

View File

@@ -56,23 +56,6 @@ var Room = (function(){
r.isOpen = function(){
return !(this._users.length >= 2);
}
/*
r.send = function(event, data){
*/
/*this.socket.publish(this._id + "|" + event, data);
this.socket.publish(this._id, {
event: event,
data: data
});
var subs = this.socket.subscriptions();
subs.forEach(function(sub) {
});*//*
this._channel.publish(event, data);
}
*/
r.getPlayers = function(){
return this._users;
@@ -92,26 +75,13 @@ var Room = (function(){
if(this.bothReady()){
this._battle.init();
}
/*
if(!this.checkIfReady()) return;
this._users[0].send("init:battle", {side: "p1"});
this._users[1].send("init:battle", {side: "p2"});
if(!this.checkIfReady()) return;
this._battle.init();*/
}
r.bothReady = function(){
return !!this._ready[this._users[0].getID()] && !!this._ready[this._users[1].getID()];
}
/*
r.checkIfReady = function(){
for(var i = 0; i < this._users.length; i++) {
if(!this._ready[this._users[i].getID()]) return false;
}
return true;
}*/
return Room;
})();

View File

@@ -1,2 +0,0 @@
var socket = require("./Socket")();