Last active
August 29, 2015 14:08
-
-
Save vasi/9f62ad066f7d33630a06 to your computer and use it in GitHub Desktop.
autokittens.js fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildUI() { | |
| var tableContainer = document.createElement('div'); | |
| tableContainer.style.width = '100%'; | |
| tableContainer.style.height = '50px'; | |
| tableContainer.style.bottom = '0px'; | |
| tableContainer.style.position = 'absolute'; | |
| tableContainer.innerHTML = '<table id="timerTable" style="width: 100%; table-layout: fixed;"></table>'; | |
| document.body.appendChild(tableContainer); | |
| document.getElementById('game').style.marginBottom = '50px'; | |
| document.getElementById('footerLinks').style.marginBottom = '60px'; | |
| document.body.style.backgroundPosition = 'center bottom 30px'; | |
| adjustColumns(); | |
| $(resetGameLogHeight); | |
| $('#headerLinks').append(' | <a onclick="rebuildOptionsUI();$(\'#autoOptions\').toggle();" href="#">AutoKittens</a> | <a onclick="rebuildCalculatorUI();$(\'#kittenCalcs\').toggle();" href="#">Calculators</a>'); | |
| var uiContainer = document.createElement('div'); | |
| uiContainer.className = 'help'; | |
| uiContainer.id = 'autoOptions'; | |
| uiContainer.style.display = 'none'; | |
| uiContainer.style.overflowY = 'scroll'; | |
| $('#gamePageContainer').append(uiContainer); | |
| var calcContainer = document.createElement('div'); | |
| calcContainer.className = 'help'; | |
| calcContainer.id = 'kittenCalcs'; | |
| calcContainer.style.display = 'none'; | |
| calcContainer.style.overflowY = 'scroll'; | |
| $('#gamePageContainer').append(calcContainer); | |
| } | |
| function adjustColumns() { | |
| document.getElementById('midColumn').style.width = autoOptions.widenUI ? '1000px' : ''; | |
| document.getElementById('leftColumn').style.maxWidth = autoOptions.widenUI ? '25%' : ''; | |
| } | |
| function addCheckbox(container, prefix, optionName, caption) { | |
| addNamedCheckbox(container, prefix, optionName, optionName, caption); | |
| } | |
| function addTriggerCheckbox(container, prefix, optionName, caption, trigger) | |
| { | |
| addTriggerNamedCheckbox(container, prefix, optionName, optionName, caption, trigger); | |
| } | |
| function addNamedCheckbox(container, prefix, optionName, controlName, caption) { | |
| addTriggerNamedCheckbox(container, prefix, optionName, controlName, caption, ''); | |
| } | |
| function addTriggerNamedCheckbox(container, prefix, optionName, controlName, caption, trigger) { | |
| container.append('<label><input id="autoKittens_'+controlName+'" onclick="'+prefix+'.'+optionName+' = $(\'#autoKittens_'+controlName+'\')[0].checked;saveAutoOptions();'+trigger+'" type="checkbox">'+caption+'</label><br>'); | |
| } | |
| function addHeading(container, title) { | |
| container.append('<h3>'+title+'</h3>') | |
| } | |
| function addOptionMenu(container, prefix, optionName, left_caption, options, right_caption) { | |
| addTriggerOptionMenu(container, prefix, optionName, left_caption, options, right_caption, ''); | |
| } | |
| function addTriggerOptionMenu(container, prefix, optionName, left_caption, options, right_caption, trigger) { | |
| s = left_caption + ' <select id="autoKittens_'+optionName+'" onchange="'+prefix+'.'+optionName+' = $(\'#autoKittens_'+optionName+'\')[0].value;saveAutoOptions();'+trigger+'">'; | |
| var arrayLength = options.length; | |
| for (var i = 0; i < arrayLength; i++) { | |
| s += '<option value='+options[i][1]+'>'+options[i][0]+'</option>' | |
| } | |
| s+='</select> '+right_caption+'<br>' | |
| container.append(s); | |
| } | |
| function addIndent(container) { | |
| container.append('<span style="width:20px; display:inline-block;"></span>'); | |
| } | |
| function addInputField(container, prefix, optionName, left_caption, right_caption) { | |
| container.append(left_caption + ' <input id="autoKittens_'+optionName+'" size="3" oninput="tryNumericSet('+prefix+', \''+optionName+'\', $(\'#autoKittens_'+optionName+'\')[0].value);saveAutoOptions();"> '+right_caption+'<br>'); | |
| } | |
| function tryNumericSet(collection, attrName, value) { | |
| newVal = parseFloat(value); | |
| if (!isNaN(newVal) && isFinite(newVal) && newVal > 0) | |
| collection[attrName] = newVal; | |
| } | |
| function prepareContainer(id) { | |
| var result = $('#'+id); | |
| result.html('<a style="top: 10px; right: 45px; position: absolute;" onclick="$(\'#'+id+'\').hide();" href="#"><div style="position: fixed;">close</div></a>'); | |
| return result | |
| } | |
| function rebuildOptionsUI() { | |
| var uiContainer = prepareContainer('autoOptions'); | |
| addCheckbox(uiContainer, 'autoOptions', 'warnOnLeave', 'Warn before leaving the page'); | |
| addTriggerCheckbox(uiContainer, 'autoOptions', 'widenUI', 'Make the game use more horizontal space (particularly useful for Grassy theme)', 'adjustColumns();'); | |
| addCheckbox(uiContainer, 'autoOptions', 'autoStar', 'Automatically witness astronomical events'); | |
| addCheckbox(uiContainer, 'autoOptions', 'autoCraft', 'Craft materials when storage is near limit'); | |
| addCheckbox(uiContainer, 'autoOptions', 'autoHunt', 'Hunt when catpower is near limit'); | |
| addCheckbox(uiContainer, 'autoOptions', 'autoPray', 'Praise the sun when faith is near limit'); | |
| addIndent(uiContainer);addOptionMenu(uiContainer, 'autoOptions', 'prayLimit', 'Pray when faith is', [["95%", 0.95], ["98%", 0.98], ["99%", 0.99], ["99.5%", 0.995], ["99.9%", 0.999], ["100%", 1]], 'full'); | |
| addCheckbox(uiContainer, 'autoOptions', 'autoTrade', 'Trade when gold is near limit'); | |
| addTriggerOptionMenu(uiContainer, 'autoOptions', 'timeDisplay', 'Format for time displays', [["default", "standard"], ["short", "short"], ["seconds", "seconds"]], '', 'changeTimeFormat()'); | |
| addHeading(uiContainer, 'Auto-trading') | |
| races = [["No one", ""]]; | |
| gamePage.diplomacy.races.forEach(function (r) { | |
| if (r.unlocked) { | |
| races.push([r.title || r.name, r.name]); | |
| } | |
| }); | |
| addOptionMenu(uiContainer, 'autoOptions.tradeOptions', 'tradePartner', 'Trade with', races, ''); | |
| addOptionMenu(uiContainer, 'autoOptions.tradeOptions', 'tradeLimit', 'Trade when gold is', [["95%", 0.95], ["98%", 0.98], ["99%", 0.99], ["99.5%", 0.995], ["99.9%", 0.999], ["100%", 1]], 'full'); | |
| addCheckbox(uiContainer, 'autoOptions.tradeOptions', 'tradeSpring', 'Allow trading in spring'); | |
| addCheckbox(uiContainer, 'autoOptions.tradeOptions', 'tradeSummer', 'Allow trading in summer'); | |
| addCheckbox(uiContainer, 'autoOptions.tradeOptions', 'tradeAutumn', 'Allow trading in autumn'); | |
| addCheckbox(uiContainer, 'autoOptions.tradeOptions', 'tradeWinter', 'Allow trading in winter'); | |
| addHeading(uiContainer, 'Auto-crafting'); | |
| addOptionMenu(uiContainer, 'autoOptions.craftOptions', 'craftLimit', 'Craft when storage is', [["95%", 0.95], ["98%", 0.98], ["99%", 0.99], ["99.5%", 0.995], ["99.9%", 0.999], ["100%", 1]], 'full') | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftWood', 'Automatically convert catnip to wood'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'woodAmount', 'Craft', 'wood at a time'); | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftBeam', 'Automatically convert wood to beams'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'beamAmount', 'Craft', 'beam(s) at a time'); | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftSlab', 'Automatically convert minerals to slabs'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'slabAmount', 'Craft', 'slab(s) at a time'); | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftSteel', 'Automatically convert coal to steel'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'steelAmount', 'Craft', 'steel at a time'); | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftPlate', 'Automatically convert iron to plates'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'plateAmount', 'Craft', 'plate(s) at a time'); | |
| addCheckbox(uiContainer, 'autoOptions.craftOptions', 'craftAlloy', 'Automatically convert titanium to alloy'); | |
| addIndent(uiContainer);addInputField(uiContainer, 'autoOptions.craftOptions', 'alloyAmount', 'Craft', 'alloy at a time'); | |
| addHeading(uiContainer, 'Auto-hunting'); | |
| addOptionMenu(uiContainer, 'autoOptions.craftOptions', 'huntLimit', 'Hunt when catpower is', [["95%", 0.95], ["98%", 0.98], ["99%", 0.99], ["99.5%", 0.995], ["99.9%", 0.999], ["100%", 1]], 'full') | |
| addCheckbox(uiContainer, 'autoOptions.huntOptions', 'huntEarly', 'Hunt as soon as the maximum number of hunts is reached (relative to the limit)'); | |
| addCheckbox(uiContainer, 'autoOptions.huntOptions', 'craftParchment', 'Automatically convert all furs to parchment'); | |
| addCheckbox(uiContainer, 'autoOptions.huntOptions', 'craftManuscript', 'Automatically convert all parchment to manuscripts'); | |
| addCheckbox(uiContainer, 'autoOptions.huntOptions', 'craftCompendium', 'Automatically convert all manuscripts to compendiums'); | |
| addCheckbox(uiContainer, 'autoOptions.huntOptions', 'craftBlueprint', 'Automatically convert all compendiums to blueprints'); | |
| addHeading(uiContainer, 'Timer displays'); | |
| gamePage.resPool.resources.forEach(function (r) { | |
| if (typeof autoOptions.displayOptions[r.name] !== 'undefined') { | |
| addNamedCheckbox(uiContainer, 'autoOptions.displayOptions', r.name, 'show' + r.name, 'Show ' + (r.title || r.name)); | |
| } | |
| }); | |
| addHeading(uiContainer, 'Reset options'); | |
| uiContainer.append('<a onclick="autoOptions = defaultOptions;saveAutoOptions();updateOptionsUI();" href="#">Reset options</a>'); | |
| updateOptionsUI(); | |
| } | |
| function saveAutoOptions() { | |
| LCstorage["kittensgame.autoOptions"] = JSON.stringify(autoOptions); | |
| } | |
| function changeTimeFormat() { | |
| var formats = { | |
| standard: defaultTimeFormat, | |
| short: shortTimeFormat, | |
| seconds: rawSecondsFormat | |
| }; | |
| gamePage.toDisplaySeconds = formats[autoOptions.timeDisplay]; | |
| } | |
| var defaultTimeFormat = gamePage.toDisplaySeconds; | |
| function shortTimeFormat(secondsRaw) { | |
| var sec_num = parseInt(secondsRaw, 10); // don't forget the second param | |
| var hours = Math.floor(sec_num / 3600); | |
| var minutes = Math.floor((sec_num - (hours * 3600)) / 60); | |
| var seconds = sec_num - (hours * 3600) - (minutes * 60); | |
| var timeFormated = ""; | |
| if ( hours ) { timeFormated = hours + ":" } | |
| timeFormated += (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds + ""; | |
| return timeFormated; | |
| } | |
| function rawSecondsFormat(secondsRaw) { | |
| return parseInt(secondsRaw, 10)+"s"; | |
| } | |
| var defaultOptions = { | |
| warnOnLeave: true, | |
| autoStar: true, | |
| autoCraft: false, | |
| autoHunt: false, | |
| autoPray: false, | |
| autoTrade: false, | |
| craftOptions: { | |
| craftLimit: 0.99, | |
| craftWood: false, | |
| woodAmount: 100, | |
| craftBeam: false, | |
| beamAmount: 1, | |
| craftSlab: false, | |
| slabAmount: 1, | |
| craftSteel: false, | |
| steelAmount: 1, | |
| craftPlate: false, | |
| plateAmount: 1, | |
| craftAlloy: false, | |
| alloyAmount: 1 | |
| }, | |
| huntOptions: { | |
| huntLimit: 0.99, | |
| huntEarly: true, | |
| craftParchment: false, | |
| craftManuscript: false, | |
| craftCompendium: false, | |
| craftBlueprint: false | |
| }, | |
| prayLimit: 0.99, | |
| widenUI: false, | |
| displayOptions: { | |
| }, | |
| timeDisplay: "standard", | |
| tradeOptions : { | |
| tradeLimit: 0.99, | |
| tradePartner: "", | |
| tradeSpring: false, | |
| tradeSummer: false, | |
| tradeAutumn: false, | |
| tradeWinter: false | |
| } | |
| } | |
| autoOptions = defaultOptions | |
| if (LCstorage["kittensgame.autoOptions"]) { | |
| copyObject(JSON.parse(LCstorage["kittensgame.autoOptions"]), autoOptions); | |
| } | |
| function copyObject(source, target) | |
| { | |
| for (var attrname in source) { | |
| if (typeof source[attrname] === "object") { | |
| if (typeof target[attrname] === "undefined") { | |
| target[attrname] = {}; | |
| } | |
| copyObject(source[attrname], target[attrname]); | |
| } else { | |
| target[attrname] = source[attrname]; | |
| } | |
| } | |
| } | |
| function updateOptionsUI() { | |
| traverseObject(autoOptions); | |
| changeTimeFormat(); | |
| } | |
| function traverseObject(obj) { | |
| for (o in obj) { | |
| if (o === "displayOptions") { | |
| handleDisplayOptions(obj[o]) | |
| } | |
| else if (typeof obj[o] === "object") { | |
| traverseObject(obj[o]) | |
| } | |
| else if (typeof obj[o] === "boolean") { | |
| elms = $("#autoKittens_"+o); | |
| if (elms && elms[0]) { | |
| elms[0].checked = obj[o]; | |
| } | |
| } | |
| else { | |
| elms = $("#autoKittens_"+o); | |
| if (elms && elms[0]) { | |
| elms[0].value = obj[o]; | |
| } | |
| } | |
| } | |
| } | |
| function handleDisplayOptions(obj) { | |
| for (o in obj) { | |
| $("#autoKittens_show"+o)[0].checked = obj[o]; | |
| } | |
| } | |
| function formatTableRow(name, title, value) { | |
| if (typeof autoOptions.displayOptions[name] === 'undefined') { | |
| autoOptions.displayOptions[name] = true; | |
| } | |
| if (autoOptions.displayOptions[name]) { | |
| return '<td style="text-align:center">'+title+'<br>'+value+'</td>'; | |
| } | |
| return ''; | |
| } | |
| fillTable = function () { | |
| var contents = '<tr>'; | |
| var tickRate = 5; | |
| gamePage.resPool.resources.forEach(function (r) { | |
| var name = r.name, title = r.title || r.name; | |
| if (r.perTickUI !== 0) { | |
| if (r.maxValue > 0) { | |
| if (r.value <= 0) { | |
| contents += formatTableRow(name, title, 'Empty'); | |
| } else if (r.value >= r.maxValue) { | |
| contents += formatTableRow(name, title, 'Full'); | |
| } else if (r.perTickUI > 0) { | |
| contents += formatTableRow(name, title, "Full: "+gamePage.toDisplaySeconds((r.maxValue - r.value)/(r.perTickUI * tickRate))); | |
| } else if (r.perTickUI < 0) { | |
| contents += formatTableRow(name, title, "Left: "+gamePage.toDisplaySeconds(-r.value/(r.perTickUI * tickRate))); | |
| } | |
| } | |
| else if (r.value > 0 && r.perTickUI < 0) { | |
| contents += formatTableRow(name, title, "Left: "+gamePage.toDisplaySeconds(-r.value/(r.perTickUI * tickRate))); | |
| }; | |
| } | |
| }); | |
| contents += '</tr>'; | |
| document.getElementById('timerTable').innerHTML = contents; | |
| } | |
| if (typeof tableUpdater !== 'undefined') clearInterval(tableUpdater); | |
| tableUpdater = setInterval(fillTable, 200); | |
| if (!document.getElementById('timerTable')) { | |
| buildUI(); | |
| } | |
| var checkInterval = 200; | |
| // Based on http://www.reddit.com/r/kittensgame/comments/2eqlt5/a_few_kittens_game_scripts_ive_put_together/ | |
| starClick = function () { | |
| if (autoOptions.autoStar) { | |
| $("#gameLog").find("input").click(); | |
| } | |
| } | |
| if (typeof starMonitor !== 'undefined') clearInterval(starMonitor); | |
| starMonitor = setInterval(starClick, checkInterval); | |
| autoHunt = function () { | |
| if (!autoOptions.autoHunt) | |
| return; | |
| var catpower = gamePage.resPool.get('manpower'); | |
| var leftBeforeCap = (1 - autoOptions.huntOptions.huntLimit) * catpower.maxValue | |
| if (catpower.value / catpower.maxValue >= autoOptions.huntOptions.huntLimit || (autoOptions.huntOptions.huntEarly && catpower.value >= (catpower.maxValue - leftBeforeCap) - ((catpower.maxValue - leftBeforeCap) % 100))) { | |
| if (autoOptions.huntOptions.craftParchment && gamePage.workshop.getCraft('parchment').unlocked) { gamePage.craftAll('parchment'); } | |
| if (autoOptions.huntOptions.craftManuscript && gamePage.workshop.getCraft('manuscript').unlocked) { gamePage.craftAll('manuscript'); } | |
| if (autoOptions.huntOptions.craftCompendium && gamePage.workshop.getCraft('compedium').unlocked) { gamePage.craftAll('compedium'); } | |
| if (autoOptions.huntOptions.craftBlueprint && gamePage.workshop.getCraft('blueprint').unlocked) { gamePage.craftAll('blueprint'); } | |
| $("a:contains('Send hunters')").click(); | |
| } | |
| } | |
| if (typeof catpowerMonitor !== 'undefined') clearInterval(catpowerMonitor); | |
| catpowerMonitor = setInterval(autoHunt, checkInterval); | |
| autoCraft = function () { | |
| if (!autoOptions.autoCraft) | |
| return; | |
| var resources = [ | |
| ["catnip", "wood" , "craftWood"], | |
| ["wood", "beam" , "craftBeam"], | |
| ["minerals", "slab" , "craftSlab"], | |
| ["coal", "steel", "craftSteel"], | |
| ["iron", "plate", "craftPlate"], | |
| ["titanium", "alloy", "craftAlloy"] | |
| ]; | |
| for (var i = 0; i < resources.length; i++) { | |
| var curRes = gamePage.resPool.get(resources[i][0]); | |
| if (autoOptions.craftOptions[resources[i][2]] && curRes.value / curRes.maxValue >= autoOptions.craftOptions.craftLimit && gamePage.workshop.getCraft(resources[i][1]).unlocked) { | |
| gamePage.craft(resources[i][1], autoOptions.craftOptions[resources[i][1]+'Amount']); | |
| } | |
| } | |
| } | |
| if (typeof resourceMonitor !== 'undefined') clearInterval(resourceMonitor); | |
| resourceMonitor = setInterval(autoCraft, checkInterval); | |
| window.onbeforeunload = function(){ | |
| if (autoOptions.warnOnLeave) | |
| return 'Are you sure you want to leave?'; | |
| }; | |
| autoPray = function () { | |
| if (!autoOptions.autoPray) | |
| return; | |
| var origTab = gamePage.activeTabId; | |
| var faith = gamePage.resPool.get('faith'); | |
| if (faith.value / faith.maxValue >= autoOptions.prayLimit) { | |
| gamePage.activeTabId = 'Religion'; gamePage.render(); | |
| $(".btnContent:contains('Praise the sun')").click(); | |
| gamePage.activeTabId = origTab; gamePage.render(); | |
| } | |
| } | |
| if (typeof faithMonitor !== 'undefined') clearInterval(faithMonitor); | |
| faithMonitor = setInterval(autoPray, checkInterval); | |
| autoTrade = function () { | |
| if (!autoOptions.autoTrade || autoOptions.tradeOptions.tradePartner === "") | |
| { | |
| return; | |
| } | |
| var race = gamePage.diplomacy.get(autoOptions.tradeOptions.tradePartner); | |
| if (!race.unlocked) | |
| { | |
| autoOptions.tradeOptions.tradePartner = ""; | |
| saveAutoOptions(); | |
| return | |
| } | |
| var gold = gamePage.resPool.get('gold'); | |
| if (gamePage.resPool.get(race.buys[0].name).value < race.buys[0].val || gamePage.resPool.get("manpower").value < 50 || gold.value / gold.maxValue < autoOptions.tradeOptions.tradeLimit) { | |
| return; | |
| } | |
| season = ["Spring", "Summer", "Autumn", "Winter"][gamePage.calendar.season] | |
| if (autoOptions.tradeOptions['trade' + season]) | |
| { | |
| var origTab = gamePage.activeTabId; | |
| if (gamePage.diplomacyTab.racePanels.length == 0) { | |
| gamePage.activeTabId = 'Trade'; gamePage.render(); | |
| } | |
| for (var i = 0; i < gamePage.diplomacyTab.racePanels.length; i++) { | |
| if (gamePage.diplomacyTab.racePanels[i].name == race.title) { | |
| if (!gamePage.diplomacyTab.racePanels[i].tradeBtn.enabled) { | |
| gamePage.activeTabId = 'Trade'; gamePage.render(); | |
| } | |
| gamePage.diplomacyTab.racePanels[i].tradeBtn.onClick(); | |
| break; | |
| } | |
| } | |
| if (gamePage.activeTabId != origTab) { | |
| gamePage.activeTabId = origTab; gamePage.render(); | |
| } | |
| } | |
| } | |
| if (typeof tradeMonitor !== 'undefined') clearInterval(tradeMonitor); | |
| tradeMonitor = setInterval(autoTrade, checkInterval); | |
| // Calculator UI | |
| function rebuildCalculatorUI() { | |
| var calcContainer = prepareContainer('kittenCalcs'); | |
| addHeading(calcContainer, 'Unicorn structures'); | |
| calcContainer.append('<h5>(<a href="https://www.reddit.com/r/kittensgame/comments/2iungv/turning_the_sacrificing_of_unicorns_into_an_exact/" target="_blank">Based on spreadsheet by /u/yatima2975</a>)</h5>'); | |
| calcContainer.append(calculateUnicornBuild()); | |
| } | |
| // Unicorn calculator | |
| function getZiggurats() { | |
| return gamePage.bld.get('ziggurat').val; | |
| } | |
| function calculateUnicornBuild() { | |
| if (gamePage.bld.get('unicornPasture').val == 0) | |
| return 'You need at least one Unicorn Pasture to use this. Send off some hunters!'; | |
| var ziggurats = getZiggurats(); | |
| if (ziggurats == 0) | |
| return 'You need at least one Ziggurat to use this.'; | |
| var startUps = calculateEffectiveUps(); | |
| var details = ''; | |
| var result = 'Base unicorn production per second: ' + gamePage.getDisplayValue(calculateBaseUps()); | |
| result += '<br>Rift production per second (amortized): ' + gamePage.getDisplayValue(calculateRiftUps()); | |
| result += '<br>Current effective unicorn production per second: ' + gamePage.getDisplayValue(startUps); | |
| var buildings = ['Unicorn Pasture', 'Unicorn Tomb', 'Ivory Tower', 'Ivory Citadel', 'Sky Palace']; | |
| var tears = getTearPrices(); | |
| var ivory = getIvoryPrices(); | |
| var increases = [0, 0, 0, 0, 0]; | |
| var best = 0, secondBest = 0; | |
| for (var i = 0; i < 5; i++) { | |
| extras = [0, 0, 0, 0, 0]; | |
| extras[i] = 1; | |
| increases[i] = calculateEffectiveUps(extras) - startUps; | |
| if (tears[best] / increases[best] > tears[i] / increases[i]) { | |
| secondBest = best; | |
| best = i; | |
| } | |
| if (tears[secondBest] / increases[secondBest] > tears[i] / increases[i] && i != best) { | |
| secondBest = i; | |
| } | |
| details += 'Unicorn/s increase with 1 more ' + buildings[i] + ': ' + gamePage.getDisplayValue(increases[i]); | |
| if (i != 0) { | |
| details += '<br>Total unicorns needed: ' + Math.ceil(tears[i] / ziggurats) * 2500; | |
| details += ' (' + gamePage.getDisplayValue(tears[i]) +' tears, ' + Math.ceil(tears[i] / ziggurats) + ' sacrifice(s))'; | |
| details += '<br>'+checkUnicornReserves(tears[i], false, startUps, ivory[i]) | |
| } else { | |
| details += '<br>Total unicorns needed: ' + gamePage.getDisplayValue(tears[i] / ziggurats * 2500); | |
| details += '<br>'+checkUnicornReserves(tears[i] / ziggurats * 2500, true, startUps, ivory[i]) | |
| } | |
| details += '<br>Tears for 1 extra unicorn/s: ' + gamePage.getDisplayValue(tears[i] / increases[i]) + '<br><br>'; | |
| } | |
| result += '<br><br>Best purchase is '+buildings[best]+', by a factor of ' + gamePage.getDisplayValue((tears[secondBest] / increases[secondBest]) / (tears[best] / increases[best])); | |
| if (best != 0) { | |
| result += '<br>'+checkUnicornReserves(tears[best], false, startUps, ivory[best]) | |
| } else { | |
| result += '<br>'+checkUnicornReserves(tears[best] / ziggurats * 2500, true, startUps, ivory[best]) | |
| } | |
| result += '<h4 onclick="$(\'#unicornDetails\').toggle();">Calculation details (click to show/hide)</h4><div id="unicornDetails" style="display:none">'+details+'</div>' | |
| return result; | |
| } | |
| function checkUnicornReserves(resNumber, isPasture, currUps, ivoryNeeded) { | |
| var unicornsLeft = 0; | |
| if (!isPasture) { | |
| var tearsLeft = resNumber - gamePage.resPool.get('tears').value; | |
| unicornsLeft = 2500 * Math.ceil(tearsLeft / getZiggurats()); | |
| } else { | |
| unicornsLeft = resNumber; | |
| } | |
| unicornsLeft = unicornsLeft - gamePage.resPool.get('unicorns').value; | |
| var ivoryLeft = ivoryNeeded - gamePage.resPool.get('ivory').value; | |
| if (unicornsLeft > 0) { | |
| return "You need "+gamePage.getDisplayValue(unicornsLeft)+" more unicorns to build this (approximately "+gamePage.toDisplaySeconds(unicornsLeft/currUps)+")."; | |
| } if (ivoryLeft > 0){ | |
| return "You have enough unicorns, but need more ivory to build this."; | |
| } else { | |
| return "You have enough resources to build this now."; | |
| } | |
| } | |
| function getTearPrices() { | |
| var result = [0, 0, 0, 0, 0]; | |
| var buildings = [gamePage.bld.get('unicornPasture'), gamePage.religion.getZU('unicornTomb'), gamePage.religion.getZU('ivoryTower'), gamePage.religion.getZU('ivoryCitadel'), gamePage.religion.getZU('skyPalace')] | |
| for (var i = 0; i < 5; i++) { | |
| for (var j = 0; j < buildings[i].prices.length; j++) { | |
| if (buildings[i].prices[j].name == 'unicorns') { | |
| result[i] = calcPrice(buildings[i].prices[j].val, buildings[i].priceRatio, buildings[i].val) / 2500 * getZiggurats(); | |
| } else if (buildings[i].prices[j].name == 'tears') { | |
| result[i] = calcPrice(buildings[i].prices[j].val, buildings[i].priceRatio, buildings[i].val); | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| function getIvoryPrices() { | |
| var result = [0, 0, 0, 0, 0]; | |
| var buildings = [gamePage.bld.get('unicornPasture'), gamePage.religion.getZU('unicornTomb'), gamePage.religion.getZU('ivoryTower'), gamePage.religion.getZU('ivoryCitadel'), gamePage.religion.getZU('skyPalace')] | |
| for (var i = 0; i < 5; i++) { | |
| for (var j = 0; j < buildings[i].prices.length; j++) { | |
| if (buildings[i].prices[j].name == 'ivory') { | |
| result[i] = calcPrice(buildings[i].prices[j].val, buildings[i].priceRatio, buildings[i].val); | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| function calcPrice(base, ratio, num) { | |
| for (i = 0; i < num; i++) { | |
| base *= ratio; | |
| } | |
| return base; | |
| } | |
| function calculateBaseUps(extras) { | |
| extras = extras || []; | |
| var pastures = gamePage.bld.get('unicornPasture').val + (extras[0] || 0); | |
| var baseUps = pastures * gamePage.bld.get('unicornPasture').effects['unicornsPerTickBase'] * 5; | |
| var tombs = gamePage.religion.getZU('unicornTomb').val + (extras[1] || 0); | |
| var towers = gamePage.religion.getZU('ivoryTower').val + (extras[2] || 0); | |
| var citadels = gamePage.religion.getZU('ivoryCitadel').val + (extras[3] || 0); | |
| var palaces = gamePage.religion.getZU('skyPalace').val + (extras[4] || 0); | |
| var tombEffect = gamePage.religion.getZU('unicornTomb').effects['unicornsRatio']; | |
| var towerEffect = gamePage.religion.getZU('ivoryTower').effects['unicornsRatio']; | |
| var citadelEffect = gamePage.religion.getZU('ivoryCitadel').effects['unicornsRatio']; | |
| var palaceEffect = gamePage.religion.getZU('skyPalace').effects['unicornsRatio']; | |
| var bldEffect = 1 + tombEffect * tombs + towerEffect * towers + citadelEffect * citadels + palaceEffect * palaces; | |
| var faithEffect = 1; | |
| if (gamePage.religion.getRU("solarRevolution").researched){ | |
| faithEffect += gamePage.religion.getProductionBonus() / 100; | |
| } | |
| var paragonRatio = gamePage.resPool.get("paragon").value * 0.01; | |
| paragonRatio = 1 + gamePage.bld.getHyperbolicEffect(paragonRatio, 2); | |
| return baseUps * bldEffect * faithEffect * paragonRatio; | |
| } | |
| function calculateRiftUps(extras) { | |
| extras = extras || []; | |
| return Math.min(50, 0.125 * (gamePage.religion.getZU('ivoryTower').val + (extras[2] || 0))); | |
| } | |
| function calculateEffectiveUps(extras) { | |
| return calculateBaseUps(extras) + calculateRiftUps(extras); | |
| } | |
| // vim:expandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment