/** * GenerationalGameplaySystem.js * ============================== * KRVAVA Ε½ETEV - Generational Gameplay System (P12) * * Features: * - Permadeath mode * - Character switching (Kai β†’ Child) * - Inheritance system * - NPC memory system * - Multi-generation gameplay * - Legacy tracking * * @author NovaFarma Team * @date 2025-12-23 */ export default class GenerationalGameplaySystem { constructor(scene) { this.scene = scene; // Generational data this.generations = []; this.currentGeneration = 0; this.currentProtagonist = null; // Legacy tracking this.familyTree = new Map(); // personId -> family data this.legacyPoints = 0; this.familyAchievements = []; // NPC memory this.npcMemories = new Map(); // npcId -> memories // Permadeath settings this.permadeathEnabled = true; this.hasGameOver = false; console.log('⚰️ GenerationalGameplaySystem initialized'); // Initialize first generation (Kai) this.initializeKai(); } /** * Initialize Kai as Generation 1 */ initializeKai() { const kai = { id: 'kai_gen1', name: 'Kai', generation: 1, age: 25, isProtagonist: true, isAlive: true, isPlayer: true, // Family spouse: null, children: [], parents: [], // Stats stats: { itemsCollected: 0, zombiesTamed: 0, bossesDefeated: 0, questsCompleted: 0 }, // Legacy accomplishments: [], deathDate: null, causeOfDeath: null, graveLocation: null }; this.familyTree.set(kai.id, kai); this.currentProtagonist = kai; this.generations.push([kai]); console.log('πŸ‘€ Generation 1: Kai initialized'); } /** * 12.1 - Handle player death (Permadeath) */ handlePlayerDeath(causeOfDeath = 'unknown') { if (!this.permadeathEnabled) { console.log('⚠️ Permadeath disabled, respawning...'); return false; } const protagonist = this.currentProtagonist; if (!protagonist) return false; console.log(`⚰️ ${protagonist.name} has died! (${causeOfDeath})`); // Mark as dead protagonist.isAlive = false; protagonist.isPlayer = false; protagonist.deathDate = this.scene.timeSystem?.getCurrentDate() || new Date(); protagonist.causeOfDeath = causeOfDeath; // Check for adult children const adultChildren = this.getAdultChildren(protagonist.id); if (adultChildren.length === 0) { // GAME OVER - No heir this.triggerGameOver(); return true; } // Legacy transition this.triggerLegacyTransition(protagonist, adultChildren); return true; } /** * 12.1 - Trigger game over (no heir) */ triggerGameOver() { this.hasGameOver = true; console.log('πŸ’€ GAME OVER - No living heir!'); // TODO: Show game over screen with legacy stats this.showNotification({ title: 'Legacy Ended', text: 'The bloodline has ended. Your legacy is complete.', icon: '⚰️' }); // Show final stats this.showLegacyStats(); } /** * 12.2 - Legacy transition cutscene */ triggerLegacyTransition(deceased, heirs) { console.log(`πŸŒ… Legacy transition: ${deceased.name} β†’ ${heirs[0].name}`); // TODO: Implement full cutscene with: // - Funeral scene // - "Legacy lives on..." text // - Family mourning // - Heir accepts responsibility // For now, show notification this.showNotification({ title: 'Legacy Lives On...', text: `⚰️ ${deceased.name} has passed. ${heirs[0].name} continues the legacy.`, icon: 'πŸŒ…' }); // Switch to heir setTimeout(() => { this.switchProtagonist(heirs[0].id); }, 3000); } /** * 12.2 - Switch protagonist to heir */ switchProtagonist(heirId) { const heir = this.familyTree.get(heirId); if (!heir) { console.error(`Heir ${heirId} not found!`); return false; } const previousProtagonist = this.currentProtagonist; // Make heir the new protagonist heir.isProtagonist = true; heir.isPlayer = true; this.currentProtagonist = heir; this.currentGeneration = heir.generation; console.log(`πŸ‘€ New protagonist: ${heir.name} (Generation ${heir.generation})`); // Transfer everything this.transferInheritance(previousProtagonist, heir); // Update NPCs to mother becomes mentor this.updateFamilyRoles(previousProtagonist, heir); // Trigger new questline this.startGenerationQuest(heir); return true; } /** * 12.2 - Transfer inheritance */ transferInheritance(deceased, heir) { console.log(`πŸ“¦ Transferring inheritance from ${deceased.name} to ${heir.name}`); // Transfer items (100%) if (this.scene.inventorySystem) { // Items automatically stay in house/chests console.log('πŸ“¦ Items inherited'); } // Transfer property console.log('🏑 Farm/house inherited'); // Transfer zombies if (this.scene.zombieSystem) { console.log('🧟 Zombie army inherited'); } // Transfer animals if (this.scene.animalBreeding) { console.log('πŸ” Animals inherited'); } // Transfer money if (this.scene.inventorySystem) { console.log('πŸ’° Money inherited'); } // Calculate legacy bonus const legacyBonus = this.calculateLegacyBonus(deceased); this.applyLegacyBonus(heir, legacyBonus); this.showNotification({ title: 'Inheritance Received', text: `πŸ“¦ ${heir.name} inherited everything! +${legacyBonus} Legacy Points`, icon: 'πŸ‘‘' }); } /** * Calculate legacy bonus from previous generation */ calculateLegacyBonus(deceased) { let bonus = 0; // Quests completed bonus += deceased.stats.questsCompleted * 10; // Bosses defeated bonus += deceased.stats.bossesDefeated * 50; // Zombies tamed bonus += deceased.stats.zombiesTamed * 5; // Items collected (rare) bonus += deceased.stats.itemsCollected * 2; return bonus; } /** * Apply legacy bonus to heir */ applyLegacyBonus(heir, bonus) { // Legacy points grant bonuses this.legacyPoints += bonus; // Grant starting stats based on legacy const statBonus = Math.floor(bonus / 100); // TODO: Apply stat bonuses console.log(`⭐ ${heir.name} receives +${statBonus} stat bonus from legacy!`); } /** * 12.2 - Update family roles */ updateFamilyRoles(deceased, heir) { // Wife becomes NPC mentor if (deceased.spouse) { const spouse = this.familyTree.get(deceased.spouse); if (spouse) { spouse.role = 'mentor'; console.log(`πŸ‘© ${spouse.name} is now a mentor NPC`); } } // Ana becomes "aunt" figure if (heir.generation > 1) { console.log('πŸ‘© Ana is now an aunt figure'); // Update Ana dialogues for new generation } } /** * 12.3 - NPC Memory System */ rememberDeceased(npcId, deceasedId) { const deceased = this.familyTree.get(deceasedId); if (!deceased) return; if (!this.npcMemories.has(npcId)) { this.npcMemories.set(npcId, { remembers: [], relationships: new Map() }); } const memory = this.npcMemories.get(npcId); memory.remembers.push({ personId: deceasedId, name: deceased.name, relationship: 'friend', // TODO: Get actual relationship memories: [ `I remember when ${deceased.name} helped me...`, `${deceased.name} was a good person.`, `Your father was brave.` ] }); } /** * 12.3 - Get NPC dialogue for new generation */ getNPCDialogueForGeneration(npcId, protagonistId) { const protagonist = this.familyTree.get(protagonistId); const memory = this.npcMemories.get(npcId); if (!memory || protagonist.generation === 1) { return null; // Normal dialogue } // Special dialogue for child of previous protagonist const dialogues = [ `You have your father's eyes...`, `Kai would be so proud of you!`, `I knew your father well. He was a great man.`, `You remind me so much of ${protagonist.parents[0]}`, `Your family has done so much for this town.` ]; return Phaser.Utils.Array.GetRandom(dialogues); } /** * 12.4 - Start generation-specific quest */ startGenerationQuest(heir) { if (heir.generation === 1) return; // Kai has main quest console.log(`πŸ“– Starting "Following Father's Footsteps" quest for ${heir.name}`); const questData = { id: `gen${heir.generation}_legacy`, title: 'Following Father\'s Footsteps', description: 'Honor your father\'s memory and continue his legacy.', objectives: [ { id: 'visit_grave', type: 'location', description: `Visit ${heir.parents[0]}'s grave`, target: { x: 100, y: 200, radius: 50 } }, { id: 'talk_to_mother', type: 'dialogue', description: 'Talk to your mother about father' }, { id: 'continue_mission', type: 'event', description: 'Swear to continue father\'s mission' } ], rewards: { xp: 500, items: [{ id: 'father_memento', amount: 1 }], bondStrength: 10 // With Ana } }; // TODO: Integrate with QuestSystem console.log(`πŸ“œ Quest "${questData.title}" available`); } /** * 12.5 - Multi-generation system */ addChild(parentId, childData) { const parent = this.familyTree.get(parentId); if (!parent) { console.error('Parent not found'); return null; } // Determine generation const generation = parent.generation + 1; const child = { id: `${childData.name.toLowerCase()}_gen${generation}`, name: childData.name, gender: childData.gender, generation: generation, age: 0, isProtagonist: false, isAlive: true, isPlayer: false, // Family spouse: null, children: [], parents: [parentId], // Stats stats: { itemsCollected: 0, zombiesTamed: 0, bossesDefeated: 0, questsCompleted: 0 }, // Legacy accomplishments: [], deathDate: null, causeOfDeath: null }; this.familyTree.set(child.id, child); parent.children.push(child.id); // Add to generation array if (!this.generations[generation]) { this.generations[generation] = []; } this.generations[generation].push(child); console.log(`πŸ‘Ά ${child.name} added to Generation ${generation}`); return child; } /** * Get adult children of a person */ getAdultChildren(personId) { const person = this.familyTree.get(personId); if (!person) return []; return person.children .map(childId => this.familyTree.get(childId)) .filter(child => child && child.age >= 6570 && child.isAlive); // 18 years } /** * Create grave for deceased */ createGrave(deceasedId, location) { const deceased = this.familyTree.get(deceasedId); if (!deceased) return; deceased.graveLocation = location; // TODO: Actually place grave object in world console.log(`⚰️ Grave created for ${deceased.name} at (${location.x}, ${location.y})`); this.showNotification({ title: 'Grave Placed', text: `⚰️ ${deceased.name} will be remembered forever.`, icon: 'πŸ•ŠοΈ' }); } /** * Show legacy stats */ showLegacyStats() { const stats = { totalGenerations: this.generations.length, totalDescendants: this.familyTree.size, legacyPoints: this.legacyPoints, achievements: this.familyAchievements.length }; console.log('πŸ“Š LEGACY STATS:'); console.log(`Generations: ${stats.totalGenerations}`); console.log(`Total Family Members: ${stats.totalDescendants}`); console.log(`Legacy Points: ${stats.legacyPoints}`); console.log(`Achievements: ${stats.achievements}`); // TODO: Show actual UI screen } /** * Get family tree */ getFamilyTree() { return this.familyTree; } /** * Get current protagonist */ getCurrentProtagonist() { return this.currentProtagonist; } /** * Check if game over */ isGameOver() { return this.hasGameOver; } /** * Helper: Show notification */ showNotification(notification) { console.log(`πŸ“’ ${notification.icon} ${notification.title}: ${notification.text}`); const ui = this.scene.scene.get('UIScene'); if (ui && ui.showNotification) { ui.showNotification(notification); } } }