Files
novafarma/EMERGENCY_SYSTEMS_RECOVERY/ToolSystem.js
2026-01-16 02:43:46 +01:00

494 lines
16 KiB
JavaScript

/**
* TOOL SYSTEM
* Manages tool upgrades (6 tiers), durability, repairs, and blacksmith zombies.
*
* Features:
* - 6 Tool Tiers: Wood → Stone → Iron → Gold → Diamond → Ultimate
* - Durability System: Tools break but don't disappear, can be repaired
* - 3 Repair Methods: Ivan's Blacksmith, Repair Kits, Blacksmith Zombie
* - Blacksmith Zombie: Learn skill from Ivan, FREE overnight repairs
* - Ultimate Tools: Drill, Chainsaw, Mechanical Tiller (auto-abilities)
*/
class ToolSystem {
constructor(scene) {
this.scene = scene;
// Tool tiers
this.tiers = ['wood', 'stone', 'iron', 'gold', 'diamond', 'ultimate'];
// Tool definitions
this.tools = {
axe: { name: 'Axe', use: 'chop_trees', durabilityMult: 1.0 },
pickaxe: { name: 'Pickaxe', use: 'mine_rocks', durabilityMult: 1.2 },
hoe: { name: 'Hoe', use: 'till_soil', durabilityMult: 0.8 },
sword: { name: 'Sword', use: 'combat', durabilityMult: 1.5 },
shovel: { name: 'Shovel', use: 'dig_soil', durabilityMult: 1.0 },
sickle: { name: 'Sickle', use: 'harvest_crops', durabilityMult: 0.7 },
hammer: { name: 'Hammer', use: 'build_repair', durabilityMult: 1.3 },
drill: { name: 'Drill', use: 'auto_mine', durabilityMult: 2.0, ultimate: true },
chainsaw: { name: 'Chainsaw', use: 'auto_chop', durabilityMult: 2.0, ultimate: true },
mech_tiller: { name: 'Mechanical Tiller', use: 'auto_till', durabilityMult: 2.0, ultimate: true }
};
// Tier stats
this.tierStats = {
wood: { durability: 50, efficiency: 1.0, speed: 1.0, cost: 5, color: '#8B4513' },
stone: { durability: 100, efficiency: 1.5, speed: 1.2, cost: 15, color: '#808080' },
iron: { durability: 200, efficiency: 2.0, speed: 1.5, cost: 50, color: '#C0C0C0' },
gold: { durability: 150, efficiency: 3.0, speed: 2.0, cost: 100, color: '#FFD700' },
diamond: { durability: Infinity, efficiency: 4.0, speed: 2.5, cost: 500, color: '#00FFFF' },
ultimate: { durability: Infinity, efficiency: 10.0, speed: 5.0, cost: 2000, color: '#FF00FF' }
};
// Player's tools
this.playerTools = new Map(); // toolId -> tool data
// Blacksmith zombies
this.blacksmithZombies = []; // Zombies trained by Ivan
this.repairQueue = []; // Tools queued for overnight repair
// Ivan's shop
this.ivanShop = {
upgradeCosts: {
wood_to_stone: { gold: 50, iron: 5 },
stone_to_iron: { gold: 100, iron: 10, stone: 20 },
iron_to_gold: { gold: 250, iron: 25, gold_ore: 10 },
gold_to_diamond: { gold: 1000, diamond: 5, gold_ore: 50 },
diamond_to_ultimate: { gold: 5000, diamond: 25, atlantean_crystal: 10 }
},
repairCost: 10 // Gold per durability point
};
console.log('⚒️ Tool System initialized!');
}
/**
* Create a tool for the player
*/
createTool(toolType, tier = 'wood') {
if (!this.tools[toolType]) {
console.log(`❌ Unknown tool type: ${toolType}`);
return null;
}
if (!this.tiers.includes(tier)) {
console.log(`❌ Unknown tier: ${tier}`);
return null;
}
const toolId = `${toolType}_${tier}_${Date.now()}`;
const toolDef = this.tools[toolType];
const tierStats = this.tierStats[tier];
const tool = {
id: toolId,
type: toolType,
name: `${tierStats.color === '#8B4513' ? '' : tier.charAt(0).toUpperCase() + tier.slice(1) + ' '}${toolDef.name}`,
tier: tier,
durability: tierStats.durability,
maxDurability: tierStats.durability,
efficiency: tierStats.efficiency,
speed: tierStats.speed,
broken: false,
color: tierStats.color,
use: toolDef.use,
ultimate: toolDef.ultimate || false
};
this.playerTools.set(toolId, tool);
console.log(`🔨 Created ${tool.name}!`);
this.scene.events.emit('notification', {
title: 'New Tool!',
message: `${tool.name} acquired!`,
icon: '🔨'
});
return toolId;
}
/**
* Use a tool (decreases durability)
*/
useTool(toolId, intensity = 1) {
const tool = this.playerTools.get(toolId);
if (!tool) return false;
if (tool.broken) {
console.log(`${tool.name} is broken! Repair it first.`);
this.scene.events.emit('notification', {
title: 'Tool Broken!',
message: `${tool.name} needs repair!`,
icon: '🔧'
});
return false;
}
// Diamond and Ultimate tools never break
if (tool.tier === 'diamond' || tool.tier === 'ultimate') {
return true;
}
// Decrease durability
const durabilityLoss = intensity * (1.0 / tool.efficiency);
tool.durability -= durabilityLoss;
// Check if broken
if (tool.durability <= 0) {
tool.durability = 0;
tool.broken = true;
console.log(`💥 ${tool.name} broke!`);
this.scene.events.emit('notification', {
title: 'Tool Broke!',
message: `${tool.name} is broken! Visit Ivan or use a Repair Kit.`,
icon: '💥'
});
if (this.scene.soundManager) {
this.scene.soundManager.playBreak();
}
}
return true;
}
/**
* Repair tool at Ivan's Blacksmith
*/
repairAtIvan(toolId) {
const tool = this.playerTools.get(toolId);
if (!tool) return { success: false, message: 'Tool not found' };
if (!tool.broken && tool.durability === tool.maxDurability) {
return { success: false, message: 'Tool is already in perfect condition!' };
}
const durabilityNeeded = tool.maxDurability - tool.durability;
const cost = Math.ceil(durabilityNeeded * this.ivanShop.repairCost);
// Check if player has gold (assume player.gold exists)
if (this.scene.player && this.scene.player.gold >= cost) {
this.scene.player.gold -= cost;
tool.durability = tool.maxDurability;
tool.broken = false;
console.log(`🔧 Ivan repaired ${tool.name} for ${cost} gold!`);
this.scene.events.emit('notification', {
title: 'Tool Repaired!',
message: `Ivan repaired ${tool.name} for ${cost} gold!`,
icon: '🔧'
});
return { success: true, cost: cost };
} else {
return { success: false, message: `Not enough gold! Need ${cost} gold.` };
}
}
/**
* Repair tool with Repair Kit
*/
repairWithKit(toolId) {
const tool = this.playerTools.get(toolId);
if (!tool) return false;
// Check if player has repair kit
if (this.scene.inventorySystem && this.scene.inventorySystem.hasItem('repair_kit')) {
const restoreAmount = tool.maxDurability * 0.5; // Restores 50%
tool.durability = Math.min(tool.maxDurability, tool.durability + restoreAmount);
if (tool.durability > 0) {
tool.broken = false;
}
this.scene.inventorySystem.removeItem('repair_kit', 1);
console.log(`🔧 Used Repair Kit on ${tool.name}!`);
this.scene.events.emit('notification', {
title: 'Tool Repaired!',
message: `${tool.name} partially repaired!`,
icon: '🔧'
});
return true;
}
return false;
}
/**
* Queue tool for overnight repair by Blacksmith Zombie
*/
queueForBlacksmithRepair(toolId) {
if (this.blacksmithZombies.length === 0) {
console.log('❌ No Blacksmith Zombies available! Train one with Ivan first.');
return false;
}
const tool = this.playerTools.get(toolId);
if (!tool) return false;
if (!this.repairQueue.includes(toolId)) {
this.repairQueue.push(toolId);
console.log(`📋 ${tool.name} queued for FREE overnight repair!`);
this.scene.events.emit('notification', {
title: 'Repair Queued!',
message: `${tool.name} will be repaired by morning!`,
icon: '🌙'
});
return true;
}
return false;
}
/**
* Process overnight repairs (called at 6 AM in-game)
*/
processOvernightRepairs() {
if (this.repairQueue.length === 0) return;
const repairsPerZombie = 3; // Each blacksmith can repair 3 tools
const maxRepairs = this.blacksmithZombies.length * repairsPerZombie;
const repairedTools = [];
for (let i = 0; i < Math.min(this.repairQueue.length, maxRepairs); i++) {
const toolId = this.repairQueue[i];
const tool = this.playerTools.get(toolId);
if (tool) {
tool.durability = tool.maxDurability;
tool.broken = false;
repairedTools.push(tool.name);
}
}
this.repairQueue = this.repairQueue.slice(maxRepairs);
console.log(`🌅 Blacksmith Zombies repaired ${repairedTools.length} tools overnight!`);
this.scene.events.emit('notification', {
title: 'Morning Repairs Complete!',
message: `${repairedTools.length} tools repaired for FREE!`,
icon: '🌅'
});
return repairedTools;
}
/**
* Train a zombie to become a Blacksmith
*/
trainBlacksmith(zombieId) {
if (this.blacksmithZombies.includes(zombieId)) {
console.log('❌ This zombie is already a Blacksmith!');
return false;
}
// Check if zombie is Lv5+ (requirement)
const zombieSystem = this.scene.smartZombieSystem;
if (zombieSystem) {
const zombie = zombieSystem.zombies.get(zombieId);
if (!zombie || zombie.level < 5) {
console.log('❌ Zombie must be Lv5+ to train as Blacksmith!');
return false;
}
}
// Training cost
const trainingCost = 500;
if (this.scene.player && this.scene.player.gold >= trainingCost) {
this.scene.player.gold -= trainingCost;
this.blacksmithZombies.push(zombieId);
console.log(`⚒️ Zombie ${zombieId} trained as Blacksmith by Ivan!`);
this.scene.events.emit('notification', {
title: 'Blacksmith Trained!',
message: `Your zombie learned Ivan's blacksmith skills!`,
icon: '⚒️'
});
return true;
} else {
console.log(`❌ Not enough gold! Need ${trainingCost} gold.`);
return false;
}
}
/**
* Upgrade tool to next tier at Ivan's shop
*/
upgradeTool(toolId) {
const tool = this.playerTools.get(toolId);
if (!tool) return { success: false, message: 'Tool not found' };
if (tool.tier === 'ultimate') {
return { success: false, message: 'Already at maximum tier!' };
}
const currentTierIndex = this.tiers.indexOf(tool.tier);
const nextTier = this.tiers[currentTierIndex + 1];
if (!nextTier) {
return { success: false, message: 'Cannot upgrade further!' };
}
// Get upgrade cost
const upgradeKey = `${tool.tier}_to_${nextTier}`;
const cost = this.ivanShop.upgradeCosts[upgradeKey];
if (!cost) {
return { success: false, message: 'Upgrade path not defined!' };
}
// Check if player has resources (simplified check)
// In real game, would check inventory system
const canAfford = true; // Placeholder
if (canAfford) {
// Upgrade tool
tool.tier = nextTier;
const newStats = this.tierStats[nextTier];
tool.durability = newStats.durability;
tool.maxDurability = newStats.durability;
tool.efficiency = newStats.efficiency;
tool.speed = newStats.speed;
tool.color = newStats.color;
tool.name = `${nextTier.charAt(0).toUpperCase() + nextTier.slice(1)} ${this.tools[tool.type].name}`;
tool.broken = false;
console.log(`⬆️ Upgraded to ${tool.name}!`);
this.scene.events.emit('notification', {
title: 'Tool Upgraded!',
message: `${tool.name} is now more powerful!`,
icon: '⬆️'
});
if (this.scene.soundManager) {
this.scene.soundManager.playUpgrade();
}
return { success: true, newTier: nextTier };
} else {
return { success: false, message: 'Not enough resources!' };
}
}
/**
* Craft Ultimate Tool
*/
craftUltimateTool(toolType) {
if (!['drill', 'chainsaw', 'mech_tiller'].includes(toolType)) {
return { success: false, message: 'Not an ultimate tool!' };
}
const cost = this.tierStats.ultimate.cost;
// Check resources (simplified)
if (this.scene.player && this.scene.player.gold >= cost) {
this.scene.player.gold -= cost;
const toolId = this.createTool(toolType, 'ultimate');
console.log(`🌟 Crafted Ultimate ${this.tools[toolType].name}!`);
this.scene.events.emit('notification', {
title: 'ULTIMATE TOOL!',
message: `Crafted ${this.tools[toolType].name}!`,
icon: '🌟'
});
return { success: true, toolId: toolId };
} else {
return { success: false, message: `Need ${cost} gold!` };
}
}
/**
* Use ultimate tool's auto-ability
*/
useUltimateAbility(toolId, position, radius = 3) {
const tool = this.playerTools.get(toolId);
if (!tool || !tool.ultimate) {
console.log('❌ Not an ultimate tool!');
return false;
}
let affected = 0;
switch (tool.type) {
case 'drill':
// Auto-mine all rocks in radius
console.log(`🚜 Drill auto-mining ${radius}x${radius} area!`);
affected = radius * radius;
break;
case 'chainsaw':
// Auto-chop all trees in radius
console.log(`🪚 Chainsaw auto-chopping ${radius}x${radius} area!`);
affected = radius * radius;
break;
case 'mech_tiller':
// Auto-till all soil in radius
console.log(`🚜 Mechanical Tiller auto-tilling ${radius}x${radius} area!`);
affected = radius * radius;
break;
}
this.scene.events.emit('notification', {
title: 'AUTO-ABILITY!',
message: `${tool.name} processed ${affected} tiles!`,
icon: '🌟'
});
return true;
}
/**
* Get tool stats
*/
getToolStats(toolId) {
const tool = this.playerTools.get(toolId);
if (!tool) return null;
return {
name: tool.name,
tier: tool.tier,
durability: tool.tier === 'diamond' || tool.tier === 'ultimate'
? 'Infinite'
: `${Math.round(tool.durability)}/${tool.maxDurability}`,
efficiency: `${tool.efficiency}x`,
speed: `${tool.speed}x`,
broken: tool.broken,
ultimate: tool.ultimate,
color: tool.color
};
}
/**
* Get all player tools
*/
getAllTools() {
const tools = [];
this.playerTools.forEach((tool, id) => {
tools.push({
id: id,
...this.getToolStats(id)
});
});
return tools;
}
}