// ======================================================== // KONSTANTE IN IGRALČEVI PODATKI // ======================================================== const XP_REQUIRED_BASE = 100; // Osnovni XP, potrebni za LVL 2 const XP_GROWTH_FACTOR = 1.5; // Za vsak LVL potrebujete 1.5x več XP class StatsSystem { constructor(scene) { this.scene = scene; // Leveling System this.currentLevel = 1; this.currentXP = 0; this.xpToNextLevel = XP_REQUIRED_BASE; this.score = 0; // GLOBAL SCORE (Za Legacy) this.totalPlaytime = 0; // Skupni čas igranja (sekunde) // Stats this.health = 100; this.maxHealth = 100; this.hunger = 100; // 100 = full this.maxHunger = 100; this.thirst = 100; // 100 = not thirsty this.maxThirst = 100; // Decay rates (per second) this.hungerDecay = 0.5; // Pade na 0 v 200s (cca 3 min) this.thirstDecay = 0.8; // Pade na 0 v 125s (cca 2 min) this.damageTickTimer = 0; // Friendship System (Hearts ❤️) this.friendship = { merchant: 0, zombie: 0, villager: 0 }; } update(delta) { const seconds = delta / 1000; this.totalPlaytime += seconds; // Track playtime // Decay if (this.hunger > 0) { this.hunger -= this.hungerDecay * seconds; } if (this.thirst > 0) { this.thirst -= this.thirstDecay * seconds; } // Clamp values this.hunger = Math.max(0, this.hunger); this.thirst = Math.max(0, this.thirst); // Starvation / Dehydration logic if (this.hunger <= 0 || this.thirst <= 0) { this.damageTickTimer += delta; if (this.damageTickTimer >= 1000) { // Vsako sekundo damage this.damageTickTimer = 0; this.takeDamage(5); // 5 DMG na sekundo če si lačen/žejen // Shake camera effect za opozorilo this.scene.cameras.main.shake(100, 0.005); } } else { this.damageTickTimer = 0; // Natural regeneration if full if (this.hunger > 80 && this.thirst > 80 && this.health < this.maxHealth) { this.health += 1 * seconds; } } this.health = Math.min(this.health, this.maxHealth); this.updateUI(); } takeDamage(amount) { this.health -= amount; if (this.health <= 0) { this.health = 0; this.die(); } } eat(amount) { this.hunger += amount; this.hunger = Math.min(this.hunger, this.maxHunger); } drink(amount) { this.thirst += amount; this.thirst = Math.min(this.thirst, this.maxThirst); } // SCORE & DEATH LOGIC addScore(points) { this.score += points; // console.log(`⭐ Score +${points} (Total: ${this.score})`); } die() { console.log('💀 Player died!'); // SCORE PENALTY (Legacy Cost) // Igralec NE izgubi farme, ampak izgubi del Dediščine (Točk). const penalty = Math.floor(this.score * 0.25); // Izguba 25% točk this.score = Math.max(0, this.score - penalty); console.log(`📉 Dediščina Oškodovana: -${penalty} Točk (Novo stanje: ${this.score})`); // Trigger Player Animation if (this.scene.player) { this.scene.player.dieAnimation(); } // Show Notification & Overlay in UI Scene const uiScene = this.scene.scene.get('UIScene'); if (uiScene) { // Full screen overlay using scale dimensions const width = uiScene.scale.width; const height = uiScene.scale.height; const bg = uiScene.add.rectangle(width / 2, height / 2, width, height, 0x000000, 0.8); const txt = uiScene.add.text(width / 2, height / 2 - 50, 'YOU DIED', { fontSize: '64px', color: '#ff0000', fontStyle: 'bold' }).setOrigin(0.5); const sub = uiScene.add.text(width / 2, height / 2 + 20, `Legacy Lost: -${penalty} Score pts`, { fontSize: '24px', color: '#ffffff' }).setOrigin(0.5); const sub2 = uiScene.add.text(width / 2, height / 2 + 60, '(Farm Preserved)', { fontSize: '18px', color: '#aaaaaa', fontStyle: 'italic' }).setOrigin(0.5); // Wait and Respawn uiScene.time.delayedCall(3000, () => { if (bg) bg.destroy(); if (txt) txt.destroy(); if (sub) sub.destroy(); if (sub2) sub2.destroy(); // Reset Stats (but keep Score penalty) this.health = 100; this.hunger = 100; this.thirst = 100; this.updateUI(); // Reset Player if (this.scene.player) { this.scene.player.respawn(); } }); } } updateUI() { const uiScene = this.scene.scene.get('UIScene'); if (uiScene) { if (uiScene.healthBar) uiScene.setBarValue(uiScene.healthBar, this.health); if (uiScene.hungerBar) uiScene.setBarValue(uiScene.hungerBar, this.hunger); if (uiScene.thirstBar) uiScene.setBarValue(uiScene.thirstBar, this.thirst); } this.updateLevelUI(); } updateLevelUI() { const xpPercent = (this.currentXP / this.xpToNextLevel) * 100; const levelText = `LV: ${this.currentLevel}`; // Uporaba Antigravity Engine UI klicev, kot zahtevano if (window.Antigravity && window.Antigravity.UI) { window.Antigravity.UI.setText(this.scene, 'LevelDisplay', levelText); window.Antigravity.UI.setBarValue(this.scene, 'XPBar', xpPercent); } } // Friendship System addFriendship(npcType, amount) { if (this.friendship[npcType] !== undefined) { this.friendship[npcType] += amount; console.log(`❤️ +${amount} Friendship with ${npcType} (Total: ${this.friendship[npcType]})`); } } getFriendship(npcType) { return this.friendship[npcType] || 0; } setFriendship(npcType, amount) { if (this.friendship[npcType] !== undefined) { this.friendship[npcType] = amount; } } // ======================================================== // LEVELING SYSTEM // ======================================================== addXP(amount) { this.currentXP += amount; // 1. Preverimo, ali je igralec pripravljen za Level Up while (this.currentXP >= this.xpToNextLevel) { this.levelUp(); } this.updateUI(); } levelUp() { // Povečamo Level this.currentLevel++; // Izračunamo nov XP prag this.xpToNextLevel = Math.floor(this.xpToNextLevel * XP_GROWTH_FACTOR); // Preostanek XP prenesemo v nov Level this.currentXP = this.currentXP - (this.xpToNextLevel / XP_GROWTH_FACTOR); // Bonus Stats this.maxHealth += 10; this.health = this.maxHealth; this.maxHunger += 5; this.maxThirst += 5; this.hunger = this.maxHunger; this.thirst = this.maxThirst; // Vizualni učinek / Prikaz sporočila console.log(`🎉 LEVEL UP! Dosežen level ${this.currentLevel}!`); if (window.Antigravity && window.Antigravity.UI) { window.Antigravity.UI.showMessage( this.scene, `LEVEL UP! Dosežen level ${this.currentLevel}!`, '#FFD700' ); } } }