-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminer.js
79 lines (68 loc) · 2.63 KB
/
miner.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
73
74
75
76
77
78
79
var roleupgrader = require('upgrader');
//var roleprobe = require('probe');
var utilities = require('extra');
var roleminer = {
/** @param {Creep} creep **/
run: function(creep)
{
utilities.droproad(creep);
if(creep.carry.energy == creep.carryCapacity){
creep.memory.mode = 'drop';
}
else if (creep.carry.energy == 0)
{
creep.memory.mode = 'mine';
}
if (creep.memory.mode == 'mine')
// if(creep.carry.energy < creep.carryCapacity)
{
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE)
{
creep.moveTo(sources[0], { visualizePathStyle: { stroke: '#ffaa00' } }, { reusePath: 15 });
}
}
if (creep.memory.mode == 'drop')
// if (creep.carry.energy == 0)
{
const targets = creep.pos.findInRange(FIND_STRUCTURES,2,
{
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER);
}
});
if(targets.length > 0)
{
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE)
{
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}},{reusePath: 15});
}
}
else
{
var targets2 = creep.room.find(FIND_STRUCTURES,
{
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION
|| structure.structureType == STRUCTURE_SPAWN
|| structure.structureType == STRUCTURE_TOWER)
&& structure.energy < structure.energyCapacity;
}
});
if(targets2.length > 0)
{
if(creep.transfer(targets2[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE)
{
creep.moveTo(targets2[0], {visualizePathStyle: {stroke: '#ffffff'}},{reusePath: 15});
}
}
else
{
// creep.moveTo(Game.spawns.Spawn1.pos);
roleupgrader.run(creep);
// creep.say('probe');
}
}
}}
};
module.exports = roleminer;