|
var purchaseSleep = 500; |
|
var cookieClickSleep = 5; |
|
var goldCookieClickSleep = 200; |
|
var sugarLumpClickSleep = 24*60*60*1000; |
|
var maxUpgradeWait = 10*60; |
|
var priorityUpgrades = [476]; |
|
var excludeUpgrades = ["toggle","tech"]; |
|
|
|
function buyBestThing(){ |
|
var myCookies = Game.cookies; |
|
var upgradeId = getBestUpgradeId(myCookies); |
|
var buildingId = getBestBuildingId(myCookies); |
|
|
|
if (shouldBuyUpgrade(upgradeId, Game.cookiesPs)) { |
|
getUpgradeDom(upgradeId).click(); |
|
} else if (shouldBuyBuilding()){ |
|
getBuildingDom(buildingId).click(); |
|
} |
|
|
|
setTimeout(buyBestThing, purchaseSleep); |
|
} |
|
|
|
function shouldBuyUpgrade(upgradeId, cookiesPerSecond){ |
|
if (upgradeId == -1) |
|
return false; |
|
var upgrade = getUpgrade(upgradeId); |
|
return upgrade.getPrice() <= maxUpgradeWait * cookiesPerSecond; |
|
} |
|
|
|
function shouldBuyBuilding(){ |
|
return document.getElementById("storeBulkBuy").classList.contains("selected") |
|
} |
|
|
|
function getBestBuildingId(currentCookies){ |
|
var lastBuildingId = getLastUnlockedBuildingId(); |
|
var expensiveBuildingId = 0; |
|
var expensivePrice = 0; |
|
|
|
for(var i = lastBuildingId; i >= 0; i--){ |
|
var currentPrice = getBuilding(i).price; |
|
if (expensivePrice < currentPrice && currentPrice < currentCookies){ |
|
expensiveBuildingId = i; |
|
expensivePrice = currentPrice; |
|
} |
|
} |
|
|
|
return expensiveBuildingId; |
|
}; |
|
|
|
function getBestUpgradeId(currentCookies){ |
|
var minUpgrade = -1; |
|
var minPrice = Number.MAX_VALUE; |
|
for (var i = 0; i < 100; i++){ |
|
if (getUpgradeDom(i) == null){ |
|
break; |
|
} |
|
var upgrade = getUpgrade(i); |
|
var currentPrice = upgrade.getPrice(); |
|
if (excludeUpgrades.includes(upgrade.pool)) { |
|
continue; |
|
} |
|
if (priorityUpgrades.includes(upgrade.id)){ |
|
return i; |
|
} |
|
if (minPrice > currentPrice){ |
|
minUpgrade = i; |
|
minPrice = currentPrice; |
|
} |
|
} |
|
return minUpgrade; |
|
}; |
|
|
|
function getLastUnlockedBuildingId(){ |
|
var maxBuildingId = 15; |
|
for(var buildingId = maxBuildingId; buildingId >= 0; buildingId--){ |
|
if(isUnlocked(buildingId)) { |
|
return buildingId; |
|
}; |
|
}; |
|
} |
|
|
|
function isUnlocked(buildingId){ |
|
return getBuildingDom(buildingId).classList.contains("unlocked") |
|
} |
|
|
|
function getBuilding(index){ |
|
return Game.ObjectsById[index]; |
|
} |
|
|
|
function getBuildingDom(index){ |
|
return document.getElementById("product" + index); |
|
} |
|
|
|
function getUpgrade(index){ |
|
var dom = getUpgradeDom(index); |
|
var clickFunction = dom.onclick.toString(); |
|
var upgradeId = clickFunction.substring(clickFunction.indexOf("[") + 1,clickFunction.indexOf("]")); |
|
return Game.UpgradesById[upgradeId]; |
|
} |
|
|
|
function getUpgradeDom(index){ |
|
return document.getElementById("upgrade" + index); |
|
} |
|
|
|
function clickBigCookie() { |
|
document.getElementById('bigCookie').click(); |
|
setTimeout(clickBigCookie, cookieClickSleep); |
|
} |
|
|
|
function clickGoldCookie() { |
|
var cookies = document.getElementsByClassName('shimmer'); |
|
for(var i = 0; i<cookies.length; i++) |
|
cookies[i].click(); |
|
setTimeout(clickGoldCookie, goldCookieClickSleep); |
|
} |
|
|
|
function spendSugarLumpOnCursorUpgrade() { |
|
var upgradeButton = document.getElementById("productLevel0"); |
|
upgradeButton.click(); |
|
setTimeout(spendSugarLumpOnCursorUpgrade, sugarLumpClickSleep); |
|
} |
|
|
|
clickBigCookie(); |
|
clickGoldCookie(); |
|
spendSugarLumpOnCursorUpgrade(); |
|
buyBestThing(); |