# 🛠️ Crafting System Guide Kompletni vodič za dodajanje in ustvarjanje crafting receptov v KRVAVA ŽETEV igri. --- ## 📖 Pregled Igra ima **crafting sistem** ki omogoča igralcu izdelovanje: - **Orodja** (sekira, kramp, motika) - **Orožje** (meč, lok) - **Zgradbe** (ograja, chest, furnace) - **Materiale** (palica, bakla) --- ## 📂 Lokacija Datotek ``` c:\novafarma\src\data\CraftingRecipes.js ← Vsi recepti c:\novafarma\src\systems\CraftingTiersSystem.js ← Tier sistem ``` --- ## 🎯 DVA FORMATA RECEPTOV ### **Format 1: Obstoječi (Podroben)** ✅ PRIPOROČENO ```javascript const CRAFTING_RECIPES = { '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.' } }; ``` **Prednosti:** - ✅ Podpira kategorije (tools, weapons, buildings...) - ✅ Podpira opise - ✅ Združljivo z obstoječim sistemom - ✅ Enostavno razširljivo --- ### **Format 2: Enostaven/Kompakten** ```javascript const craftingRecipes = { 'lesena_ograda': { requires: { 'wood': 2 }, yields: 5 }, 'sekira_osnovna': { requires: { 'wood': 3, 'stone': 2 }, yields: 1 } }; ``` **Prednosti:** - ✅ Krajši - ✅ Hitrejši za pisanje **Slabosti:** - ❌ Ni kategorij - ❌ Ni opisov - ❌ Potreben converter --- ## 🔧 Converter Funkcija Če želiš uporabljati enostavni format, uporabi converter: ```javascript /** * Pretvori enostavni format v obstoječi format * @param {Object} simpleRecipes - Enostavni format receptov * @returns {Object} - Obstoječi format receptov */ function convertToStandardFormat(simpleRecipes) { const standardRecipes = {}; for (const [id, recipe] of Object.entries(simpleRecipes)) { // Pretvori requires v ingredients array const ingredients = []; for (const [item, amount] of Object.entries(recipe.requires)) { ingredients.push({ item, amount }); } // Ustvari standardni format standardRecipes[id] = { id: id, name: id.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()), ingredients: ingredients, result: { item: id, amount: recipe.yields }, category: 'custom', description: `Crafted item: ${id}` }; } return standardRecipes; } // UPORABA: const enostavniRecepti = { 'lesena_ograda': { requires: { 'wood': 2 }, yields: 5 } }; const standardRecepti = convertToStandardFormat(enostavniRecepti); // Rezultat: // { // 'lesena_ograda': { // id: 'lesena_ograda', // name: 'Lesena Ograda', // ingredients: [{ item: 'wood', amount: 2 }], // result: { item: 'lesena_ograda', amount: 5 }, // category: 'custom', // description: 'Crafted item: lesena_ograda' // } // } ``` --- ## ✨ Kako Dodati Nov Recept ### **Korak 1: Odpri CraftingRecipes.js** ``` c:\novafarma\src\data\CraftingRecipes.js ``` ### **Korak 2: Dodaj Nov Recept** Najdi ustrezno kategorijo in dodaj: ```javascript const CRAFTING_RECIPES = { // ... obstoječi recepti ... // ================================== // CUSTOM RECIPES (Novi!) // ================================== '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.' } }; ``` ### **Korak 3: Shrani in Osveži** - Shrani datoteko - Osveži igro (Ctrl+R) - Odpri crafting menu (C tipka) --- ## 📋 Kategorije Receptov | Kategorija | Opis | Primeri | |------------|------|---------| | `tools` | Orodja | Sekira, kramp, motika | | `weapons` | Orožje | Meč, lok, kopje | | `buildings` | Zgradbe | Ograja, chest, furnace | | `materials` | Materiali | Palica, deska, bakla | | `storage` | Shranjevanje | Chest, barrel | | `workstation` | Delavnice | Furnace, anvil | | `lighting` | Svetloba | Bakla, svetilka | | `custom` | Po meri | Tvoji recepti | --- ## 🎮 Helper Funkcije ### **getCraftingRecipe(id)** ```javascript const recipe = getCraftingRecipe('lesena_ograda'); console.log(recipe.name); // "Lesena Ograda" console.log(recipe.ingredients); // [{ item: 'wood', amount: 2 }] ``` ### **canCraft(id, inventory)** ```javascript const canMake = canCraft('lesena_ograda', playerInventory); if (canMake) { console.log('✅ Lahko narediš ograjo!'); } else { console.log('❌ Manjka material!'); } ``` ### **craftItem(id, inventory)** ```javascript const success = craftItem('lesena_ograda', playerInventory); if (success) { console.log('🔨 Izdelano!'); // Inventory: wood -= 2, lesena_ograda += 5 } ``` --- ## 💡 Praktični Primeri ### **Primer 1: Enostavna Palica** ```javascript 'stick': { id: 'stick', name: 'Palica', ingredients: [ { item: 'wood', amount: 1 } ], result: { item: 'stick', amount: 4 }, category: 'materials', description: 'Osnoven material za crafting.' } ``` ### **Primer 2: Sekira (Več Ingredientov)** ```javascript 'stone_axe': { id: 'stone_axe', name: 'Kamnita Sekira', ingredients: [ { item: 'stone', amount: 3 }, { item: 'stick', amount: 2 } ], result: { item: 'stone_axe', amount: 1 }, category: 'tools', description: 'Izboljšana sekira za hitrejše sekanje.' } ``` ### **Primer 3: Furnace (Kompleksno)** ```javascript 'furnace': { id: 'furnace', name: 'Peč', ingredients: [ { item: 'stone', amount: 8 }, { item: 'coal', amount: 4 } ], result: { item: 'furnace', amount: 1 }, category: 'workstation', description: 'Topi rude v ingote.' } ``` --- --- ## 🔄 Crafting Funkcija Primerjava ### **Obstoječa Funkcija (Podroben Format)** ```javascript /** * 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; } // UPORABA: craftItem('lesena_ograda', playerInventory); // Rezultat: wood -= 2, lesena_ograda += 5 ``` --- ### **Enostavna Funkcija (Enostaven Format)** ```javascript /** * Poskuša izdelati določen predmet (Enostaven Format). * @param {string} recipeKey - Ime recepta (npr. 'lesena_ograda'). */ function craftItem(recipeKey) { const recipe = craftingRecipes[recipeKey]; if (!recipe) { console.error(`Recept '${recipeKey}' ne obstaja.`); return false; } // Preverimo, ali imamo dovolj vseh sestavin for (const requiredItem in recipe.requires) { const requiredAmount = recipe.requires[requiredItem]; // Če je predmeta manj v inventarju, ne moremo craftati! if (inventory[requiredItem] === undefined || inventory[requiredItem] < requiredAmount) { console.warn(`Ni dovolj ${requiredItem} za izdelavo ${recipeKey}. Potrebno: ${requiredAmount}, Imate: ${inventory[requiredItem] || 0}`); return false; } } // Če pridemo sem, imamo dovolj sestavin: // 1. Odstranimo porabljene sestavine iz inventarja for (const requiredItem in recipe.requires) { const requiredAmount = recipe.requires[requiredItem]; inventory[requiredItem] -= requiredAmount; } // 2. Dodamo izdelan predmet v inventar addItemToInventory(recipeKey, recipe.yields); console.log(`${recipeKey} uspešno izdelan!`); return true; } // UPORABA: craftItem('lesena_ograda'); // Rezultat: inventory.wood -= 2, inventory.lesena_ograda += 5 ``` --- ### **Primerjava Funkcij** | Lastnost | Obstoječa | Enostavna | |----------|-----------|-----------| | Format receptov | `ingredients: [{item, amount}]` | `requires: {item: amount}` | | Inventory sistem | Uporablja `playerInventory` objekt | Uporablja globalni `inventory` objekt | | Preverjanje | `canCraft()` helper funkcija | Direktno v funkciji | | Fleksibilnost | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | | Enostavnost | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | --- ### **Kdy Uporabiti Katero?** **Uporabi OBSTOJEČO funkcijo** če: - ✅ Uporabljaš InventorySystem class - ✅ Rabiš kategorije in opise - ✅ Delaš kompleksnejšo igro - ✅ Rabiš helper funkcije (`canCraft`, `getCraftingRecipe`) **Uporabi ENOSTAVNO funkcijo** če: - ✅ Imaš preprost inventory (object) - ✅ Delaš prototip/testiranje - ✅ Rabiš hitro implementacijo - ✅ Ne rabiš kategorij --- ## 🔍 Debugging ### **Problem: Recept ne deluje** ```javascript // Preveri če recept obstaja const recipe = getCraftingRecipe('moj_recept'); if (!recipe) { console.error('❌ Recept ne obstaja!'); } // Preveri ingrediente const canMake = canCraft('moj_recept', playerInventory); console.log('Can craft:', canMake); // Preveri inventory console.log('Player wood:', playerInventory.getItemCount('wood')); ``` ### **Problem: Material se ne porabi** ```javascript // Poglej craftItem funkcijo v CraftingRecipes.js // Preveri če removeItem() deluje: playerInventory.removeItem('wood', 2); console.log('Wood after:', playerInventory.getItemCount('wood')); ``` --- ## 🎨 Best Practices ### ✅ DO: - Uporabi smiselne ID-je (`stone_axe`, ne `item_123`) - Dodaj opise za vse recepte - Uporabi ustrezne kategorije - Testiraj recepte pred objavo ### ❌ DON'T: - Ne uporabljaj presledkov v ID-jih (`stone axe` ❌) - Ne pozabi `yields`/`result.amount` - Ne uporabljaj item-ov ki ne obstajajo --- ## 📊 Obstoječi Recepti Trenutno v igri: | Recept | Kategorija | Ingredienti | |--------|-----------|-------------| | Bone Pickaxe | tools | bone (3), wood (2) | | Bone Axe | tools | bone (3), wood (2) | | Bone Hoe | tools | bone (2), wood (2) | | Bone Sword | weapons | bone (2), wood (1) | | Wooden Pickaxe | tools | wood (3), stick (2) | | Stone Pickaxe | tools | stone (3), stick (2) | | Stick | materials | wood (1) → 4x | | Torch | lighting | stick (1), coal (1) → 4x | | Chest | storage | wood (8) | | Furnace | workstation | stone (8), coal (4) | --- ## 🚀 Naslednji Koraki 1. **Odpri** `c:\novafarma\src\data\CraftingRecipes.js` 2. **Dodaj** svoje recepte v ustrezno kategorijo 3. **Shrani** datoteko 4. **Osveži** igro (Ctrl+R) 5. **Testiraj** v crafting meniju (C tipka) --- **Zadnja posodobitev:** 14.12.2025 **Avtor:** KRVAVA ŽETEV Team **Status:** ✅ Ready to use **Lokacija:** `c:\novafarma\src\data\CraftingRecipes.js`