ardon-income/calculate.js

129 lines
4.5 KiB
JavaScript
Raw Normal View History

2017-09-09 03:30:59 +00:00
"use strict";
//Licensed under the Apache License 2.0. See license file for information.
2017-10-22 02:50:49 +00:00
// Ardon Income Calculator v3.5 stable.
// Written by Josh Mudge
// Ad Mejorem Dei Glorium
function usesaved () {
var blocks = localStorage.blocks
var soldiers = localStorage.soldiers
var one = localStorage.one
var hotel = localStorage.hotel
var gov = localStorage.gov
var govspecial = localStorage.govspecial
var indesign = localStorage.indesign
var outdesign = localStorage.outdesign
var embassies = localStorage.embassies
var capital = localStorage.capital
var infra = localStorage.infra
var chain = localStorage.chain
var town = localStorage.town
var city = localStorage.city
var metro = localStorage.metro
calculate();
}
2017-09-09 03:30:59 +00:00
function calculate() {
var numReg = /^\d+$/;
//Get input
var blocks = document.getElementById("blocks").value;
2017-09-20 21:44:54 +00:00
var soldiers = document.getElementById("soldiers").value;
var one = document.getElementById("one").value;
var hotel = document.getElementById("hotel").value;
var govspecial = document.getElementById("govspecial").value;
var gov = document.getElementById("gov").value;
var indesign = document.getElementById("indesign").value;
var outdesign = document.getElementById("outdesign").value;
2017-09-09 04:15:16 +00:00
var embassies = document.getElementById("embassies").value;
var capital = document.getElementById("capital").value;
var infra = document.getElementById("infra").value;
2017-09-17 00:50:30 +00:00
var chain = document.getElementById("chain").value;
2017-09-16 03:40:20 +00:00
var town = document.getElementById("town").value;
var city = document.getElementById("city").value;
var metro = document.getElementById("metro").value;
2017-09-09 03:30:59 +00:00
//Store values.
localStorage.blocks = document.getElementById("blocks").value;
localStorage.soldiers = document.getElementById("soldiers").value;
localStorage.one = document.getElementById("one").value;
localStorage.hotel = document.getElementById("hotel").value;
localStorage.govspecial = document.getElementById("govspecial").value;
localStorage.gov = document.getElementById("gov").value;
localStorage.indesign = document.getElementById("indesign").value;
localStorage.outdesign = document.getElementById("outdesign").value;
localStorage.embassies = document.getElementById("embassies").value;
localStorage.capital = document.getElementById("capital").value;
localStorage.infra = document.getElementById("infra").value;
localStorage.chain = document.getElementById("chain").value;
localStorage.town = document.getElementById("town").value;
localStorage.city = document.getElementById("city").value;
localStorage.metro = document.getElementById("metro").value;
2017-09-09 04:15:16 +00:00
if (blocks.match(numReg))
2017-09-09 03:30:59 +00:00
{
//Do nothing.
}
else
{
//Tells them to enter only numbers.
alert("Please enter only numbers in this field.");
}
2017-09-19 01:25:09 +00:00
var gold = +blocks / 1000 * 100
2017-09-17 00:50:30 +00:00
console.log(gold)
var gold = +gold - (soldiers * 50) // Note to self: Fix possibiliy of giving bonuses to negative incomes.
2017-09-20 21:44:54 +00:00
console.log(gold)
2017-09-20 21:36:13 +00:00
var infra = +infra / 1000 * 0.0025
2017-09-16 04:05:42 +00:00
console.log(infra)
var one = +one / 1000 * 0.01
console.log(one)
2017-09-17 00:50:30 +00:00
var chain = +chain * 0.0025
console.log(chain)
var indesign = +indesign / 1000 * 0.02
console.log(outdesign)
var outdesign = +outdesign / 1000 * 0.015
console.log(indesign)
var hotel = +hotel * 0.015
console.log(hotel)
var gov = +gov * 0.015
console.log(gov)
var govspecial = +govspecial * 0.03 // Limit to 4 if govspecial > 4 limiting
console.log(govspecial)
2017-09-16 04:10:51 +00:00
var embassies = +embassies * 0.02
2017-09-09 04:15:16 +00:00
console.log(embassies)
var capital = +capital * 0.05 // Limit to 1 capital.
2017-09-09 04:15:16 +00:00
console.log(capital)
2017-09-16 03:40:20 +00:00
var town = +town * 0.005
console.log(town)
var city = +city * 0.01
console.log(city)
var metro = +metro * 0.01
console.log(metro)
var percent = +one + +indesign + +outdesign +hotel + +gov + +govspecial + +embassies + +capital + +infra + +chain + +town + +city + +metro
2017-09-09 04:15:16 +00:00
console.log(percent)
var bonus = +percent * 100
var bonus = bonus.toFixed(2);
console.log(bonus)
2017-09-19 19:48:41 +00:00
var total = +gold * +percent
console.log(total)
var total = +total + +gold
console.log(total)
2017-09-17 00:50:30 +00:00
var total = total.toFixed(0);
2017-09-09 04:15:16 +00:00
console.log(total)
var emeralds = +total / 100
console.log(emeralds)
//var date = Date();
//console.log(date)
2017-09-09 03:30:59 +00:00
//Show result
alert("Your Income is " + total + " Gold (or " + emeralds + " emeralds) per Minecraft Year (5 days)");
document.getElementById("Bonus").innerHTML = "Your Efficiency bonus is " + bonus + "%";
document.getElementById("Income").innerHTML = "Your Income is " + total + " Gold (or " + emeralds + " emeralds) per Minecraft Year (5 days)";
2017-09-09 03:30:59 +00:00
}