rough data draft of recipes
This commit is contained in:
parent
2bb3512316
commit
7f6607f3d9
108
src/lib/items.ts
108
src/lib/items.ts
|
@ -16,6 +16,12 @@ interface Behavior {
|
|||
action?: (item: Item, user: User) => Promise<boolean>
|
||||
}
|
||||
|
||||
enum DefaultItems {
|
||||
COIN = 1,
|
||||
WORKBENCH = 2,
|
||||
PEBBLE = 3
|
||||
}
|
||||
|
||||
export const defaultItems: DefaultItem[] = [
|
||||
{
|
||||
'id': -1,
|
||||
|
@ -24,6 +30,24 @@ export const defaultItems: DefaultItem[] = [
|
|||
'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
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -39,17 +63,96 @@ export const behaviors: Behavior[] = [
|
|||
}
|
||||
];
|
||||
|
||||
interface Items {
|
||||
item: Item,
|
||||
quantity: number
|
||||
}
|
||||
|
||||
const defaultFormatRecipe = (inputs: Items[], requirements: Items[], outputs: Items[]) =>
|
||||
`${formatItemsArray(inputs)}${requirements.length === 0 ? '' : ` w/ ${formatItemsArray(requirements)}`} => ${formatItemsArray(outputs)}`;
|
||||
|
||||
interface CraftingStation {
|
||||
key: string,
|
||||
name: string,
|
||||
description: string,
|
||||
emoji: string,
|
||||
requires?: Item,
|
||||
// in seconds
|
||||
cooldown?: number,
|
||||
formatRecipe?: (inputs: Items[], requirements: Items[], outputs: Items[]) => string,
|
||||
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 {
|
||||
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)
|
||||
.first();
|
||||
}
|
||||
|
||||
export function getDefaultItem(id: DefaultItems): Item
|
||||
export function getDefaultItem(id: number): Item | undefined {
|
||||
return defaultItems.find(item => Math.abs(item.id) === Math.abs(id));
|
||||
}
|
||||
|
||||
export async function getItem(id: number): Promise<Item | undefined> {
|
||||
if (id >= 0) {
|
||||
return await getCustomItem(id);
|
||||
} else {
|
||||
return defaultItems.find(item => item.id === id);
|
||||
return getDefaultItem(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +208,9 @@ export function formatItem(item: Item | undefined) {
|
|||
export function formatItems(item: Item | undefined, quantity: number) {
|
||||
return `${quantity}x ${formatItem(item)}`;
|
||||
}
|
||||
export function formatItemsArray(items: Items[]) {
|
||||
return items.map(i => formatItems(i.item, i.quantity)).join(' ');
|
||||
}
|
||||
|
||||
export async function itemAutocomplete(interaction: AutocompleteInteraction) {
|
||||
const focused = interaction.options.getFocused();
|
||||
|
|
Loading…
Reference in New Issue