-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.myRoom.js
50 lines (46 loc) · 1.7 KB
/
find.myRoom.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
var findMyRoom = {
/** @param {Creep} creep **/
run: function () {
//checks if roomName is in memory
if (_.has(Memory.rooms, 'myRooms')) {
//If roomName is stored, convert into a room for myRoom
//console.log("here" +myRoom)
myRoom = Game.rooms[Memory.rooms.myRooms[0]];
//console.log("After " +myRoom)
} else {
//searches every room
for (let key in Game.rooms) {
let room = Game.rooms[key]
//checks if room has a controller and is controlled by me
if (room.controller && room.controller.my) {
console.log(room.name)
//stores room name
if (_.has(Memory, "rooms")) {
if (_.has(Memory.rooms, "myRooms")) {
var myRooms = Memory.rooms.myRooms;
//myRooms[0] = key;
myRoom = Game.rooms[key];
//console.log(Memory.rooms.myRooms[0]);
} else {
Memory.rooms.myRooms = {};
}
} else {
Memory.rooms = {};
}
}
}
//finds room and puts in myRoom without using memory
/*
for (let key in Game.rooms) {
let room = Game.rooms[key]
if (room.controller && room.controller.my) {
myRoom = room;
break;
}
}*/
}
//console.log(myRoom)
return myRoom
}
};
module.exports = findMyRoom;