kockasta mapa

This commit is contained in:
2025-12-07 14:28:39 +01:00
parent 98059a2659
commit 045bf24792
11 changed files with 670 additions and 1249 deletions

View File

@@ -17,9 +17,6 @@ class InteractionSystem {
this.scene.input.keyboard.on('keydown-E', () => {
this.handleInteractKey();
});
// Loot Array
this.drops = [];
}
handleInteractKey() {
@@ -30,7 +27,9 @@ class InteractionSystem {
let nearest = null;
let minDist = 2.5; // Interaction range
for (const npc of this.scene.npcs) {
const candidates = this.scene.spatialGrid ? this.scene.spatialGrid.query(playerPos.x, playerPos.y) : this.scene.npcs;
for (const npc of candidates) {
const d = Phaser.Math.Distance.Between(playerPos.x, playerPos.y, npc.gridX, npc.gridY);
if (d < minDist) {
minDist = d;
@@ -84,8 +83,10 @@ class InteractionSystem {
}
// 3.5 Check for NPC Interaction
if (this.scene.npcs) {
for (const npc of this.scene.npcs) {
const candidates = this.scene.spatialGrid ? this.scene.spatialGrid.query(gridX, gridY) : this.scene.npcs;
if (candidates) {
for (const npc of candidates) {
// Increased radius to 1.8 to catch moving NPCs easier
if (Math.abs(npc.gridX - gridX) < 1.8 && Math.abs(npc.gridY - gridY) < 1.8) {
@@ -139,11 +140,9 @@ class InteractionSystem {
if (decor.type === 'tree') {
damage = (activeTool === 'axe') ? 3 : 1;
if (!isAttack && activeTool !== 'axe') return;
}
else if (decor.type === 'stone') {
damage = (activeTool === 'pickaxe') ? 3 : 1;
if (!isAttack && activeTool !== 'pickaxe') return;
}
else if (decor.type === 'bush') damage = 2;
@@ -153,17 +152,18 @@ class InteractionSystem {
if (decor.hp <= 0) {
const type = this.scene.terrainSystem.removeDecoration(gridX, gridY);
// Loot logic
// Loot logic via LootSystem
let loot = 'wood';
if (type === 'stone') loot = 'stone';
if (type === 'bush') loot = 'seeds'; // Maybe berries?
if (type === 'tree') {
this.spawnLoot(gridX, gridY, 'wood');
this.spawnLoot(gridX, gridY, 'wood');
this.spawnLoot(gridX, gridY, 'wood');
}
else {
this.spawnLoot(gridX, gridY, loot);
if (this.scene.lootSystem) {
if (type === 'tree') {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'wood', 3);
}
else {
this.scene.lootSystem.spawnLoot(gridX, gridY, loot, 1);
}
}
} else {
@@ -192,42 +192,7 @@ class InteractionSystem {
this.scene.tweens.add({ targets: txt, y: txt.y - 40, alpha: 0, duration: 1000, onComplete: () => txt.destroy() });
}
spawnLoot(gridX, gridY, type) {
console.log(`🎁 Spawning ${type} at ${gridX},${gridY}`);
const screenPos = this.iso.toScreen(gridX, gridY);
const x = screenPos.x + this.scene.terrainOffsetX;
const y = screenPos.y + this.scene.terrainOffsetY;
let symbol = '?';
if (type === 'wood') symbol = '🪵';
if (type === 'stone') symbol = '🪨';
if (type === 'seeds') symbol = '🌱';
if (type === 'wheat') symbol = '🌾';
if (type === 'axe') symbol = '🪓';
if (type === 'item_bone') symbol = '🦴';
const drop = this.scene.add.text(x, y - 20, symbol, { fontSize: '20px' });
drop.setOrigin(0.5);
drop.setDepth(this.iso.getDepth(gridX, gridY) + 500);
this.scene.tweens.add({
targets: drop, y: y - 40, duration: 500, yoyo: true, ease: 'Sine.easeOut', repeat: -1
});
this.drops.push({ gridX, gridY, sprite: drop, type: type });
}
update() {
if (!this.scene.player) return;
const playerPos = this.scene.player.getPosition();
for (let i = this.drops.length - 1; i >= 0; i--) {
const drop = this.drops[i];
if (Math.abs(drop.gridX - playerPos.x) < 0.8 && Math.abs(drop.gridY - playerPos.y) < 0.8) {
if (this.scene.inventorySystem) this.scene.inventorySystem.addItem(drop.type, 1);
drop.sprite.destroy();
this.drops.splice(i, 1);
}
}
update(delta) {
// No logic needed here anymore (loot pickup handled by LootSystem)
}
}