Files
novafarma/src/systems/BlueprintSystem.js
2025-12-08 14:01:41 +01:00

103 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* BLUEPRINT SYSTEM
* Manages unlocking crafting recipes via Blueprint items.
*/
class BlueprintSystem {
constructor(scene) {
this.scene = scene;
this.unlockedRecipes = new Set(); // Stores IDs of unlocked recipes
// Default unlocked recipes (Basic tools & structures)
this.unlockedRecipes.add('stick');
this.unlockedRecipes.add('plank');
this.unlockedRecipes.add('chest');
this.unlockedRecipes.add('fence');
this.unlockedRecipes.add('axe');
this.unlockedRecipes.add('pickaxe');
this.unlockedRecipes.add('hoe');
this.unlockedRecipes.add('sword');
this.unlockedRecipes.add('furnace');
this.unlockedRecipes.add('mint');
this.unlockedRecipes.add('grave');
// Blueprint Definitions (Item ID -> Recipe ID)
this.blueprints = {
'blueprint_furnace': 'furnace',
'blueprint_anvil': 'anvil',
'blueprint_scooter_part': 'scooter_engine', // Example special part
'blueprint_grave': 'gravestone'
};
}
/**
* Unlock a recipe
*/
unlockRecipe(recipeId) {
if (this.unlockedRecipes.has(recipeId)) {
console.log(` Recipe ${recipeId} already unlocked.`);
return false;
}
this.unlockedRecipes.add(recipeId);
console.log(`📜 UNLOCKED RECIPE: ${recipeId}`);
// Notification
this.scene.events.emit('show-floating-text', {
x: this.scene.player.sprite.x,
y: this.scene.player.sprite.y - 100,
text: `NEW RECIPE: ${recipeId.toUpperCase()}!`,
color: '#00FFFF'
});
if (this.scene.soundManager) this.scene.soundManager.playSuccess();
return true;
}
/**
* Check if unlocked
*/
isUnlocked(recipeId) {
return this.unlockedRecipes.has(recipeId);
}
/**
* Use a blueprint item from inventory
*/
useBlueprint(itemId) {
const recipeId = this.blueprints[itemId];
if (!recipeId) return false;
const success = this.unlockRecipe(recipeId);
if (success) {
// Consume item
this.scene.inventorySystem.removeItem(itemId, 1);
return true;
}
return false;
}
/**
* Try to get a blueprint drop from mining/killing
* @param {string} source 'mining', 'combat', 'chest'
*/
tryDropBlueprint(x, y, source) {
let chance = 0.05; // 5% base chance
if (source === 'boss') chance = 1.0;
if (source === 'chest') chance = 0.3;
if (Math.random() < chance) {
// Select random locked blueprint
const allBlueprints = Object.keys(this.blueprints);
const dropItem = allBlueprints[Math.floor(Math.random() * allBlueprints.length)];
// Check if user already has it unlocked? Maybe drop anyway for trading?
// For now, simple drop.
if (this.scene.interactionSystem) {
this.scene.interactionSystem.spawnLoot(x, y, dropItem, 1);
console.log(`📜 Dropped Blueprint: ${dropItem}`);
}
}
}
}