-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathStatBlock.ts
130 lines (117 loc) · 2.94 KB
/
StatBlock.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import * as _ from "lodash";
import { Listable, FilterDimensions } from "./Listable";
import { probablyUniqueString } from "./Toolbox";
export interface AbilityScores {
Str: number;
Dex: number;
Con: number;
Cha: number;
Int: number;
Wis: number;
}
export interface NameAndModifier {
Name: string;
Modifier: number;
}
export interface ValueAndNotes {
Value: number;
Notes: string;
}
export interface NameAndContent {
Name: string;
Content: string;
Usage?: string;
}
export type InitiativeSpecialRoll = "advantage" | "disadvantage" | "take-ten";
export interface StatBlock extends Listable {
Source: string;
Type: string;
HP: ValueAndNotes;
AC: ValueAndNotes;
Speed: string[];
Abilities: AbilityScores;
InitiativeModifier?: number;
InitiativeSpecialRoll?: InitiativeSpecialRoll;
InitiativeAdvantage?: boolean;
DamageVulnerabilities: string[];
DamageResistances: string[];
DamageImmunities: string[];
ConditionImmunities: string[];
Saves: NameAndModifier[];
Skills: NameAndModifier[];
Senses: string[];
Languages: string[];
Challenge: string;
Traits: NameAndContent[];
Actions: NameAndContent[];
Reactions: NameAndContent[];
LegendaryActions: NameAndContent[];
BonusActions?: NameAndContent[];
MythicActions?: NameAndContent[];
Description: string;
Player: string;
ImageURL: string;
}
export namespace StatBlock {
export const AbilityNames = ["Str", "Dex", "Con", "Int", "Wis", "Cha"];
const BaseTypes = [
"aberration",
"beast",
"celestial",
"construct",
"dragon",
"elemental",
"fey",
"fiend",
"giant",
"humanoid",
"monstrosity",
"ooze",
"plant",
"undead"
];
export const GetSearchHint = (statBlock: StatBlock): string =>
statBlock.Type.toLocaleLowerCase().replace(/[^\w\s]/g, "");
export const FilterDimensions = (statBlock: StatBlock): FilterDimensions => {
const baseType = _.find(BaseTypes, t => statBlock.Type.search(t) != -1);
return {
Level: statBlock.Challenge,
Source: statBlock.Source,
Type: _.startCase(baseType)
};
};
export const IsPlayerCharacter = (statBlock: StatBlock): boolean =>
statBlock.Player.length > 0;
export const Default = (): StatBlock => ({
Id: probablyUniqueString(),
Name: "",
Path: "",
Source: "",
Type: "",
HP: { Value: 1, Notes: "(1d1+0)" },
AC: { Value: 10, Notes: "" },
InitiativeModifier: 0,
InitiativeAdvantage: false,
Speed: [],
Abilities: { Str: 10, Dex: 10, Con: 10, Int: 10, Wis: 10, Cha: 10 },
DamageVulnerabilities: [],
DamageResistances: [],
DamageImmunities: [],
ConditionImmunities: [],
Saves: [],
Skills: [],
Senses: [],
Languages: [],
Challenge: "",
Traits: [],
Actions: [],
BonusActions: [],
Reactions: [],
LegendaryActions: [],
MythicActions: [],
Description: "",
Player: "",
Version: process.env.VERSION || "0.0.0",
ImageURL: ""
});
}