move items, recipes etc to data file

This commit is contained in:
Jill 2023-11-15 13:59:38 +03:00
parent c6e5b9a00f
commit b0389f3e58
Signed by: oat
GPG Key ID: 33489AA58A955108
2 changed files with 101 additions and 100 deletions

95
src/lib/rpg/data.ts Normal file
View File

@ -0,0 +1,95 @@
import { Behavior, CraftingStation, DefaultItem, Recipe, formatItems, getDefaultItem } from './items';
enum DefaultItems {
COIN = 1,
WORKBENCH = 2,
PEBBLE = 3
}
export const defaultItems: DefaultItem[] = [
{
'id': -1,
'name': 'Coin',
'emoji': '🪙',
'type': 'plain',
'maxStack': 9999,
'untradable': false
},
{
'id': -2,
'name': 'Workbench',
'description': 'A place for you to work with tools, for simple things',
'emoji': '🛠️',
'type': 'plain',
'maxStack': 1,
'untradable': false
},
{
'id': -3,
'name': 'Pebble',
'description': 'If you get 5 of them you will instantly ! !!!',
'emoji': '🪨',
'type': 'plain',
'maxStack': 64,
'untradable': false
}
];
export const behaviors: Behavior[] = [
{
'name': 'heal',
'description': 'Heals the user by `behaviorValue`',
'itemType': 'consumable',
'action': async (item, user) => {
// todo
return false;
}
}
];
export const craftingStations: CraftingStation[] = [
{
key: 'forage',
name: 'Forage',
description: 'Pick up various sticks and stones from the forest',
emoji: '🌲',
cooldown: 60 * 5,
formatRecipe: (_inputs, _requirements, outputs) => `${outputs.map(i => formatItems(i.item, i.quantity) + '?').join(' ')}`,
manipulateResults: (outputs) =>
outputs.map(o => ({item: o.item, quantity: Math.floor(o.quantity * Math.random())})).filter(o => o.quantity !== 0)
},
{
key: 'hand',
name: 'Hand',
description: 'You can use your hands to make a small assortment of things',
emoji: '✋'
},
{
key: 'workbench',
name: 'Workbench',
description: 'A place for you to work with tools, for simple things',
emoji: '🛠️',
requires: getDefaultItem(DefaultItems.WORKBENCH)
}
];
export const recipes: Recipe[] = [
{
station: 'forage',
inputs: [],
requirements: [],
outputs: [
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 2 }
]
},
{
station: 'workbench',
inputs: [
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 2 }
],
requirements: [],
outputs: [
{ item: getDefaultItem(DefaultItems.WORKBENCH), quantity: 1 }
]
}
];

View File

@ -1,10 +1,10 @@
import { AutocompleteInteraction, User } from 'discord.js';
import { CustomItem, ItemInventory, db } from '../db';
type DefaultItem = Omit<CustomItem, 'guild'>; // uses negative IDs
type Item = DefaultItem | CustomItem;
export type DefaultItem = Omit<CustomItem, 'guild'>; // uses negative IDs
export type Item = DefaultItem | CustomItem;
interface Behavior {
export interface Behavior {
name: string,
description: string,
itemType: 'plain' | 'weapon' | 'consumable',
@ -16,54 +16,7 @@ interface Behavior {
action?: (item: Item, user: User) => Promise<boolean>
}
enum DefaultItems {
COIN = 1,
WORKBENCH = 2,
PEBBLE = 3
}
export const defaultItems: DefaultItem[] = [
{
'id': -1,
'name': 'Coin',
'emoji': '🪙',
'type': 'plain',
'maxStack': 9999,
'untradable': false
},
{
'id': -2,
'name': 'Workbench',
'description': 'A place for you to work with tools, for simple things',
'emoji': '🛠️',
'type': 'plain',
'maxStack': 1,
'untradable': false
},
{
'id': -3,
'name': 'Pebble',
'description': 'If you get 5 of them you will instantly ! !!!',
'emoji': '🪨',
'type': 'plain',
'maxStack': 64,
'untradable': false
}
];
export const behaviors: Behavior[] = [
{
'name': 'heal',
'description': 'Heals the user by `behaviorValue`',
'itemType': 'consumable',
'action': async (item: Item, user: User) => {
// todo
return false;
}
}
];
interface Items {
export interface Items {
item: Item,
quantity: number
}
@ -71,7 +24,7 @@ interface Items {
const defaultFormatRecipe = (inputs: Items[], requirements: Items[], outputs: Items[]) =>
`${formatItemsArray(inputs)}${requirements.length === 0 ? '' : ` w/ ${formatItemsArray(requirements)}`} => ${formatItemsArray(outputs)}`;
interface CraftingStation {
export interface CraftingStation {
key: string,
name: string,
description: string,
@ -83,60 +36,13 @@ interface CraftingStation {
manipulateResults?: (outputs: Items[]) => Items[]
}
export const craftingStations: CraftingStation[] = [
{
key: 'forage',
name: 'Forage',
description: 'Pick up various sticks and stones from the forest',
emoji: '🌲',
cooldown: 60 * 5,
formatRecipe: (_inputs, _requirements, outputs) => `${outputs.map(i => formatItems(i.item, i.quantity) + '?').join(' ')}`,
manipulateResults: (outputs) =>
outputs.map(o => ({item: o.item, quantity: Math.floor(o.quantity * Math.random())})).filter(o => o.quantity !== 0)
},
{
key: 'hand',
name: 'Hand',
description: 'You can use your hands to make a small assortment of things',
emoji: '✋'
},
{
key: 'workbench',
name: 'Workbench',
description: 'A place for you to work with tools, for simple things',
emoji: '🛠️',
requires: getDefaultItem(DefaultItems.WORKBENCH)
}
];
interface Recipe {
export interface Recipe {
station: string,
inputs: Items[],
requirements: Items[],
outputs: Items[]
}
export const recipes: Recipe[] = [
{
station: 'forage',
inputs: [],
requirements: [],
outputs: [
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 2 }
]
},
{
station: 'workbench',
inputs: [
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 2 }
],
requirements: [],
outputs: [
{ item: getDefaultItem(DefaultItems.WORKBENCH), quantity: 1 }
]
}
];
export async function getCustomItem(id: number) {
return await db<CustomItem>('customItems')
.where('id', id)