/** * ChildrenFamilySystem.js * ======================= * KRVAVA ŽETEV - Children & Family System (P11) * * Features: * - Pregnancy system * - Birth events * - 6 growth stages (Baby → Toddler → Child → Teen → Adult) * - Child AI (follows, helps farm, combat) * - Family events * - Generational gameplay ready * * @author NovaFarma Team * @date 2025-12-23 */ export default class ChildrenFamilySystem { constructor(scene) { this.scene = scene; // Children data this.children = new Map(); // childId -> child state this.pregnancyData = null; // Growth stages (in in-game days) this.growthStages = { BABY: { min: 0, max: 365 }, // 0-1 year TODDLER: { min: 365, max: 1095 }, // 1-3 years CHILD: { min: 1095, max: 3650 }, // 3-10 years TEEN: { min: 3650, max: 6570 }, // 10-18 years ADULT: { min: 6570, max: 999999 } // 18+ years }; // Family events this.lastFamilyDinner = null; this.familyPhotos = []; console.log('👶 ChildrenFamilySystem initialized'); } /** * 11.1 - Start Pregnancy */ startPregnancy(spouseId) { if (this.pregnancyData) { console.log('⚠️ Already pregnant!'); return false; } const spouse = this.scene.marriageRomanceSystem?.getRomanceState(spouseId); if (!spouse) { console.error('Spouse not found'); return false; } this.pregnancyData = { spouseId: spouseId, spouseName: spouse.name, startDate: this.scene.timeSystem?.getCurrentDate() || new Date(), daysSinceStart: 0, totalDays: 30, // 30 in-game days bellyStage: 0, // 0-4 stages cravings: [], isActive: true }; console.log(`🤰 ${spouse.name} is pregnant!`); // Trigger announcement cutscene this.showPregnancyAnnouncement(); return true; } /** * 11.1 - Show pregnancy announcement */ showPregnancyAnnouncement() { if (!this.pregnancyData) return; const spouse = this.scene.marriageRomanceSystem?.getRomanceState(this.pregnancyData.spouseId); // TODO: Implement cutscene this.showNotification({ title: 'Big News!', text: `🤰 ${spouse.name}: "Darling... I'm pregnant!"`, icon: '💕' }); } /** * 11.1 - Update pregnancy */ updatePregnancy(delta) { if (!this.pregnancyData || !this.pregnancyData.isActive) return; // Track days const currentDay = this.scene.timeSystem?.getCurrentDay() || 0; this.pregnancyData.daysSinceStart = currentDay - this.pregnancyData.startDate.day; // Update belly stage (0-4) const progress = this.pregnancyData.daysSinceStart / this.pregnancyData.totalDays; this.pregnancyData.bellyStage = Math.floor(progress * 5); // Random cravings every few days if (Math.random() < 0.01) { // 1% chance per update this.triggerCraving(); } // Check if ready to give birth if (this.pregnancyData.daysSinceStart >= this.pregnancyData.totalDays) { this.triggerBirth(); } } /** * 11.1 - Trigger craving */ triggerCraving() { const cravingItems = [ 'strawberry', 'pickle', 'ice_cream', 'chocolate', 'pizza', 'watermelon', 'cheese', 'sushi', 'cake', 'pasta' ]; const item = Phaser.Utils.Array.GetRandom(cravingItems); this.pregnancyData.cravings.push({ item: item, satisfied: false, timestamp: Date.now() }); this.showNotification({ title: 'Craving!', text: `${this.pregnancyData.spouseName}: "I really want ${item}!"`, icon: '🤤' }); } /** * 11.2 - Trigger Birth Event */ triggerBirth() { if (!this.pregnancyData) return; console.log('👶 Labor starting!'); this.pregnancyData.isActive = false; // Trigger labor alarm (middle of night) this.showBirthCutscene(); } /** * 11.2 - Birth cutscene */ showBirthCutscene() { // TODO: Implement full cutscene with: // - Labor alarm // - Rush to Dr. Chen // - Birth scene // - Gender selection // - Baby naming // For now, show dialog const genderOptions = ['boy', 'girl']; const gender = Phaser.Utils.Array.GetRandom(genderOptions); this.promptBabyName(gender); } /** * 11.2 - Prompt baby name */ promptBabyName(gender) { // TODO: Implement name input UI // For now, use default names const boyNames = ['Luka', 'Mark', 'Jure', 'Matej', 'Alex']; const girlNames = ['Ana', 'Maja', 'Eva', 'Nina', 'Luna']; const name = gender === 'boy' ? Phaser.Utils.Array.GetRandom(boyNames) : Phaser.Utils.Array.GetRandom(girlNames); this.createBaby(name, gender); } /** * 11.2 - Create baby */ createBaby(name, gender) { const childId = `child_${Date.now()}`; const childData = { id: childId, name: name, gender: gender, birthDate: this.scene.timeSystem?.getCurrentDate() || new Date(), age: 0, // In days stage: 'BABY', // Stats health: 100, energy: 100, happiness: 100, // Skills (0-100) skills: { farming: 0, combat: 0, crafting: 0, social: 0, intelligence: 0 }, // Personality (develops over time) personality: { brave: Math.random() * 100, kind: Math.random() * 100, smart: Math.random() * 100, creative: Math.random() * 100 }, // Relationships lovesPlayer: 100, lovesSpouse: 100, // State isAwake: true, currentActivity: 'sleeping', specialization: null, // Chosen at teen stage // Growth nextStageAge: this.growthStages.TODDLER.min }; this.children.set(childId, childData); console.log(`👶 ${name} was born! (${gender})`); // Clear pregnancy data this.pregnancyData = null; // Show birth notification this.showNotification({ title: 'Baby Born!', text: `👶 Welcome ${name}! It's a ${gender}!`, icon: '🍼' }); return childData; } /** * 11.3 - Baby Stage AI */ updateBaby(child, delta) { // Baby actions const actions = ['sleeping', 'crying', 'feeding', 'playing']; // Random crying if (Math.random() < 0.001) { // 0.1% chance child.currentActivity = 'crying'; this.showNotification({ title: 'Baby Crying!', text: `👶 ${child.name} is crying! 😭`, icon: '👶' }); } // Auto-sleep at night const hour = this.scene.timeSystem?.getCurrentHour() || 12; if (hour >= 20 || hour <= 6) { child.currentActivity = 'sleeping'; } } /** * 11.4 - Toddler Stage AI */ updateToddler(child, delta) { // Toddler can walk and talk if (!child.hasWalked) { child.hasWalked = true; this.showNotification({ title: 'First Steps!', text: `👣 ${child.name} is walking!`, icon: '🎉' }); } if (!child.hasSpoken && child.age > 380) { // ~13 months child.hasSpoken = true; const firstWord = Math.random() > 0.5 ? 'Dada!' : 'Mama!'; this.showNotification({ title: 'First Words!', text: `🗣️ ${child.name}: "${firstWord}"`, icon: '💬' }); } // Follow player sometimes if (Math.random() < 0.3) { child.currentActivity = 'following_player'; } } /** * 11.5 - Child Stage AI */ updateChild(child, delta) { // Child can help with farm if (this.scene.timeSystem?.getCurrentHour() === 8) { // Morning: Water 5 crops this.waterCrops(child, 5); } if (this.scene.timeSystem?.getCurrentHour() === 16) { // Afternoon: Feed chickens this.feedAnimals(child); } // Learn skills child.skills.farming += 0.01; child.skills.social += 0.01; } /** * 11.6 - Teen Stage AI */ updateTeen(child, delta) { // Advanced farm help if (this.scene.timeSystem?.getCurrentHour() === 7) { this.waterCrops(child, 20); } // Can do errands if (Math.random() < 0.05) { this.doErrand(child); } // Personality development (teenager attitude!) if (Math.random() < 0.01) { const attitudes = [ `"UGH, Dad! Why do I have to do chores?"`, `"Can I PLEASE go to the festival?"`, `"You don't understand me!"`, `"I'm not a kid anymore!"` ]; const attitude = Phaser.Utils.Array.GetRandom(attitudes); this.showNotification({ title: 'Teenage Attitude', text: `${child.name}: ${attitude}`, icon: '😤' }); } // Choose specialization at 14 if (child.age >= 5110 && !child.specialization) { // ~14 years this.chooseSpecialization(child); } } /** * 11.6 - Choose specialization */ chooseSpecialization(child) { const specs = []; // Based on personality and skills if (child.skills.farming > 50) specs.push('Farmer'); if (child.skills.combat > 50) specs.push('Fighter'); if (child.skills.intelligence > 50) specs.push('Scientist'); if (child.personality.creative > 70) specs.push('Artist'); // Default to highest skill if (specs.length === 0) { const highestSkill = Object.keys(child.skills).reduce((a, b) => child.skills[a] > child.skills[b] ? a : b ); specs.push(highestSkill.charAt(0).toUpperCase() + highestSkill.slice(1)); } child.specialization = Phaser.Utils.Array.GetRandom(specs); this.showNotification({ title: 'Career Choice!', text: `${child.name} wants to become a ${child.specialization}!`, icon: '🎓' }); } /** * 11.7 - Adult Stage (Becomes Playable!) */ updateAdult(child, delta) { // Full abilities unlocked child.canBoss = true; child.canCraftAll = true; // Can have own relationships if (!child.canMarry) { child.canMarry = true; this.showNotification({ title: 'All Grown Up!', text: `${child.name} is now an adult! They can marry and have their own family!`, icon: '🎓' }); } } /** * Update child growth */ updateChildGrowth(child, delta) { // Age child child.age++; // Check for stage transition if (child.age >= child.nextStageAge) { this.advanceStage(child); } // Update based on current stage switch (child.stage) { case 'BABY': this.updateBaby(child, delta); break; case 'TODDLER': this.updateToddler(child, delta); break; case 'CHILD': this.updateChild(child, delta); break; case 'TEEN': this.updateTeen(child, delta); break; case 'ADULT': this.updateAdult(child, delta); break; } } /** * Advance to next growth stage */ advanceStage(child) { const stages = ['BABY', 'TODDLER', 'CHILD', 'TEEN', 'ADULT']; const currentIndex = stages.indexOf(child.stage); if (currentIndex < stages.length - 1) { child.stage = stages[currentIndex + 1]; child.nextStageAge = this.growthStages[child.stage].max; console.log(`🎂 ${child.name} is now a ${child.stage}!`); this.showNotification({ title: 'Birthday!', text: `🎂 ${child.name} grew up to ${child.stage} stage!`, icon: '🎉' }); } } /** * Helper: Water crops */ waterCrops(child, amount) { // TODO: Integrate with FarmingSystem console.log(`💧 ${child.name} watered ${amount} crops!`); child.skills.farming += 0.5; } /** * Helper: Feed animals */ feedAnimals(child) { // TODO: Integrate with AnimalSystem console.log(`🐔 ${child.name} fed the animals!`); child.skills.farming += 0.3; } /** * Helper: Do errand */ doErrand(child) { const errands = [ 'bought groceries', 'delivered package', 'fetched water', 'collected mail' ]; const errand = Phaser.Utils.Array.GetRandom(errands); console.log(`📦 ${child.name} ${errand}!`); child.skills.social += 0.5; } /** * 11.8 - Family Dinner Event */ triggerFamilyDinner() { const spouse = this.scene.marriageRomanceSystem?.getSpouse(); if (!spouse) return; console.log('🍽️ Family dinner time!'); // TODO: Implement family dinner cutscene this.showNotification({ title: 'Family Dinner!', text: `🍽️ The whole family is having dinner together!`, icon: '👨‍👩‍👧‍👦' }); this.lastFamilyDinner = new Date(); // Boost family relationships this.children.forEach(child => { child.lovesPlayer += 5; child.lovesSpouse += 5; }); } /** * 11.8 - Take Family Photo */ takeFamilyPhoto() { const photo = { date: this.scene.timeSystem?.getCurrentDate() || new Date(), members: [ 'Player', this.scene.marriageRomanceSystem?.getSpouse()?.name || 'Spouse', ...Array.from(this.children.values()).map(c => c.name) ], location: 'Home' }; this.familyPhotos.push(photo); this.showNotification({ title: 'Family Photo!', text: `📸 Beautiful family memory captured!`, icon: '📷' }); } /** * Update system */ update(delta) { // Update pregnancy if (this.pregnancyData) { this.updatePregnancy(delta); } // Update all children this.children.forEach(child => { this.updateChildGrowth(child, delta); }); // Check for family events this.checkFamilyEvents(); } /** * Check for family events */ checkFamilyEvents() { // Weekly family dinner const daysSinceLastDinner = this.lastFamilyDinner ? (Date.now() - this.lastFamilyDinner.getTime()) / (1000 * 60 * 60 * 24) : 999; if (daysSinceLastDinner >= 7 && this.children.size > 0) { this.triggerFamilyDinner(); } } /** * Helpers */ showNotification(notification) { console.log(`📢 ${notification.icon} ${notification.title}: ${notification.text}`); const ui = this.scene.scene.get('UIScene'); if (ui && ui.showNotification) { ui.showNotification(notification); } } getChildren() { return Array.from(this.children.values()); } getChildByName(name) { return Array.from(this.children.values()).find(c => c.name === name); } isPregnant() { return this.pregnancyData && this.pregnancyData.isActive; } }