-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.fHealer.js
176 lines (146 loc) · 5.46 KB
/
role.fHealer.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* 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.fHealer');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("role.fHealer");
logger.enabled = false;
var obj = function() {
}
var base = require('role.base');
obj.prototype = new base();
global.utils.extendFunction(obj, "init", function(name, roomManager, flag) {
this._init(name, roomManager);
this.flagName = flag.name;
this.flagPos = flag.pos;
this.workerCreepIds = [];
this.requiredCreeps = 0;
});
global.utils.extendFunction(obj, "tickInit", function() {
//logger.log("tickinit", this.flagName, JSON.stringify(this.requiredCreeps))
//logger.log('-------------------------------------------',this.workerCreepIds , this.requiredCreeps)
if (Game.flags[this.flagName]) {
this.flagPos = Game.flags[this.flagName].pos;
}
if (this.workerCreepIds.length < this.requiredCreeps) {
logger.log("spawnin")
var minBodies = 0;
// if (this.roomManager.room.controller.level > 4) {
// minBodies = 3;
// }
//need some creeps
var memory = {
home: this.roomManager.roomName
};
var priority = 11;
if (this.numCreeps == 0)
priority = 200;
var req = global.utils.makeCreepRequest(this.name, "workerCreepIds", [HEAL, HEAL, MOVE, MOVE], [MOVE, HEAL], priority, memory, 50, minBodies);
req.important = true;
req.useMaxEnergy = true;
global.empire.requestHelperCreep(this.roomManager.roomName, req);
return;
}
});
global.utils.extendFunction(obj, "tick", function() {
for(var i in this.workerCreepIds) {
var creep = Game.creeps[this.workerCreepIds[i]];
if (creep) {
this.runCreep(creep);
} else {
logger.log("mofo died",this.workerCreepIds[i])
delete this.workerCreepIds[i];
}
}
});
global.utils.extendFunction(obj, "tickEnd", function() {
});
obj.prototype.runCreep = function(creep) {
//logger.log(creep.name, this.flagPos)
var moveOpts = {keepFromHostiles: 5};
var flag = Game.flags[this.flagName];
if (flag) {
this.flagPos = Game.flags[this.flagName].pos;
}
var parkSpot = this.flagPos;
if (creep.pos.roomName == this.roomManager.roomName) {
var friends = creep.room.find(FIND_MY_CREEPS, {filter: function(c){
logger.log(c.name, c.hits , c.hitsMax)
return c.hits <c.hitsMax && creep.name != c.name;
}});
if (creep.hits < creep.hitsMax) {
creep.heal(creep);
}
if (friends.length > 0 ) {
var closeFriend = creep.pos.findClosestByPath(friends);
if (closeFriend) {
if (creep.pos.isNearTo(closeFriend)) {
logger.log(creep.body, creep.heal(closeFriend));
}
if (creep.pos.inRangeTo(closeFriend, 4)) {
//logger.log(creep.name, 'healing', closeFriend.name)
logger.log(creep, creep.rangedHeal(closeFriend));
}
if (!creep.flee(4)) {
if (!creep.pos.isNearTo(closeFriend)) {
global.utils.moveCreep(creep, closeFriend, moveOpts);
}
}
} else {
logger.log('----------------You might be an idiot-----------------')
}
} else {
friends = creep.room.find(FIND_MY_CREEPS, {filter: function(c){
//logger.log(c.name, c.hits , c.hitsMax)
return c.getActiveBodyparts(RANGED_ATTACK) > 0 || c.getActiveBodyparts(ATTACK) > 0;
}});
if (friends.length > 0 ) {
var closeFriend = creep.pos.findClosestByPath(friends);
if (closeFriend) {
global.utils.moveCreep(creep, closeFriend, moveOpts)
}
}else {
global.utils.moveCreep(creep, parkSpot, moveOpts)
}
}
} else {
global.utils.moveCreep(creep, parkSpot, moveOpts)
}
}
obj.prototype.runCreep = function(creep) {
logger.log(creep.name, this.flagPos, this.roomManager.roomName)
var flag = Game.flags[this.flagName];
if (flag) {
this.flagPos = Game.flags[this.flagName].pos;
}
var parkSpot = this.flagPos;
logger.log("starting", creep.name);
if (creep.pos.roomName == this.roomManager.roomName) {
logger.log(creep.name, "in room")
//find where we want to move to
var moveTarget = this.flagPos;
var friends = creep.room.find(FIND_MY_CREEPS, {filter: function(c){
//logger.log(c.name, c.hits , c.hitsMax)
return c.hits <c.hitsMax && creep.name != c.name;
}});
if (friends.length > 0) {
moveTarget = creep.pos.findClosestByRange(friends);
}
//safeDistance, range, fleeHealth
creep.holdPosition(moveTarget, 4, 1, 0.99)
//
} else {
logger.log(creep.name, "moving to flag");
global.utils.moveCreep(creep, this.flagPos);
}
if (!creep.healSelf()) {
creep.healCreepsNearMe();
}
}
obj.prototype.attackShit = function(creep) {
}
module.exports = obj;