Files
novafarma/EMERGENCY_SYSTEMS_RECOVERY/LegacySystem.js
2026-01-16 02:43:46 +01:00

145 lines
4.7 KiB
JavaScript

class LegacySystem {
constructor(scene) {
this.scene = scene;
// AGE & GENERATION
this.generation = 1;
this.birthDay = 1; // Global Day count when current char was born
this.currentAge = 18; // Start at 18
// FAMILY
this.isMarried = false;
this.spouseName = null;
this.childName = null;
this.childAge = 0;
// FRACTIONS / REPUTATION
this.reputation = {
survivors: 0, // Human NPCs
mutants: -50, // Starts hostile
zombies: 0 // Handled by Hybrid Skill, but we can track here too
};
// Listen for Day Change logic
this.scene.events.on('update', (time, delta) => this.update(time, delta));
}
update(time, delta) {
if (!this.scene.weatherSystem) return;
const currentDay = this.scene.weatherSystem.dayCount;
// Calculate Age
// 1 Year = 28 Days (4 seasons * 7 days).
const daysAlive = Math.max(0, currentDay - this.birthDay);
const yearsAlive = Math.floor(daysAlive / 28);
// Don't spam update
if (this.currentAge !== 18 + yearsAlive) {
this.currentAge = 18 + yearsAlive;
this.scene.events.emit('update-age-ui', { gen: this.generation, age: this.currentAge });
}
// Child Growth
if (this.childName && currentDay % 28 === 0) {
// Child ages up logic could go here
}
}
// --- REPUTATION ---
modifyReputation(fraction, amount) {
if (this.reputation[fraction] !== undefined) {
this.reputation[fraction] += amount;
// Clamp -100 to 100
this.reputation[fraction] = Phaser.Math.Clamp(this.reputation[fraction], -100, 100);
if (this.scene.player) {
this.scene.events.emit('show-floating-text', {
x: this.scene.player.sprite.x,
y: this.scene.player.sprite.y - 60,
text: `Reputation (${fraction}): ${amount > 0 ? '+' : ''}${amount}`,
color: amount > 0 ? '#00FF00' : '#FF0000'
});
}
}
}
// --- MARRIAGE ---
propose(npc) {
if (this.isMarried) {
this.showText("You are already married!");
return;
}
// Logic: Need Ring and High Rep
const hasRing = this.scene.inventorySystem && this.scene.inventorySystem.hasItem('gold_coin'); // Placeholder: use Gold Coin as "Ring" for now
// Or better: Let's create 'ring' item? For now, Gold Coins (50?).
// Let's require 50 Gold Coins for now? Or specific item?
// Let's assume inventory checks are done before calling this, or simple check here.
const highRep = this.reputation.survivors >= 50;
// Temp logic: Always succeed if rep > 0 for testing?
if (highRep) {
this.isMarried = true;
this.spouseName = npc.name || "Villager";
this.showText(`You married ${this.spouseName}!`);
} else {
this.showText("They refused... (Need 50 Rep)");
}
}
haveChild() {
if (!this.isMarried) return;
if (this.childName) return;
this.childName = "Baby Jr.";
this.childAge = 0;
this.showText("A child is born!");
}
// --- INHERITANCE / DEATH ---
triggerInheritance() {
console.log('💀 TRIGGERING INHERITANCE...');
// 1. Increment Generation
this.generation++;
// 2. Reset Player Stats
if (this.scene.weatherSystem) {
this.birthDay = this.scene.weatherSystem.dayCount; // Born today
}
this.currentAge = 18; // Reset age
this.isMarried = false;
this.spouseName = null;
this.childName = null; // Clean slate (child became protagonist)
// 3. Clear transient reputation, but keep a bit?
// Inheritance bonus: Keep 20% of rep?
this.reputation.survivors = Math.floor(this.reputation.survivors * 0.2);
this.reputation.mutants = Math.floor(this.reputation.mutants * 0.2) - 40; // Still suspicious
this.showText(`Step Id: 760
Generation ${this.generation} Begins!`, '#FFD700');
// Heal
if (this.scene.player) {
this.scene.player.hp = this.scene.player.maxHp;
this.scene.player.isDead = false;
this.scene.player.sprite.setTint(0xffffff);
this.scene.player.sprite.setAlpha(1);
}
}
showText(msg, color = '#FFFFFF') {
const player = this.scene.player;
if (player) {
this.scene.events.emit('show-floating-text', {
x: player.sprite.x, y: player.sprite.y - 50, text: msg, color: color
});
}
}
}