298 lines
9.1 KiB
JavaScript
298 lines
9.1 KiB
JavaScript
/**
|
|
* MAGIC ENCHANTING SYSTEM
|
|
* Enhance tools with magical properties
|
|
*
|
|
* Features:
|
|
* - 5 Enchantment Types: Power, Speed, Fortune, Unbreaking, Auto-Collect
|
|
* - 3 Enchantment Levels per type
|
|
* - Costs mana + rare materials
|
|
* - Glowing visual effects
|
|
* - Can stack multiple enchantments
|
|
*/
|
|
class MagicEnchantingSystem {
|
|
constructor(scene) {
|
|
this.scene = scene;
|
|
|
|
// Enchantment definitions
|
|
this.enchantments = {
|
|
power: {
|
|
name: 'Power',
|
|
icon: '⚡',
|
|
description: 'Increases tool efficiency',
|
|
levels: [
|
|
{ level: 1, bonus: 0.25, cost: { mana: 50, crystal: 1 } },
|
|
{ level: 2, bonus: 0.50, cost: { mana: 100, crystal: 3 } },
|
|
{ level: 3, bonus: 1.00, cost: { mana: 200, crystal: 10 } }
|
|
],
|
|
color: 0xFF4444
|
|
},
|
|
speed: {
|
|
name: 'Speed',
|
|
icon: '⚡',
|
|
description: 'Increases tool speed',
|
|
levels: [
|
|
{ level: 1, bonus: 0.20, cost: { mana: 50, feather: 5 } },
|
|
{ level: 2, bonus: 0.40, cost: { mana: 100, feather: 15 } },
|
|
{ level: 3, bonus: 0.80, cost: { mana: 200, feather: 50 } }
|
|
],
|
|
color: 0x44FF44
|
|
},
|
|
fortune: {
|
|
name: 'Fortune',
|
|
icon: '💎',
|
|
description: 'Chance for double drops',
|
|
levels: [
|
|
{ level: 1, bonus: 0.15, cost: { mana: 75, emerald: 1 } },
|
|
{ level: 2, bonus: 0.30, cost: { mana: 150, emerald: 3 } },
|
|
{ level: 3, bonus: 0.50, cost: { mana: 300, emerald: 10 } }
|
|
],
|
|
color: 0x44FFFF
|
|
},
|
|
unbreaking: {
|
|
name: 'Unbreaking',
|
|
icon: '🛡️',
|
|
description: 'Reduces durability loss',
|
|
levels: [
|
|
{ level: 1, bonus: 0.30, cost: { mana: 60, obsidian: 5 } },
|
|
{ level: 2, bonus: 0.50, cost: { mana: 120, obsidian: 15 } },
|
|
{ level: 3, bonus: 0.75, cost: { mana: 250, obsidian: 50 } }
|
|
],
|
|
color: 0xFF44FF
|
|
},
|
|
auto_collect: {
|
|
name: 'Auto-Collect',
|
|
icon: '🌀',
|
|
description: 'Automatically collects drops',
|
|
levels: [
|
|
{ level: 1, bonus: 1.0, cost: { mana: 100, void_essence: 1 } },
|
|
{ level: 2, bonus: 2.0, cost: { mana: 200, void_essence: 3 } },
|
|
{ level: 3, bonus: 3.0, cost: { mana: 400, void_essence: 10 } }
|
|
],
|
|
color: 0x9D4EDD
|
|
}
|
|
};
|
|
|
|
// Enchanting table locations (town)
|
|
this.enchantingTables = [];
|
|
|
|
console.log('✨ Magic Enchanting System initialized');
|
|
}
|
|
|
|
/**
|
|
* Enchant a tool
|
|
*/
|
|
enchantTool(toolId, enchantmentType, level = 1) {
|
|
const toolSystem = this.scene.toolSystem;
|
|
if (!toolSystem) {
|
|
return { success: false, message: 'Tool system not available' };
|
|
}
|
|
|
|
const tool = toolSystem.playerTools.get(toolId);
|
|
if (!tool) {
|
|
return { success: false, message: 'Tool not found' };
|
|
}
|
|
|
|
const enchantment = this.enchantments[enchantmentType];
|
|
if (!enchantment) {
|
|
return { success: false, message: 'Unknown enchantment' };
|
|
}
|
|
|
|
if (level < 1 || level > 3) {
|
|
return { success: false, message: 'Invalid enchantment level' };
|
|
}
|
|
|
|
// Check if tool already has this enchantment
|
|
if (!tool.enchantments) {
|
|
tool.enchantments = {};
|
|
}
|
|
|
|
if (tool.enchantments[enchantmentType]) {
|
|
return { success: false, message: 'Tool already has this enchantment!' };
|
|
}
|
|
|
|
// Get cost
|
|
const levelData = enchantment.levels[level - 1];
|
|
const cost = levelData.cost;
|
|
|
|
// Check mana
|
|
if (this.scene.player && this.scene.player.mana < cost.mana) {
|
|
return { success: false, message: `Need ${cost.mana} mana!` };
|
|
}
|
|
|
|
// Check materials (simplified - would check inventory)
|
|
const canAfford = true; // TODO: Check inventory
|
|
|
|
if (!canAfford) {
|
|
return { success: false, message: 'Not enough materials!' };
|
|
}
|
|
|
|
// Apply enchantment
|
|
tool.enchantments[enchantmentType] = {
|
|
level: level,
|
|
bonus: levelData.bonus,
|
|
color: enchantment.color
|
|
};
|
|
|
|
// Deduct mana
|
|
if (this.scene.player) {
|
|
this.scene.player.mana -= cost.mana;
|
|
}
|
|
|
|
// Apply bonus to tool stats
|
|
this.applyEnchantmentBonus(tool, enchantmentType, levelData.bonus);
|
|
|
|
console.log(`✨ Enchanted ${tool.name} with ${enchantment.name} ${level}!`);
|
|
|
|
this.scene.events.emit('notification', {
|
|
title: 'Tool Enchanted!',
|
|
message: `${enchantment.icon} ${enchantment.name} ${level} applied!`,
|
|
icon: '✨'
|
|
});
|
|
|
|
return { success: true, enchantment: enchantmentType, level: level };
|
|
}
|
|
|
|
/**
|
|
* Apply enchantment bonus to tool
|
|
*/
|
|
applyEnchantmentBonus(tool, type, bonus) {
|
|
switch (type) {
|
|
case 'power':
|
|
tool.efficiency += bonus;
|
|
break;
|
|
case 'speed':
|
|
tool.speed += bonus;
|
|
break;
|
|
case 'fortune':
|
|
tool.fortuneChance = bonus;
|
|
break;
|
|
case 'unbreaking':
|
|
tool.durabilityMultiplier = 1 - bonus; // 30% less durability loss
|
|
break;
|
|
case 'auto_collect':
|
|
tool.autoCollect = true;
|
|
tool.autoCollectRadius = bonus;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove enchantment (costs mana)
|
|
*/
|
|
removeEnchantment(toolId, enchantmentType) {
|
|
const toolSystem = this.scene.toolSystem;
|
|
const tool = toolSystem.playerTools.get(toolId);
|
|
|
|
if (!tool || !tool.enchantments || !tool.enchantments[enchantmentType]) {
|
|
return { success: false, message: 'Enchantment not found' };
|
|
}
|
|
|
|
const cost = 25; // Mana cost to remove
|
|
|
|
if (this.scene.player && this.scene.player.mana >= cost) {
|
|
this.scene.player.mana -= cost;
|
|
|
|
// Remove bonus
|
|
const enchantData = tool.enchantments[enchantmentType];
|
|
this.removeEnchantmentBonus(tool, enchantmentType, enchantData.bonus);
|
|
|
|
delete tool.enchantments[enchantmentType];
|
|
|
|
console.log(`🔮 Removed enchantment from ${tool.name}`);
|
|
|
|
return { success: true };
|
|
}
|
|
|
|
return { success: false, message: 'Not enough mana' };
|
|
}
|
|
|
|
/**
|
|
* Remove enchantment bonus from tool
|
|
*/
|
|
removeEnchantmentBonus(tool, type, bonus) {
|
|
switch (type) {
|
|
case 'power':
|
|
tool.efficiency -= bonus;
|
|
break;
|
|
case 'speed':
|
|
tool.speed -= bonus;
|
|
break;
|
|
case 'fortune':
|
|
tool.fortuneChance = 0;
|
|
break;
|
|
case 'unbreaking':
|
|
tool.durabilityMultiplier = 1.0;
|
|
break;
|
|
case 'auto_collect':
|
|
tool.autoCollect = false;
|
|
tool.autoCollectRadius = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get all enchantments on a tool
|
|
*/
|
|
getToolEnchantments(toolId) {
|
|
const toolSystem = this.scene.toolSystem;
|
|
const tool = toolSystem.playerTools.get(toolId);
|
|
|
|
if (!tool || !tool.enchantments) {
|
|
return [];
|
|
}
|
|
|
|
const enchantments = [];
|
|
for (const [type, data] of Object.entries(tool.enchantments)) {
|
|
const enchant = this.enchantments[type];
|
|
enchantments.push({
|
|
type: type,
|
|
name: enchant.name,
|
|
level: data.level,
|
|
bonus: data.bonus,
|
|
icon: enchant.icon,
|
|
color: data.color
|
|
});
|
|
}
|
|
|
|
return enchantments;
|
|
}
|
|
|
|
/**
|
|
* Build enchanting table in town
|
|
*/
|
|
buildEnchantingTable(x, y) {
|
|
const table = {
|
|
id: `enchanting_${Date.now()}`,
|
|
x: x,
|
|
y: y,
|
|
type: 'enchanting_table',
|
|
active: true
|
|
};
|
|
|
|
this.enchantingTables.push(table);
|
|
|
|
console.log(`✨ Built Enchanting Table at (${x}, ${y})`);
|
|
|
|
this.scene.events.emit('notification', {
|
|
title: 'Enchanting Table Built!',
|
|
message: 'You can now enchant your tools!',
|
|
icon: '✨'
|
|
});
|
|
|
|
return table;
|
|
}
|
|
|
|
/**
|
|
* Check if near enchanting table
|
|
*/
|
|
isNearEnchantingTable(x, y, radius = 3) {
|
|
for (const table of this.enchantingTables) {
|
|
const distance = Phaser.Math.Distance.Between(x, y, table.x, table.y);
|
|
if (distance <= radius) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|