You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.9 KiB
77 lines
2.9 KiB
import {
|
|
ApplicationCommandType,
|
|
AutocompleteContext, type CommandContext,
|
|
CommandOptionType, Message,
|
|
SlashCommand,
|
|
type SlashCreator
|
|
} from "slash-create";
|
|
import {type GameCharacter, listCharacters, loadCharacter, saveCharacter} from "../character.js";
|
|
import {renderStatus} from "../renderStatus.js";
|
|
import {readFile} from "fs/promises";
|
|
import {join} from "path";
|
|
import {
|
|
AbstractCharacterStatusCommand,
|
|
CharacterOptionTemplate,
|
|
type GameCharacterData,
|
|
type LoadedCharacterData
|
|
} from "./base.js";
|
|
|
|
export class HealCharacterCommand extends AbstractCharacterStatusCommand {
|
|
constructor(creator: SlashCreator) {
|
|
super(creator, {
|
|
name: "heal",
|
|
description: "Heals the given character(s).",
|
|
type: ApplicationCommandType.CHAT_INPUT,
|
|
guildIDs: process.env.DEVELOPMENT_GUILD_ID,
|
|
options: [
|
|
{
|
|
...CharacterOptionTemplate,
|
|
name: "character",
|
|
description: "The name of the character(s) to heal.",
|
|
required: true,
|
|
},
|
|
{
|
|
type: CommandOptionType.INTEGER,
|
|
name: "healing",
|
|
description: "The amount of healing to apply to the character(s).",
|
|
max_value: 99,
|
|
min_value: 0,
|
|
required: true,
|
|
},
|
|
{
|
|
type: CommandOptionType.BOOLEAN,
|
|
name: "stabilize",
|
|
description: "If true, repairs the unstable status of the character(s).",
|
|
},
|
|
]
|
|
});
|
|
}
|
|
|
|
async process(ctx: CommandContext, characters: Map<string, readonly GameCharacterData[]>): Promise<readonly [string, LoadedCharacterData[]] | readonly [string, LoadedCharacterData] | readonly LoadedCharacterData[] | LoadedCharacterData | string> {
|
|
const healing: number = ctx.options["healing"]
|
|
const stabilize: boolean = ctx.options["stabilize"] ?? false
|
|
const description: string[] = []
|
|
const result: LoadedCharacterData[] = []
|
|
for (const character of characters.get("character")!) {
|
|
if (!character.success) {
|
|
description.push(`**${character.name}** healed ${healing} Harm${healing > 0 ? "!" : "."}${stabilize ? " ***Stabilized!***" : ""}`)
|
|
continue
|
|
}
|
|
character.newData = {
|
|
...(character.newData ?? character.originalData)
|
|
}
|
|
const wasUnstable = character.newData.unstable ?? false
|
|
const wasAlive = (character.newData.health ?? 8) > 0
|
|
character.newData.health = Math.min((character.newData.health ?? 8) + healing, 8)
|
|
if (stabilize) {
|
|
character.newData.unstable = false
|
|
}
|
|
const isUnstable = character.newData.unstable ?? false
|
|
const isAlive = character.newData.health > 0
|
|
description.push(`**${character.name}** healed ${healing} Harm${healing > 0 ? "!" : "."}${
|
|
!wasAlive && isAlive ? " ***Revived!***" : wasUnstable && !isUnstable ? " ***Stabilized!***" : ""}`)
|
|
result.push(character)
|
|
}
|
|
return [description.join("\n"), result]
|
|
}
|
|
}
|
|
|