HOME Q & A CHANGLOG GUIDE GITHUB

NPC Class

.constructor({ raceType, subRace, classType })

This is called when you create a new NPC.
It takes a single Object with the below properties. All properties are optional.
A full list of valid classTypes can be found here
A full list of valid raceTypes can be found here

Options

Argument Type Description Optional
raceType String Sets the race of the NPC True
subRace String Sets the sub-race of the NPC if applicable True
classType String Sets the class of the NPC True


Methods

.setRace(raceType, subRace)

Sets the race of the NPC.
Takes up to 2 Strings as arguments, and sets the race of the NPC to generate

Options

Argument Type Description Optional
raceType String Sets the race of the NPC False
subRace String Sets the sub-race of the NPC if applicable
True

Returns: this



.setClass(classType)

Sets the class of the NPC
Takes a single string as an argument.

Options

Argument Type Description Optional
classType String Sets the class of the NPC False

Returns: this



.generate()

Use this method when you're ready to generate all aspects of your NPC.
After using this, you'll recieve an NPC object.

⚠️ You can only use #generate() once per npc instance. Additional uses will simply return the same character.

Returns: Promise<Character: Object>



Example Usage

import NPC from 'dnd-npc';

const obj = {
	raceType: "warforged",
	subRace: "juggernaut",
	classType: "fighter"
}

const npc = new NPC(obj)

// Generates a Warforged-Juggernaut Fighter
const character = await npc.generate();
import NPC from 'dnd-npc';
const npc = new NPC()
	.setRace("warforged", "juggernaut")
	.setClass("fighter");

// Generates a Warforged-Juggernaut Fighter
const character = await npc.generate();

You can overwrite settings that you have already input.

import NPC from 'dnd-npc';

const obj = {
	raceType: "warforged",
	subRace: "juggernaut",
	classType: "fighter"
}

const npc = new NPC(obj)
	.setRace("human")
	.setClass("bard");
	
// Generates a Human Bard (why u make Bard tho?)
const character = await npc.generate();

Passing a sub-race as the raceType and it will generate with the correct race and sub-race.

import NPC from 'dnd-npc';
const npc = new NPC({ classType: "juggernaut" });

// Generates a Warforged-Juggernaut with a random class.
const character = await npc.generate();

Leaving the raceType or classType blank, or passing an invalid type to it, will result in that thing being randomly generated.

import NPC from 'dnd-npc';
const npc = new NPC({ raceType: "warforged" });

// Generates a Warforged with a random sub-race and class.
const character = await npc.generate();
import NPC from 'dnd-npc';
const npc = new NPC({ classType: "fighter" });

// Generates a fighter with a random race
const character = await npc.generate();
import NPC from 'dnd-npc';
const npc = new NPC();

// Generates a completely random character.
const character = await npc.generate();