-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.Source.js
63 lines (59 loc) · 1.38 KB
/
prototype.Source.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
//Resource.prototype.test = function() {
//};
Source.prototype.targeted = function() {
let targetList = []
_.forEach(Memory.creeps, (creep, id) => {
if(creep.target == this.id){
targetList.push(Game.creeps[id])
}
})
return targetList
}
Object.defineProperty(Source.prototype, 'memory', {
get: function() {
if(Memory.sources[this.id] === undefined){
Memory.sources[this.id] = {}
}
return Memory.sources[this.id]
},
enumerable: false,
configurable: true
});
Object.defineProperty(Source.prototype, 'stored', {
get: function() {
return this.energy
},
enumerable: false,
configurable: true
});
Object.defineProperty(Source.prototype, 'capacity', {
get: function() {
return this.energyCapacity
},
enumerable: false,
configurable: true
});
Object.defineProperty(Source.prototype, 'usage', {
get: function() {
let source = this
let withdrawl = 0
let deposit = 0
let net = source.stored
let capacity = source.capacity
_.forEach(Memory.taskQueue, function(t){
if(t.dest == source.id){
let target = genRoom.getObject(t.target)
if(t.type == "deposit"){
deposit += target.stored
}
if(t.type == "withdrawl"){
withdrawl -= target.capacity
}
}
})
net = net + deposit - withdrawl
return (net/capacity) * 100
},
enumerable: false,
configurable: true
});