From c6827b56a8aba7894d502f7bf5502bf5dffc5ce2 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sat, 9 Apr 2022 17:37:20 +0200 Subject: [PATCH] init --- main.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 main.mjs diff --git a/main.mjs b/main.mjs new file mode 100644 index 0000000..40d8d3c --- /dev/null +++ b/main.mjs @@ -0,0 +1,17 @@ +import { prototypes, utils, constants } from '/game'; + +export function loop() { + const tower = utils.getObjectsByPrototype(prototypes.StructureTower)[0]; + if(tower.store[constants.RESOURCE_ENERGY] < 10) { + var myCreep = utils.getObjectsByPrototype(prototypes.Creep).find(creep => creep.my); + if(myCreep.store[constants.RESOURCE_ENERGY] == 0) { + var container = utils.getObjectsByPrototype(prototypes.StructureContainer)[0]; + myCreep.withdraw(container, constants.RESOURCE_ENERGY); + } else { + myCreep.transfer(tower, constants.RESOURCE_ENERGY); + } + } else { + var target = utils.getObjectsByPrototype(prototypes.Creep).find(creep => !creep.my); + tower.attack(target); + } +} \ No newline at end of file