ok
This commit is contained in:
73
EMERGENCY_SYSTEMS_RECOVERY/BuildingRestorationSystem.js
Normal file
73
EMERGENCY_SYSTEMS_RECOVERY/BuildingRestorationSystem.js
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
/**
|
||||
* BuildingRestorationSystem.js
|
||||
* ===========================
|
||||
* Manages the repair and restoration of ruined buildings in Town Square.
|
||||
*
|
||||
* Mechanics:
|
||||
* - Buildings start in 'ruined' state.
|
||||
* - Players contribute materials (Wood, Stone, Scrap).
|
||||
* - Restoration happens in stages.
|
||||
* - Restored buildings unlock NPCs and Services.
|
||||
*/
|
||||
|
||||
export default class BuildingRestorationSystem {
|
||||
constructor(scene) {
|
||||
this.scene = scene;
|
||||
this.buildings = new Map();
|
||||
this._initBuildings();
|
||||
}
|
||||
|
||||
_initBuildings() {
|
||||
// Sample restoration targets
|
||||
this.buildings.set('blacksmith_shop', {
|
||||
name: 'Ivan\'s Blacksmith',
|
||||
state: 'ruined',
|
||||
progress: 0,
|
||||
requirements: { wood: 50, stone: 30, scrap: 10 },
|
||||
npc: 'Ivan Kovač',
|
||||
unlocked: false
|
||||
});
|
||||
|
||||
this.buildings.set('bakery', {
|
||||
name: 'Town Bakery',
|
||||
state: 'ruined',
|
||||
progress: 0,
|
||||
requirements: { wood: 40, stone: 20, scrap: 5 },
|
||||
npc: 'Marija Pekarka',
|
||||
unlocked: false
|
||||
});
|
||||
}
|
||||
|
||||
contribute(buildingId, material, amount) {
|
||||
const b = this.buildings.get(buildingId);
|
||||
if (!b) return false;
|
||||
|
||||
if (b.requirements[material] && b.requirements[material] > 0) {
|
||||
const used = Math.min(amount, b.requirements[material]);
|
||||
b.requirements[material] -= used;
|
||||
|
||||
// Check if all materials are 0
|
||||
const allDone = Object.values(b.requirements).every(val => val <= 0);
|
||||
if (allDone) {
|
||||
this.restore(buildingId);
|
||||
}
|
||||
return used;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
restore(buildingId) {
|
||||
const b = this.buildings.get(buildingId);
|
||||
if (!b) return;
|
||||
b.state = 'restored';
|
||||
b.unlocked = true;
|
||||
b.progress = 100;
|
||||
console.log(`🏰 ${b.name} has been restored!`);
|
||||
this.scene.events.emit('building_restored', b);
|
||||
}
|
||||
|
||||
getBuilding(id) {
|
||||
return this.buildings.get(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user