From 4b9f4656dbae719cbd547ceb04a7bc226688c74c Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Wed, 10 Feb 2016 16:49:44 -0800 Subject: [PATCH 1/8] Update index.html --- index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 5fef1dc..1f71f55 100644 --- a/index.html +++ b/index.html @@ -66,7 +66,8 @@   - + + Ancient From 548d55838b2ca1e7f888593149b1cbeb3b730503 Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Wed, 10 Feb 2016 16:58:31 -0800 Subject: [PATCH 2/8] Update mathmagician.js --- scripts/mathmagician.js | 133 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index 7c0e215..26ed28a 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -783,6 +783,139 @@ function optimize() { saveSettings(); } +function apply_optimize() { + var Bank = anc[0]; + var Siya = anc[5]; + var Argaiv = anc[28]; + var Iris = anc[30]; + + playstyle = $('input[type=radio][name=playstyle]:checked').val(); + var clicking = playstyle != 'idle'; + var ignoreIris = $('#ignoreIris').is(':checked'); + laxSolomon = $('#laxsolo').is(':checked'); + irisBonus = parseInt($('#irisBonus').val()); + if($('#noBossLanding').is(':checked')) { + irisBonus++; + } + + // reset cost and get the user input values to work with + for(key in anc) { + var ancient = anc[key]; + + ancient.totalCost = 0; + ancient.levelOld = parseInt($('#old'+key).val()); + ancient.levelNew = ancient.levelOld; + } + + hasMorgulis = anc[16].levelOld > 0; + + var upgradeNext, referenceLevel; + while(upgradeNext != 0) { + // optimize loop ends when the best investment is the HS bank + upgradeNext = 0; + var highestIncrease = 0; + var nextCost = 0; + var nextBestIncrease = 0; + referenceLevel = Math.max(playstyle=='active' ? Argaiv.levelNew : Siya.levelNew, 1); + var desiredBank = Math.ceil(Bank.levelNew-Bank.desiredLevel(referenceLevel)); + var nextBank = Math.ceil(Bank.levelNew-Bank.desiredLevel(referenceLevel+1)); + + for(key in anc) { + var ancient = anc[key]; + var optimal = getOptimal(ancient, referenceLevel); + if(ancient.levelNew > 0 && optimal > ancient.levelNew && (clicking == true || ancient.clicking == false) && (ignoreIris == false || key != 30)) { + // Do not process ancients the user doesn't have. + // Do not process clicking ancients when clicking checkbox is off. + // Do not process Iris if disabled. + + var upgradeCost = ancient.upgradeCost(ancient.levelNew+1); + + if(upgradeCost <= (key==5 || key==28 ? nextBank : desiredBank)) { // always keep the desired soulbank, do not spend below this + // determine the ancient that is lagging behind the most (biggest relative increase from current to optimal) + var increase = (optimal-ancient.levelNew) / ancient.levelNew; + + // assign less weight to Siya/Arga to let other ancients catch up first, only upgrade when no other ancients to upgrade + if(playstyle == 'active' && key == 28) { + increase *= 0.1; + } + else if(playstyle != 'active' && key == 5) { + increase *= 0.1; + } + + if(increase > highestIncrease) { + upgradeNext = key; + nextBestIncrease = highestIncrease; + highestIncrease = increase; + nextCost = upgradeCost; + } + } + } + } + if(upgradeNext != 0) { + var ancient = anc[upgradeNext]; + if(upgradeNext == 16) { + // Morg batch upgrade! + var morgPlus = Math.min(Math.ceil((highestIncrease - nextBestIncrease)*ancient.levelNew), Bank.levelNew); + ancient.totalCost += morgPlus; + ancient.levelNew += morgPlus; + Bank.levelNew -= morgPlus; + } + else { + ancient.totalCost += nextCost; + ancient.levelNew++; + Bank.levelNew -= nextCost; + } + } + } + + // correct for Iris not landing on the desired zone + if(Iris.levelNew > Iris.levelOld && Iris.levelNew != Iris.desiredLevel(referenceLevel)) { + irisMax = Math.floor((Iris.levelNew)/5)*5-1-irisBonus; + optimize(); + return; + } + else { + irisMax = 0; + } + + // update HTML + for(key in anc) { + var ancient = anc[key]; + var optimalLevel = getOptimal(ancient, (key == 5 && playstyle!='active' || key == 28 && playstyle=='active') ? referenceLevel-1 : referenceLevel); + + if((ancient.maxLevel != 0 && ancient.levelOld == ancient.maxLevel) || (optimalLevel == 0 && ancient.levelOld == 0 && key != 0) || (playstyle=='idle' && ancient.clicking)) { + $('#anc'+key).css('display', 'none'); + } + else { + $('#anc'+key).css('display', 'table-row'); + $('#anc'+key).text(ancient.levelNew); + $('#new'+key).text(ancient.levelNew); + $('#optimal'+key).text(optimalLevel); + + if(ancient.levelNew != ancient.levelOld) { + $('#delta'+key).text(ancient.levelNew - ancient.levelOld); + if(key != 0) { + $('#delta'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+" upgrade cost:
"+ancient.totalCost.numberFormat()+" soul"+plural(ancient.totalCost)+"');"); + } + $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"

Target level:
"+ancient.getBonus(ancient.levelNew)+"');"); + } + else { + $('#delta'+key).text(''); + $('#delta'+key).removeAttr("onmouseover"); + + if(ancient.levelOld > 0) { + $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"');"); + } + else { + $('#name'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+"
First level: "+ancient.getBonus(1)+"');"); + } + } + } + } + permaLink(); + saveSettings(); +} + function import_save(evt) { if(evt && evt.keyCode == 17) { From e63248bf7206e179a07f471b0c29625f248e3417 Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Wed, 10 Feb 2016 17:06:31 -0800 Subject: [PATCH 3/8] Update mathmagician.js --- scripts/mathmagician.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index 26ed28a..d7649d6 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -888,10 +888,11 @@ function apply_optimize() { } else { $('#anc'+key).css('display', 'table-row'); - $('#anc'+key).text(ancient.levelNew); $('#new'+key).text(ancient.levelNew); $('#optimal'+key).text(optimalLevel); + $('#old'+key).val(ancient.levelNew) + if(ancient.levelNew != ancient.levelOld) { $('#delta'+key).text(ancient.levelNew - ancient.levelOld); if(key != 0) { From 06509fbe4335c0f462968f1aa5ea71f34858a9be Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Wed, 10 Feb 2016 17:10:03 -0800 Subject: [PATCH 4/8] Update mathmagician.js --- scripts/mathmagician.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index d7649d6..bdb3af9 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -893,23 +893,14 @@ function apply_optimize() { $('#old'+key).val(ancient.levelNew) - if(ancient.levelNew != ancient.levelOld) { - $('#delta'+key).text(ancient.levelNew - ancient.levelOld); - if(key != 0) { - $('#delta'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+" upgrade cost:
"+ancient.totalCost.numberFormat()+" soul"+plural(ancient.totalCost)+"');"); - } - $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"

Target level:
"+ancient.getBonus(ancient.levelNew)+"');"); + $('#delta'+key).text(''); + $('#delta'+key).removeAttr("onmouseover"); + + if(ancient.levelOld > 0) { + $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"');"); } else { - $('#delta'+key).text(''); - $('#delta'+key).removeAttr("onmouseover"); - - if(ancient.levelOld > 0) { - $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"');"); - } - else { - $('#name'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+"
First level: "+ancient.getBonus(1)+"');"); - } + $('#name'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+"
First level: "+ancient.getBonus(1)+"');"); } } } From b60da85b58dffd21af6807c46bfb30b70320cc08 Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Thu, 11 Feb 2016 11:09:26 -0800 Subject: [PATCH 5/8] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28da724..72775a2 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -# ancient +# Clicker Heroes Ancient Optimizer +A HTML form to help calculate what levels your ancients should be at for optimum play. +* Forked from https://github.com/hsoptimizer/ancient + +## Changelog +* Added an "apply optimization" button. From 1face9c95bacbb69db1c41e280196238a34b3f31 Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Thu, 11 Feb 2016 11:10:54 -0800 Subject: [PATCH 6/8] Update mathmagician.js --- scripts/mathmagician.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index bdb3af9..0100abb 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -886,15 +886,18 @@ function apply_optimize() { if((ancient.maxLevel != 0 && ancient.levelOld == ancient.maxLevel) || (optimalLevel == 0 && ancient.levelOld == 0 && key != 0) || (playstyle=='idle' && ancient.clicking)) { $('#anc'+key).css('display', 'none'); } + else { else { $('#anc'+key).css('display', 'table-row'); $('#new'+key).text(ancient.levelNew); $('#optimal'+key).text(optimalLevel); $('#old'+key).val(ancient.levelNew) + ancient.levelOld = ancient.levelNew $('#delta'+key).text(''); - $('#delta'+key).removeAttr("onmouseover"); + if (key != 0) + $('#delta'+key).removeAttr("onmouseover"); if(ancient.levelOld > 0) { $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"');"); From cdae6b716dcf476cf6cc146c72a611c02042a85e Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Thu, 11 Feb 2016 11:14:12 -0800 Subject: [PATCH 7/8] Update mathmagician.js --- scripts/mathmagician.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index 0100abb..df1a368 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -886,7 +886,6 @@ function apply_optimize() { if((ancient.maxLevel != 0 && ancient.levelOld == ancient.maxLevel) || (optimalLevel == 0 && ancient.levelOld == 0 && key != 0) || (playstyle=='idle' && ancient.clicking)) { $('#anc'+key).css('display', 'none'); } - else { else { $('#anc'+key).css('display', 'table-row'); $('#new'+key).text(ancient.levelNew); From 09b5186b9dfed63ffb4231253d059e81f4e1d434 Mon Sep 17 00:00:00 2001 From: second-hand-earth Date: Wed, 24 Feb 2016 13:46:36 -0800 Subject: [PATCH 8/8] Update mathmagician.js --- scripts/mathmagician.js | 122 ++++++---------------------------------- 1 file changed, 18 insertions(+), 104 deletions(-) diff --git a/scripts/mathmagician.js b/scripts/mathmagician.js index df1a368..01a4f7e 100644 --- a/scripts/mathmagician.js +++ b/scripts/mathmagician.js @@ -783,125 +783,39 @@ function optimize() { saveSettings(); } -function apply_optimize() { - var Bank = anc[0]; - var Siya = anc[5]; - var Argaiv = anc[28]; - var Iris = anc[30]; - - playstyle = $('input[type=radio][name=playstyle]:checked').val(); - var clicking = playstyle != 'idle'; - var ignoreIris = $('#ignoreIris').is(':checked'); - laxSolomon = $('#laxsolo').is(':checked'); - irisBonus = parseInt($('#irisBonus').val()); - if($('#noBossLanding').is(':checked')) { - irisBonus++; - } - - // reset cost and get the user input values to work with - for(key in anc) { - var ancient = anc[key]; - - ancient.totalCost = 0; - ancient.levelOld = parseInt($('#old'+key).val()); - ancient.levelNew = ancient.levelOld; - } - - hasMorgulis = anc[16].levelOld > 0; - - var upgradeNext, referenceLevel; - while(upgradeNext != 0) { - // optimize loop ends when the best investment is the HS bank - upgradeNext = 0; - var highestIncrease = 0; - var nextCost = 0; - var nextBestIncrease = 0; - referenceLevel = Math.max(playstyle=='active' ? Argaiv.levelNew : Siya.levelNew, 1); - var desiredBank = Math.ceil(Bank.levelNew-Bank.desiredLevel(referenceLevel)); - var nextBank = Math.ceil(Bank.levelNew-Bank.desiredLevel(referenceLevel+1)); - - for(key in anc) { - var ancient = anc[key]; - var optimal = getOptimal(ancient, referenceLevel); - if(ancient.levelNew > 0 && optimal > ancient.levelNew && (clicking == true || ancient.clicking == false) && (ignoreIris == false || key != 30)) { - // Do not process ancients the user doesn't have. - // Do not process clicking ancients when clicking checkbox is off. - // Do not process Iris if disabled. - - var upgradeCost = ancient.upgradeCost(ancient.levelNew+1); - - if(upgradeCost <= (key==5 || key==28 ? nextBank : desiredBank)) { // always keep the desired soulbank, do not spend below this - // determine the ancient that is lagging behind the most (biggest relative increase from current to optimal) - var increase = (optimal-ancient.levelNew) / ancient.levelNew; - - // assign less weight to Siya/Arga to let other ancients catch up first, only upgrade when no other ancients to upgrade - if(playstyle == 'active' && key == 28) { - increase *= 0.1; - } - else if(playstyle != 'active' && key == 5) { - increase *= 0.1; - } - - if(increase > highestIncrease) { - upgradeNext = key; - nextBestIncrease = highestIncrease; - highestIncrease = increase; - nextCost = upgradeCost; - } - } - } - } - if(upgradeNext != 0) { - var ancient = anc[upgradeNext]; - if(upgradeNext == 16) { - // Morg batch upgrade! - var morgPlus = Math.min(Math.ceil((highestIncrease - nextBestIncrease)*ancient.levelNew), Bank.levelNew); - ancient.totalCost += morgPlus; - ancient.levelNew += morgPlus; - Bank.levelNew -= morgPlus; - } - else { - ancient.totalCost += nextCost; - ancient.levelNew++; - Bank.levelNew -= nextCost; - } - } - } - - // correct for Iris not landing on the desired zone - if(Iris.levelNew > Iris.levelOld && Iris.levelNew != Iris.desiredLevel(referenceLevel)) { - irisMax = Math.floor((Iris.levelNew)/5)*5-1-irisBonus; - optimize(); - return; - } - else { - irisMax = 0; - } +function apply_optimize() +{ + optimize(); // update HTML - for(key in anc) { + for(key in anc) + { var ancient = anc[key]; - var optimalLevel = getOptimal(ancient, (key == 5 && playstyle!='active' || key == 28 && playstyle=='active') ? referenceLevel-1 : referenceLevel); - if((ancient.maxLevel != 0 && ancient.levelOld == ancient.maxLevel) || (optimalLevel == 0 && ancient.levelOld == 0 && key != 0) || (playstyle=='idle' && ancient.clicking)) { + if((ancient.maxLevel != 0 && ancient.levelOld == ancient.maxLevel) || (ancient.levelOld == 0 && key != 0) || (playstyle=='idle' && ancient.clicking)) + { $('#anc'+key).css('display', 'none'); } - else { + else + { + console.log('poop'); +// Show the Ancient. $('#anc'+key).css('display', 'table-row'); - $('#new'+key).text(ancient.levelNew); - $('#optimal'+key).text(optimalLevel); - $('#old'+key).val(ancient.levelNew) ancient.levelOld = ancient.levelNew - + console.log('poop'); +// Clear the Delta $('#delta'+key).text(''); +// Remove previous mouse over except for "Souls in bank:" if (key != 0) $('#delta'+key).removeAttr("onmouseover"); - if(ancient.levelOld > 0) { + if(ancient.levelOld > 0) + { $('#name'+key).attr("onmouseover", "nhpup.popup('Current level:
"+ancient.getBonus(ancient.levelOld)+"');"); } - else { + else + { $('#name'+key).attr("onmouseover", "nhpup.popup('"+ancient.Name+"
First level: "+ancient.getBonus(1)+"');"); } }