Skip to content

Commit

Permalink
Add injury command, readme, and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DTCurrie committed Jul 18, 2021
1 parent 8d0f57f commit 6c6e16e
Show file tree
Hide file tree
Showing 21 changed files with 518 additions and 216 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Dice Boy

A discord bot for runnning Fallout RPG games.

## Usage

To run a command with **Dice Boy**, use the `!vats` command or `@Dice Boy` command. For example, `!vats command` or `@Dice Boy command`.

Use the `!vats help <command>` command to view detailed information about a specific command.
Use `!vats help all` help all to view a list of all commands, not just available ones.

Available commands for **Dice Boy**

### Rolls: 1. Be Smart 2. Be Safe 3. Don't Screw Up!

#### `combat`

Spread Democracy for Uncle Sam! Uses the Vault-Tec recommended `{dice} {damage type} [{effects,...}] [{hit location}] [{hit location type}]` notation.

```bash
| Description | Formula |
| ------------------------------ | ------------------- |
| 1 Physical | 1 ph |
| 2 Radiation Vicious | 2 ra vicious |
| 3 Energy Piercing 2 Stun | 3 en piercing2,stun |
| 4 Poison Stun Head | 4 po stun h |
| 1 Energy Stun Mr. Handy | 1 en stun handy |
| 1 Energy Stun Optics Mr. Handy | 1 en stun o handy |
| ---------------------------------------------------- |
```

#### `roll`

