-
Notifications
You must be signed in to change notification settings - Fork 4
/
PowerSpawns.js
34 lines (34 loc) · 1.57 KB
/
PowerSpawns.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
let Util = require('Util');
const PowerSpawns = {
run: function (gameRoom) {
if ((Memory.MemRooms[gameRoom.name].IsPowerSpawnActive || Game.time % 30 === 0)) {
if(!Memory.MemRooms[gameRoom.name].PowerSpawnId){
const foundPowerSpawn = gameRoom.find(FIND_MY_STRUCTURES, {
filter: (s) => {
return s.structureType === STRUCTURE_POWER_SPAWN;
}
})[0];
if(foundPowerSpawn){
Memory.MemRooms[gameRoom.name].PowerSpawnId = foundPowerSpawn.id;
}else{
return; // no powerSpawn found
}
}
const powerSpawn = Game.getObjectById(Memory.MemRooms[gameRoom.name].PowerSpawnId);
if (powerSpawn){
if(powerSpawn.store.getUsedCapacity(RESOURCE_POWER) > 0 && powerSpawn.store.getUsedCapacity(RESOURCE_ENERGY) >= 50) {
powerSpawn.processPower();
if(!Memory.MemRooms[gameRoom.name].IsPowerSpawnActive){
Memory.MemRooms[gameRoom.name].IsPowerSpawnActive = true;
}
}else{
Memory.MemRooms[gameRoom.name].IsPowerSpawnActive = false;
}
}else{
Util.ErrorLog('PowerSpawns','PowerSpawns','Power spawn gone in ' + gameRoom.name + ' ' + Memory.MemRooms[gameRoom.name].PowerSpawnId);
delete Memory.MemRooms[gameRoom.name].PowerSpawnId;
}
}
}
};
module.exports = PowerSpawns;