From 8ad18e9b19b1d5aeb44cb42fc5bbf8a817e57156 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Tue, 21 Nov 2023 23:40:15 +0300 Subject: [PATCH] remove behaviors and rethink how they should work --- migrations/20231121203119_behaviors.js | 26 +++++++++++++++++++ src/commands/item.ts | 36 -------------------------- src/lib/db.ts | 2 -- src/lib/rpg/items.ts | 3 ++- 4 files changed, 28 insertions(+), 39 deletions(-) create mode 100644 migrations/20231121203119_behaviors.js diff --git a/migrations/20231121203119_behaviors.js b/migrations/20231121203119_behaviors.js new file mode 100644 index 0000000..8f55873 --- /dev/null +++ b/migrations/20231121203119_behaviors.js @@ -0,0 +1,26 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function(knex) { + return knex.schema + .createTable('itemBehaviors', table => { + table.integer('item').notNullable(); + table.string('behavior').notNullable(); + table.float('value'); + }) + .alterTable('customItems', table => { + table.dropColumn('behavior'); + table.dropColumn('behaviorValue'); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +exports.down = function(knex) { + // no + throw 'Not implemented'; +}; diff --git a/src/commands/item.ts b/src/commands/item.ts index 89d0dcf..af4968e 100644 --- a/src/commands/item.ts +++ b/src/commands/item.ts @@ -1,7 +1,6 @@ import { AutocompleteInteraction, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { Counter, CustomCraftingRecipeItem, CustomItem, db } from '../lib/db'; import { customItemAutocomplete, formatItem, formatItems, getItem, giveItem, itemAutocomplete } from '../lib/rpg/items'; -import { behaviors } from '../lib/rpg/behaviors'; import { Command } from '../types/index'; import { formatRecipe, getCustomRecipe } from '../lib/rpg/recipes'; @@ -43,22 +42,11 @@ export default { .setName('maxstack') .setDescription('Maximum amount of this item you\'re able to hold at once') ) - .addStringOption(opt => - opt - .setName('behavior') - .setDescription('Special behavior type') - .setChoices(...behaviors.filter(b => b.itemType === 'plain').map(b => ({name: `${b.name} - ${b.description}`, value: b.name}))) - ) .addBooleanOption(opt => opt .setName('untradable') .setDescription('Can you give this item to other people?') ) - .addNumberOption(opt => - opt - .setName('behaviorvalue') - .setDescription('A value to use for the behavior type; not always applicable') - ) ) .addSubcommand(cmd => cmd @@ -87,22 +75,11 @@ export default { .setName('description') .setDescription('A short description') ) - .addStringOption(opt => - opt - .setName('behavior') - .setDescription('Special behavior type') - .setChoices(...behaviors.filter(b => b.itemType === 'weapon').map(b => ({name: `${b.name} - ${b.description}`, value: b.name}))) - ) .addBooleanOption(opt => opt .setName('untradable') .setDescription('Can you give this item to other people?') ) - .addNumberOption(opt => - opt - .setName('behaviorvalue') - .setDescription('A value to use for the behavior type; not always applicable') - ) ) .addSubcommand(cmd => cmd @@ -130,22 +107,11 @@ export default { .setName('maxstack') .setDescription('Maximum amount of this item you\'re able to hold at once') ) - .addStringOption(opt => - opt - .setName('behavior') - .setDescription('Special behavior type') - .setChoices(...behaviors.filter(b => b.itemType === 'consumable').map(b => ({name: `${b.name} - ${b.description}`, value: b.name}))) - ) .addBooleanOption(opt => opt .setName('untradable') .setDescription('Can you give this item to other people?') ) - .addNumberOption(opt => - opt - .setName('behaviorvalue') - .setDescription('A value to use for the behavior type; not always applicable') - ) ) ) .addSubcommand(cmd => @@ -203,9 +169,7 @@ export default { 'emoji': interaction.options.getString('emoji', true).trim(), 'type': subcommand as 'plain' | 'weapon' | 'consumable', // kind of wild that ts makes you do this 'maxStack': (interaction.options.getInteger('maxstack') || interaction.options.getInteger('damage')) || (subcommand === 'weapon' ? 1 : 64), - 'behavior': interaction.options.getString('behavior') || undefined, 'untradable': interaction.options.getBoolean('untradable') || false, - 'behaviorValue': interaction.options.getNumber('behaviorValue') || undefined, }) .returning('*'); diff --git a/src/lib/db.ts b/src/lib/db.ts index 812994c..62244b6 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -55,9 +55,7 @@ export interface CustomItem { type: 'plain' | 'weapon' | 'consumable', // also damage for weapons; weapons are always unstackable (cus i said so) maxStack: number, - behavior?: string, untradable: boolean, - behaviorValue?: number } export interface ItemInventory { user: string, diff --git a/src/lib/rpg/items.ts b/src/lib/rpg/items.ts index 43f9762..e9ec8a3 100644 --- a/src/lib/rpg/items.ts +++ b/src/lib/rpg/items.ts @@ -1,7 +1,8 @@ import { AutocompleteInteraction } from 'discord.js'; import { CustomItem, ItemInventory, db } from '../db'; -export type DefaultItem = Omit; // uses negative IDs +// uses negative IDs +export type DefaultItem = Omit; export type Item = DefaultItem | CustomItem; export interface Items {