forked from sparticle999/SpaceCompany
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocketParts.js
70 lines (59 loc) · 2.53 KB
/
rocketParts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Game.interstellar.rocketParts = (function(){
var instance = {};
instance.entries = {};
instance.categoryEntries = {};
instance.initialise = function(){
for (var id in Game.rocketPartsData) {
var data = Game.rocketPartsData[id];
this.navCount++;
this.entries[id] = $.extend({}, data, {
id: id,
htmlId: 'rocpart_' + id,
count: 0,
displayNeedsUpdate: true
});
}
}
instance.calcCost = function(self, resource){
return Math.floor(self.defaultCost[resource.toString()] * Math.pow(1.1,self.count) * rocketPrice);
}
instance.updateCost = function(entryName){
for(var resource in this.entries[entryName].cost){
var target = 0;
for(var i = 0; i < Object.keys(Game.interstellarUI.rocketPartObservers[entryName]).length; i++){
if(resource == Game.interstellarUI.rocketPartObservers[entryName][i].resource){
this.entries[entryName].cost[resource.toString()] = this.calcCost(this.entries[entryName], resource);
Game.interstellarUI.rocketPartObservers[entryName][i].value = this.entries[entryName].cost[resource.toString()];
}
}
}
}
instance.buildPart = function(entryName, buyNum) {
// Add the buildings and clamp to the maximum
for(var i = 0; i < buyNum; i++){
var resourcePass = 0;
for(var resource in this.entries[entryName].cost){
if(window[resource.toString()] >= this.entries[entryName].cost[resource.toString()]){
resourcePass += 1;
}
}
if(resourcePass === Object.keys(Game.interstellar.rocketParts.entries[entryName].cost).length){
var newValue = Math.floor(this.entries[entryName].count + 1);
this.entries[entryName].count = Math.min(newValue, this.entries[entryName].max);
for(var resource in this.entries[entryName].cost){
window[resource.toString()] -= this.entries[entryName].cost[resource.toString()];
}
this.entries[entryName].displayNeedsUpdate = true;
}
}
this.updateCost(entryName);
};
instance.unlock = function(id) {
this.entries[id].unlocked = true;
this.entries[id].displayNeedsUpdate = true;
};
instance.getPartData = function(id) {
return this.entries[id];
};
return instance;
}());