/** * PLAYER STATS - AGING SYSTEM IMPLEMENTATION * Handles Kai's visual aging based on story progression */ class PlayerStats { constructor(scene, player) { this.scene = scene; this.player = player; // Aging progression this.currentAge = 14; this.ageLevel = 1; // 1-9 this.memoriesFound = 0; this.totalMemories = 100; // Age to sprite mapping this.ageSpriteMap = { 1: 'kai_age14', // 0-10% memories 2: 'kai_age16', // 10-25% memories 3: 'kai_age20', // 25-35% memories 4: 'kai_age25', // 35-50% memories 5: 'kai_age30', // 50-60% memories 6: 'kai_age40', // 60-75% memories 7: 'kai_age50', // 75-90% memories 8: 'kai_age55', // 90-95% memories 9: 'kai_age60' // 95-100% memories }; // Age descriptions this.ageDescriptions = { 1: 'Confused teen, just awakened', 2: 'Young survivor, first memories', 3: 'Young adult, understanding loss', 4: 'Experienced survivor, battle-worn', 5: 'Hardened adult, haunted by past', 6: 'Weathered veteran, scars tell stories', 7: 'Wise elder, close to truth', 8: 'Ancient soul, nearly complete', 9: 'Elder guardian, all memories found' }; this.load(); } /** * UPDATE AGE BASED ON MEMORIES FOUND */ updateAge(memoriesFound) { this.memoriesFound = memoriesFound; const progress = (memoriesFound / this.totalMemories) * 100; let newAgeLevel = 1; let newAge = 14; // Calculate new age level based on progress if (progress >= 95) { newAgeLevel = 9; newAge = 60; } else if (progress >= 90) { newAgeLevel = 8; newAge = 55; } else if (progress >= 75) { newAgeLevel = 7; newAge = 50; } else if (progress >= 60) { newAgeLevel = 6; newAge = 40; } else if (progress >= 50) { newAgeLevel = 5; newAge = 30; } else if (progress >= 35) { newAgeLevel = 4; newAge = 25; } else if (progress >= 25) { newAgeLevel = 3; newAge = 20; } else if (progress >= 10) { newAgeLevel = 2; newAge = 16; } // Check if aged up if (newAgeLevel > this.ageLevel) { this.triggerAging(newAgeLevel, newAge); } this.save(); } /** * TRIGGER AGING CUTSCENE AND SPRITE CHANGE */ triggerAging(newLevel, newAge) { const oldAge = this.currentAge; const oldLevel = this.ageLevel; console.log(`⏰ KAI AGES UP!`); console.log(` ${oldAge} → ${newAge} years old`); console.log(` Level: ${oldLevel} → ${newLevel}`); // Update stats this.currentAge = newAge; this.ageLevel = newLevel; // Get new sprite key const newSprite = this.ageSpriteMap[newLevel]; const description = this.ageDescriptions[newLevel]; console.log(` Sprite: ${newSprite}`); console.log(` "${description}"`); // CHANGE PLAYER SPRITE this.changeSpriteToAge(newSprite); // PLAY AGING CUTSCENE this.playAgingCutscene(oldAge, newAge, newSprite, description); this.save(); } /** * CHANGE PLAYER'S SPRITE (VISUAL AGING) */ changeSpriteToAge(spriteKey) { if (!this.player) { console.error('❌ Player sprite not found!'); return; } // Store current position const x = this.player.x; const y = this.player.y; const flipX = this.player.flipX; // Change texture if (this.scene.textures.exists(spriteKey)) { this.player.setTexture(spriteKey); console.log(`✅ Player sprite changed to: ${spriteKey}`); } else { console.warn(`⚠️ Sprite ${spriteKey} not loaded, using default`); // Fall back to default if (this.scene.textures.exists('kai_age14')) { this.player.setTexture('kai_age14'); } } // Restore position this.player.setPosition(x, y); this.player.setFlipX(flipX); } /** * PLAY AGING CUTSCENE */ playAgingCutscene(oldAge, newAge, newSprite, description) { // Fade to black const width = this.scene.cameras.main.width; const height = this.scene.cameras.main.height; const blackScreen = this.scene.add.rectangle( width / 2, height / 2, width, height, 0x000000, 0 ); blackScreen.setDepth(1000); blackScreen.setScrollFactor(0); // Fade in this.scene.tweens.add({ targets: blackScreen, alpha: 1, duration: 1000, onComplete: () => { // Show aging message const agingText = this.scene.add.text( width / 2, height / 2, [ 'TIME PASSES...', '', `Age ${oldAge} → Age ${newAge}`, '', `"${description}"` ], { fontSize: '24px', fontFamily: 'Georgia, serif', color: '#f4e4c1', align: 'center', stroke: '#000000', strokeThickness: 6 } ); agingText.setOrigin(0.5); agingText.setDepth(1001); agingText.setScrollFactor(0); agingText.setAlpha(0); // Fade in text this.scene.tweens.add({ targets: agingText, alpha: 1, duration: 1000, delay: 500, onComplete: () => { // Hold for 3 seconds this.scene.time.delayedCall(3000, () => { // Fade out this.scene.tweens.add({ targets: [blackScreen, agingText], alpha: 0, duration: 1500, onComplete: () => { blackScreen.destroy(); agingText.destroy(); } }); }); } }); } }); // Emit event for other systems this.scene.events.emit('kai-aged', { oldAge: oldAge, newAge: newAge, level: this.ageLevel, sprite: newSprite, description: description }); } /** * GET CURRENT AGE INFO */ getAgeInfo() { return { age: this.currentAge, level: this.ageLevel, sprite: this.ageSpriteMap[this.ageLevel], description: this.ageDescriptions[this.ageLevel], memories: this.memoriesFound, progress: (this.memoriesFound / this.totalMemories) * 100 }; } /** * MANUALLY SET AGE (for testing) */ setAge(ageLevel) { if (ageLevel < 1) ageLevel = 1; if (ageLevel > 9) ageLevel = 9; const ages = [14, 16, 20, 25, 30, 40, 50, 55, 60]; const newAge = ages[ageLevel - 1]; this.triggerAging(ageLevel, newAge); } /** * SAVE TO LOCALSTORAGE */ save() { const data = { currentAge: this.currentAge, ageLevel: this.ageLevel, memoriesFound: this.memoriesFound }; localStorage.setItem('player_stats', JSON.stringify(data)); } /** * LOAD FROM LOCALSTORAGE */ load() { const stored = localStorage.getItem('player_stats'); if (!stored) return; try { const data = JSON.parse(stored); this.currentAge = data.currentAge || 14; this.ageLevel = data.ageLevel || 1; this.memoriesFound = data.memoriesFound || 0; console.log('📊 Player stats loaded:', this.getAgeInfo()); } catch (e) { console.warn('Failed to load player stats:', e); } } /** * RESET (for new game) */ reset() { this.currentAge = 14; this.ageLevel = 1; this.memoriesFound = 0; localStorage.removeItem('player_stats'); console.log('🔄 Player stats reset to age 14'); } } export default PlayerStats;