-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.Creep.js
78 lines (66 loc) · 2.67 KB
/
prototype.Creep.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
module.exports = function() {
Creep.prototype.moveToHomeRoom = function(){
homeRoomName = creep.memory.homeRoom;
if(_.isEqual(this.pos.roomName, homeRoomName)){
this.memory.imHome=true;
return OK;
}else{
if(Game.flags[homeRoomName])
this.moveTo(Game.flags[homeRoomName]);
else
try{
this.moveTo(new RoomPosition(25, 25, Game.rooms[homeRoomName]));
}catch(e){
console.log('Cannot move '+this.name+' to homeroom')
}
}
}
Creep.prototype.moveToSourceRoom = function(){
sourcePos = Utils.getObjectPosById(this.memory.source);
sourceRoomName = sourcePos.roomName;
if(_.isEqual(this.pos.roomName, sourceRoomName)){
return OK;
}else{
if(Game.flags[sourceRoomName])
this.moveTo(Game.flags[sourceRoomName]);
else
try{
this.moveTo(new RoomPosition(25, 25, Game.rooms[sourceRoomName]));
}catch(e){
console.log('Cannot move '+this.name+' to sourceRoomName')
}
}
}
Creep.prototype.moveToTargetRoom = function(){
sourcePos = Utils.getObjectPosById(this.memory.source);
sourceRoomName = sourcePos.roomName;
if(_.isEqual(this.pos.roomName, sourceRoomName)){
return OK;
}else{
if(Game.flags[sourceRoomName])
this.moveTo(Game.flags[sourceRoomName]);
else
try{
this.moveTo(new RoomPosition(25, 25, Game.rooms[sourceRoomName]));
}catch(e){
console.log('Cannot move '+this.name+' to sourceRoomName')
}
}
}
//rewrites the moveTo function that doesn't include options to include a set of options you choose
// NOTE: this function will automatically replace any existing usage you have in your code.
// simply add require('prototype.Creep')(); to the beginning the module you want to use this in
// let oldMoveTo = Creep.prototype.moveTo
Creep.prototype.goto = function(arg1, arg2, arg3){
if (!this.my) {return ERR_NOT_OWNER;}
if (this.spawning) {return ERR_BUSY;}
if (this.fatigue > 0) {return ERR_TIRED;}
if (this.getActiveBodyparts(C.MOVE) == 0) {return ERR_NO_BODYPART;}
if(arg1 instanceof Object) {
oldOpt = arg2;
newOpt = {reusePath: 5, ignoreCreeps:true};
if(!oldOpt) return this.moveTo(arg1, newOpt);
}
}
// Creep.prototype.oldMoveTo = oldMoveTo;//
};