2017-04-25 23:35:17 +02:00
|
|
|
/* Pop up Purchase Ram for Home Computer Pop-up Box */
|
|
|
|
function purchaseRamForHomeBoxInit() {
|
|
|
|
var cancelButton = document.getElementById("purchase-ram-for-home-box-cancel");
|
|
|
|
|
|
|
|
//Close Dialog box
|
|
|
|
cancelButton.addEventListener("click", function() {
|
|
|
|
purchaseRamForHomeBoxClose();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", purchaseRamForHomeBoxInit, false);
|
|
|
|
|
|
|
|
purchaseRamForHomeBoxClose = function() {
|
|
|
|
var purchaseRamForHomeBox = document.getElementById("purchase-ram-for-home-box-container");
|
|
|
|
purchaseRamForHomeBox.style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
purchaseRamForHomeBoxOpen = function() {
|
|
|
|
var purchaseRamForHomeBox = document.getElementById("purchase-ram-for-home-box-container");
|
2017-05-03 06:38:58 +02:00
|
|
|
purchaseRamForHomeBox.style.display = "block";
|
2017-04-25 23:35:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
purchaseRamForHomeBoxSetText = function(txt) {
|
|
|
|
var textElem = document.getElementById("purchase-ram-for-home-box-text");
|
|
|
|
textElem.innerHTML = txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
//ram argument is in GB
|
|
|
|
purchaseRamForHomeBoxCreate = function() {
|
|
|
|
//Calculate how many times ram has been upgraded (doubled)
|
|
|
|
var currentRam = Player.getHomeComputer().maxRam;
|
|
|
|
var newRam = currentRam * 2;
|
|
|
|
var numUpgrades = Math.log2(currentRam);
|
|
|
|
|
|
|
|
//Calculate cost
|
2017-05-15 19:09:11 +02:00
|
|
|
//Have cost increase by some percentage each time RAM has been upgraded
|
2017-05-10 19:42:46 +02:00
|
|
|
var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome;
|
2017-05-15 19:09:11 +02:00
|
|
|
var mult = Math.pow(1.33, numUpgrades);
|
2017-04-25 23:35:17 +02:00
|
|
|
cost = cost * mult;
|
|
|
|
|
|
|
|
purchaseRamForHomeBoxSetText("Would you like to purchase additional RAM for your home computer? <br><br>" +
|
|
|
|
"This will upgrade your RAM from " + currentRam + "GB to " + newRam + "GB. <br><br>" +
|
2017-05-08 16:33:26 +02:00
|
|
|
"This will cost $" + formatNumber(cost, 2));
|
2017-04-25 23:35:17 +02:00
|
|
|
|
2017-05-03 06:38:58 +02:00
|
|
|
purchaseRamForHomeBoxOpen();
|
|
|
|
|
2017-04-25 23:35:17 +02:00
|
|
|
//Clear old event listeners from Confirm button
|
2017-05-05 23:27:35 +02:00
|
|
|
var newConfirmButton = clearEventListeners("purchase-ram-for-home-box-confirm");
|
2017-04-25 23:35:17 +02:00
|
|
|
newConfirmButton.addEventListener("click", function() {
|
|
|
|
purchaseRamForHomeBoxClose();
|
|
|
|
purchaseRamForHomeComputer(cost);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|