1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-11-23 19:36:53 +00:00
not-gwent-online/server/Card.js

125 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-06-13 19:36:02 +00:00
var CardData = require("../assets/data/cards");
var AbilityData = require("../assets/data/abilities");
var Card = (function(){
var Card = function(key){
if(!(this instanceof Card)){
return (new Card(key));
}
/**
* constructor here
*/
2015-06-18 13:06:13 +00:00
this.setDisabled(false);
2015-06-15 19:03:12 +00:00
this.channel = {};
2015-06-13 19:36:02 +00:00
this._key = key;
this._data = CardData[key];
2015-06-18 13:06:13 +00:00
this._data.key = key;
2015-06-13 19:36:02 +00:00
this._boost = 0;
this._forcedPower = -1;
this._init();
};
var r = Card.prototype;
/**
* methods && properties here
* r.property = null;
* r.getProperty = function() {...}
*/
r._key = null;
r._data = null;
r._id = null;
r._owner = null;
r._boost = null;
r._forcedPower = null;
2015-06-18 13:06:13 +00:00
r._disabled = null;
2015-06-13 19:36:02 +00:00
Card.__id = 0;
Card.TYPE = {
CLOSE_COMBAT: 0,
RANGED: 1,
SIEGE: 2,
LEADER: 3,
SPECIAL: 4,
WEATHER: 5
};
2015-06-15 19:03:12 +00:00
r.channel = null
2015-06-14 18:50:53 +00:00
2015-06-13 19:36:02 +00:00
r._init = function(){
this._id = ++Card.__id;
}
r.getName = function(){
return this._data.name;
}
r.getPower = function(){
2015-06-17 19:18:14 +00:00
if(this._data.power === -1) return 0;
2015-06-14 18:50:53 +00:00
if(this._forcedPower > -1){
2015-06-13 19:36:02 +00:00
return this._forcedPower + this._boost;
}
return this._data.power + this._boost;
}
2015-06-17 19:18:14 +00:00
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());
}
}
2015-06-14 18:50:53 +00:00
r.setForcedPower = function(nr){
2015-06-13 19:36:02 +00:00
this._forcedPower = nr;
}
2015-06-14 18:50:53 +00:00
r.getRawAbility = function(){
2015-06-13 19:36:02 +00:00
return this._data.ability;
}
r.getAbility = function(){
2015-06-18 18:47:17 +00:00
if(Array.isArray(this._data.ability)) {
var res = [];
this._data.ability.forEach(function(ability) {
res.push(AbilityData[ability]);
})
return res;
}
2015-06-13 19:36:02 +00:00
return AbilityData[this._data.ability];
}
r.getImage = function(){
return "../assets/cards/" + this._data.img + ".png";
}
r.getFaction = function(){
return this._data.faction;
}
r.getType = function(){
return this._data.type;
}
r.getKey = function(){
return this._key;
}
2015-06-14 14:01:25 +00:00
r.getID = function(){
2015-06-13 19:36:02 +00:00
return this._id;
}
2015-06-14 18:50:53 +00:00
r.boost = function(nr){
2015-06-17 19:18:14 +00:00
/*this.getPower(); //to recalculate this._power;*/
2015-06-13 19:36:02 +00:00
this._boost += nr;
}
2015-06-18 13:06:13 +00:00
r.isDisabled = function() {
return this._disabled;
}
r.setDisabled = function(b) {
this._disabled = b;
}
2015-06-13 19:36:02 +00:00
r.getProperty = function(prop){
return this._data[prop];
}
return Card;
})();
module.exports = Card;