mirror of
https://github.com/exane/not-gwent-online
synced 2024-11-20 11:26:54 +00:00
add cardmanager (handling card ids)
This commit is contained in:
parent
c62ac4c91b
commit
2f605767ec
@ -3,6 +3,7 @@ var Card = require("./Card");
|
||||
var Deck = require("./Deck");
|
||||
var shortid = require("shortid");
|
||||
var Promise = require("jquery-deferred");
|
||||
var CardManager = require("./CardManager")
|
||||
|
||||
|
||||
var Battle = (function(){
|
||||
@ -13,12 +14,12 @@ var Battle = (function(){
|
||||
/**
|
||||
* constructor here
|
||||
*/
|
||||
this.cm = CardManager();
|
||||
this.events = {};
|
||||
this._id = id;
|
||||
this._user1 = p1;
|
||||
this._user2 = p2;
|
||||
this.socket = socket;
|
||||
this.channel = {};
|
||||
};
|
||||
var r = Battle.prototype;
|
||||
/**
|
||||
@ -33,6 +34,8 @@ var Battle = (function(){
|
||||
r._user2 = null;
|
||||
r.turn = 0;
|
||||
|
||||
r.cm = null;
|
||||
|
||||
r.socket = null;
|
||||
|
||||
r._id = null;
|
||||
@ -57,27 +60,6 @@ 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.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();
|
||||
|
@ -22,6 +22,8 @@ Battleside = (function(){
|
||||
this._isWaiting = true;
|
||||
this.socket = user.socket;
|
||||
|
||||
this.cm = battle.cm;
|
||||
|
||||
this.field = {};
|
||||
this.field[Card.TYPE.LEADER] = Field(this);
|
||||
this.field[Card.TYPE.CLOSE_COMBAT] = Field(this, true);
|
||||
@ -32,7 +34,7 @@ Battleside = (function(){
|
||||
this._name = user.getName();
|
||||
this.battle = battle;
|
||||
this.hand = Hand();
|
||||
this.deck = Deck(DeckData[deck]);
|
||||
this.deck = Deck(DeckData[deck], this);
|
||||
this._discard = [];
|
||||
|
||||
this.runEvent = this.battle.runEvent.bind(this.battle);
|
||||
@ -132,11 +134,17 @@ Battleside = (function(){
|
||||
r.socket = null;
|
||||
r.n = null;
|
||||
|
||||
r.cm = null;
|
||||
|
||||
r.foe = null;
|
||||
r.hand = null;
|
||||
r.battle = null;
|
||||
r.deck = null;
|
||||
|
||||
r.createCard = function(key) {
|
||||
return this.cm.create(key, this.n);
|
||||
}
|
||||
|
||||
r.isPassing = function(){
|
||||
return this._passing;
|
||||
}
|
||||
@ -308,7 +316,8 @@ Battleside = (function(){
|
||||
obj = _.extend({}, obj);
|
||||
|
||||
if(typeof card === "string"){
|
||||
card = Card(card);
|
||||
//card = Card(card);
|
||||
card = this.createCard(card);
|
||||
}
|
||||
|
||||
this.checkAbilities(card, obj);
|
||||
@ -357,7 +366,9 @@ Battleside = (function(){
|
||||
field = typeof field === "undefined" ? null : field;
|
||||
|
||||
if(typeof card === "string"){
|
||||
card = Card(card);
|
||||
//card = Card(card);
|
||||
//card = this.cm.create(card);
|
||||
card = this.createCard(card);
|
||||
}
|
||||
|
||||
if(typeof field === "number"){
|
||||
|
@ -2,13 +2,15 @@ var CardData = require("../assets/data/cards");
|
||||
var AbilityData = require("../assets/data/abilities");
|
||||
|
||||
var Card = (function(){
|
||||
var Card = function(key){
|
||||
var Card = function(key, owner, id){
|
||||
if(!(this instanceof Card)){
|
||||
return (new Card(key));
|
||||
return (new Card(key, owner, id));
|
||||
}
|
||||
/**
|
||||
* constructor here
|
||||
*/
|
||||
this._owner = owner;
|
||||
this._id = id;
|
||||
this.boost = 0;
|
||||
this._uidEvents = {};
|
||||
this.setDisabled(false);
|
||||
@ -17,7 +19,7 @@ var Card = (function(){
|
||||
this._data.key = key;
|
||||
this._boost = {};
|
||||
this._forcedPower = -1;
|
||||
this._init();
|
||||
//this._init();
|
||||
};
|
||||
var r = Card.prototype;
|
||||
/**
|
||||
@ -33,7 +35,7 @@ var Card = (function(){
|
||||
r._forcedPower = null;
|
||||
r._disabled = null;
|
||||
r._changedType = null;
|
||||
Card.__id = 0;
|
||||
//Card.__id = 0;
|
||||
Card.TYPE = {
|
||||
CLOSE_COMBAT: 0,
|
||||
RANGED: 1,
|
||||
@ -54,7 +56,7 @@ var Card = (function(){
|
||||
}
|
||||
|
||||
r._init = function(){
|
||||
this._id = ++Card.__id;
|
||||
//this._id = ++Card.__id;
|
||||
}
|
||||
|
||||
r.getName = function(){
|
||||
|
31
server/CardManager.js
Normal file
31
server/CardManager.js
Normal 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;
|
@ -2,13 +2,15 @@ var Card = require("./Card");
|
||||
/*var CardManager = require("./CardManager");*/
|
||||
|
||||
var Deck = (function(){
|
||||
var Deck = function(deck){
|
||||
var Deck = function(deck, side){
|
||||
if(!(this instanceof Deck)){
|
||||
return (new Deck(deck));
|
||||
return (new Deck(deck, side));
|
||||
}
|
||||
/**
|
||||
* constructor here
|
||||
*/
|
||||
|
||||
this.side = side;
|
||||
this._deck = [];
|
||||
|
||||
if(typeof deck !== "object") throw new Error("Deck is not an object!");
|
||||
@ -28,6 +30,8 @@ var Deck = (function(){
|
||||
r._originalDeck = null;
|
||||
r._faction = null;
|
||||
|
||||
r.side = null;
|
||||
|
||||
Deck.FACTION = {
|
||||
NORTHERN_REALM: "northern",
|
||||
SCOIATAEL: "scoiatael",
|
||||
@ -66,8 +70,10 @@ var Deck = (function(){
|
||||
}
|
||||
|
||||
r._loadCards = function(){
|
||||
var self = this;
|
||||
this._deck = this.getDeck().map(function(cardkey){
|
||||
return Card(cardkey);
|
||||
//return Card(cardkey);
|
||||
return self.side.createCard(cardkey);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user