Skip to content

Commit 6c6e16e

Browse files
committed
Add injury command, readme, and cleanup
1 parent 8d0f57f commit 6c6e16e

File tree

21 files changed

+518
-216
lines changed

21 files changed

+518
-216
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Dice Boy
2+
3+
A discord bot for runnning Fallout RPG games.
4+
5+
## Usage
6+
7+
To run a command with **Dice Boy**, use the `!vats` command or `@Dice Boy` command. For example, `!vats command` or `@Dice Boy command`.
8+
9+
Use the `!vats help <command>` command to view detailed information about a specific command.
10+
Use `!vats help all` help all to view a list of all commands, not just available ones.
11+
12+
Available commands for **Dice Boy**
13+
14+
### Rolls: 1. Be Smart 2. Be Safe 3. Don't Screw Up!
15+
16+
#### `combat`
17+
18+
Spread Democracy for Uncle Sam! Uses the Vault-Tec recommended `{dice} {damage type} [{effects,...}] [{hit location}] [{hit location type}]` notation.
19+
20+
```bash
21+
| Description | Formula |
22+
| ------------------------------ | ------------------- |
23+
| 1 Physical | 1 ph |
24+
| 2 Radiation Vicious | 2 ra vicious |
25+
| 3 Energy Piercing 2 Stun | 3 en piercing2,stun |
26+
| 4 Poison Stun Head | 4 po stun h |
27+
| 1 Energy Stun Mr. Handy | 1 en stun handy |
28+
| 1 Energy Stun Optics Mr. Handy | 1 en stun o handy |
29+
| ---------------------------------------------------- |
30+
```
31+
32+
#### `roll`
33+
34+
Try your luck with some dice! Uses [standard dice notation](https://greenimp.github.io/rpg-dice-roller/guide/notation/).
35+
36+
#### `skill`
37+
38+
Use your skills to help your fellow citizens! Uses the Vault-Tec recommended `{target} [d{dice}][t{tag}][c{complication}] [{difficulty}]` notation.
39+
40+
```bash
41+
| Description | Formula |
42+
| -------------------------- | ------------ |
43+
| 10 Target | 10 |
44+
| 10 Target, 2 Difficulty | 10 2 |
45+
| 10 Target, 3 Dice | 10 d3 |
46+
| 10 Target, 4 Tag | 10 t4 |
47+
| 10 Target, 19 Complication | 10 c19 |
48+
| A little bit of everything | 10 3dt4c19 2 |
49+
| ----------------------------------------- |
50+
```
51+
52+
### Rules: Knowledge is power, and knowing is half the battle!
53+
54+
#### `injury`
55+
56+
The outside world can never hurt you! Uses the Vault-Tec recommended `{hit location} [{hit location type}]` notation.
57+
58+
```bash
59+
| Description | Formula |
60+
| ---------------- | ------- |
61+
| Head | h |
62+
| Mr. Handy Optics | o handy |
63+
| -------------------------- |
64+
```
65+
66+
### Utility
67+
68+
`help`: Displays a list of available commands, or detailed information for a specified command.
69+
`ping`: Checks the bot's ping to the Discord server.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dice-boy",
33
"version": "0.1.0",
4-
"description": "A Fallout 2d20 dice rolling bot for Discord",
4+
"description": "A Fallout RPG dice rolling bot for Discord",
55
"main": "dist/index.js",
66
"devDependencies": {
77
"@types/events": "3.0.0",

src/commands/rolls/combat.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ import {
1818
combatNotation,
1919
combatNotationRegex,
2020
} from "../../utils/rolls/notation";
21-
import { DamageEffect, DamageEffectType } from "../../utils/damage-effect";
22-
import { DamageType } from "../../utils/damage";
23-
import { getHitLocationText, HitLocationType } from "../../utils/hit-locations";
24-
import { capitalize } from "../../utils/capitalize";
21+
import {
22+
DamageEffect,
23+
DamageEffectType,
24+
} from "../../utils/damage/damage-effect";
25+
import { DamageType } from "../../utils/damage/damage";
26+
import {
27+
getHitLocationText,
28+
HitLocation,
29+
HitLocationType,
30+
} from "../../utils/hit-locations";
31+
import { capitalize } from "../../utils/text/capitalize";
32+
import { failureColor, successColor, warningColor } from "../../utils/color";
2533

2634
class CombatRollCommand extends Command {
2735
constructor(client: CommandoClient) {
@@ -36,7 +44,7 @@ class CombatRollCommand extends Command {
3644
{
3745
key: "formula",
3846
type: "string",
39-
prompt: `Enter a combat roll using the \`${combatNotation}\` notation.`,
47+
prompt: `Enter a combat roll using the \`${combatNotation}\` notation.\nNote: \`{}\` indicate where a value should be entered, \`[]\` indicate an optional value. Do not include either \`{}\` or \`[]\` in your formula.\n`,
4048
},
4149
],
4250
});
@@ -64,7 +72,18 @@ class CombatRollCommand extends Command {
6472
this.showResultsMessage(
6573
message,
6674
options,
67-
combatReroll(2, options, results)
75+
combatReroll(options.dice < 2 ? options.dice : 2, options, results)
76+
);
77+
78+
private rerollThree = (
79+
message: CommandoMessage,
80+
options: CombatRollOptions,
81+
results: CombatRollResult
82+
): void =>
83+
this.showResultsMessage(
84+
message,
85+
options,
86+
combatReroll(options.dice < 3 ? options.dice : 3, options, results)
6887
);
6988

7089
private rerollAll = (
@@ -97,7 +116,7 @@ class CombatRollCommand extends Command {
97116
content: new MessageEmbed({
98117
...getAuthorData(this.client),
99118
title: success ? "Success!" : "Failure!",
100-
color: success ? "#33e83c" : "#eb4034",
119+
color: success ? successColor : failureColor,
101120

102121
description: success
103122
? "> Your efforts will help build a better tomorrow!"
@@ -140,7 +159,7 @@ class CombatRollCommand extends Command {
140159
results,
141160
rolls,
142161
}),
143-
"2️⃣": () =>
162+
"🤞": () =>
144163
this.rerollTwo(message, options, {
145164
damage,
146165
effects,
@@ -149,8 +168,8 @@ class CombatRollCommand extends Command {
149168
results,
150169
rolls,
151170
}),
152-
"3️⃣": () =>
153-
this.rerollTwo(message, options, {
171+
"🎰": () =>
172+
this.rerollThree(message, options, {
154173
damage,
155174
effects,
156175
hitLocation,
@@ -199,7 +218,7 @@ class CombatRollCommand extends Command {
199218
| ---------------------------------------------------- |
200219
\`\`\`\n
201220
${errorMessage || ""}`,
202-
color: "#e6b032",
221+
color: warningColor,
203222
})
204223
);
205224

@@ -218,32 +237,24 @@ class CombatRollCommand extends Command {
218237
arg.search(combatDamageEffectNotation) >= 0 ||
219238
arg.search(combatDamageEffectsNotation) >= 0
220239
);
221-
console.log("damageEffectArgs", damageEffectArgs);
222240

223241
const damageEffects: DamageEffect[] =
224242
(damageEffectArgs || "").split(",").map((effect) => {
225243
const effectArgs = effect.split(/(\d+)/);
226-
console.log("damageEffects effectArgs", effectArgs);
227244
const type = effectArgs[0] as DamageEffectType;
228-
console.log("damageEffects type", type);
245+
const rating = effectArgs[1];
229246
const result: DamageEffect = {
230247
type,
248+
rating: rating ? parseInt(rating) : undefined,
231249
};
232250

233-
if (effectArgs[1]) {
234-
result.rating = parseInt(effectArgs[1]);
235-
}
236-
237-
console.log("damageEffects result", result);
238251
return result;
239252
}) || [];
240253

241-
console.log("damageEffects", damageEffects);
242-
243254
const hitLocation = optionArgs.find(
244255
(arg) =>
245256
arg.search(new RegExp(`^${combatHitLocationNotation.source}$`)) >= 0
246-
);
257+
) as HitLocation | undefined;
247258

248259
const hitLocationType =
249260
(optionArgs.find(

src/commands/rolls/roll.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command, CommandoClient, CommandoMessage } from "discord.js-commando";
33

44
import { roll } from "../../utils/rolls/roll";
55
import { getAuthorData } from "../../utils/author";
6+
import { infoColor, warningColor } from "../../utils/color";
67

78
class RollCommand extends Command {
89
constructor(client: CommandoClient) {
@@ -36,7 +37,7 @@ class RollCommand extends Command {
3637
new MessageEmbed({
3738
...authorData,
3839
title: "Results",
39-
color: "#0099ff",
40+
color: infoColor,
4041
description: "_Good luck out there!_",
4142
fields: [{ name: "\u200B", value: output }],
4243
timestamp: Date.now(),
@@ -47,7 +48,7 @@ class RollCommand extends Command {
4748
new MessageEmbed({
4849
...authorData,
4950
title: "Error",
50-
color: "#e6b032",
51+
color: warningColor,
5152
description: `Uh oh, there was a problem with your formula. Please use [standard dice notation](https://greenimp.github.io/rpg-dice-roller/guide/notation/) and try again!
5253
\n\t_Error: ${error.message}_`,
5354
})

src/commands/rolls/skill.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
} from "../../utils/rolls/skill-roll";
1212
import { getAuthorData } from "../../utils/author";
1313
import { skillNotation, skillNotationRegex } from "../../utils/rolls/notation";
14-
import { getNextSymbolOrSpace } from "../../utils/parse";
14+
import { getNextSymbolOrSpace } from "../../utils/text/parse";
15+
import { failureColor, successColor, warningColor } from "../../utils/color";
1516

1617
class SkillRollCommand extends Command {
1718
constructor(client: CommandoClient) {
@@ -26,7 +27,7 @@ class SkillRollCommand extends Command {
2627
{
2728
key: "formula",
2829
type: "string",
29-
prompt: `Enter a skill roll using the \`${skillNotation}\` notation.`,
30+
prompt: `Enter a skill roll using the \`${skillNotation}\` notation.\nNote: \`{}\` indicate where a value should be entered, \`[]\` indicate an optional value. Do not include either \`{}\` or \`[]\` in your formula.\n`,
3031
},
3132
],
3233
});
@@ -78,7 +79,7 @@ class SkillRollCommand extends Command {
7879
content: new MessageEmbed({
7980
...getAuthorData(this.client),
8081
title: success ? "Success!" : "Failure!",
81-
color: success ? "#33e83c" : "#eb4034",
82+
color: success ? successColor : failureColor,
8283

8384
description: success
8485
? "> Your efforts will help build a better tomorrow!"
@@ -158,7 +159,7 @@ class SkillRollCommand extends Command {
158159
| A little bit of everything | 10 3dt4c19 2 |
159160
| ----------------------------------------- |
160161
\`\`\``,
161-
color: "#e6b032",
162+
color: warningColor,
162163
})
163164
);
164165

src/commands/rules/injury.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { MessageEmbed, TextChannel } from "discord.js";
2+
import { Command, CommandoClient, CommandoMessage } from "discord.js-commando";
3+
import { Menu } from "discord.js-menu";
4+
5+
import { getAuthorData } from "../../utils/author";
6+
import {
7+
injuryNotation,
8+
injuryNotationRegex,
9+
} from "../../utils/rolls/notation";
10+
import {
11+
getCriticalHitLocation,
12+
HitLocation,
13+
HitLocationType,
14+
} from "../../utils/hit-locations";
15+
import { infoColor, warningColor } from "../../utils/color";
16+
import {
17+
criticalHitInjuries,
18+
CriticalHitLocation,
19+
} from "../../utils/damage/critical-hit";
20+
import { capitalize } from "../../utils/text/capitalize";
21+
22+
class CombatRollCommand extends Command {
23+
constructor(client: CommandoClient) {
24+
super(client, {
25+
name: "injury",
26+
aliases: ["i"],
27+
group: "rules",
28+
memberName: "injury",
29+
description: `The outside world can never hurt you! Uses the Vault-Tec recommended ${injuryNotation} notation.`,
30+
clientPermissions: ["MANAGE_MESSAGES"],
31+
args: [
32+
{
33+
key: "formula",
34+
type: "string",
35+
prompt: `Enter a enter hit location and optional type using the \`${injuryNotation}\` notation.\nNote: \`{}\` indicate where a value should be entered, \`[]\` indicate an optional value. Do not include either \`{}\` or \`[]\` in your formula.\n`,
36+
},
37+
],
38+
});
39+
}
40+
41+
private showResultsMessage = (
42+
message: CommandoMessage,
43+
location: CriticalHitLocation
44+
) => {
45+
new Menu(message.channel as TextChannel, message.author.id, [
46+
{
47+
name: "main",
48+
content: new MessageEmbed({
49+
...getAuthorData(this.client),
50+
title: "Injury!",
51+
color: infoColor,
52+
53+
description: "> The outside world can never hurt you!",
54+
fields: [
55+
{
56+
name: "Location",
57+
value: capitalize(location),
58+
inline: false,
59+
},
60+
{
61+
name: "Injury",
62+
value: criticalHitInjuries[location],
63+
inline: false,
64+
},
65+
],
66+
}),
67+
reactions: {},
68+
},
69+
]).start();
70+
};
71+
72+
public run = (
73+
message: CommandoMessage,
74+
{ formula }: { formula: string }
75+
): null => {
76+
const authorData = getAuthorData(this.client);
77+
78+
const showError = (error?: Error): null => {
79+
const errorMessage = error && `**Vault-Tec Error: ${error.message}.**`;
80+
81+
message.say(
82+
new MessageEmbed({
83+
...authorData,
84+
title: "Error",
85+
description: `Uh oh, there was a problem with your formula. Please use the Vault-Tec approved \`${injuryNotation}\` notation and try again!\n\t
86+
Here is a few examples:
87+
\`\`\`
88+
| Description | Formula |
89+
| ---------------- | ------- |
90+
| Head | h |
91+
| Mr. Handy Optics | o handy |
92+
| -------------------------- |
93+
\`\`\`\n
94+
${errorMessage || ""}`,
95+
color: warningColor,
96+
})
97+
);
98+
99+
return null;
100+
};
101+
102+
if (injuryNotationRegex.test(formula)) {
103+
try {
104+
const args = formula.split(" ");
105+
const hitLocation = args[0] as HitLocation;
106+
const hitLocationType =
107+
(args[1] as HitLocationType) || HitLocationType.Default;
108+
109+
if (!hitLocation || !hitLocationType) {
110+
return showError();
111+
}
112+
113+
const location = getCriticalHitLocation(hitLocationType, hitLocation);
114+
115+
this.showResultsMessage(message, location);
116+
117+
return null;
118+
} catch (error) {
119+
return showError(error);
120+
}
121+
}
122+
123+
return showError();
124+
};
125+
}
126+
127+
export default CombatRollCommand;

0 commit comments

Comments
 (0)