MASTER SYSTEMS + Town & Privacy
This commit is contained in:
454
src/systems/MasterGameSystemsManager.js
Normal file
454
src/systems/MasterGameSystemsManager.js
Normal file
@@ -0,0 +1,454 @@
|
||||
/**
|
||||
* MASTER GAME SYSTEMS MANAGER
|
||||
* Centralized coordinator for all game systems
|
||||
* Created: January 4, 2026
|
||||
*
|
||||
* Integrates:
|
||||
* - Sleep System
|
||||
* - Crafting Tables System
|
||||
* - Bakery Shop System
|
||||
* - Barber Shop System
|
||||
* - Lawyer Office System
|
||||
* - Zombie Miner Automation System
|
||||
* - Town Growth System
|
||||
* - NPC Privacy System
|
||||
* - Existing Mining System
|
||||
*/
|
||||
|
||||
import SleepSystem from './SleepSystem.js';
|
||||
import CraftingTablesSystem from './CraftingTablesSystem.js';
|
||||
import BakeryShopSystem from './BakeryShopSystem.js';
|
||||
import BarberShopSystem from './BarberShopSystem.js';
|
||||
import LawyerOfficeSystem from './LawyerOfficeSystem.js';
|
||||
import ZombieMinerAutomationSystem from './ZombieMinerAutomationSystem.js';
|
||||
import TownGrowthSystem from './TownGrowthSystem.js';
|
||||
import NPCPrivacySystem from './NPCPrivacySystem.js';
|
||||
|
||||
export class MasterGameSystemsManager {
|
||||
constructor(game) {
|
||||
this.game = game;
|
||||
this.scene = game.scene;
|
||||
|
||||
console.log('🎮 Initializing Master Game Systems Manager...');
|
||||
|
||||
// Initialize all systems
|
||||
this.initializeSystems();
|
||||
|
||||
// Set up cross-system event listeners
|
||||
this.setupEventListeners();
|
||||
|
||||
console.log('✅ Master Game Systems Manager initialized!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all game systems
|
||||
*/
|
||||
initializeSystems() {
|
||||
// HOME & SLEEP
|
||||
this.sleepSystem = new SleepSystem(this.game);
|
||||
console.log(' ✓ Sleep System');
|
||||
|
||||
// CRAFTING
|
||||
this.craftingSystem = new CraftingTablesSystem(this.game);
|
||||
console.log(' ✓ Crafting Tables System');
|
||||
|
||||
// TOWN BUILDINGS
|
||||
this.bakerySystem = new BakeryShopSystem(this.game);
|
||||
console.log(' ✓ Bakery Shop System');
|
||||
|
||||
this.barberSystem = new BarberShopSystem(this.game);
|
||||
console.log(' ✓ Barber Shop System');
|
||||
|
||||
this.lawyerSystem = new LawyerOfficeSystem(this.game);
|
||||
console.log(' ✓ Lawyer Office System');
|
||||
|
||||
// MINING & AUTOMATION
|
||||
this.zombieMinerSystem = new ZombieMinerAutomationSystem(this.game);
|
||||
console.log(' ✓ Zombie Miner Automation System');
|
||||
|
||||
// TOWN GROWTH
|
||||
this.townGrowthSystem = new TownGrowthSystem(this.game);
|
||||
console.log(' ✓ Town Growth System');
|
||||
|
||||
// NPC SYSTEMS
|
||||
this.npcPrivacySystem = new NPCPrivacySystem(this.game);
|
||||
console.log(' ✓ NPC Privacy System');
|
||||
|
||||
// Register all systems globally
|
||||
this.registerSystems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register systems to game registry
|
||||
*/
|
||||
registerSystems() {
|
||||
this.game.registry.set('sleepSystem', this.sleepSystem);
|
||||
this.game.registry.set('craftingSystem', this.craftingSystem);
|
||||
this.game.registry.set('bakerySystem', this.bakerySystem);
|
||||
this.game.registry.set('barberSystem', this.barberSystem);
|
||||
this.game.registry.set('lawyerSystem', this.lawyerSystem);
|
||||
this.game.registry.set('zombieMinerSystem', this.zombieMinerSystem);
|
||||
this.game.registry.set('townGrowthSystem', this.townGrowthSystem);
|
||||
this.game.registry.set('npcPrivacySystem', this.npcPrivacySystem);
|
||||
|
||||
console.log(' ✓ All systems registered to game registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up cross-system event listeners
|
||||
*/
|
||||
setupEventListeners() {
|
||||
// TOWN GROWTH → SERVICES
|
||||
this.game.events.on('serviceUnlocked', (data) => {
|
||||
this.onServiceUnlocked(data);
|
||||
});
|
||||
|
||||
// MARRIAGE → LAWYER AUTO-UNLOCK
|
||||
this.game.events.on('marriageComplete', () => {
|
||||
this.lawyerSystem.checkAutoUnlock();
|
||||
});
|
||||
|
||||
// RELATIONSHIP CHANGE → LAWYER AUTO-UNLOCK
|
||||
this.game.events.on('relationshipChanged', (data) => {
|
||||
if (data.hearts <= 3) {
|
||||
this.lawyerSystem.checkAutoUnlock();
|
||||
}
|
||||
});
|
||||
|
||||
// BUILDING UNLOCKED → TOWN GROWTH
|
||||
this.game.events.on('buildingUnlocked', (data) => {
|
||||
this.townGrowthSystem.checkPopulationUnlocks();
|
||||
});
|
||||
|
||||
// ZOMBIE HIRED → TOWN GROWTH CHECK
|
||||
this.game.events.on('zombieWorkerHired', () => {
|
||||
this.townGrowthSystem.checkPopulationUnlocks();
|
||||
});
|
||||
|
||||
// SLEEP → ZOMBIE LOYALTY DECAY PAUSE
|
||||
this.game.events.on('sleepStarted', () => {
|
||||
this.pauseZombieLoyaltyDecay = true;
|
||||
});
|
||||
|
||||
this.game.events.on('wakeUp', () => {
|
||||
this.pauseZombieLoyaltyDecay = false;
|
||||
});
|
||||
|
||||
console.log(' ✓ Cross-system event listeners configured');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle service unlock
|
||||
*/
|
||||
onServiceUnlocked(data) {
|
||||
const { serviceId, population } = data;
|
||||
|
||||
console.log(`🏛️ Service unlocked: ${serviceId} at pop ${population}`);
|
||||
|
||||
// Trigger service-specific initialization
|
||||
switch (serviceId) {
|
||||
case 'market':
|
||||
this.initializeMarket();
|
||||
break;
|
||||
case 'hospital':
|
||||
this.initializeHospital();
|
||||
break;
|
||||
case 'school':
|
||||
this.initializeSchool();
|
||||
break;
|
||||
case 'bank':
|
||||
this.initializeBank();
|
||||
break;
|
||||
case 'museum':
|
||||
this.initializeMuseum();
|
||||
break;
|
||||
case 'theater':
|
||||
this.initializeTheater();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Service initializers (placeholders for future implementation)
|
||||
*/
|
||||
initializeMarket() {
|
||||
console.log(' → Market initialized');
|
||||
// TODO: Implement market system
|
||||
}
|
||||
|
||||
initializeHospital() {
|
||||
console.log(' → Hospital initialized');
|
||||
// TODO: Implement hospital system
|
||||
}
|
||||
|
||||
initializeSchool() {
|
||||
console.log(' → School initialized');
|
||||
// TODO: Implement school system
|
||||
}
|
||||
|
||||
initializeBank() {
|
||||
console.log(' → Bank initialized');
|
||||
// TODO: Implement bank system
|
||||
}
|
||||
|
||||
initializeMuseum() {
|
||||
console.log(' → Museum initialized');
|
||||
// TODO: Implement museum system
|
||||
}
|
||||
|
||||
initializeTheater() {
|
||||
console.log(' → Theater initialized');
|
||||
// TODO: Implement theater system
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all systems (called every frame)
|
||||
*/
|
||||
update(time, delta) {
|
||||
const deltaSeconds = delta / 1000;
|
||||
|
||||
// Update systems that need per-frame updates
|
||||
this.sleepSystem.update(deltaSeconds);
|
||||
this.craftingSystem.update(deltaSeconds);
|
||||
|
||||
// Update zombie miners (if not paused by sleep)
|
||||
if (!this.pauseZombieLoyaltyDecay) {
|
||||
this.zombieMinerSystem.update(deltaSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hourly update (called when game hour changes)
|
||||
*/
|
||||
onHourChange(hour) {
|
||||
// Update time-sensitive systems
|
||||
this.bakerySystem.update();
|
||||
this.townGrowthSystem.update();
|
||||
|
||||
// Check for automation collection reminders
|
||||
if (hour % 4 === 0) { // Every 4 hours
|
||||
this.checkAutomationReminders();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check automation reminders
|
||||
*/
|
||||
checkAutomationReminders() {
|
||||
// Zombie miner automation
|
||||
if (this.zombieMinerSystem.automationActive) {
|
||||
const hours = this.zombieMinerSystem.getHoursSinceLastCollection();
|
||||
|
||||
if (hours >= 8) {
|
||||
this.game.showNotification({
|
||||
title: '⛏️ Automation Ready',
|
||||
text: `${hours.toFixed(0)}h of mining ready to collect!`,
|
||||
icon: '⛏️'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily update (called at midnight)
|
||||
*/
|
||||
onDayChange(day) {
|
||||
console.log(`📅 Day ${day} - Running daily system updates...`);
|
||||
|
||||
// Town growth check
|
||||
this.townGrowthSystem.update();
|
||||
|
||||
// Restock shops
|
||||
this.bakerySystem.restockInventory();
|
||||
|
||||
// Birthday cake deliveries
|
||||
this.bakerySystem.checkBirthdayCakeDeliveries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all systems state
|
||||
*/
|
||||
saveAllSystems() {
|
||||
return {
|
||||
version: '1.0',
|
||||
timestamp: Date.now(),
|
||||
systems: {
|
||||
sleep: {
|
||||
playerBed: this.sleepSystem.playerBed,
|
||||
unlockedBeds: Object.entries(this.sleepSystem.bedTypes)
|
||||
.filter(([_, bed]) => bed.unlocked)
|
||||
.map(([key, _]) => key)
|
||||
},
|
||||
crafting: {
|
||||
currentTable: this.craftingSystem.currentTable.id,
|
||||
unlockedRecipes: this.craftingSystem.unlockedRecipes,
|
||||
largeTableUnlocked: this.craftingSystem.tables.LARGE.unlocked
|
||||
},
|
||||
bakery: {
|
||||
isUnlocked: this.bakerySystem.isUnlocked,
|
||||
inventory: this.bakerySystem.inventory,
|
||||
birthdayOrders: this.bakerySystem.birthdayCakeOrders
|
||||
},
|
||||
barber: {
|
||||
isUnlocked: this.barberSystem.isUnlocked,
|
||||
playerAppearance: this.barberSystem.playerAppearance,
|
||||
savedLooks: this.barberSystem.savedLooks,
|
||||
visitCount: this.barberSystem.visitCount
|
||||
},
|
||||
lawyer: {
|
||||
isUnlocked: this.lawyerSystem.isUnlocked,
|
||||
hasPrenup: this.lawyerSystem.hasPrenup,
|
||||
divorceHistory: this.lawyerSystem.divorceHistory,
|
||||
counselingInProgress: this.lawyerSystem.counselingInProgress
|
||||
},
|
||||
zombieMiners: {
|
||||
miners: this.zombieMinerSystem.zombieMiners,
|
||||
equipment: this.zombieMinerSystem.zombieEquipment,
|
||||
lastCollectionTime: this.zombieMinerSystem.lastCollectionTime
|
||||
},
|
||||
townGrowth: {
|
||||
population: this.townGrowthSystem.population,
|
||||
populationSlots: this.townGrowthSystem.populationSlots,
|
||||
villages: this.townGrowthSystem.villages,
|
||||
services: this.townGrowthSystem.services
|
||||
},
|
||||
npcPrivacy: {
|
||||
npcHomes: this.npcPrivacySystem.npcHomes,
|
||||
visitHistory: this.npcPrivacySystem.visitHistory,
|
||||
lastVisitTimes: this.npcPrivacySystem.lastVisitTimes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all systems state
|
||||
*/
|
||||
loadAllSystems(saveData) {
|
||||
if (!saveData || !saveData.systems) {
|
||||
console.warn('No save data to load');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const systems = saveData.systems;
|
||||
|
||||
// Load sleep system
|
||||
if (systems.sleep) {
|
||||
systems.sleep.unlockedBeds.forEach(bedKey => {
|
||||
this.sleepSystem.bedTypes[bedKey].unlocked = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Load crafting system
|
||||
if (systems.crafting) {
|
||||
this.craftingSystem.tables.LARGE.unlocked = systems.crafting.largeTableUnlocked;
|
||||
this.craftingSystem.unlockedRecipes = systems.crafting.unlockedRecipes || [];
|
||||
}
|
||||
|
||||
// Load bakery
|
||||
if (systems.bakery) {
|
||||
this.bakerySystem.isUnlocked = systems.bakery.isUnlocked;
|
||||
this.bakerySystem.birthdayCakeOrders = systems.bakery.birthdayOrders || [];
|
||||
}
|
||||
|
||||
// Load barber
|
||||
if (systems.barber) {
|
||||
this.barberSystem.isUnlocked = systems.barber.isUnlocked;
|
||||
this.barberSystem.playerAppearance = systems.barber.playerAppearance;
|
||||
this.barberSystem.savedLooks = systems.barber.savedLooks || [];
|
||||
this.barberSystem.visitCount = systems.barber.visitCount || 0;
|
||||
}
|
||||
|
||||
// Load lawyer
|
||||
if (systems.lawyer) {
|
||||
this.lawyerSystem.isUnlocked = systems.lawyer.isUnlocked;
|
||||
this.lawyerSystem.hasPrenup = systems.lawyer.hasPrenup || false;
|
||||
this.lawyerSystem.divorceHistory = systems.lawyer.divorceHistory || [];
|
||||
this.lawyerSystem.counselingInProgress = systems.lawyer.counselingInProgress || false;
|
||||
}
|
||||
|
||||
// Load zombie miners
|
||||
if (systems.zombieMiners) {
|
||||
this.zombieMinerSystem.zombieMiners = systems.zombieMiners.miners || [];
|
||||
this.zombieMinerSystem.zombieEquipment = systems.zombieMiners.equipment || {};
|
||||
this.zombieMinerSystem.lastCollectionTime = systems.zombieMiners.lastCollectionTime;
|
||||
this.zombieMinerSystem.updateAutomationYield();
|
||||
}
|
||||
|
||||
// Load town growth
|
||||
if (systems.townGrowth) {
|
||||
this.townGrowthSystem.population = systems.townGrowth.population;
|
||||
this.townGrowthSystem.populationSlots = systems.townGrowth.populationSlots;
|
||||
this.townGrowthSystem.villages = systems.townGrowth.villages || [];
|
||||
this.townGrowthSystem.services = systems.townGrowth.services || {};
|
||||
}
|
||||
|
||||
// Load NPC privacy
|
||||
if (systems.npcPrivacy) {
|
||||
this.npcPrivacySystem.npcHomes = systems.npcPrivacy.npcHomes || {};
|
||||
this.npcPrivacySystem.visitHistory = systems.npcPrivacy.visitHistory || {};
|
||||
this.npcPrivacySystem.lastVisitTimes = systems.npcPrivacy.lastVisitTimes || {};
|
||||
}
|
||||
|
||||
console.log('✅ All systems loaded from save data');
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error loading systems:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all systems status (for debug/admin panel)
|
||||
*/
|
||||
getAllSystemsStatus() {
|
||||
return {
|
||||
sleep: {
|
||||
active: true,
|
||||
currentBed: this.sleepSystem.playerBed.name,
|
||||
isSleeping: this.sleepSystem.isSleeping
|
||||
},
|
||||
crafting: {
|
||||
active: true,
|
||||
currentTable: this.craftingSystem.currentTable.name,
|
||||
isCrafting: this.craftingSystem.isCrafting,
|
||||
queueLength: this.craftingSystem.craftingQueue.length
|
||||
},
|
||||
bakery: {
|
||||
active: this.bakerySystem.isUnlocked,
|
||||
isOpen: this.bakerySystem.isOpen,
|
||||
stockLevel: Object.values(this.bakerySystem.inventory)
|
||||
.reduce((sum, item) => sum + item.stock, 0)
|
||||
},
|
||||
barber: {
|
||||
active: this.barberSystem.isUnlocked,
|
||||
isOpen: this.barberSystem.isOpen,
|
||||
currentStyle: this.barberSystem.playerAppearance.hairstyle
|
||||
},
|
||||
lawyer: {
|
||||
active: this.lawyerSystem.isUnlocked,
|
||||
counselingActive: this.lawyerSystem.counselingInProgress,
|
||||
hasPrenup: this.lawyerSystem.hasPrenup
|
||||
},
|
||||
zombieMiners: {
|
||||
active: this.zombieMinerSystem.automationActive,
|
||||
minerCount: this.zombieMinerSystem.zombieMiners.length,
|
||||
yieldPerHour: this.zombieMinerSystem.totalYieldPerHour
|
||||
},
|
||||
townGrowth: {
|
||||
active: true,
|
||||
population: this.townGrowthSystem.population,
|
||||
maxPopulation: this.townGrowthSystem.maxPopulation,
|
||||
status: this.townGrowthSystem.getTownStatus()
|
||||
},
|
||||
npcPrivacy: {
|
||||
active: true,
|
||||
homesGenerated: Object.keys(this.npcPrivacySystem.npcHomes).length
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default MasterGameSystemsManager;
|
||||
Reference in New Issue
Block a user