2023-11-15 16:33:08 +01:00
|
|
|
import { pickRandom } from '../util';
|
2023-11-15 16:11:48 +01:00
|
|
|
import { DefaultItems, Item, Items, formatItems, getDefaultItem, getItemQuantity } from './items';
|
|
|
|
|
|
|
|
export interface CraftingStation {
|
|
|
|
key: string,
|
|
|
|
name: string,
|
|
|
|
description: string,
|
|
|
|
emoji: string,
|
|
|
|
requires?: Item,
|
|
|
|
// in seconds
|
|
|
|
cooldown?: number,
|
2023-11-15 16:22:57 +01:00
|
|
|
formatRecipe?: (inputs: Items[], requirements: Items[], outputs: Items[], disableBold?: boolean) => string,
|
2023-11-15 16:11:48 +01:00
|
|
|
manipulateResults?: (outputs: Items[]) => Items[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStation(key: string) {
|
|
|
|
return craftingStations.find(station => station.key === key);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const craftingStations: CraftingStation[] = [
|
|
|
|
{
|
|
|
|
key: 'forage',
|
|
|
|
name: 'Forage',
|
|
|
|
description: 'Pick up various sticks and stones from the forest',
|
|
|
|
emoji: '🌲',
|
|
|
|
cooldown: 60 * 5,
|
2023-11-15 16:22:57 +01:00
|
|
|
formatRecipe: (_inputs, _requirements, outputs, disableBold = false) => `${outputs.map(i => formatItems(i.item, i.quantity, disableBold) + '?').join(' ')}`,
|
2023-11-15 16:33:08 +01:00
|
|
|
manipulateResults: (outputs) => {
|
|
|
|
const totalItems = outputs.reduce((a, b) => a + b.quantity, 0);
|
|
|
|
// grab from 1/2 to the entire pool, ensure it never goes below 1
|
|
|
|
const rolledItems = Math.max(Math.round(totalItems/2 + Math.random() * totalItems/2), 1);
|
|
|
|
const res: Items[] = [];
|
|
|
|
for (let i = 0; i < rolledItems; i++) {
|
|
|
|
const rolled = pickRandom(outputs);
|
|
|
|
const r = res.find(r => r.item.id === rolled.item.id);
|
|
|
|
if (r) {
|
|
|
|
r.quantity = r.quantity + 1;
|
|
|
|
} else {
|
|
|
|
res.push({ item: rolled.item, quantity: rolled.quantity });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2023-11-15 16:11:48 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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 async function canUseStation(user: string, station: CraftingStation) {
|
|
|
|
if (!station.requires) return true;
|
|
|
|
|
|
|
|
const inv = await getItemQuantity(user, station.requires.id);
|
|
|
|
return inv.quantity > 0;
|
|
|
|
}
|