-
-
Save fractaloop/c867061b71e34a8f8e476edbc78269b3 to your computer and use it in GitHub Desktop.
Battle whitelist for screeps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var USERNAME_WHITELIST = ['chrisinajar', 'ho0ber', 'fractaloop', 'n7-anthony', 'overra', 'tyrel', 'fervens']; | |
module.exports = { | |
findEnemy: findEnemy, | |
run: run | |
}; | |
/* | |
var target = findEnemy(creep); | |
*/ | |
function findEnemy (creep) { | |
var targets = creep.room.find(FIND_HOSTILE_CREEPS, { | |
filter: (c) => { | |
return (USERNAME_WHITELIST.indexOf(c.owner.username.toLowerCase()) === -1); | |
} | |
}); | |
if (!targets.length) { | |
targets = creep.room.find(FIND_STRUCTURES, { | |
filter: function(object) { | |
if (object.my) { | |
return false; | |
} | |
if (object.structureType !== STRUCTURE_TOWER && object.structureType !== STRUCTURE_SPAWN && object.structureType !== STRUCTURE_EXTENSION) { | |
return false; | |
} | |
return object.owner | |
? (USERNAME_WHITELIST.indexOf(object.owner.username.toLowerCase()) === -1) | |
: true; | |
} | |
}); | |
} | |
return creep.pos.findClosestByPath(targets); | |
} | |
function run (creep) { | |
var target = findEnemy(creep); | |
if (!target) { | |
target = findWall(creep); | |
if (!target) { | |
return false; | |
} | |
// getDirectionTo | |
if (!creep.pos.isNearTo(target)) { | |
return creep.moveTo(target); | |
} else { | |
creep.attack(target); | |
} | |
var direction = creep.pos.getDirectionTo(target); | |
creep.memory.wallDirection = direction; | |
return true; | |
} else { | |
creep.moveTo(target); | |
creep.attack(target); | |
return true; | |
} | |
return false; | |
} | |
function findWall (creep) { | |
var targets = creep.room.find(FIND_STRUCTURES, { | |
filter: function(object) { | |
if (object.my || USERNAME_WHITELIST.indexOf(creep.room.controller.owner.username.toLowerCase()) !== -1) { | |
return false; | |
} | |
if (object.structureType !== STRUCTURE_TOWER && object.structureType !== STRUCTURE_WALL) { | |
return false; | |
} | |
return object.owner | |
? (USERNAME_WHITELIST.indexOf(object.owner.username.toLowerCase()) === -1) | |
: true; | |
} | |
}); | |
return creep.pos.findClosestByPath(targets); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment