phase 11 koncano

This commit is contained in:
2025-12-08 14:01:41 +01:00
parent 07f0752d81
commit f3d476e843
21 changed files with 1503 additions and 200 deletions

View File

@@ -7,13 +7,19 @@ class BuildingSystem {
this.buildingsData = {
fence: { name: 'Fence', cost: { wood: 2 }, w: 1, h: 1 },
wall: { name: 'Stone Wall', cost: { stone: 2 }, w: 1, h: 1 },
house: { name: 'House', cost: { wood: 20, stone: 20, gold: 50 }, w: 1, h: 1 } // Visual is bigger but anchor is 1 tile
house: { name: 'House', cost: { wood: 20, stone: 20, gold: 50 }, w: 1, h: 1 }, // Visual is bigger but anchor is 1 tile
barn: { name: 'Barn', cost: { wood: 50, stone: 10 }, w: 1, h: 1 },
silo: { name: 'Silo', cost: { wood: 30, stone: 30 }, w: 1, h: 1 }
};
// Textures init
if (!this.scene.textures.exists('struct_fence')) TextureGenerator.createStructureSprite(this.scene, 'struct_fence', 'fence');
if (!this.scene.textures.exists('struct_wall')) TextureGenerator.createStructureSprite(this.scene, 'struct_wall', 'wall');
if (!this.scene.textures.exists('struct_house')) TextureGenerator.createStructureSprite(this.scene, 'struct_house', 'house');
if (!this.scene.textures.exists('struct_barn')) TextureGenerator.createStructureSprite(this.scene, 'struct_barn', 'barn');
if (this.scene.textures.exists('struct_silo')) TextureGenerator.createStructureSprite(this.scene, 'struct_silo', 'silo');
// House Lv2 Texture
TextureGenerator.createStructureSprite(this.scene, 'struct_house_lv2', 'house_lv2');
}
toggleBuildMode() {
@@ -85,13 +91,12 @@ class BuildingSystem {
}
// 4. Place Building
// Using decorations layer for now, but marking as building
// Need to add texture to TerrainSystem pool?
// Or better: TerrainSystem should handle 'placing structure'
// Using decorations layer for now
const structType = `struct_${this.selectedBuilding}`;
terrain.addDecoration(gridX, gridY, structType);
// Let's modify TerrainSystem to support 'structures' better or just hack decorations
const success = terrain.placeStructure(gridX, gridY, `struct_${this.selectedBuilding}`);
if (success) {
// Assume success if no error (addDecoration checks internally but doesn't return value easily, but we checked space before)
{
this.showFloatingText(`Built ${building.name}!`, gridX, gridY, '#00FF00');
// Build Sound
@@ -108,6 +113,43 @@ class BuildingSystem {
return true;
}
tryUpgrade(gridX, gridY) {
const terrain = this.scene.terrainSystem;
const decKey = `${gridX},${gridY}`;
const decor = terrain.decorationsMap.get(decKey);
if (!decor) return false;
// Check if House Lv1
if (decor.type === 'struct_house') {
const cost = { wood: 100, stone: 50, gold: 100 };
const inv = this.scene.inventorySystem;
// Check Resources
if (!inv.hasItem('wood', cost.wood) || !inv.hasItem('stone', cost.stone) || inv.gold < cost.gold) {
this.showFloatingText('Upgrade Cost: 100 Wood, 50 Stone, 100G', gridX, gridY, '#FF4444');
return true;
}
// Pay
inv.removeItem('wood', cost.wood);
inv.removeItem('stone', cost.stone);
inv.gold -= cost.gold;
inv.updateUI();
// Perform Upgrade
terrain.removeDecoration(gridX, gridY);
terrain.addDecoration(gridX, gridY, 'struct_house_lv2'); // Re-add Lv2
this.showFloatingText('HOUSE CRADED! (Lv. 2)', gridX, gridY, '#00FFFF');
if (this.scene.soundManager) this.scene.soundManager.playSuccess();
return true;
}
return false;
}
showFloatingText(text, gridX, gridY, color) {
const iso = new IsometricUtils(48, 24);
const pos = iso.toScreen(gridX, gridY);