import { Component } from '../core/Component.js'; import { GameConfig } from '../GameConfig.js'; import { Events } from '../core/EventBus.js'; export class Evolution extends Component { constructor() { super('Evolution'); this.human = 0; this.beast = 0; this.slime = 100; // Start as pure slime // Mutation tracking this.mutations = new Set(); // Use Set for unique functional mutations this.mutationEffects = { electricSkin: false, glowingBody: false, hardenedShell: false }; } /** * Check and apply functional mutations */ checkMutations(stats, engine = null) { if (!stats) return; const config = GameConfig.Evolution.thresholds; // Threshold-based functional mutations if (stats.constitution > config.hardenedShell.constitution && !this.mutationEffects.hardenedShell) { this.mutationEffects.hardenedShell = true; this.mutations.add('Hardened Shell'); if (engine) engine.emit(Events.MUTATION_GAINED, { name: 'Hardened Shell', description: 'Defense Up' }); console.log("Mutation Gained: Hardened Shell (Defense Up)"); } if (stats.intelligence > config.electricSkin.intelligence && !this.mutationEffects.electricSkin) { this.mutationEffects.electricSkin = true; this.mutations.add('Electric Skin'); if (engine) engine.emit(Events.MUTATION_GAINED, { name: 'Electric Skin', description: 'Damage Reflection' }); console.log("Mutation Gained: Electric Skin (Damage Reflection)"); } if (this.human > config.glowingBody.human && !this.mutationEffects.glowingBody) { this.mutationEffects.glowingBody = true; this.mutations.add('Bioluminescence'); if (engine) engine.emit(Events.MUTATION_GAINED, { name: 'Bioluminescence', description: 'Light Source' }); console.log("Mutation Gained: Bioluminescence (Light Source)"); } } /** * Add evolution points */ addEvolution(human = 0, beast = 0, slime = 0) { this.human += human; this.beast += beast; this.slime += slime; // Normalize to keep total around target const target = GameConfig.Evolution.totalTarget; const total = this.human + this.beast + this.slime; if (total > target) { const factor = target / total; this.human *= factor; this.beast *= factor; this.slime *= factor; } // Ensure no negative values this.human = Math.max(0, this.human); this.beast = Math.max(0, this.beast); this.slime = Math.max(0, this.slime); } /** * Get dominant form */ getDominantForm() { if (this.human > this.beast && this.human > this.slime) { return 'human'; } else if (this.beast > this.human && this.beast > this.slime) { return 'beast'; } else { return 'slime'; } } /** * Get form percentage (0-1) */ getFormPercentage(form) { const total = this.human + this.beast + this.slime; if (total === 0) return 0; return this[form] / total; } /** * Add a mutation */ addMutation(mutation) { this.mutations.push(mutation); } }