-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.claimer.js
76 lines (63 loc) · 2.38 KB
/
role.claimer.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
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('role.claimer');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("role.claimer");
var obj = function() {
}
var base = require('role.base');
obj.prototype = new base();
global.utils.extendFunction(obj, "init", function(name, targetRoomName, roomManager) {
logger.log(roomManager)
this._init(name, roomManager);
this.targetRoomName = targetRoomName;
this.creepId = false;//actually the name now
this.creep = false;
});
global.utils.extendFunction(obj, "tickInit", function() {
this.creep = Game.creeps[this.creepId];
logger.log("num", this.name, this.creep, this.roomManager)
if (!this.creep && this.roomManager) {
//we don't have a creep! spawn one dem mofos
this.creepId = false;
var memory = {
home:this.targetRoomName
}
var priority = 200;
// if (this.numCreeps == 0)
// priority = 10;
var req = global.utils.makeCreepRequest(this.name, "creepId", [MOVE, CLAIM], [], priority, memory, 1)
req.important = true;
this.roomManager.requestCreep(req);
//global.empire.requestHelperCreep(this.roomManager.roomName, req);
}
});
global.utils.extendFunction(obj, "tick", function() {
if (this.creep && !this.creep.spawning) {
if (this.creep.pos.roomName == this.targetRoomName) {
var c = Game.rooms[this.targetRoomName].controller;
if (this.creep.pos.isNearTo(c)) {
this.creep.claimController(c);
for(var f in Game.flags) {
var flag = Game.flags[f];
if (flag.pos.roomName == this.targetRoomName && flag.color == COLOR_GREEN && flag.secondaryColor == COLOR_GREEN) {
logger.log(this.creep.name, "removing flag", flag)
flag.remove();
}
}
} else {
global.utils.moveCreep(this.creep, c);
}
} else {
global.utils.moveCreep(this.creep, new RoomPosition(25, 25, this.targetRoomName));
}
}
});
global.utils.extendFunction(obj, "tickEnd", function() {
});
module.exports = obj;