From b5dfb44faf8750aff065806af6f7a55fd21a3f85 Mon Sep 17 00:00:00 2001 From: ObeseTermite Date: Tue, 3 Jun 2025 21:53:39 -0700 Subject: [PATCH] Started working on classes, everything is borked rn though --- role.base.js | 15 +++++++++++++++ role.dispatcher.js | 3 +-- role.guard.js | 13 ++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 role.base.js diff --git a/role.base.js b/role.base.js new file mode 100644 index 0000000..8ac6774 --- /dev/null +++ b/role.base.js @@ -0,0 +1,15 @@ +class roleBase{ + constructor(){ + this.body = [ MOVE, WORK, CARRY ]; + this.name = 'Creep'; + } + /** @param {Creep} creep **/ + run(creep) { } + spawn(spawn){ + spawn.spawnCreep(this.body, this.name + Game.time, + memory : {role : this.name} + }); + } +}; + +module.exports = roleBase; diff --git a/role.dispatcher.js b/role.dispatcher.js index 5d917c7..c829f51 100644 --- a/role.dispatcher.js +++ b/role.dispatcher.js @@ -37,8 +37,7 @@ function spawnCreeps(spawn){ if(roleCreeps.length < count && !spawn.spawning) { var newName = role + Game.time; - console.log(spawn.spawnCreep(roleMap[role].body, newName, - {memory: {role: role}})); + roleMap[role].spawn(spawn); break; } } diff --git a/role.guard.js b/role.guard.js index 9ad0ce7..551cefa 100644 --- a/role.guard.js +++ b/role.guard.js @@ -5,8 +5,6 @@ const body = [ ]; var roleGuard = { - body, - /** @param {Creep} creep **/ run: function(creep) { const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); @@ -16,7 +14,16 @@ var roleGuard = { } } else { - creep.moveTo(Game.flags.IdleArea); + var currentWaypoint = Game.flags[creep.memory.waypoints[creep.memory.currentWaypoint]]; + if(getRangeTo(currentWaypoint) > 0){ + creep.moveTo(currentWaypoint); + } + else{ + creep.memory.currentWaypoint += 1; + if(creep.memory.currentWaypoint > creep.memory.waypoints.length){ + creep.memory.currentWaypoint = 0; + } + } } } };