remove behaviors and rethink how they should work

This commit is contained in:
Jill 2023-11-21 23:40:15 +03:00
parent c4980da8b7
commit 8ad18e9b19
Signed by: oat
GPG Key ID: 33489AA58A955108
4 changed files with 28 additions and 39 deletions

View File

@ -0,0 +1,26 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
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<void> }
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
exports.down = function(knex) {
// no
throw 'Not implemented';
};

View File

@ -1,7 +1,6 @@
import { AutocompleteInteraction, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { AutocompleteInteraction, CommandInteraction, SlashCommandBuilder } from 'discord.js';
import { Counter, CustomCraftingRecipeItem, CustomItem, db } from '../lib/db'; import { Counter, CustomCraftingRecipeItem, CustomItem, db } from '../lib/db';
import { customItemAutocomplete, formatItem, formatItems, getItem, giveItem, itemAutocomplete } from '../lib/rpg/items'; import { customItemAutocomplete, formatItem, formatItems, getItem, giveItem, itemAutocomplete } from '../lib/rpg/items';
import { behaviors } from '../lib/rpg/behaviors';
import { Command } from '../types/index'; import { Command } from '../types/index';
import { formatRecipe, getCustomRecipe } from '../lib/rpg/recipes'; import { formatRecipe, getCustomRecipe } from '../lib/rpg/recipes';
@ -43,22 +42,11 @@ export default {
.setName('maxstack') .setName('maxstack')
.setDescription('Maximum amount of this item you\'re able to hold at once') .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 => .addBooleanOption(opt =>
opt opt
.setName('untradable') .setName('untradable')
.setDescription('Can you give this item to other people?') .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 => .addSubcommand(cmd =>
cmd cmd
@ -87,22 +75,11 @@ export default {
.setName('description') .setName('description')
.setDescription('A short 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 => .addBooleanOption(opt =>
opt opt
.setName('untradable') .setName('untradable')
.setDescription('Can you give this item to other people?') .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 => .addSubcommand(cmd =>
cmd cmd
@ -130,22 +107,11 @@ export default {
.setName('maxstack') .setName('maxstack')
.setDescription('Maximum amount of this item you\'re able to hold at once') .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 => .addBooleanOption(opt =>
opt opt
.setName('untradable') .setName('untradable')
.setDescription('Can you give this item to other people?') .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 => .addSubcommand(cmd =>
@ -203,9 +169,7 @@ export default {
'emoji': interaction.options.getString('emoji', true).trim(), 'emoji': interaction.options.getString('emoji', true).trim(),
'type': subcommand as 'plain' | 'weapon' | 'consumable', // kind of wild that ts makes you do this '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), '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, 'untradable': interaction.options.getBoolean('untradable') || false,
'behaviorValue': interaction.options.getNumber('behaviorValue') || undefined,
}) })
.returning('*'); .returning('*');

View File

@ -55,9 +55,7 @@ export interface CustomItem {
type: 'plain' | 'weapon' | 'consumable', type: 'plain' | 'weapon' | 'consumable',
// also damage for weapons; weapons are always unstackable (cus i said so) // also damage for weapons; weapons are always unstackable (cus i said so)
maxStack: number, maxStack: number,
behavior?: string,
untradable: boolean, untradable: boolean,
behaviorValue?: number
} }
export interface ItemInventory { export interface ItemInventory {
user: string, user: string,

View File

@ -1,7 +1,8 @@
import { AutocompleteInteraction } from 'discord.js'; import { AutocompleteInteraction } from 'discord.js';
import { CustomItem, ItemInventory, db } from '../db'; import { CustomItem, ItemInventory, db } from '../db';
export type DefaultItem = Omit<CustomItem, 'guild'>; // uses negative IDs // uses negative IDs
export type DefaultItem = Omit<CustomItem, 'guild'>;
export type Item = DefaultItem | CustomItem; export type Item = DefaultItem | CustomItem;
export interface Items { export interface Items {