Try your luck with some dice! Uses [standard dice notation](https://greenimp.github.io/rpg-dice-roller/guide/notation/).

#### `skill`

Use your skills to help your fellow citizens! Uses the Vault-Tec recommended `{target} [d{dice}][t{tag}][c{complication}] [{difficulty}]` notation.

```bash
| Description | Formula |
| -------------------------- | ------------ |
| 10 Target | 10 |
| 10 Target, 2 Difficulty | 10 2 |
| 10 Target, 3 Dice | 10 d3 |
| 10 Target, 4 Tag | 10 t4 |
| 10 Target, 19 Complication | 10 c19 |
| A little bit of everything | 10 3dt4c19 2 |
| ----------------------------------------- |
```

### Rules: Knowledge is power, and knowing is half the battle!

#### `injury`

The outside world can never hurt you! Uses the Vault-Tec recommended `{hit location} [{hit location type}]` notation.

```bash
| Description | Formula |
| ---------------- | ------- |
| Head | h |
| Mr. Handy Optics | o handy |
| -------------------------- |
```

### Utility

`help`: Displays a list of available commands, or detailed information for a specified command.
`ping`: Checks the bot's ping to the Discord server.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dice-boy",
"version": "0.1.0",
"description": "A Fallout 2d20 dice rolling bot for Discord",
"description": "A Fallout RPG dice rolling bot for Discord",
"main": "dist/index.js",
"devDependencies": {
"@types/events": "3.0.0",
Expand Down
55 changes: 33 additions & 22 deletions src/commands/rolls/combat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ import {
combatNotation,
combatNotationRegex,
} from "../../utils/rolls/notation";
import { DamageEffect, DamageEffectType } from "../../utils/damage-effect";
import { DamageType } from "../../utils/damage";
import { getHitLocationText, HitLocationType } from "../../utils/hit-locations";
import { capitalize } from "../../utils/capitalize";
import {
DamageEffect,
DamageEffectType,
} from "../../utils/damage/damage-effect";
import { DamageType } from "../../utils/damage/damage";
import {
getHitLocationText,
HitLocation,
HitLocationType,
} from "../../utils/hit-locations";
import { capitalize } from "../../utils/text/capitalize";
import { failureColor, successColor, warningColor } from "../../utils/color";

class CombatRollCommand extends Command {
constructor(client: CommandoClient) {
Expand All @@ -36,7 +44,7 @@ class CombatRollCommand extends Command {
{
key: "formula",
type: "string",
prompt: `Enter a combat roll using the \`${combatNotation}\` notation.`,
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`,
},
],
});
Expand Down Expand Up @@ -64,7 +72,18 @@ class CombatRollCommand extends Command {
this.showResultsMessage(
message,
options,
combatReroll(2, options, results)
combatReroll(options.dice < 2 ? options.dice : 2, options, results)
);

private rerollThree = (
message: CommandoMessage,
options: CombatRollOptions,
results: CombatRollResult
): void =>
this.showResultsMessage(
message,
options,
combatReroll(options.dice < 3 ? options.dice : 3, options, results)
);

private rerollAll = (
Expand Down Expand Up @@ -97,7 +116,7 @@ class CombatRollCommand extends Command {
content: new MessageEmbed({
...getAuthorData(this.client),
title: success ? "Success!" : "Failure!",
color: success ? "#33e83c" : "#eb4034",
color: success ? successColor : failureColor,

description: success
? "> Your efforts will help build a better tomorrow!"
Expand Down Expand Up @@ -140,7 +159,7 @@ class CombatRollCommand extends Command {
results,
rolls,
}),
"2️⃣": () =>
"🤞": () =>
this.rerollTwo(message, options, {
damage,
effects,
Expand All @@ -149,8 +168,8 @@ class CombatRollCommand extends Command {
results,
rolls,
}),
"3️⃣": () =>
this.rerollTwo(message, options, {
"🎰": () =>
this.rerollThree(message, options, {
damage,
effects,
hitLocation,
Expand Down Expand Up @@ -199,7 +218,7 @@ class CombatRollCommand extends Command {
| ---------------------------------------------------- |
\`\`\`\n
${errorMessage || ""}`,
color: "#e6b032",
color: warningColor,
})
);

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

const damageEffects: DamageEffect[] =
(damageEffectArgs || "").split(",").map((effect) => {
const effectArgs = effect.split(/(\d+)/);
console.log("damageEffects effectArgs", effectArgs);
const type = effectArgs[0] as DamageEffectType;
console.log("damageEffects type", type);
const rating = effectArgs[1];
const result: DamageEffect = {
type,
rating: rating ? parseInt(rating) : undefined,
};

if (effectArgs[1]) {
result.rating = parseInt(effectArgs[1]);
}

console.log("damageEffects result", result);
return result;
}) || [];

console.log("damageEffects", damageEffects);

const hitLocation = optionArgs.find(
(arg) =>
arg.search(new RegExp(`^${combatHitLocationNotation.source}$`)) >= 0
);
) as HitLocation | undefined;

const hitLocationType =
(optionArgs.find(
Expand Down
5 changes: 3 additions & 2 deletions src/commands/rolls/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command, CommandoClient, CommandoMessage } from "discord.js-commando";

import { roll } from "../../utils/rolls/roll";
import { getAuthorData } from "../../utils/author";
import { infoColor, warningColor } from "../../utils/color";

class RollCommand extends Command {
constructor(client: CommandoClient) {
Expand Down Expand Up @@ -36,7 +37,7 @@ class RollCommand extends Command {
new MessageEmbed({
...authorData,
title: "Results",
color: "#0099ff",
color: infoColor,
description: "_Good luck out there!_",
fields: [{ name: "\u200B", value: output }],
timestamp: Date.now(),
Expand All @@ -47,7 +48,7 @@ class RollCommand extends Command {
new MessageEmbed({
...authorData,
title: "Error",
color: "#e6b032",
color: warningColor,
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!
\n\t_Error: ${error.message}_`,
})
Expand Down
9 changes: 5 additions & 4 deletions src/commands/rolls/skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
} from "../../utils/rolls/skill-roll";
import { getAuthorData } from "../../utils/author";
import { skillNotation, skillNotationRegex } from "../../utils/rolls/notation";
import { getNextSymbolOrSpace } from "../../utils/parse";
import { getNextSymbolOrSpace } from "../../utils/text/parse";
import { failureColor, successColor, warningColor } from "../../utils/color";

class SkillRollCommand extends Command {
constructor(client: CommandoClient) {
Expand All @@ -26,7 +27,7 @@ class SkillRollCommand extends Command {
{
key: "formula",
type: "string",
prompt: `Enter a skill roll using the \`${skillNotation}\` notation.`,
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`,
},
],
});
Expand Down Expand Up @@ -78,7 +79,7 @@ class SkillRollCommand extends Command {
content: new MessageEmbed({
...getAuthorData(this.client),
title: success ? "Success!" : "Failure!",
color: success ? "#33e83c" : "#eb4034",
color: success ? successColor : failureColor,

description: success
? "> Your efforts will help build a better tomorrow!"
Expand Down Expand Up @@ -158,7 +159,7 @@ class SkillRollCommand extends Command {
| A little bit of everything | 10 3dt4c19 2 |
| ----------------------------------------- |
\`\`\``,
color: "#e6b032",
color: warningColor,
})
);

Expand Down
127 changes: 127 additions & 0 deletions src/commands/rules/injury.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { MessageEmbed, TextChannel } from "discord.js";
import { Command, CommandoClient, CommandoMessage } from "discord.js-commando";
import { Menu } from "discord.js-menu";

import { getAuthorData } from "../../utils/author";
import {
injuryNotation,
injuryNotationRegex,
} from "../../utils/rolls/notation";
import {
getCriticalHitLocation,
HitLocation,
HitLocationType,
} from "../../utils/hit-locations";
import { infoColor, warningColor } from "../../utils/color";
import {
criticalHitInjuries,
CriticalHitLocation,
} from "../../utils/damage/critical-hit";
import { capitalize } from "../../utils/text/capitalize";

class CombatRollCommand extends Command {
constructor(client: CommandoClient) {
super(client, {
name: "injury",
aliases: ["i"],
group: "rules",
memberName: "injury",
description: `The outside world can never hurt you! Uses the Vault-Tec recommended ${injuryNotation} notation.`,
clientPermissions: ["MANAGE_MESSAGES"],
args: [
{
key: "formula",
type: "string",
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`,
},
],
});
}

private showResultsMessage = (
message: CommandoMessage,
location: CriticalHitLocation
) => {
new Menu(message.channel as TextChannel, message.author.id, [
{
name: "main",
content: new MessageEmbed({
...getAuthorData(this.client),
title: "Injury!",
color: infoColor,

description: "> The outside world can never hurt you!",
fields: [
{
name: "Location",
value: capitalize(location),
inline: false,
},
{
name: "Injury",
value: criticalHitInjuries[location],
inline: false,
},
],
}),
reactions: {},
},
]).start();
};

public run = (
message: CommandoMessage,
{ formula }: { formula: string }
): null => {
const authorData = getAuthorData(this.client);

const showError = (error?: Error): null => {
const errorMessage = error && `**Vault-Tec Error: ${error.message}.**`;

message.say(
new MessageEmbed({
...authorData,
title: "Error",
description: `Uh oh, there was a problem with your formula. Please use the Vault-Tec approved \`${injuryNotation}\` notation and try again!\n\t
Here is a few examples:
\`\`\`
| Description | Formula |
| ---------------- | ------- |
| Head | h |
| Mr. Handy Optics | o handy |
| -------------------------- |
\`\`\`\n
${errorMessage || ""}`,
color: warningColor,
})
);

return null;
};

if (injuryNotationRegex.test(formula)) {
try {
const args = formula.split(" ");
const hitLocation = args[0] as HitLocation;
const hitLocationType =
(args[1] as HitLocationType) || HitLocationType.Default;

if (!hitLocation || !hitLocationType) {
return showError();
}

const location = getCriticalHitLocation(hitLocationType, hitLocation);

this.showResultsMessage(message, location);

return null;
} catch (error) {
return showError(error);
}
}

return showError();
};
}

export default CombatRollCommand;
Loading

0 comments on commit 6c6e16e

Please sign in to comment.