213 lines
5.8 KiB
JavaScript
213 lines
5.8 KiB
JavaScript
/**
|
|
* CRAFTING RECIPES
|
|
* Defines all crafting recipes for basic items and tools
|
|
* Format: { id, name, ingredients: [{item, amount}], result: {item, amount}, category }
|
|
*/
|
|
|
|
const CRAFTING_RECIPES = {
|
|
// ==================================
|
|
// BONE TOOLS (New!)
|
|
// ==================================
|
|
'bone_pickaxe': {
|
|
id: 'bone_pickaxe',
|
|
name: 'Bone Pickaxe',
|
|
ingredients: [
|
|
{ item: 'bone', amount: 3 },
|
|
{ item: 'wood', amount: 2 }
|
|
],
|
|
result: { item: 'bone_pickaxe', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Weak pickaxe made from bones. Better than nothing!'
|
|
},
|
|
'bone_axe': {
|
|
id: 'bone_axe',
|
|
name: 'Bone Axe',
|
|
ingredients: [
|
|
{ item: 'bone', amount: 3 },
|
|
{ item: 'wood', amount: 2 }
|
|
],
|
|
result: { item: 'bone_axe', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Crude axe for chopping wood.'
|
|
},
|
|
'bone_hoe': {
|
|
id: 'bone_hoe',
|
|
name: 'Bone Hoe',
|
|
ingredients: [
|
|
{ item: 'bone', amount: 2 },
|
|
{ item: 'wood', amount: 2 }
|
|
],
|
|
result: { item: 'bone_hoe', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Farming tool for tilling soil.'
|
|
},
|
|
'bone_sword': {
|
|
id: 'bone_sword',
|
|
name: 'Bone Sword',
|
|
ingredients: [
|
|
{ item: 'bone', amount: 2 },
|
|
{ item: 'wood', amount: 1 }
|
|
],
|
|
result: { item: 'bone_sword', amount: 1 },
|
|
category: 'weapons',
|
|
description: 'Sharp bone weapon. +5 damage.'
|
|
},
|
|
|
|
// ==================================
|
|
// BASIC TOOLS (Existing)
|
|
// ==================================
|
|
'wooden_pickaxe': {
|
|
id: 'wooden_pickaxe',
|
|
name: 'Wooden Pickaxe',
|
|
ingredients: [
|
|
{ item: 'wood', amount: 3 },
|
|
{ item: 'stick', amount: 2 }
|
|
],
|
|
result: { item: 'wooden_pickaxe', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Basic mining tool.'
|
|
},
|
|
'stone_pickaxe': {
|
|
id: 'stone_pickaxe',
|
|
name: 'Stone Pickaxe',
|
|
ingredients: [
|
|
{ item: 'stone', amount: 3 },
|
|
{ item: 'stick', amount: 2 }
|
|
],
|
|
result: { item: 'stone_pickaxe', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Improved mining tool.'
|
|
},
|
|
|
|
// ==================================
|
|
// BASIC ITEMS
|
|
// ==================================
|
|
'stick': {
|
|
id: 'stick',
|
|
name: 'Stick',
|
|
ingredients: [
|
|
{ item: 'wood', amount: 1 }
|
|
],
|
|
result: { item: 'stick', amount: 4 },
|
|
category: 'materials',
|
|
description: 'Basic crafting material.'
|
|
},
|
|
'torch': {
|
|
id: 'torch',
|
|
name: 'Torch',
|
|
ingredients: [
|
|
{ item: 'stick', amount: 1 },
|
|
{ item: 'coal', amount: 1 }
|
|
],
|
|
result: { item: 'torch', amount: 4 },
|
|
category: 'lighting',
|
|
description: 'Provides light in darkness.'
|
|
},
|
|
|
|
// ==================================
|
|
// BUILDINGS
|
|
// ==================================
|
|
'chest': {
|
|
id: 'chest',
|
|
name: 'Chest',
|
|
ingredients: [
|
|
{ item: 'wood', amount: 8 }
|
|
],
|
|
result: { item: 'chest', amount: 1 },
|
|
category: 'storage',
|
|
description: 'Storage container.'
|
|
},
|
|
'furnace': {
|
|
id: 'furnace',
|
|
name: 'Furnace',
|
|
ingredients: [
|
|
{ item: 'stone', amount: 8 },
|
|
{ item: 'coal', amount: 4 }
|
|
],
|
|
result: { item: 'furnace', amount: 1 },
|
|
category: 'workstation',
|
|
description: 'Smelts ores into bars.'
|
|
},
|
|
|
|
// ==================================
|
|
// CUSTOM RECIPES (NEW!)
|
|
// ==================================
|
|
'lesena_ograda': {
|
|
id: 'lesena_ograda',
|
|
name: 'Lesena Ograda',
|
|
ingredients: [
|
|
{ item: 'wood', amount: 2 }
|
|
],
|
|
result: { item: 'lesena_ograda', amount: 5 },
|
|
category: 'buildings',
|
|
description: 'Lesena ograja za zaščito farme.'
|
|
},
|
|
'sekira_osnovna': {
|
|
id: 'sekira_osnovna',
|
|
name: 'Osnovna Sekira',
|
|
ingredients: [
|
|
{ item: 'wood', amount: 3 },
|
|
{ item: 'stone', amount: 2 }
|
|
],
|
|
result: { item: 'sekira_osnovna', amount: 1 },
|
|
category: 'tools',
|
|
description: 'Osnovno orodje za sekanje dreves.'
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Helper function to get recipe by ID
|
|
*/
|
|
function getCraftingRecipe(recipeId) {
|
|
return CRAFTING_RECIPES[recipeId] || null;
|
|
}
|
|
|
|
/**
|
|
* Helper function to check if player has ingredients
|
|
*/
|
|
function canCraft(recipeId, playerInventory) {
|
|
const recipe = getCraftingRecipe(recipeId);
|
|
if (!recipe) return false;
|
|
|
|
for (const ingredient of recipe.ingredients) {
|
|
const playerAmount = playerInventory.getItemCount(ingredient.item);
|
|
if (playerAmount < ingredient.amount) {
|
|
return false; // Missing ingredient
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Helper function to craft item (consumes ingredients)
|
|
*/
|
|
function craftItem(recipeId, playerInventory) {
|
|
if (!canCraft(recipeId, playerInventory)) {
|
|
console.warn('⚠️ Cannot craft - missing ingredients!');
|
|
return false;
|
|
}
|
|
|
|
const recipe = getCraftingRecipe(recipeId);
|
|
|
|
// Consume ingredients
|
|
for (const ingredient of recipe.ingredients) {
|
|
playerInventory.removeItem(ingredient.item, ingredient.amount);
|
|
}
|
|
|
|
// Add result
|
|
playerInventory.addItem(recipe.result.item, recipe.result.amount);
|
|
|
|
console.log(`✅ Crafted ${recipe.result.amount}x ${recipe.name}`);
|
|
return true;
|
|
}
|
|
|
|
// Export for use in other systems
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = {
|
|
CRAFTING_RECIPES,
|
|
getCraftingRecipe,
|
|
canCraft,
|
|
craftItem
|
|
};
|
|
}
|