dreva in kamni top

This commit is contained in:
2025-12-07 22:32:45 +01:00
parent 974141c08c
commit 6b8f9aee66
13 changed files with 384 additions and 90 deletions

View File

@@ -125,6 +125,26 @@ class InteractionSystem {
}
}
// 4. Try Planting Tree (Manual Planting)
if (!isAttack && (activeTool === 'tree_sapling' || activeTool === 'item_sapling')) {
const tile = this.scene.terrainSystem.getTile(gridX, gridY);
// Dovolimo sajenje samo na travo in dirt
if (tile && !tile.hasDecoration && !tile.hasCrop && (tile.type.includes('grass') || tile.type.includes('dirt'))) {
const saplingSprite = window.SPRITE_TREE_SAPLING || 'tree_sapling';
this.scene.terrainSystem.addDecoration(gridX, gridY, saplingSprite);
// Remove 1 sapling from hand
if (this.scene.inventorySystem) {
this.scene.inventorySystem.removeItem(activeTool, 1);
}
// Sound
// this.scene.soundManager.playPlant();
return;
}
}
// 4. Try Farming Action
if (this.scene.farmingSystem && !isAttack) {
const didFarm = this.scene.farmingSystem.interact(gridX, gridY, activeTool);
@@ -136,38 +156,74 @@ class InteractionSystem {
if (this.scene.terrainSystem.decorationsMap.has(id)) {
const decor = this.scene.terrainSystem.decorationsMap.get(id);
// handleTreeHit Logic (User Request)
// Preverimo tip in ustrezno orodje
let damage = 1;
if (decor.type === 'tree') {
damage = (activeTool === 'axe') ? 3 : 1;
// DREVESA (sapling, healthy, dead, blue)
if (decor.type.includes('tree') || decor.type.includes('sapling')) {
damage = (activeTool === 'axe') ? 5 : 1; // Povečal damage z sekiro
}
else if (decor.type === 'stone') {
damage = (activeTool === 'pickaxe') ? 3 : 1;
// KAMNI (rock, stone)
else if (decor.type.includes('rock') || decor.type.includes('stone')) {
damage = (activeTool === 'pickaxe') ? 5 : 1;
}
else if (decor.type === 'bush') damage = 2;
else if (decor.type.includes('bush')) damage = 5;
// Apply damage
decor.hp -= damage;
this.showFloatingText(`${-damage}`, gridX, gridY, '#ffaaaa');
this.showFloatingText(`-${damage}`, gridX, gridY, '#ffaaaa');
// Chop Sound
// Sound
if (this.scene.soundManager) {
this.scene.soundManager.playChop();
if (decor.type.includes('tree')) this.scene.soundManager.playChop();
else this.scene.soundManager.playHit(); // Generic hit for rocks
}
if (decor.hp <= 0) {
const type = this.scene.terrainSystem.removeDecoration(gridX, gridY);
// Loot logic via LootSystem
let loot = 'wood';
if (type === 'stone') loot = 'stone';
if (type === 'bush') loot = 'seeds'; // Maybe berries?
const prevType = decor.type;
if (this.scene.lootSystem) {
if (type === 'tree') {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'wood', 3);
// Logic: If Tree (and not sapling), turn into Sapling immediately (Regrowth)
if ((prevType.includes('tree') || prevType.includes('final')) && !prevType.includes('sapling')) {
decor.type = window.SPRITE_TREE_SAPLING || 'tree_sapling';
decor.hp = 2; // Fragile sapling
decor.scale = 1.0;
// Update visual immediately
const sprite = this.scene.terrainSystem.visibleDecorations.get(id);
if (sprite) {
sprite.setTexture(decor.type);
sprite.setScale(decor.scale);
// Shrink effect to simulate falling/replacement
this.scene.tweens.add({
targets: sprite, scaleX: { from: 1.2, to: 1.0 }, scaleY: { from: 1.2, to: 1.0 }, duration: 200
});
}
else {
this.scene.lootSystem.spawnLoot(gridX, gridY, loot, 1);
// Drop Wood Only
if (this.scene.lootSystem) {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'item_wood', Math.floor(Math.random() * 3) + 2);
}
console.log('🌱 Tree replanted automatically.');
}
else {
const type = this.scene.terrainSystem.removeDecoration(gridX, gridY);
// Loot logic handled here via LootSystem
if (this.scene.lootSystem) {
if (type.includes('rock') || type.includes('stone')) {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'item_stone', Math.floor(Math.random() * 3) + 1);
}
else if (type.includes('bush') || type.includes('sapling')) {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'item_seeds', 1);
if (type.includes('sapling')) {
this.scene.lootSystem.spawnLoot(gridX, gridY, window.SPRITE_TREE_SAPLING || 'tree_sapling', 1);
}
}
else if (type.includes('flowers')) {
this.scene.lootSystem.spawnLoot(gridX, gridY, 'item_seeds', 1);
}
}
}