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

201 lines
4.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(){
2015-06-30 10:11:50 +00:00
var Card = function(key, owner, id){
2015-06-13 19:36:02 +00:00
if(!(this instanceof Card)){
2015-06-30 10:11:50 +00:00
return (new Card(key, owner, id));
2015-06-13 19:36:02 +00:00
}
/**
* constructor here
*/
2015-06-30 10:11:50 +00:00
this._owner = owner;
this._id = id;
2015-06-22 18:19:06 +00:00
this.boost = 0;
2015-06-19 19:53:48 +00:00
this._uidEvents = {};
2015-06-18 13:06:13 +00:00
this.setDisabled(false);
2015-06-30 16:26:24 +00:00
this._data = CardData[key] ? CardData[key] : CardData["none"];
2015-07-01 08:40:57 +00:00
if(!(this._data = CardData[key])){
2015-06-30 16:26:24 +00:00
this._data = CardData["none"];
key = "none";
}
2015-06-13 19:36:02 +00:00
this._key = key;
2015-06-18 13:06:13 +00:00
this._data.key = key;
2015-06-19 19:53:48 +00:00
this._boost = {};
2015-06-13 19:36:02 +00:00
this._forcedPower = -1;
2015-06-30 10:11:50 +00:00
//this._init();
2015-06-13 19:36:02 +00:00
};
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-19 15:15:26 +00:00
r._changedType = null;
2015-06-30 10:11:50 +00:00
//Card.__id = 0;
2015-06-13 19:36:02 +00:00
Card.TYPE = {
CLOSE_COMBAT: 0,
RANGED: 1,
SIEGE: 2,
LEADER: 3,
SPECIAL: 4,
WEATHER: 5
};
2015-06-19 19:53:48 +00:00
r._uidEvents = null;
2015-06-22 18:19:06 +00:00
r.boost = null;
r.power = null;
r.diff = null;
r.diffPos = null;
2015-06-15 19:03:12 +00:00
2015-06-22 16:48:08 +00:00
r.getUidEvents = function(key){
2015-06-19 19:53:48 +00:00
return this._uidEvents[key];
}
2015-06-14 18:50:53 +00:00
2015-06-13 19:36:02 +00:00
r._init = function(){
2015-06-30 10:11:50 +00:00
//this._id = ++Card.__id;
2015-06-13 19:36:02 +00:00
}
r.getName = function(){
return this._data.name;
}
2015-06-22 16:48:08 +00:00
2015-06-22 18:19:06 +00:00
r.getBasePower = function(){
2015-06-22 16:48:08 +00:00
var base = this._data.power;
if(this._forcedPower > -1){
base = this._forcedPower > this._data.power ? this._data.power : this._forcedPower;
}
return base;
}
2015-06-13 19:36:02 +00:00
r.getPower = function(){
2015-06-22 18:19:06 +00:00
this.power = null;
this.diff = null;
this.diffPos = null;
2015-06-17 19:18:14 +00:00
if(this._data.power === -1) return 0;
2015-06-22 18:19:06 +00:00
this.diff = (this.power = (this.getBasePower() + this.getBoost())) - this.getRawPower();
if(this.diff > 0) this.diffPos = true;
return this.power;
2015-06-13 19:36:02 +00:00
}
2015-06-19 16:48:40 +00:00
r.getRawPower = function(){
2015-06-17 19:18:14 +00:00
return this._data.power;
}
2015-06-14 18:50:53 +00:00
r.setForcedPower = function(nr){
2015-06-13 19:36:02 +00:00
this._forcedPower = nr;
2015-07-02 17:34:30 +00:00
this.getBoost(); //recalculate
2015-06-13 19:36:02 +00:00
}
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-19 16:48:40 +00:00
if(Array.isArray(this._data.ability)){
2015-06-18 18:47:17 +00:00
var res = [];
2015-06-19 16:48:40 +00:00
this._data.ability.forEach(function(ability){
2015-06-18 18:47:17 +00:00
res.push(AbilityData[ability]);
})
return res;
}
2015-06-13 19:36:02 +00:00
return AbilityData[this._data.ability];
}
2015-06-22 16:48:08 +00:00
r.hasAbility = function(ability){
2015-06-21 14:50:50 +00:00
var a = this.getRawAbility();
2015-06-22 16:48:08 +00:00
if(Array.isArray(a)){
for(var i = 0; i < a.length; i++) {
2015-06-21 14:50:50 +00:00
var _a = a[i];
if(_a === ability) return true;
}
}
return a === ability;
}
2015-06-13 19:36:02 +00:00
r.getImage = function(){
return "../assets/cards/" + this._data.img + ".png";
}
r.getFaction = function(){
return this._data.faction;
}
2015-06-19 16:48:40 +00:00
r.getMusterType = function(){
2015-06-19 12:14:37 +00:00
return this._data.musterType || null;
}
2015-06-13 19:36:02 +00:00
r.getType = function(){
2015-06-19 15:34:16 +00:00
return this._changedType == null ? this._data.type : this._changedType;
2015-06-19 15:15:26 +00:00
}
2015-06-19 16:48:40 +00:00
r.changeType = function(type){
2015-06-19 15:15:26 +00:00
this._changedType = type;
2015-06-13 19:36:02 +00:00
}
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-07-05 08:55:27 +00:00
r.resetTightBond = function() {
for(var key in this._boost) {
if(this._boost[key] !== "tight_bond") continue;
delete this._boost[key];
}
}
2015-06-22 16:48:08 +00:00
r.getBoost = function(){
2015-06-19 19:53:48 +00:00
var res = 0;
2015-07-01 08:40:57 +00:00
var doubles = 0;
2015-06-19 19:53:48 +00:00
for(var key in this._boost) {
2015-07-01 08:40:57 +00:00
if(key === "commanders_horn" || key === "commanders_horn_card") continue
if(this._boost[key] === "tight_bond"){
doubles++;
continue;
}
2015-06-19 19:53:48 +00:00
res += this._boost[key];
}
2015-06-22 16:48:08 +00:00
2015-07-01 08:40:57 +00:00
if(doubles){ //tight bond
for(var i = 0; i < doubles; i++) {
res += res + this.getBasePower();
}
}
2015-06-22 16:48:08 +00:00
if(this._boost["commanders_horn"] || this._boost["commanders_horn_card"]){
res += res + this.getBasePower();
}
2015-06-19 19:53:48 +00:00
this.boost = res;
return res;
}
2015-06-22 16:48:08 +00:00
r.setBoost = function(key, val){
2015-06-19 19:53:48 +00:00
this._boost[key] = val;
this.getBoost(); //to recalculate this.boost
2015-06-13 19:36:02 +00:00
}
2015-06-19 16:48:40 +00:00
r.isDisabled = function(){
2015-06-18 13:06:13 +00:00
return this._disabled;
}
2015-06-19 16:48:40 +00:00
r.setDisabled = function(b){
2015-06-18 13:06:13 +00:00
this._disabled = b;
}
2015-06-13 19:36:02 +00:00
r.getProperty = function(prop){
2015-06-19 12:14:37 +00:00
if(!this._data[prop]) return {};
2015-06-13 19:36:02 +00:00
return this._data[prop];
}
2015-06-19 19:53:48 +00:00
r.reset = function(){
2015-06-19 15:15:26 +00:00
this._changedType = null;
2015-07-05 08:27:42 +00:00
this._forcedPower = -1;
2015-06-19 19:53:48 +00:00
this._boost = {};
this.boost = 0;
2015-06-19 12:14:37 +00:00
}
2015-06-13 19:36:02 +00:00
return Card;
})();
module.exports = Card;