narejeno
This commit is contained in:
377
src/systems/CraftingTiersSystem.js
Normal file
377
src/systems/CraftingTiersSystem.js
Normal file
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* CRAFTING TIERS SYSTEM
|
||||
* Tool tiers, durability, and repair mechanics
|
||||
*/
|
||||
class CraftingTiersSystem {
|
||||
constructor(scene) {
|
||||
this.scene = scene;
|
||||
this.enabled = true;
|
||||
|
||||
// Tool tiers
|
||||
this.tiers = {
|
||||
wood: { name: 'Wooden', durability: 50, speed: 1.0, damage: 1.0, color: 0x8B4513 },
|
||||
bronze: { name: 'Bronze', durability: 150, speed: 1.2, damage: 1.3, color: 0xCD7F32 },
|
||||
iron: { name: 'Iron', durability: 300, speed: 1.5, damage: 1.6, color: 0xC0C0C0 },
|
||||
steel: { name: 'Steel', durability: 600, speed: 1.8, damage: 2.0, color: 0x4682B4 },
|
||||
enchanted: { name: 'Enchanted', durability: 1200, speed: 2.5, damage: 3.0, color: 0x9370DB }
|
||||
};
|
||||
|
||||
// Tool types
|
||||
this.toolTypes = ['sword', 'pickaxe', 'axe', 'hoe', 'shovel'];
|
||||
|
||||
// Player's tools
|
||||
this.playerTools = new Map();
|
||||
|
||||
// Crafting recipes
|
||||
this.recipes = new Map();
|
||||
|
||||
this.loadProgress();
|
||||
this.init();
|
||||
|
||||
console.log('✅ Crafting Tiers System initialized');
|
||||
}
|
||||
|
||||
init() {
|
||||
this.defineRecipes();
|
||||
console.log('⚒️ Crafting recipes ready');
|
||||
}
|
||||
|
||||
// ========== RECIPE DEFINITIONS ==========
|
||||
|
||||
defineRecipes() {
|
||||
// BRONZE TIER (Copper + Tin)
|
||||
this.defineRecipe('bronze_sword', {
|
||||
name: 'Bronze Sword',
|
||||
tier: 'bronze',
|
||||
type: 'sword',
|
||||
materials: { copper: 3, tin: 1 },
|
||||
unlockLevel: 5
|
||||
});
|
||||
|
||||
this.defineRecipe('bronze_pickaxe', {
|
||||
name: 'Bronze Pickaxe',
|
||||
tier: 'bronze',
|
||||
type: 'pickaxe',
|
||||
materials: { copper: 3, tin: 1, wood: 2 },
|
||||
unlockLevel: 5
|
||||
});
|
||||
|
||||
this.defineRecipe('bronze_axe', {
|
||||
name: 'Bronze Axe',
|
||||
tier: 'bronze',
|
||||
type: 'axe',
|
||||
materials: { copper: 3, tin: 1, wood: 2 },
|
||||
unlockLevel: 5
|
||||
});
|
||||
|
||||
// IRON TIER
|
||||
this.defineRecipe('iron_sword', {
|
||||
name: 'Iron Sword',
|
||||
tier: 'iron',
|
||||
type: 'sword',
|
||||
materials: { iron: 5 },
|
||||
unlockLevel: 10
|
||||
});
|
||||
|
||||
this.defineRecipe('iron_pickaxe', {
|
||||
name: 'Iron Pickaxe',
|
||||
tier: 'iron',
|
||||
type: 'pickaxe',
|
||||
materials: { iron: 5, wood: 3 },
|
||||
unlockLevel: 10
|
||||
});
|
||||
|
||||
this.defineRecipe('iron_axe', {
|
||||
name: 'Iron Axe',
|
||||
tier: 'iron',
|
||||
type: 'axe',
|
||||
materials: { iron: 5, wood: 3 },
|
||||
unlockLevel: 10
|
||||
});
|
||||
|
||||
// STEEL TIER (Iron + Coal)
|
||||
this.defineRecipe('steel_sword', {
|
||||
name: 'Steel Sword',
|
||||
tier: 'steel',
|
||||
type: 'sword',
|
||||
materials: { iron: 5, coal: 3 },
|
||||
unlockLevel: 20
|
||||
});
|
||||
|
||||
this.defineRecipe('steel_pickaxe', {
|
||||
name: 'Steel Pickaxe',
|
||||
tier: 'steel',
|
||||
type: 'pickaxe',
|
||||
materials: { iron: 5, coal: 3, wood: 2 },
|
||||
unlockLevel: 20
|
||||
});
|
||||
|
||||
// ENCHANTED TIER (Magical)
|
||||
this.defineRecipe('enchanted_sword', {
|
||||
name: 'Enchanted Sword',
|
||||
tier: 'enchanted',
|
||||
type: 'sword',
|
||||
materials: { steel_sword: 1, magic_crystal: 5, dragon_scale: 3 },
|
||||
unlockLevel: 30
|
||||
});
|
||||
}
|
||||
|
||||
defineRecipe(id, data) {
|
||||
this.recipes.set(id, {
|
||||
id,
|
||||
...data
|
||||
});
|
||||
}
|
||||
|
||||
// ========== CRAFTING ==========
|
||||
|
||||
canCraft(recipeId) {
|
||||
const recipe = this.recipes.get(recipeId);
|
||||
if (!recipe) return false;
|
||||
|
||||
// Check level requirement
|
||||
if (this.scene.skillTree && this.scene.skillTree.playerLevel < recipe.unlockLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check materials
|
||||
if (!this.scene.inventorySystem) return false;
|
||||
|
||||
for (const [material, amount] of Object.entries(recipe.materials)) {
|
||||
const has = this.scene.inventorySystem.getItemCount(material);
|
||||
if (has < amount) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
craft(recipeId) {
|
||||
if (!this.canCraft(recipeId)) {
|
||||
console.log('❌ Cannot craft:', recipeId);
|
||||
return false;
|
||||
}
|
||||
|
||||
const recipe = this.recipes.get(recipeId);
|
||||
|
||||
// Consume materials
|
||||
for (const [material, amount] of Object.entries(recipe.materials)) {
|
||||
this.scene.inventorySystem.removeItem(material, amount);
|
||||
}
|
||||
|
||||
// Create tool
|
||||
const tool = this.createTool(recipe.tier, recipe.type);
|
||||
this.playerTools.set(`${recipe.type}_${recipe.tier}`, tool);
|
||||
|
||||
// Add to inventory
|
||||
if (this.scene.inventorySystem) {
|
||||
this.scene.inventorySystem.addItem(recipeId, 1);
|
||||
}
|
||||
|
||||
// Unlock achievement
|
||||
if (this.scene.uiGraphics) {
|
||||
if (recipe.tier === 'enchanted') {
|
||||
this.scene.uiGraphics.unlockAchievement('master_crafter');
|
||||
}
|
||||
}
|
||||
|
||||
this.saveProgress();
|
||||
console.log(`✅ Crafted: ${recipe.name}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========== TOOL MANAGEMENT ==========
|
||||
|
||||
createTool(tier, type) {
|
||||
const tierData = this.tiers[tier];
|
||||
|
||||
return {
|
||||
tier,
|
||||
type,
|
||||
durability: tierData.durability,
|
||||
maxDurability: tierData.durability,
|
||||
speed: tierData.speed,
|
||||
damage: tierData.damage,
|
||||
color: tierData.color,
|
||||
enchantments: []
|
||||
};
|
||||
}
|
||||
|
||||
getTool(type) {
|
||||
// Get best available tool of this type
|
||||
const tierOrder = ['enchanted', 'steel', 'iron', 'bronze', 'wood'];
|
||||
|
||||
for (const tier of tierOrder) {
|
||||
const key = `${type}_${tier}`;
|
||||
const tool = this.playerTools.get(key);
|
||||
if (tool && tool.durability > 0) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
useTool(type, amount = 1) {
|
||||
const tool = this.getTool(type);
|
||||
if (!tool) return false;
|
||||
|
||||
tool.durability -= amount;
|
||||
|
||||
// Tool broke
|
||||
if (tool.durability <= 0) {
|
||||
tool.durability = 0;
|
||||
console.log(`💔 ${this.tiers[tool.tier].name} ${tool.type} broke!`);
|
||||
|
||||
// Visual effect
|
||||
if (this.scene.visualEnhancements) {
|
||||
const player = this.scene.player;
|
||||
if (player) {
|
||||
const pos = player.getPosition();
|
||||
this.scene.visualEnhancements.createSparkleEffect(pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.saveProgress();
|
||||
return true;
|
||||
}
|
||||
|
||||
getToolDurabilityPercent(type) {
|
||||
const tool = this.getTool(type);
|
||||
if (!tool) return 0;
|
||||
|
||||
return (tool.durability / tool.maxDurability) * 100;
|
||||
}
|
||||
|
||||
// ========== TOOL REPAIR ==========
|
||||
|
||||
canRepair(type) {
|
||||
const tool = this.getTool(type);
|
||||
if (!tool || tool.durability === tool.maxDurability) return false;
|
||||
|
||||
// Check materials
|
||||
const repairCost = this.getRepairCost(tool);
|
||||
if (!this.scene.inventorySystem) return false;
|
||||
|
||||
for (const [material, amount] of Object.entries(repairCost)) {
|
||||
const has = this.scene.inventorySystem.getItemCount(material);
|
||||
if (has < amount) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
getRepairCost(tool) {
|
||||
const durabilityLost = tool.maxDurability - tool.durability;
|
||||
const repairPercent = durabilityLost / tool.maxDurability;
|
||||
|
||||
// Cost scales with damage
|
||||
const baseCost = {
|
||||
wood: { wood: 2 },
|
||||
bronze: { copper: 2, tin: 1 },
|
||||
iron: { iron: 3 },
|
||||
steel: { iron: 3, coal: 2 },
|
||||
enchanted: { magic_crystal: 2 }
|
||||
};
|
||||
|
||||
const cost = {};
|
||||
const tierCost = baseCost[tool.tier];
|
||||
|
||||
for (const [material, amount] of Object.entries(tierCost)) {
|
||||
cost[material] = Math.ceil(amount * repairPercent);
|
||||
}
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
repair(type) {
|
||||
if (!this.canRepair(type)) {
|
||||
console.log('❌ Cannot repair:', type);
|
||||
return false;
|
||||
}
|
||||
|
||||
const tool = this.getTool(type);
|
||||
const cost = this.getRepairCost(tool);
|
||||
|
||||
// Consume materials
|
||||
for (const [material, amount] of Object.entries(cost)) {
|
||||
this.scene.inventorySystem.removeItem(material, amount);
|
||||
}
|
||||
|
||||
// Repair tool
|
||||
tool.durability = tool.maxDurability;
|
||||
|
||||
// Visual effect
|
||||
if (this.scene.visualEnhancements) {
|
||||
const player = this.scene.player;
|
||||
if (player) {
|
||||
const pos = player.getPosition();
|
||||
this.scene.visualEnhancements.createSparkleEffect(pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
|
||||
this.saveProgress();
|
||||
console.log(`🔧 Repaired: ${this.tiers[tool.tier].name} ${tool.type}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========== ENCHANTMENTS ==========
|
||||
|
||||
enchantTool(type, enchantment) {
|
||||
const tool = this.getTool(type);
|
||||
if (!tool || tool.tier !== 'enchanted') return false;
|
||||
|
||||
tool.enchantments.push(enchantment);
|
||||
this.saveProgress();
|
||||
console.log(`✨ Enchanted ${tool.type} with ${enchantment}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========== PERSISTENCE ==========
|
||||
|
||||
saveProgress() {
|
||||
const data = {
|
||||
tools: {}
|
||||
};
|
||||
|
||||
for (const [key, tool] of this.playerTools.entries()) {
|
||||
data.tools[key] = {
|
||||
tier: tool.tier,
|
||||
type: tool.type,
|
||||
durability: tool.durability,
|
||||
enchantments: tool.enchantments
|
||||
};
|
||||
}
|
||||
|
||||
localStorage.setItem('novafarma_crafting_tiers', JSON.stringify(data));
|
||||
}
|
||||
|
||||
loadProgress() {
|
||||
const saved = localStorage.getItem('novafarma_crafting_tiers');
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved);
|
||||
|
||||
for (const [key, toolData] of Object.entries(data.tools)) {
|
||||
const tool = this.createTool(toolData.tier, toolData.type);
|
||||
tool.durability = toolData.durability;
|
||||
tool.enchantments = toolData.enchantments || [];
|
||||
this.playerTools.set(key, tool);
|
||||
}
|
||||
|
||||
console.log('✅ Crafting progress loaded');
|
||||
} catch (error) {
|
||||
console.error('Failed to load crafting progress:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.saveProgress();
|
||||
console.log('⚒️ Crafting Tiers System destroyed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user