Compare commits
4 Commits
39014d3b90
...
20b914417f
Author | SHA1 | Date |
---|---|---|
Jill | 20b914417f | |
Jill | 9af3499d3d | |
Jill | cb503e3cf9 | |
Jill | 8a935e00db |
|
@ -1,6 +1,6 @@
|
|||
import { AutocompleteInteraction, GuildMember, Interaction, SlashCommandBuilder } from 'discord.js';
|
||||
import { CraftingStationCooldown, db } from '../lib/db';
|
||||
import { getStation, canUseStation, craftingStations } from '../lib/rpg/craftingStations';
|
||||
import { getStation, canUseStation, craftingStations, verb } from '../lib/rpg/craftingStations';
|
||||
import { formatItem, getItemQuantity, formatItems, getMaxStack, giveItem, formatItemsArray } from '../lib/rpg/items';
|
||||
import { getRecipe, defaultRecipes, formatRecipe } from '../lib/rpg/recipes';
|
||||
|
||||
|
@ -47,7 +47,7 @@ module.exports = {
|
|||
}
|
||||
for (const out of recipe.outputs) {
|
||||
const inv = await getItemQuantity(member.id, out.item.id);
|
||||
if (inv.quantity + out.quantity > getMaxStack(out.item)) return interaction.followUp(`You do not have enough inventory storage for this recipe! (${formatItems(out.item, inv.quantity + out.quantity)} is bigger than the stack size of ${getMaxStack(out.item)}.)`);
|
||||
if (inv.quantity + out.quantity > getMaxStack(out.item)) return interaction.followUp(`You do not have enough inventory storage for this recipe! (${formatItems(out.item, inv.quantity + out.quantity)} is bigger than the stack size of ${getMaxStack(out.item)}x.)`);
|
||||
}
|
||||
|
||||
let cooldown;
|
||||
|
@ -92,7 +92,7 @@ module.exports = {
|
|||
nextUsableAt = Date.now() + station.cooldown * 1000;
|
||||
}
|
||||
|
||||
return interaction.followUp(`${station.emoji} Crafted ${formatItemsArray(outputs)}!${nextUsableAt ? `\n${station.name} usable again <t:${Math.floor(nextUsableAt / 1000)}:R>` : ''}`);
|
||||
return interaction.followUp(`${station.emoji} ${verb(station)} ${formatItemsArray(outputs)}!${nextUsableAt ? `\n${station.name} usable again <t:${Math.floor(nextUsableAt / 1000)}:R>` : ''}`);
|
||||
},
|
||||
|
||||
autocomplete: async (interaction: AutocompleteInteraction) => {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { pickRandom } from '../util';
|
||||
import { DefaultItems, Item, Items, formatItems, getDefaultItem, getItemQuantity } from './items';
|
||||
import { DefaultItems, Item, Items, formatItems, formatItemsArray, getDefaultItem, getItemQuantity } from './items';
|
||||
|
||||
export interface CraftingStation {
|
||||
key: string,
|
||||
name: string,
|
||||
verb?: string,
|
||||
description: string,
|
||||
emoji: string,
|
||||
requires?: Item,
|
||||
|
@ -17,14 +18,18 @@ export function getStation(key: string) {
|
|||
return craftingStations.find(station => station.key === key);
|
||||
}
|
||||
|
||||
export const defaultVerb = 'Crafted';
|
||||
|
||||
export const craftingStations: CraftingStation[] = [
|
||||
{
|
||||
key: 'forage',
|
||||
name: 'Forage',
|
||||
verb: 'Foraged',
|
||||
description: 'Pick up various sticks and stones from the forest',
|
||||
emoji: '🌲',
|
||||
cooldown: 60 * 5,
|
||||
formatRecipe: (_inputs, _requirements, outputs, disableBold = false) => `${outputs.map(i => formatItems(i.item, i.quantity, disableBold) + '?').join(' ')}`,
|
||||
formatRecipe: (_inputs, requirements, outputs, disableBold = false) =>
|
||||
`${requirements.length > 0 ? `w/ ${formatItemsArray(requirements, disableBold)}: ` : ''}${outputs.map(i => formatItems(i.item, i.quantity, disableBold) + '?').join(' ')}`,
|
||||
manipulateResults: (outputs) => {
|
||||
const totalItems = outputs.reduce((a, b) => a + b.quantity, 0);
|
||||
// grab from 1/3 to the entire pool, ensure it never goes below 1
|
||||
|
@ -34,7 +39,12 @@ export const craftingStations: CraftingStation[] = [
|
|||
const rolled = pickRandom(outputs);
|
||||
const r = res.find(r => r.item.id === rolled.item.id);
|
||||
if (r) {
|
||||
r.quantity = r.quantity + 1;
|
||||
if (r.quantity === rolled.quantity) {
|
||||
// don't roll more than can be rolled
|
||||
i--;
|
||||
} else {
|
||||
r.quantity = r.quantity + 1;
|
||||
}
|
||||
} else {
|
||||
res.push({ item: rolled.item, quantity: 1 });
|
||||
}
|
||||
|
@ -45,6 +55,7 @@ export const craftingStations: CraftingStation[] = [
|
|||
{
|
||||
key: 'hand',
|
||||
name: 'Hand',
|
||||
verb: 'Made',
|
||||
description: 'You can use your hands to make a small assortment of things',
|
||||
emoji: '✋'
|
||||
},
|
||||
|
@ -62,4 +73,8 @@ export async function canUseStation(user: string, station: CraftingStation) {
|
|||
|
||||
const inv = await getItemQuantity(user, station.requires.id);
|
||||
return inv.quantity > 0;
|
||||
}
|
||||
|
||||
export function verb(station: CraftingStation) {
|
||||
return station.verb || defaultVerb;
|
||||
}
|
|
@ -16,6 +16,9 @@ export enum DefaultItems {
|
|||
TWIG = 4,
|
||||
APPLE = 5,
|
||||
BERRIES = 6,
|
||||
LOG = 7,
|
||||
AXE = 8,
|
||||
BLOOD = 9,
|
||||
}
|
||||
|
||||
export const defaultItems: DefaultItem[] = [
|
||||
|
@ -71,7 +74,34 @@ export const defaultItems: DefaultItem[] = [
|
|||
type: 'consumable',
|
||||
maxStack: 16,
|
||||
untradable: false
|
||||
}
|
||||
},
|
||||
{
|
||||
id: -7,
|
||||
name: 'Log',
|
||||
description: '㏒',
|
||||
emoji: '🪵',
|
||||
type: 'plain',
|
||||
maxStack: 64,
|
||||
untradable: false
|
||||
},
|
||||
{
|
||||
id: -8,
|
||||
name: 'Axe',
|
||||
description: 'You could chop trees with this. Or commit murder! The choice is up to you',
|
||||
emoji: '🪓',
|
||||
type: 'weapon',
|
||||
maxStack: 1,
|
||||
untradable: false
|
||||
},
|
||||
{
|
||||
id: -9,
|
||||
name: 'Blood',
|
||||
description: 'ow',
|
||||
emoji: '🩸',
|
||||
type: 'plain',
|
||||
maxStack: 1024,
|
||||
untradable: false
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ export const defaultRecipes: DefaultRecipe[] = [
|
|||
requirements: [],
|
||||
outputs: [
|
||||
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 4 },
|
||||
{ item: getDefaultItem(DefaultItems.TWIG), quantity: 3 },
|
||||
{ item: getDefaultItem(DefaultItems.TWIG), quantity: 2 },
|
||||
{ item: getDefaultItem(DefaultItems.BERRIES), quantity: 2 }
|
||||
]
|
||||
},
|
||||
|
@ -40,7 +40,7 @@ export const defaultRecipes: DefaultRecipe[] = [
|
|||
inputs: [],
|
||||
requirements: [],
|
||||
outputs: [
|
||||
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 3 },
|
||||
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 2 },
|
||||
{ item: getDefaultItem(DefaultItems.TWIG), quantity: 4 },
|
||||
{ item: getDefaultItem(DefaultItems.APPLE), quantity: 1 }
|
||||
]
|
||||
|
@ -57,6 +57,41 @@ export const defaultRecipes: DefaultRecipe[] = [
|
|||
{ item: getDefaultItem(DefaultItems.BERRIES), quantity: 6 },
|
||||
]
|
||||
},
|
||||
{
|
||||
id: -5,
|
||||
station: 'forage',
|
||||
inputs: [],
|
||||
requirements: [
|
||||
{ item: getDefaultItem(DefaultItems.AXE), quantity: 1 },
|
||||
],
|
||||
outputs: [
|
||||
{ item: getDefaultItem(DefaultItems.TWIG), quantity: 1 },
|
||||
{ item: getDefaultItem(DefaultItems.LOG), quantity: 3 },
|
||||
]
|
||||
},
|
||||
{
|
||||
id: -6,
|
||||
station: 'workbench',
|
||||
inputs: [
|
||||
{ item: getDefaultItem(DefaultItems.PEBBLE), quantity: 4 },
|
||||
{ item: getDefaultItem(DefaultItems.TWIG), quantity: 2 },
|
||||
],
|
||||
requirements: [],
|
||||
outputs: [
|
||||
{ item: getDefaultItem(DefaultItems.AXE), quantity: 1 },
|
||||
]
|
||||
},
|
||||
{
|
||||
id: -7,
|
||||
station: 'hand',
|
||||
inputs: [],
|
||||
requirements: [
|
||||
{ item: getDefaultItem(DefaultItems.AXE), quantity: 1 },
|
||||
],
|
||||
outputs: [
|
||||
{ item: getDefaultItem(DefaultItems.BLOOD), quantity: 6 },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export function getDefaultRecipe(id: number): DefaultRecipe | undefined {
|
||||
|
|
Loading…
Reference in New Issue