Last active
August 20, 2016 17:36
-
-
Save kgroat/d5c1bc0d652f40cd1c6fc8f7d2d9796d to your computer and use it in GitHub Desktop.
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
// How to use: | |
// Go to http://trimps.github.io/ | |
// Open up developer console on your browser. | |
// In Google Chrome, this is done by pressing F12 if you're on PC or Cmd+Alt+I if you're on a Mac | |
// Paste this code into the Console tab of the dev tools and hit enter | |
// In the console, write window.getNextHeirloom(true) if your next heirloom will be from Bones, | |
// or window.getNextHeirloom(false) if the heirloom will not be from Bones | |
// Hit enter | |
(function(){ | |
function createHeirloom(zone, fromBones){ | |
var slots = [1, 2, 2, 3, 3, 4, 4]; | |
var rarityNames = ['Common', 'Uncommon', 'Rare', 'Epic', 'Legendary', 'Magnificent', 'Ethereal']; | |
//Determine Type | |
var seed = (fromBones) ? game.global.heirloomBoneSeed : game.global.heirloomSeed; | |
var type = (getRandomIntSeeded(seed++, 0, 2) == 0) ? "Shield" : "Staff"; | |
//Sort through modifiers and build a list of eligible items. Check filters if applicable | |
var elligible = []; | |
for (var item in game.heirlooms[type]){ | |
var heirloom = game.heirlooms[type][item]; | |
if (typeof heirloom.filter !== 'undefined' && !heirloom.filter()) continue; | |
elligible.push(item); | |
} | |
//Determine type rarity | |
var rarity = getHeirloomRarity(zone, seed++); | |
slots = slots[rarity]; | |
var name = rarityNames[rarity] + " " + type; | |
//Heirloom configuration | |
//{name: "", type: "", rarity: #, mods: [[ModName, value, createdStepsFromCap, upgradesPurchased, seed]]} | |
var buildHeirloom = {name: name, type: type, rarity: rarity, mods: []}; | |
var x = 0; | |
for (x; x < slots; x++){ | |
var roll = getRandomIntSeeded(seed++, 0, elligible.length); | |
var thisMod = elligible[roll]; | |
elligible.splice(roll, 1); | |
var steps = (typeof game.heirlooms[type][thisMod].steps !== 'undefined') ? game.heirlooms[type][thisMod].steps : game.heirlooms.defaultSteps; | |
steps = getRandomBySteps(steps[rarity], null, fromBones); | |
buildHeirloom.mods.push([thisMod, steps[0], steps[1], 0, getRandomIntSeeded(seed++, 0, 1000)]); | |
} | |
seed += 6 - (x * 2); | |
buildHeirloom.mods.sort(function(a, b){ | |
a = a[0].toLowerCase(); | |
b = b[0].toLowerCase(); | |
if (a == "empty") return 1; | |
if (b == "empty") return -1; | |
if (a < b) | |
return -1; | |
if (a > b) | |
return 1; | |
return 0; | |
}) | |
return buildHeirloom; | |
} | |
function getHeirloomZoneBreakpoint(zone){ | |
if (!zone) zone = game.global.world; | |
var rarityBreakpoints = game.heirlooms.rarityBreakpoints; | |
for (var x = 0; x < rarityBreakpoints.length; x++){ | |
if (zone < rarityBreakpoints[x]) return x; | |
} | |
return rarityBreakpoints.length; | |
} | |
function getHeirloomRarity(zone, seed){ //zone is optional, and will override world | |
if (!zone) zone = game.global.world; | |
var rarities = game.heirlooms.rarities[getHeirloomZoneBreakpoint(zone)]; | |
var nextTest = 0; | |
var selectedRarity; | |
var rarityRoll = getRandomIntSeeded(seed, 0, 10000); | |
for (var y = 0; y < rarities.length; y++){ | |
if (rarities[y] == -1) continue; | |
nextTest += rarities[y]; | |
if (rarityRoll < nextTest) { | |
selectedRarity = y; | |
break; | |
} | |
} | |
return selectedRarity; | |
} | |
function seededRandom(seed){ | |
var x = Math.sin(seed++) * 10000; | |
return (x - Math.floor(x)); | |
} | |
function getRandomIntSeeded(seed, minIncl, maxExcl) { | |
return Math.floor(seededRandom(seed) * (maxExcl - minIncl)) + minIncl; | |
} | |
function getRandomBySteps(steps, mod, fromBones){ | |
var seed; | |
if (mod && typeof mod[4] !== 'undefined'){ | |
seed = mod[4]++; | |
} | |
else { | |
seed = (fromBones) ? game.global.heirloomBoneSeed : game.global.heirloomSeed; | |
} | |
var possible = ((steps[1] - steps[0]) / steps[2]); | |
var roll = getRandomIntSeeded(seed, 0, possible + 1); | |
var result = steps[0] + (roll * steps[2]); | |
result = Math.floor(result * 10) / 10; | |
return ([result, (possible - roll)]); | |
} | |
window.getNextHeirloom = function(byBones){ | |
if(byBones){ | |
return createHeirloom(game.global.highestLevelCleared + 1, true); | |
} else { | |
return createHeirloom(); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment