različne velikosti dreves
This commit is contained in:
@@ -86,95 +86,71 @@ class InteractionSystem {
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Try damage decoration (fallback)
|
||||
// 5. Try damage or interact decoration
|
||||
if (this.scene.terrainSystem) {
|
||||
const id = `${gridPos.x},${gridPos.y}`;
|
||||
if (this.scene.terrainSystem.decorationsMap.has(id)) {
|
||||
const decor = this.scene.terrainSystem.decorationsMap.get(id);
|
||||
// 5. Try damage decoration
|
||||
const id = `${gridPos.x},${gridPos.y}`;
|
||||
if (this.scene.terrainSystem.decorationsMap.has(id)) {
|
||||
const decor = this.scene.terrainSystem.decorationsMap.get(id);
|
||||
|
||||
// Calculate Damage based on Tool
|
||||
let damage = 1; // Default hand damage
|
||||
|
||||
// Ruin Interaction - Town Restoration
|
||||
if (decor.type === 'ruin' || decor.type === 'ruin_borut') {
|
||||
// Check if near
|
||||
if (dist > 2.5) {
|
||||
console.log('Ruin too far.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show Project Menu
|
||||
const uiScene = this.scene.scene.get('UIScene');
|
||||
if (uiScene) {
|
||||
// Define requirements based on ruin type
|
||||
let req = { reqWood: 100, reqStone: 50, reqGold: 50 };
|
||||
let ruinName = "Borut's Smithy"; // Default
|
||||
let npcType = 'merchant';
|
||||
|
||||
if (decor.type === 'ruin') {
|
||||
ruinName = "Merchant House";
|
||||
req = { reqWood: 50, reqStone: 30, reqGold: 30 };
|
||||
}
|
||||
|
||||
uiScene.showProjectMenu(req, () => {
|
||||
// On Contribute Logic
|
||||
if (invSys) {
|
||||
const hasWood = invSys.hasItem('wood', req.reqWood);
|
||||
const hasStone = invSys.hasItem('stone', req.reqStone || 0);
|
||||
const hasGold = invSys.hasItem('gold', req.reqGold || 0);
|
||||
|
||||
// Check all requirements
|
||||
if (hasWood && hasStone && hasGold) {
|
||||
// Consume materials
|
||||
invSys.removeItem('wood', req.reqWood);
|
||||
invSys.removeItem('stone', req.reqStone);
|
||||
invSys.removeItem('gold', req.reqGold);
|
||||
invSys.updateUI();
|
||||
|
||||
console.log(`🏗️ Restoring ${ruinName}...`);
|
||||
|
||||
// Transform Ruin -> House
|
||||
this.scene.terrainSystem.removeDecoration(gridPos.x, gridPos.y);
|
||||
this.scene.terrainSystem.placeStructure(gridPos.x, gridPos.y, 'house');
|
||||
|
||||
// Spawn NPC nearby
|
||||
const npc = new NPC(this.scene, gridPos.x + 1, gridPos.y + 1,
|
||||
this.scene.terrainOffsetX, this.scene.terrainOffsetY, npcType);
|
||||
this.scene.npcs.push(npc);
|
||||
|
||||
// Increase friendship (hearts)
|
||||
if (this.scene.statsSystem) {
|
||||
this.scene.statsSystem.addFriendship(npcType, 10); // +10 hearts
|
||||
}
|
||||
|
||||
console.log(`✅ ${ruinName} Restored! +10 ❤️ Friendship`);
|
||||
|
||||
// Play build sound
|
||||
if (this.scene.soundManager) this.scene.soundManager.playBuild();
|
||||
} else {
|
||||
// Not enough materials
|
||||
const missing = [];
|
||||
if (!hasWood) missing.push(`${req.reqWood} Wood`);
|
||||
if (!hasStone) missing.push(`${req.reqStone} Stone`);
|
||||
if (!hasGold) missing.push(`${req.reqGold} Gold`);
|
||||
|
||||
console.log(`❌ Not enough materials! Need: ${missing.join(', ')}`);
|
||||
alert(`Potrebuješ še: ${missing.join(', ')} da obnoviš ${ruinName}.`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return; // Don't damage it
|
||||
}
|
||||
// Tool Logic
|
||||
if (decor.type === 'tree' && activeTool === 'axe') {
|
||||
damage = 3; // Axe destroys tree fast
|
||||
} else if ((decor.type === 'bush' || decor.type === 'stone') && activeTool === 'pickaxe') {
|
||||
damage = 3; // Pickaxe destroys stone fast
|
||||
}
|
||||
|
||||
const result = this.scene.terrainSystem.damageDecoration(gridPos.x, gridPos.y, 1);
|
||||
// Apply damage
|
||||
const result = this.scene.terrainSystem.damageDecoration(gridPos.x, gridPos.y, damage);
|
||||
|
||||
if (result === 'destroyed') {
|
||||
// Play chop sound
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
// Play proper sound
|
||||
if (decor.type === 'tree') {
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
} else {
|
||||
// Play stone break sound (using chop for now or generic hit)
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
}
|
||||
|
||||
// AUTO-LOOT directly to Inventory
|
||||
let lootType = 'wood'; // Default
|
||||
let lootCount = 1;
|
||||
|
||||
if (decor.type === 'tree') {
|
||||
lootType = 'wood';
|
||||
lootCount = 3 + Math.floor(Math.random() * 3); // 3-5 wood
|
||||
} else if (decor.type === 'bush' || decor.type === 'stone') {
|
||||
lootType = 'stone';
|
||||
lootCount = 2 + Math.floor(Math.random() * 3); // 2-4 stone
|
||||
} else if (decor.type === 'flower') {
|
||||
lootType = 'seeds'; // Flowers drop seeds? Or flower item?
|
||||
lootCount = 1;
|
||||
}
|
||||
|
||||
console.log(`🎁 Auto-looted: ${lootCount}x ${lootType}`);
|
||||
|
||||
if (invSys) {
|
||||
invSys.addItem(lootType, lootCount);
|
||||
|
||||
// Show floating text feedback " +3 Wood "
|
||||
const screenPos = this.iso.toScreen(gridPos.x, gridPos.y);
|
||||
const txt = this.scene.add.text(
|
||||
screenPos.x + this.scene.terrainOffsetX,
|
||||
screenPos.y + this.scene.terrainOffsetY - 30,
|
||||
`+${lootCount} ${lootType.toUpperCase()}`,
|
||||
{ fontSize: '14px', fill: '#ffff00', stroke: '#000', strokeThickness: 2 }
|
||||
);
|
||||
txt.setOrigin(0.5);
|
||||
this.scene.tweens.add({
|
||||
targets: txt,
|
||||
y: txt.y - 40,
|
||||
alpha: 0,
|
||||
duration: 1000,
|
||||
onComplete: () => txt.destroy()
|
||||
});
|
||||
}
|
||||
|
||||
// Spawn loot
|
||||
this.spawnLoot(gridPos.x, gridPos.y, 'wood');
|
||||
} else if (result === 'hit') {
|
||||
// Play hit sound
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
@@ -182,6 +158,99 @@ class InteractionSystem {
|
||||
}
|
||||
}
|
||||
|
||||
handleDecorationClick(gridX, gridY) {
|
||||
if (!this.scene.player) return;
|
||||
|
||||
// Check distance
|
||||
const playerPos = this.scene.player.getPosition();
|
||||
const dist = Phaser.Math.Distance.Between(playerPos.x, playerPos.y, gridX, gridY);
|
||||
|
||||
if (dist > 3.0) { // Slightly increased radius for easier clicking
|
||||
console.log('Too far:', dist.toFixed(1));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Active Tool
|
||||
let activeTool = null;
|
||||
const uiScene = this.scene.scene.get('UIScene');
|
||||
const invSys = this.scene.inventorySystem;
|
||||
|
||||
if (uiScene && invSys) {
|
||||
const selectedIdx = uiScene.selectedSlot;
|
||||
const slotData = invSys.slots[selectedIdx];
|
||||
if (slotData) activeTool = slotData.type;
|
||||
}
|
||||
|
||||
// REUSE LOGIC
|
||||
const id = `${gridX},${gridY}`;
|
||||
if (this.scene.terrainSystem.decorationsMap.has(id)) {
|
||||
const decor = this.scene.terrainSystem.decorationsMap.get(id);
|
||||
|
||||
// Calculate Damage based on Tool
|
||||
let damage = 1; // Default hand damage
|
||||
|
||||
// Tool Logic
|
||||
if (decor.type === 'tree' && activeTool === 'axe') {
|
||||
damage = 3; // Axe destroys tree fast
|
||||
} else if ((decor.type === 'bush' || decor.type === 'stone') && activeTool === 'pickaxe') {
|
||||
damage = 3; // Pickaxe destroys stone fast
|
||||
}
|
||||
|
||||
// Apply damage
|
||||
const result = this.scene.terrainSystem.damageDecoration(gridX, gridY, damage);
|
||||
|
||||
if (result === 'destroyed') {
|
||||
// Play proper sound
|
||||
if (decor.type === 'tree') {
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
} else {
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
}
|
||||
|
||||
// AUTO-LOOT directly to Inventory
|
||||
let lootType = 'wood'; // Default
|
||||
let lootCount = 1;
|
||||
|
||||
if (decor.type === 'tree') {
|
||||
lootType = 'wood';
|
||||
lootCount = 3 + Math.floor(Math.random() * 3); // 3-5 wood
|
||||
} else if (decor.type === 'bush' || decor.type === 'stone') {
|
||||
lootType = 'stone';
|
||||
lootCount = 2 + Math.floor(Math.random() * 3); // 2-4 stone
|
||||
} else if (decor.type === 'flower') {
|
||||
lootType = 'seeds';
|
||||
lootCount = 1;
|
||||
}
|
||||
|
||||
console.log(`🎁 Auto-looted: ${lootCount}x ${lootType}`);
|
||||
|
||||
if (invSys) {
|
||||
invSys.addItem(lootType, lootCount);
|
||||
|
||||
// Show floating text feedback
|
||||
const screenPos = this.iso.toScreen(gridX, gridY);
|
||||
const txt = this.scene.add.text(
|
||||
screenPos.x + this.scene.terrainOffsetX,
|
||||
screenPos.y + this.scene.terrainOffsetY - 30,
|
||||
`+${lootCount} ${lootType.toUpperCase()}`,
|
||||
{ fontSize: '14px', fill: '#ffff00', stroke: '#000', strokeThickness: 2 }
|
||||
);
|
||||
txt.setOrigin(0.5);
|
||||
this.scene.tweens.add({
|
||||
targets: txt,
|
||||
y: txt.y - 40,
|
||||
alpha: 0,
|
||||
duration: 1000,
|
||||
onComplete: () => txt.destroy()
|
||||
});
|
||||
}
|
||||
|
||||
} else if (result === 'hit') {
|
||||
if (this.scene.soundManager) this.scene.soundManager.playChop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spawnLoot(gridX, gridY, type) {
|
||||
console.log(`🎁 Spawning ${type} at ${gridX},${gridY}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user