-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
74 lines (60 loc) · 1.62 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import _rolePicker from "./src/functions/rolePicker.js";
import _racePicker from "./src/functions/racePicker.js";
import _generateNPC from "./src/functions/generate.js";
import { StarterObject, Character } from "./interfaces.js";
/**
* @class NPC
* @description A class for generating pseudo NPCs
**/
export default class NPC {
#roleType: string = "random";
#raceType: string = "random";
character: Character | undefined = undefined;
constructor(starterObject: StarterObject) {
const subRace = starterObject?.subRace || "";
if(starterObject?.raceType) this.#raceType = _racePicker(starterObject.raceType, subRace);
if(starterObject?.classType) this.#roleType = _rolePicker(starterObject.classType);
}
/**
* @param {string} raceType
* @param {string} [subRace]
* @returns {NPC}
**/
setRace(raceType: string, subRace: string = ""): NPC {
if(this.character) return this;
this.#raceType = _racePicker(raceType, subRace);
return this;
}
/**
* @returns {string}
**/
getRace(): string {
return this.#raceType;
}
/**
* @param {string} roleType
* @returns {NPC}
**/
setClass(roleType: string): NPC {
if(this.character) return this;
this.#roleType = _rolePicker(roleType);
return this;
}
/**
* @returns {string}
**/
getClass(): string {
return this.#roleType;
}
/**
* @returns {Character}
**/
async generate(): Promise<Character> {
if(this.character) return this.character;
this.character = await _generateNPC(this.#raceType, this.#roleType);
return this.character;
}
}
export {
StarterObject, Character
};