-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmission.missionUtility.js
69 lines (59 loc) · 1.81 KB
/
mission.missionUtility.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
const getAllMissions = () => {
return Memory.missions;
};
const getAllMissionsOfType = (type) => {
return _.pick(Memory.missions, (m) => m.type === type);
};
const getMissionType = (roomName) => {
if (!Memory.missions[roomName]) return 0;
return Memory.missions[roomName].type;
};
const createMission = (roomName, type, supporters) => {
for (const supporter of supporters) {
if (!Memory.colonies[supporter].missions) {
Memory.colonies[supporter].missions = [];
}
if (!Memory.colonies[supporter].missions.includes(roomName)) {
Memory.colonies[supporter].missions.push(roomName);
}
}
console.log("creating: " + roomName);
Memory.missions[roomName] = {
type,
created: Game.time,
supporters,
creepNamesAndRoles: [],
};
};
const removeMission = (roomName) => {
console.log("removing: " + roomName);
for (const supporter of Memory.missions[roomName].supporters) {
Memory.colonies[supporter].missions = Memory.colonies[
supporter
].missions.filter((m) => m !== roomName);
}
delete Memory.missions[roomName];
};
const countMissionCreeps = (mission, role) => {
return mission.creepNamesAndRoles.filter((c) => c.role === role).length;
};
const getColoniesInRange = (point, maxDist, minRCL = 0) => {
const supporters = [];
for (const colony in Memory.colonies) {
if (Memory.colonies[colony].rcl < minRCL) continue;
const route = Game.map.findRoute(colony, point);
if (route.length <= maxDist) {
supporters.push(colony);
}
}
return supporters;
};
module.exports = {
getAllMissions,
getAllMissionsOfType,
getMissionType,
createMission,
removeMission,
countMissionCreeps,
getColoniesInRange,
};