phase 11 part1

This commit is contained in:
2025-12-08 12:30:15 +01:00
parent 3336b59e7d
commit 07f0752d81
15 changed files with 1383 additions and 133 deletions

205
src/systems/GraveSystem.js Normal file
View File

@@ -0,0 +1,205 @@
/**
* GRAVE SYSTEM
* Zombi workers lahko počivajo v grobovih za regeneracijo
*/
class GraveSystem {
constructor(scene) {
this.scene = scene;
this.graves = []; // Seznam vseh postavljenih grobov
}
/**
* Place grave on terrain
*/
placeGrave(gridX, gridY) {
const terrain = this.scene.terrainSystem;
if (!terrain) return false;
const tile = terrain.getTile(gridX, gridY);
if (!tile) return false;
// Check if already has grave
const key = `${gridX},${gridY}`;
if (this.graves.find(g => g.key === key)) {
console.log('⚠️ Grave already exists here!');
return false;
}
// Create grave object
const grave = {
gridX,
gridY,
key,
occupiedBy: null, // Zombie currently resting
sprite: null
};
// Create visual sprite
const screenPos = this.scene.iso.toScreen(gridX, gridY);
grave.sprite = this.scene.add.sprite(
screenPos.x + this.scene.terrainOffsetX,
screenPos.y + this.scene.terrainOffsetY,
'gravestone'
);
grave.sprite.setOrigin(0.5, 1);
grave.sprite.setScale(0.3);
grave.sprite.setDepth(this.scene.iso.getDepth(gridX, gridY, this.scene.iso.LAYER_OBJECTS));
this.graves.push(grave);
console.log(`🪦 Grave placed at ${gridX},${gridY}`);
return true;
}
/**
* Remove grave
*/
removeGrave(gridX, gridY) {
const key = `${gridX},${gridY}`;
const index = this.graves.findIndex(g => g.key === key);
if (index === -1) return false;
const grave = this.graves[index];
// Kick out occupant
if (grave.occupiedBy) {
grave.occupiedBy.workerData.isResting = false;
grave.occupiedBy = null;
}
if (grave.sprite) grave.sprite.destroy();
this.graves.splice(index, 1);
console.log(`🪦 Grave removed at ${gridX},${gridY}`);
return true;
}
/**
* Assign zombie to rest in grave
*/
assignZombieToGrave(zombie) {
if (!zombie.workerData) return false;
// Find empty grave
const emptyGrave = this.graves.find(g => g.occupiedBy === null);
if (!emptyGrave) {
console.log('🚫 No empty graves available!');
return false;
}
// Mark zombie as resting
zombie.workerData.isResting = true;
zombie.workerData.restingGrave = emptyGrave;
emptyGrave.occupiedBy = zombie;
// Move zombie to grave
zombie.gridX = emptyGrave.gridX;
zombie.gridY = emptyGrave.gridY;
zombie.updatePosition();
// Visual: Make zombie semi-transparent
if (zombie.sprite) {
zombie.sprite.setAlpha(0.5);
}
console.log(`🪦 Zombie resting in grave at ${emptyGrave.gridX},${emptyGrave.gridY}`);
return true;
}
/**
* Wake zombie from grave
*/
wakeZombie(zombie) {
if (!zombie.workerData || !zombie.workerData.isResting) return false;
const grave = zombie.workerData.restingGrave;
if (grave) {
grave.occupiedBy = null;
}
zombie.workerData.isResting = false;
zombie.workerData.restingGrave = null;
// Restore visual
if (zombie.sprite) {
zombie.sprite.setAlpha(1.0);
}
console.log(`🪦 Zombie woke up from grave`);
return true;
}
/**
* Update - regenerate resting zombies
*/
update(delta) {
for (const grave of this.graves) {
if (grave.occupiedBy && grave.occupiedBy.workerData) {
const zombie = grave.occupiedBy;
const wd = zombie.workerData;
// Regenerate energy (slower than normal decay)
wd.energy += (0.2 * delta) / 1000; // +0.2 energy/sec
wd.energy = Math.min(100, wd.energy);
// Regenerate HP if energy > 50
if (wd.energy > 50) {
zombie.hp += (0.1 * delta) / 1000; // +0.1 HP/sec
zombie.hp = Math.min(zombie.maxHp, zombie.hp);
}
// Visual feedback - green tint when regenerating
if (zombie.sprite) {
zombie.sprite.setTint(0x00FF00);
}
}
}
}
/**
* Find nearest empty grave
*/
findNearestEmptyGrave(x, y) {
let nearest = null;
let minDist = 999;
for (const grave of this.graves) {
if (grave.occupiedBy === null) {
const dist = Phaser.Math.Distance.Between(x, y, grave.gridX, grave.gridY);
if (dist < minDist) {
minDist = dist;
nearest = grave;
}
}
}
return nearest;
}
/**
* Auto-rest: Send low-energy zombies to graves
*/
autoRest() {
if (!this.scene.zombieWorkerSystem) return;
for (const worker of this.scene.zombieWorkerSystem.workers) {
if (!worker.workerData) continue;
// If energy < 20 and not resting, send to grave
if (worker.workerData.energy < 20 && !worker.workerData.isResting) {
const grave = this.findNearestEmptyGrave(worker.gridX, worker.gridY);
if (grave) {
this.assignZombieToGrave(worker);
console.log(`🪦 Auto-rest: Zombie sent to grave (Low energy)`);
}
}
// If energy > 80 and resting, wake up
if (worker.workerData.energy > 80 && worker.workerData.isResting) {
this.wakeZombie(worker);
console.log(`🪦 Auto-wake: Zombie restored and ready to work`);
}
}
}
}