|
|
@ -183,7 +183,11 @@ let game = new Vue({ |
|
|
|
isUpgradeable: true, |
|
|
|
isUpgradeable: true, |
|
|
|
amount: 5, |
|
|
|
amount: 5, |
|
|
|
price: 500, |
|
|
|
price: 500, |
|
|
|
intervalInSeconds: 60, |
|
|
|
resourcesToBuild: { |
|
|
|
|
|
|
|
wood: 400, |
|
|
|
|
|
|
|
stone: 350 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
intervalInSeconds: 15, |
|
|
|
amountPerLevel: [100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000, 5000], |
|
|
|
amountPerLevel: [100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000, 5000], |
|
|
|
pricePerLevel: [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000], |
|
|
|
pricePerLevel: [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000], |
|
|
|
intervalPerLevel: [15, 25, 30, 45, 60, 90, 90, 120, 120, 120], |
|
|
|
intervalPerLevel: [15, 25, 30, 45, 60, 90, 90, 120, 120, 120], |
|
|
@ -350,17 +354,56 @@ let game = new Vue({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buyBuilding(building) { |
|
|
|
buyBuilding(building) { |
|
|
|
if (this.resources.gold.amount >= building.price) { |
|
|
|
if (building.resourcesToBuild) { |
|
|
|
this.sub(building.price); |
|
|
|
if (this.buildingIsBuildable(building)) { |
|
|
|
building.isOwned = true; |
|
|
|
Object.keys(building.resourcesToBuild).forEach((resourceToBuild) => { |
|
|
|
building.price = building.pricePerLevel[0]; |
|
|
|
game.resources[resourceToBuild].amount -= building.resourcesToBuild[resourceToBuild]; |
|
|
|
building.amount = building.amountPerLevel[0]; |
|
|
|
}); |
|
|
|
building.interval = building.intervalPerLevel[0]; |
|
|
|
|
|
|
|
|
|
|
|
building.isOwned = true; |
|
|
|
|
|
|
|
building.price = building.pricePerLevel[0]; |
|
|
|
|
|
|
|
building.amount = building.amountPerLevel[0]; |
|
|
|
|
|
|
|
building.interval = building.intervalPerLevel[0]; |
|
|
|
|
|
|
|
|
|
|
|
this.upgradeBuilding(building, true); |
|
|
|
this.upgradeBuilding(building, true); |
|
|
|
this.saveBuildingsToStorage(); |
|
|
|
this.saveBuildingsToStorage(); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.sendWarning('Not enough gold'); |
|
|
|
if (this.resources.gold.amount >= building.price) { |
|
|
|
|
|
|
|
this.sub(building.price); |
|
|
|
|
|
|
|
building.isOwned = true; |
|
|
|
|
|
|
|
building.price = building.pricePerLevel[0]; |
|
|
|
|
|
|
|
building.amount = building.amountPerLevel[0]; |
|
|
|
|
|
|
|
building.interval = building.intervalPerLevel[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.upgradeBuilding(building, true); |
|
|
|
|
|
|
|
this.saveBuildingsToStorage(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.sendWarning('Not enough gold'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buildingIsBuildable(building) { |
|
|
|
|
|
|
|
let game = this; |
|
|
|
|
|
|
|
let resourcesMissing = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(building.resourcesToBuild).forEach((resourceToBuild) => { |
|
|
|
|
|
|
|
if (building.resourcesToBuild[resourceToBuild] > game.resources[resourceToBuild].amount) { |
|
|
|
|
|
|
|
resourcesMissing.push(resourceToBuild); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resourcesMissing.length) { |
|
|
|
|
|
|
|
resourcesMissing.forEach((resource) => { |
|
|
|
|
|
|
|
game.sendWarning( |
|
|
|
|
|
|
|
'Not enough ' + resource + ' to build ' + building.name + '!' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|