-
-
Notifications
You must be signed in to change notification settings - Fork 35
Creep Role Contribution
First, add the role name to constants.roles
, in the constants.ts file.
Next in main.ts
add the role name to the CreepRoles
type
Go to creepClasses.ts
and create a class for the role. Export it, and assign in the creepClasses
object. With haulers for example:
export class Hauler extends Creep {
constructor(creepID: Id<Creep>) {
super(creepID)
}
}
creepClasses.hauler = Hauler
Create a file for the role logic. Example: hauler.ts
inside export a function for managing the role. It should look like this:
import { Hauler } from '../../creepClasses'
export function haulerManager(room: Room, creepsOfRole: string[]) {
for (const creepName of creepsOfRole) {
const creep: Hauler = Game.creeps[creepName]
}
}
- Finally, go to
creepRoleManagers.ts
, import the role manager, and create a role reference for it in themanagers
object
Now onto actually adding functionality. Basic code like function calls should go inside the role manager, while more complex code and functions should be attached as prototypes to the role's class. Back in creepClasses.ts
we can add prototypes and properties to the role
export class Hauler extends Creep {
property: string
method?(): void
constructor(creepID: Id<Creep>) {
super(creepID)
}
}
creepClasses.hauler = Hauler
Meanwhile, in the role's file - such as hauler.ts
- we can attach the prototype:
Hauler.prototype.method = function () {
this.say('It works')
}
And of course, reference it above in the manager
import { Hauler } from '../../creepClasses'
export function haulerManager(room: Room, creepsOfRole: string[]) {
for (const creepName of creepsOfRole) {
const creep: Hauler = Game.creeps[creepName]
creep.method()
}
}