This commit is contained in:
2025-12-08 00:18:56 +01:00
parent b36cc981d6
commit 7834aee111
10 changed files with 466 additions and 43 deletions

View File

@@ -125,6 +125,34 @@ class InteractionSystem {
}
}
// 3.5 Try Opening Chest
if (!isAttack && this.scene.terrainSystem) {
const decorKey = `${gridX},${gridY}`;
const decor = this.scene.terrainSystem.decorationsMap.get(decorKey);
if (decor && decor.type === 'chest') {
// Open chest and spawn loot!
console.log('📦 Opening treasure chest!');
// Random loot
const lootTable = ['item_scrap', 'item_chip', 'item_wood', 'item_stone', 'item_bone'];
const lootCount = Phaser.Math.Between(2, 4);
for (let i = 0; i < lootCount; i++) {
const randomLoot = Phaser.Utils.Array.GetRandom(lootTable);
if (this.scene.lootSystem) {
const offsetX = Phaser.Math.Between(-1, 1);
const offsetY = Phaser.Math.Between(-1, 1);
this.scene.lootSystem.spawnLoot(gridX + offsetX, gridY + offsetY, randomLoot);
}
}
// Remove chest
this.scene.terrainSystem.removeDecoration(gridX, gridY);
return;
}
}
// 4. Try Planting Tree (Manual Planting)
if (!isAttack && (activeTool === 'tree_sapling' || activeTool === 'item_sapling')) {
const tile = this.scene.terrainSystem.getTile(gridX, gridY);

View File

@@ -104,6 +104,7 @@ class TerrainSystem {
STONE: { name: 'stone', height: 0.7, color: 0x888888 },
PAVEMENT: { name: 'pavement', height: 0.6, color: 0x777777 },
RUINS: { name: 'ruins', height: 0.6, color: 0x555555 },
WALL_EDGE: { name: 'WALL_EDGE', height: 0.8, color: 0x505050, solid: true }, // OBZIDJE
PATH: { name: 'path', height: -1, color: 0xc2b280 },
FARMLAND: { name: 'farmland', height: -1, color: 0x5c4033 },
// MINE TYPES
@@ -222,11 +223,26 @@ class TerrainSystem {
if (Math.abs(x - FARM_CENTER_X) <= FARM_SIZE / 2 && Math.abs(y - FARM_CENTER_Y) <= FARM_SIZE / 2) {
terrainType = this.terrainTypes.DIRT;
}
// CITY AREA - 15x15 območje z OBZIDJEM
if (x >= CITY_START_X && x < CITY_START_X + CITY_SIZE &&
y >= CITY_START_Y && y < CITY_START_Y + CITY_SIZE) {
terrainType = this.terrainTypes.PAVEMENT;
if (Math.random() < 0.2) {
terrainType = this.terrainTypes.RUINS;
// Preverimo, ali smo na ROBOVIH (Obzidje)
const isEdge = (x === CITY_START_X ||
x === CITY_START_X + CITY_SIZE - 1 ||
y === CITY_START_Y ||
y === CITY_START_Y + CITY_SIZE - 1);
if (isEdge) {
// OBZIDJE - trdno, igralec ne more čez
terrainType = { name: 'WALL_EDGE', color: 0x505050, solid: true };
} else {
// NOTRANJOST MESTA - tlakovci (pavement)
terrainType = this.terrainTypes.PAVEMENT;
// Naključne ruševine v mestu
if (Math.random() < 0.15) {
terrainType = this.terrainTypes.RUINS;
}
}
}
@@ -234,7 +250,8 @@ class TerrainSystem {
type: terrainType.name,
texture: terrainType.name,
hasDecoration: false,
hasCrop: false
hasCrop: false,
solid: terrainType.solid || false // Inherits from terrain type
};
// Place Trees dynamically during generation
@@ -712,4 +729,45 @@ class TerrainSystem {
}
}
}
placeStructure(x, y, type) {
// Generate textures if needed
if (type === 'chest' && !this.scene.textures.exists('chest')) {
TextureGenerator.createChestSprite(this.scene, 'chest');
}
if (type === 'spawner' && !this.scene.textures.exists('spawner')) {
TextureGenerator.createSpawnerSprite(this.scene, 'spawner');
}
if (type === 'ruin' && !this.scene.textures.exists('ruin')) {
TextureGenerator.createStructureSprite(this.scene, 'ruin', 'ruin');
}
if (type === 'arena' && !this.scene.exists('arena')) {
// Arena uses ruin texture for now
TextureGenerator.createStructureSprite(this.scene, 'arena', 'ruin');
}
if (type.startsWith('signpost')) {
const textMap = { 'signpost_city': '→', 'signpost_farm': '←', 'signpost_both': '⇅' };
const text = textMap[type] || '?';
if (!this.scene.textures.exists(type)) {
TextureGenerator.createSignpostSprite(this.scene, type, text);
}
}
// Place as decoration
this.addDecoration(x, y, type);
console.log(`🏛️ Place ${type} at (${x}, ${y})`);
}
setSolid(x, y, isSolid) {
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
this.tiles[y][x].solid = isSolid;
}
}
isSolid(x, y) {
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
return this.tiles[y][x].solid || false;
}
return true; // Out of bounds = solid
}
}