-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.attacker.js
42 lines (39 loc) · 1.63 KB
/
role.attacker.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
var roleAttacker = {
run: function(creep) {
// Attack behavior
if (creep.hits === 0) {
creep.memory.attacking = false;
creep.say('🔄 Healing');
}
if (!creep.memory.attacking && creep.hits === creep.hitsMax) {
creep.memory.attacking = true;
creep.say('⚡ Attacking');
}
if (creep.memory.attacking) {
// Find and attack the nearest hostile creep or structure
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if (target) {
console.log("targetPos", target.pos.x)
if (creep.getActiveBodyparts(ATTACK) > 0) {
// Creep has ATTACK body part
if (creep.pos.isNearTo(target)) {
creep.attack(target);
} else {
creep.moveTo(target, { visualizePathStyle: { stroke: '#ff0000' } });
}
} else if (creep.getActiveBodyparts(RANGED_ATTACK) > 0) {
// Creep has RANGED_ATTACK body part
if (creep.pos.inRangeTo(target, 3)) {
creep.rangedAttack(target);
} else {
creep.moveTo(target, { visualizePathStyle: { stroke: '#ff0000' } });
}
}
}
} else {
// Move to a room position to respawn if needed // reSpawn Logic to be written
creep.moveTo(25, 25, { visualizePathStyle: { stroke: '#ffffff' } });
}
}
};
module.exports = roleAttacker;