-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.Resource.js
72 lines (67 loc) · 1.61 KB
/
prototype.Resource.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
71
72
//Resource.prototype.test = function() {
//};
Object.defineProperty(Resource.prototype, 'memory', {
get: function() {
if(Memory.resources[this.id] === undefined){
Memory.resources[this.id] = {}
}
return Memory.resources[this.id]
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resource.prototype, 'netEnergy', {
get: function() {
if(this.resourceType == RESOURCE_ENERGY){
let net = this.amount
let targeters = this.targeted()
let neg = _.reduce(targeters, function(sum, targeter){
sum += targeter.store.getFreeCapacity()
return sum
}, 0)
return net - neg
} else {
return 0
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resource.prototype, 'stored', {
get: function() {
return this.amount
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resource.prototype, 'capacity', {
get: function() {
return this.amount
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resource.prototype, 'usage', {
get: function() {
let resource = this
let withdrawl = 0
let deposit = 0
let net = resource.stored
let capacity = resource.capacity
_.forEach(Memory.taskQueue, function(t){
if(t.dest == resource.id){
let target = genRoom.getObject(t.target)
if(t.type == "deposit"){
deposit += target.stored
}
if(t.type == "pickup"){
withdrawl += target.capacity
}
}
})
net = net + deposit - withdrawl
return (net/capacity) * 100
},
enumerable: false,
configurable: true
});