1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-10-31 10:36:53 +00:00

add cardmanager (handling card ids)

This commit is contained in:
exane 2015-06-30 12:11:50 +02:00
parent c62ac4c91b
commit 2f605767ec
5 changed files with 65 additions and 33 deletions

View File

@ -3,6 +3,7 @@ var Card = require("./Card");
var Deck = require("./Deck"); var Deck = require("./Deck");
var shortid = require("shortid"); var shortid = require("shortid");
var Promise = require("jquery-deferred"); var Promise = require("jquery-deferred");
var CardManager = require("./CardManager")
var Battle = (function(){ var Battle = (function(){
@ -13,12 +14,12 @@ var Battle = (function(){
/** /**
* constructor here * constructor here
*/ */
this.cm = CardManager();
this.events = {}; this.events = {};
this._id = id; this._id = id;
this._user1 = p1; this._user1 = p1;
this._user2 = p2; this._user2 = p2;
this.socket = socket; this.socket = socket;
this.channel = {};
}; };
var r = Battle.prototype; var r = Battle.prototype;
/** /**
@ -33,6 +34,8 @@ var Battle = (function(){
r._user2 = null; r._user2 = null;
r.turn = 0; r.turn = 0;
r.cm = null;
r.socket = null; r.socket = null;
r._id = null; r._id = null;
@ -57,27 +60,6 @@ var Battle = (function(){
this.p2.setLeadercard(); this.p2.setLeadercard();
this.p1.draw(10); this.p1.draw(10);
this.p2.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"));
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(); this.update();

View File

@ -22,6 +22,8 @@ Battleside = (function(){
this._isWaiting = true; this._isWaiting = true;
this.socket = user.socket; this.socket = user.socket;
this.cm = battle.cm;
this.field = {}; this.field = {};
this.field[Card.TYPE.LEADER] = Field(this); this.field[Card.TYPE.LEADER] = Field(this);
this.field[Card.TYPE.CLOSE_COMBAT] = Field(this, true); this.field[Card.TYPE.CLOSE_COMBAT] = Field(this, true);
@ -32,7 +34,7 @@ Battleside = (function(){
this._name = user.getName(); this._name = user.getName();
this.battle = battle; this.battle = battle;
this.hand = Hand(); this.hand = Hand();
this.deck = Deck(DeckData[deck]); this.deck = Deck(DeckData[deck], this);
this._discard = []; this._discard = [];
this.runEvent = this.battle.runEvent.bind(this.battle); this.runEvent = this.battle.runEvent.bind(this.battle);
@ -132,11 +134,17 @@ Battleside = (function(){
r.socket = null; r.socket = null;
r.n = null; r.n = null;
r.cm = null;
r.foe = null; r.foe = null;
r.hand = null; r.hand = null;
r.battle = null; r.battle = null;
r.deck = null; r.deck = null;
r.createCard = function(key) {
return this.cm.create(key, this.n);
}
r.isPassing = function(){ r.isPassing = function(){
return this._passing; return this._passing;
} }
@ -308,7 +316,8 @@ Battleside = (function(){
obj = _.extend({}, obj); obj = _.extend({}, obj);
if(typeof card === "string"){ if(typeof card === "string"){
card = Card(card); //card = Card(card);
card = this.createCard(card);
} }
this.checkAbilities(card, obj); this.checkAbilities(card, obj);
@ -357,7 +366,9 @@ Battleside = (function(){
field = typeof field === "undefined" ? null : field; field = typeof field === "undefined" ? null : field;
if(typeof card === "string"){ if(typeof card === "string"){
card = Card(card); //card = Card(card);
//card = this.cm.create(card);
card = this.createCard(card);
} }
if(typeof field === "number"){ if(typeof field === "number"){

View File

@ -2,13 +2,15 @@ var CardData = require("../assets/data/cards");
var AbilityData = require("../assets/data/abilities"); var AbilityData = require("../assets/data/abilities");
var Card = (function(){ var Card = (function(){
var Card = function(key){ var Card = function(key, owner, id){
if(!(this instanceof Card)){ if(!(this instanceof Card)){
return (new Card(key)); return (new Card(key, owner, id));
} }
/** /**
* constructor here * constructor here
*/ */
this._owner = owner;
this._id = id;
this.boost = 0; this.boost = 0;
this._uidEvents = {}; this._uidEvents = {};
this.setDisabled(false); this.setDisabled(false);
@ -17,7 +19,7 @@ var Card = (function(){
this._data.key = key; this._data.key = key;
this._boost = {}; this._boost = {};
this._forcedPower = -1; this._forcedPower = -1;
this._init(); //this._init();
}; };
var r = Card.prototype; var r = Card.prototype;
/** /**
@ -33,7 +35,7 @@ var Card = (function(){
r._forcedPower = null; r._forcedPower = null;
r._disabled = null; r._disabled = null;
r._changedType = null; r._changedType = null;
Card.__id = 0; //Card.__id = 0;
Card.TYPE = { Card.TYPE = {
CLOSE_COMBAT: 0, CLOSE_COMBAT: 0,
RANGED: 1, RANGED: 1,
@ -54,7 +56,7 @@ var Card = (function(){
} }
r._init = function(){ r._init = function(){
this._id = ++Card.__id; //this._id = ++Card.__id;
} }
r.getName = function(){ r.getName = function(){

31
server/CardManager.js Normal file
View File

@ -0,0 +1,31 @@
var Card = require("./Card");
var CardManager = (function(){
var CardManager = function(){
if(!(this instanceof CardManager)){
return (new CardManager());
}
/**
* constructor here
*/
this._id = 0;
};
var r = CardManager.prototype;
/**
* methods && properties here
* r.property = null;
* r.getProperty = function() {...}
*/
r._id = null;
r.create = function(key, owner) {
return this._cards[this._id] = Card(key, owner, this._id++);
}
return CardManager;
})();
module.exports = CardManager;

View File

@ -2,13 +2,15 @@ var Card = require("./Card");
/*var CardManager = require("./CardManager");*/ /*var CardManager = require("./CardManager");*/
var Deck = (function(){ var Deck = (function(){
var Deck = function(deck){ var Deck = function(deck, side){
if(!(this instanceof Deck)){ if(!(this instanceof Deck)){
return (new Deck(deck)); return (new Deck(deck, side));
} }
/** /**
* constructor here * constructor here
*/ */
this.side = side;
this._deck = []; this._deck = [];
if(typeof deck !== "object") throw new Error("Deck is not an object!"); if(typeof deck !== "object") throw new Error("Deck is not an object!");
@ -28,6 +30,8 @@ var Deck = (function(){
r._originalDeck = null; r._originalDeck = null;
r._faction = null; r._faction = null;
r.side = null;
Deck.FACTION = { Deck.FACTION = {
NORTHERN_REALM: "northern", NORTHERN_REALM: "northern",
SCOIATAEL: "scoiatael", SCOIATAEL: "scoiatael",
@ -66,8 +70,10 @@ var Deck = (function(){
} }
r._loadCards = function(){ r._loadCards = function(){
var self = this;
this._deck = this.getDeck().map(function(cardkey){ this._deck = this.getDeck().map(function(cardkey){
return Card(cardkey); //return Card(cardkey);
return self.side.createCard(cardkey);
}); });
} }