|
|
@ -12,6 +12,15 @@ let game = new Vue({ |
|
|
|
coal: 0, |
|
|
|
coal: 0, |
|
|
|
planks: 0 |
|
|
|
planks: 0 |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
hadResource: { |
|
|
|
|
|
|
|
wood: false, |
|
|
|
|
|
|
|
stone: false, |
|
|
|
|
|
|
|
iron: false, |
|
|
|
|
|
|
|
bricks: false, |
|
|
|
|
|
|
|
corn: false, |
|
|
|
|
|
|
|
coal: false, |
|
|
|
|
|
|
|
planks: false |
|
|
|
|
|
|
|
}, |
|
|
|
storageNames: null, |
|
|
|
storageNames: null, |
|
|
|
buildings: [ |
|
|
|
buildings: [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -139,6 +148,7 @@ let game = new Vue({ |
|
|
|
this.storageNames = { |
|
|
|
this.storageNames = { |
|
|
|
lastVersion: 'lastVersion', |
|
|
|
lastVersion: 'lastVersion', |
|
|
|
resources: 'resources' + this.version, |
|
|
|
resources: 'resources' + this.version, |
|
|
|
|
|
|
|
hadResource: 'hadResource' + this.version, |
|
|
|
buildings: 'buildings' + this.version, |
|
|
|
buildings: 'buildings' + this.version, |
|
|
|
currentQuest: 'currentQuest' + this.version |
|
|
|
currentQuest: 'currentQuest' + this.version |
|
|
|
} |
|
|
|
} |
|
|
@ -146,6 +156,7 @@ let game = new Vue({ |
|
|
|
this.checkVersion(); |
|
|
|
this.checkVersion(); |
|
|
|
|
|
|
|
|
|
|
|
this.checkBuildings(); |
|
|
|
this.checkBuildings(); |
|
|
|
|
|
|
|
this.loadHadResourceFromStorage(); |
|
|
|
this.loadResourcesFromStorage(); |
|
|
|
this.loadResourcesFromStorage(); |
|
|
|
this.currentQuest = JSON.parse(localStorage.getItem(this.storageNames.currentQuest)); |
|
|
|
this.currentQuest = JSON.parse(localStorage.getItem(this.storageNames.currentQuest)); |
|
|
|
|
|
|
|
|
|
|
@ -153,6 +164,8 @@ let game = new Vue({ |
|
|
|
this.reloadBuildings(); |
|
|
|
this.reloadBuildings(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
|
|
|
|
// System & Saving
|
|
|
|
|
|
|
|
// Check if a new version is played and notify the user of the loss of his beloved score & progress
|
|
|
|
checkVersion() { |
|
|
|
checkVersion() { |
|
|
|
let lastVersion = localStorage.getItem(this.storageNames.lastVersion); |
|
|
|
let lastVersion = localStorage.getItem(this.storageNames.lastVersion); |
|
|
|
|
|
|
|
|
|
|
@ -163,6 +176,7 @@ let game = new Vue({ |
|
|
|
localStorage.setItem(this.storageNames.lastVersion, this.version); |
|
|
|
localStorage.setItem(this.storageNames.lastVersion, this.version); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if buildings-array is outdated
|
|
|
|
checkBuildings() { |
|
|
|
checkBuildings() { |
|
|
|
let savedBuildings = JSON.parse(localStorage.getItem(this.storageNames.buildings)); |
|
|
|
let savedBuildings = JSON.parse(localStorage.getItem(this.storageNames.buildings)); |
|
|
|
|
|
|
|
|
|
|
@ -174,6 +188,7 @@ let game = new Vue({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save buildings with progress -> has to resetted while in beta via version
|
|
|
|
saveBuildingsToStorage() { |
|
|
|
saveBuildingsToStorage() { |
|
|
|
localStorage.setItem(this.storageNames.buildings, JSON.stringify(this.buildings)); |
|
|
|
localStorage.setItem(this.storageNames.buildings, JSON.stringify(this.buildings)); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -196,6 +211,7 @@ let game = new Vue({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save resources a user has
|
|
|
|
saveResourcesToStorage() { |
|
|
|
saveResourcesToStorage() { |
|
|
|
localStorage.setItem(this.storageNames.resources, JSON.stringify(this.resources)); |
|
|
|
localStorage.setItem(this.storageNames.resources, JSON.stringify(this.resources)); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -208,42 +224,65 @@ let game = new Vue({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save resources a user ever had to generate quests
|
|
|
|
|
|
|
|
saveHadResourceToStorage() { |
|
|
|
|
|
|
|
localStorage.setItem(this.storageNames.hadResource, JSON.stringify(this.hadResource)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadHadResourceFromStorage: function () { |
|
|
|
|
|
|
|
let savedHadResource = JSON.parse(localStorage.getItem(this.storageNames.hadResource)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (savedHadResource) { |
|
|
|
|
|
|
|
this.hadResource = savedHadResource; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resource-Management
|
|
|
|
add(amount = 0, resource = 'gold') { |
|
|
|
add(amount = 0, resource = 'gold') { |
|
|
|
switch (resource) { |
|
|
|
switch (resource) { |
|
|
|
case 'wood': |
|
|
|
case 'wood': |
|
|
|
this.sendResourceMessage(amount, 'wood'); |
|
|
|
this.sendResourceMessage(amount, 'wood'); |
|
|
|
this.resources.wood += amount; |
|
|
|
this.resources.wood += amount; |
|
|
|
|
|
|
|
this.hadResource.wood = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'planks': |
|
|
|
case 'planks': |
|
|
|
this.sendResourceMessage(amount, 'planks'); |
|
|
|
this.sendResourceMessage(amount, 'planks'); |
|
|
|
this.resources.planks += amount; |
|
|
|
this.resources.planks += amount; |
|
|
|
|
|
|
|
this.hadResource.planks = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'stone': |
|
|
|
case 'stone': |
|
|
|
this.sendResourceMessage(amount, 'stone'); |
|
|
|
this.sendResourceMessage(amount, 'stone'); |
|
|
|
this.resources.stone += amount; |
|
|
|
this.resources.stone += amount; |
|
|
|
|
|
|
|
this.hadResource.stone = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'bricks': |
|
|
|
case 'bricks': |
|
|
|
this.sendResourceMessage(amount, 'bricks'); |
|
|
|
this.sendResourceMessage(amount, 'bricks'); |
|
|
|
this.resources.bricks += amount; |
|
|
|
this.resources.bricks += amount; |
|
|
|
|
|
|
|
this.hadResource.bricks = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'coal': |
|
|
|
case 'coal': |
|
|
|
this.sendResourceMessage(amount, 'coal'); |
|
|
|
this.sendResourceMessage(amount, 'coal'); |
|
|
|
this.resources.coal += amount; |
|
|
|
this.resources.coal += amount; |
|
|
|
|
|
|
|
this.hadResource.coal = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'iron': |
|
|
|
case 'iron': |
|
|
|
this.sendResourceMessage(amount, 'iron'); |
|
|
|
this.sendResourceMessage(amount, 'iron'); |
|
|
|
this.resources.iron = Number(this.resources.iron + amount); |
|
|
|
this.resources.iron += amount; |
|
|
|
|
|
|
|
this.hadResource.iron = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'corn': |
|
|
|
case 'corn': |
|
|
|
this.sendResourceMessage(amount, 'corn'); |
|
|
|
this.sendResourceMessage(amount, 'corn'); |
|
|
|
this.resources.corn += amount; |
|
|
|
this.resources.corn += amount; |
|
|
|
|
|
|
|
this.hadResource.corn = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'gold': |
|
|
|
case 'gold': |
|
|
|
this.sendResourceMessage(amount, 'gold'); |
|
|
|
this.sendResourceMessage(amount, 'gold'); |
|
|
|
this.resources.gold += amount; |
|
|
|
this.resources.gold += amount; |
|
|
|
|
|
|
|
this.hadResource.gold = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.saveHadResourceToStorage(); |
|
|
|
this.saveResourcesToStorage(); |
|
|
|
this.saveResourcesToStorage(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -252,10 +291,7 @@ let game = new Vue({ |
|
|
|
return this.saveResourcesToStorage(); |
|
|
|
return this.saveResourcesToStorage(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getFormattedNumber(value) { |
|
|
|
// Buying & upgrading buildings + checks + interval-generators
|
|
|
|
return value.toLocaleString('de-DE'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reloadBuildings() { |
|
|
|
reloadBuildings() { |
|
|
|
let vue = this; |
|
|
|
let vue = this; |
|
|
|
|
|
|
|
|
|
|
@ -303,21 +339,6 @@ let game = new Vue({ |
|
|
|
this.loadedIntervals.push(building.intervalEarnID, building.intervalLoadingID); |
|
|
|
this.loadedIntervals.push(building.intervalEarnID, building.intervalLoadingID); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildingHasEnoughResourcesToStart(building) { |
|
|
|
|
|
|
|
if (building.requires) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
building.requires.wood > this.resources.wood || |
|
|
|
|
|
|
|
building.requires.stone > this.resources.stone || |
|
|
|
|
|
|
|
building.requires.iron > this.resources.iron || |
|
|
|
|
|
|
|
building.requires.bricks > this.resources.bricks || |
|
|
|
|
|
|
|
building.requires.coal > this.resources.coal || |
|
|
|
|
|
|
|
building.requires.corn > this.resources.corn |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buyBuilding(building) { |
|
|
|
buyBuilding(building) { |
|
|
|
if (this.resources.gold >= building.price) { |
|
|
|
if (this.resources.gold >= building.price) { |
|
|
|
this.sub(building.price); |
|
|
|
this.sub(building.price); |
|
|
@ -386,7 +407,24 @@ let game = new Vue({ |
|
|
|
this.initiateIntervals(building); |
|
|
|
this.initiateIntervals(building); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buildingHasEnoughResourcesToStart(building) { |
|
|
|
|
|
|
|
if (building.requires) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
building.requires.wood > this.resources.wood || |
|
|
|
|
|
|
|
building.requires.stone > this.resources.stone || |
|
|
|
|
|
|
|
building.requires.iron > this.resources.iron || |
|
|
|
|
|
|
|
building.requires.bricks > this.resources.bricks || |
|
|
|
|
|
|
|
building.requires.coal > this.resources.coal || |
|
|
|
|
|
|
|
building.requires.corn > this.resources.corn |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Quests
|
|
|
|
generateQuestWithRandomItems() { |
|
|
|
generateQuestWithRandomItems() { |
|
|
|
|
|
|
|
// defines the rates of possible amounts of resources for quests
|
|
|
|
let possibleAmountsForQuest = [ |
|
|
|
let possibleAmountsForQuest = [ |
|
|
|
0, 0, 0, 0, 5, 10, 15, 20, 25, 30, 35, 5, 10, 15, 20, 25, 30, 35, 50 |
|
|
|
0, 0, 0, 0, 5, 10, 15, 20, 25, 30, 35, 5, 10, 15, 20, 25, 30, 35, 50 |
|
|
|
]; |
|
|
|
]; |
|
|
@ -401,37 +439,37 @@ let game = new Vue({ |
|
|
|
|
|
|
|
|
|
|
|
let rewardSum = 0; |
|
|
|
let rewardSum = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.wood > 0) { |
|
|
|
if (this.hadResource.wood > 0) { |
|
|
|
randomWood = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomWood = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomWood * 5); |
|
|
|
rewardSum += (randomWood * 5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.stone > 0) { |
|
|
|
if (this.hadResource.stone > 0) { |
|
|
|
randomStone = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomStone = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomStone * 7); |
|
|
|
rewardSum += (randomStone * 7); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.iron > 0) { |
|
|
|
if (this.hadResource.iron > 0) { |
|
|
|
randomIron = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomIron = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomIron * 200); |
|
|
|
rewardSum += (randomIron * 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.bricks > 0) { |
|
|
|
if (this.hadResource.bricks > 0) { |
|
|
|
randomBricks = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomBricks = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomBricks * 25); |
|
|
|
rewardSum += (randomBricks * 25); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.corn > 0) { |
|
|
|
if (this.hadResource.corn > 0) { |
|
|
|
randomCorn = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomCorn = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomCorn * 30); |
|
|
|
rewardSum += (randomCorn * 30); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.coal > 0) { |
|
|
|
if (this.hadResource.coal > 0) { |
|
|
|
randomCoal = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomCoal = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomCoal * 10); |
|
|
|
rewardSum += (randomCoal * 10); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.resources.planks > 0) { |
|
|
|
if (this.hadResource.planks > 0) { |
|
|
|
randomPlanks = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
randomPlanks = this.getRandomElementForQuestResource(possibleAmountsForQuest); |
|
|
|
rewardSum += (randomPlanks * 5); |
|
|
|
rewardSum += (randomPlanks * 5); |
|
|
|
} |
|
|
|
} |
|
|
@ -503,6 +541,10 @@ let game = new Vue({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Templating
|
|
|
|
// Templating
|
|
|
|
|
|
|
|
getFormattedNumber(value) { |
|
|
|
|
|
|
|
return value.toLocaleString('de-DE'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getResourceIconForBuilding(building) { |
|
|
|
getResourceIconForBuilding(building) { |
|
|
|
return this.getResourceIcon(building.resource); |
|
|
|
return this.getResourceIcon(building.resource); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -536,6 +578,8 @@ let game = new Vue({ |
|
|
|
message: 'You got a reward of ' + reward + ' gold!', |
|
|
|
message: 'You got a reward of ' + reward + ' gold!', |
|
|
|
position: 'bottomCenter', |
|
|
|
position: 'bottomCenter', |
|
|
|
timeout: 1500, |
|
|
|
timeout: 1500, |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -546,6 +590,8 @@ let game = new Vue({ |
|
|
|
position: 'bottomCenter', |
|
|
|
position: 'bottomCenter', |
|
|
|
message: amount + ' ' + resource, |
|
|
|
message: amount + ' ' + resource, |
|
|
|
timeout: 1000, |
|
|
|
timeout: 1000, |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -554,6 +600,8 @@ let game = new Vue({ |
|
|
|
color: 'green', |
|
|
|
color: 'green', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
position: 'bottomCenter', |
|
|
|
position: 'bottomCenter', |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -563,6 +611,8 @@ let game = new Vue({ |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
position: 'topCenter', |
|
|
|
position: 'topCenter', |
|
|
|
timeout: 7000, |
|
|
|
timeout: 7000, |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -571,6 +621,8 @@ let game = new Vue({ |
|
|
|
color: 'red', |
|
|
|
color: 'red', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
position: 'bottomCenter', |
|
|
|
position: 'bottomCenter', |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -579,6 +631,8 @@ let game = new Vue({ |
|
|
|
color: 'blue', |
|
|
|
color: 'blue', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
position: 'bottomCenter', |
|
|
|
position: 'bottomCenter', |
|
|
|
|
|
|
|
transitionIn: 'boundInRight', |
|
|
|
|
|
|
|
transitionInMobile: 'boundInRight' |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|