Files
adarkroom/script/prestige.js
T

104 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-10-12 13:19:38 +11:00
var Prestige = {
2013-10-16 17:45:41 -04:00
name: 'Prestige',
2013-10-12 13:19:38 +11:00
options: {},
2013-10-16 17:45:41 -04:00
2013-10-12 13:19:38 +11:00
init: function(options) {
2013-10-16 17:45:41 -04:00
this.options = $.extend(this.options, options);
},
2013-11-01 23:00:51 -04:00
storesMap: [
{ store: 'wood', type: 'g' },
{ store: 'fur', type: 'g' },
{ store: 'meat', type: 'g' },
{ store: 'iron', type: 'g' },
{ store: 'coal', type: 'g' },
{ store: 'sulphur', type: 'g' },
{ store: 'steel', type: 'g' },
{ store: 'cured meat', type: 'g' },
{ store: 'scales', type: 'g' },
{ store: 'teeth', type: 'g' },
{ store: 'leather', type: 'g' },
{ store: 'bait', type: 'g' },
{ store: 'torch', type: 'g' },
{ store: 'cloth', type: 'g' },
{ store: 'bone spear', type: 'w' },
{ store: 'iron sword', type: 'w' },
{ store: 'steel sword', type: 'w' },
{ store: 'bayonet', type: 'w' },
{ store: 'rifle', type: 'w' },
{ store: 'laser rifle', type: 'w' },
{ store: 'bullets', type: 'a' },
{ store: 'energy cell', type: 'a' },
{ store: 'grenade', type: 'a' },
{ store: 'bolas', type: 'a' }
],
getStores: function(reduce) {
var stores = [];
for(var i in this.storesMap) {
var s = this.storesMap[i];
2014-11-18 10:14:50 -05:00
stores.push(Math.floor($SM.get('stores["' + s.store + '"]', true) /
(reduce ? this.randGen(s.type) : 1)));
2013-10-16 17:45:41 -04:00
}
2013-11-01 23:00:51 -04:00
return stores;
2013-10-16 17:45:41 -04:00
},
2013-11-01 23:00:51 -04:00
get: function() {
return {
stores: $SM.get('previous.stores'),
score: $SM.get('previous.score')
2013-10-16 17:45:41 -04:00
};
2013-11-01 23:00:51 -04:00
},
set: function(prestige) {
$SM.set('previous.stores', prestige.stores);
$SM.set('previous.score', prestige.score);
},
save: function() {
$SM.set('previous.stores', this.getStores(true));
$SM.set('previous.score', Score.totalScore());
2013-10-16 17:45:41 -04:00
},
2013-10-12 13:19:38 +11:00
2013-11-01 23:00:51 -04:00
collectStores : function() {
2013-10-16 17:45:41 -04:00
var prevStores = $SM.get('previous.stores');
2013-10-31 14:37:19 -04:00
if(prevStores != null) {
2013-11-01 23:00:51 -04:00
var toAdd = {};
for(var i in this.storesMap) {
var s = this.storesMap[i];
toAdd[s.store] = prevStores[i];
}
$SM.addM('stores', toAdd);
// Loading the stores clears em from the save
prevStores.length = 0;
2013-10-31 14:37:19 -04:00
}
2013-10-16 17:45:41 -04:00
},
randGen : function(storeType) {
2014-11-18 10:14:50 -05:00
var amount;
2013-11-01 23:00:51 -04:00
switch(storeType) {
case 'g':
2014-11-18 10:14:50 -05:00
amount = Math.floor(Math.random() * 10);
break;
2013-11-01 23:00:51 -04:00
case 'w':
2014-11-18 10:14:50 -05:00
amount = Math.floor(Math.floor(Math.random() * 10) / 2);
break;
2013-11-01 23:00:51 -04:00
case 'a':
2014-11-18 10:14:50 -05:00
amount = Math.ceil(Math.random() * 10 * Math.ceil(Math.random() * 10));
break;
2013-11-01 23:00:51 -04:00
default:
return 1;
}
2014-11-18 10:14:50 -05:00
if (amount !== 0) {
return amount;
}
return 1;
2013-10-16 17:45:41 -04:00
}
2013-10-31 14:37:19 -04:00
};