-
-
Notifications
You must be signed in to change notification settings - Fork 35
Creep Role Contribution
Carson edited this page Jul 5, 2022
·
8 revisions
- First, add the role name to
constants.roles
, in the constants.ts file. - Next in
main.ts
add the role name to theCreepRoles
type
- Go to
creepClasses.ts
and create a class for the role. Export it, and assign in thecreepClasses
object - 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()
}
}