Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- let shuffle = function(array, power) {
- let currentIndex = array.length - 1,
- temporaryValue,
- randomIndex,
- distance
- while (0 !== currentIndex) {
- // Get new index
- randomIndex = Math.floor(Math.random() * currentIndex)
- //Find distance
- distance = randomIndex - currentIndex
- //Nerf distance
- distance *= power
- //Reapply it
- randomIndex = Math.round(currentIndex + distance)
- temporaryValue = array[currentIndex]
- array[currentIndex] = array[randomIndex]
- array[randomIndex] = temporaryValue
- currentIndex -= 1
- }
- return array
- }
- let clone = function(obj) {
- let copy = new obj.constructor()
- for (const attr in obj) {
- if (obj.hasOwnProperty(attr)) {
- if (obj[attr] instanceof Object) {
- copy[attr] = clone(obj[attr])
- } else {
- copy[attr] = obj[attr]
- }
- }
- }
- return copy
- }
- window.randomizeArray = function(input, params) {
- params.enforce = params.enforce || {}
- let values = {}
- let empty = Symbol("empty")
- //Assume all objects have the same prototype
- let prototype = input[0].__proto__
- input.forEach(element => {
- //Scan for all properties
- Object.keys(element).forEach(element => {
- values[element] = []
- })
- })
- input.forEach(element => {
- //Actually add values to the array
- Object.keys(values).forEach(prop => {
- values[prop].push(element[prop] !== undefined ? element[prop] : empty)
- })
- })
- Object.keys(values).forEach(prop => {
- values[prop] = shuffle(values[prop], params.power)
- })
- let output = []
- input.forEach((_value, i) => {
- output[i] = {}
- output[i].__proto__ = prototype
- Object.keys(values).forEach(prop => {
- let add = values[prop].shift()
- if (add !== empty) output[i][prop] = add
- })
- Object.keys(params.enforce).forEach(key => {
- output[i][key] =
- params.enforce[key] instanceof Function
- ? params.enforce[key](output[i])
- : params.enforce[key]
- })
- })
- return output
- }
- }
- Game.Tiers[0] = {}
- window.CCR = {
- upgrades: function(power) {
- Game.UpgradesById = randomizeArray(Game.UpgradesById, {
- enforce: {
- buildingTie1: {
- basePrice:
- Game.ObjectsById[Game.ObjectsById.length - 1].price * Math.random()
- },
- buildingTie2: {
- basePrice:
- Game.ObjectsById[Game.ObjectsById.length - 1].price * Math.random()
- }
- },
- power: power / 255
- })
- ;[...Game.UpgradesById].forEach(val => {
- Game.UpgradesById[val.id] = val
- Game.Upgrades[val.name] = val
- })
- },
- achievements: function(power) {
- Game.AchievementsById = randomizeArray(Game.AchievementsById, {
- power: power / 255
- })
- ;[...Game.AchievementsById].forEach(val => {
- Game.AchievementsById[val.id] = val
- Game.Achievements[val.name] = val
- })
- },
- milk: function(power) {
- Game.Milks = randomizeArray(Game.Milks, { power: power / 255 })
- }
- }
- function randomizePrompt() {
- Game.timedout = true
- window.CCR.randomize = () => {
- const seed = document.getElementById("seed").value
- Math.seedrandom(seed)
- const power = document.getElementById("power").value
- const checkboxes = ["Upgrades", "Achievements", "Milk"]
- checkboxes.forEach(val => {
- const randomize = document.getElementById(`randomize${val}`).checked
- if (randomize) CCR[val.toLowerCase()](power)
- })
- Game.timedout = false
- Game.Loop()
- }
- Game.Prompt(
- `Seed:
- <input placeholder="Enter seed here" id="seed"><br>
- Power(0-255):
- <input type="number" min="0" max="255" id="power" placeholder="Enter power here"><br>
- Randomize:<br><br>
- Upgrades<input type="checkbox" id="randomizeUpgrades">
- Achievements<input type="checkbox" id="randomizeAchievements">
- Buildings<input type="checkbox" id ="randomizeBuildings">
- Milk<input type="checkbox" id="randomizeMilk">
- `,
- [["Let's go", "CCR.randomize();Game.ClosePrompt()"], "Nevermind"]
- )
- }
- Game.UpdateMenu = new Proxy(Game.UpdateMenu, {
- apply: (target, thisArg, argumentsList) => {
- target.apply(thisArg, argumentsList)
- if (Game.onMenu === "prefs") {
- //Create master div
- const div = document.createElement("div")
- div.classList.add("listing")
- //Create title
- const title = document.createElement("div")
- title.innerText = "Randomizer"
- title.classList.add("title")
- div.appendChild(title)
- //Create our button
- const button = document.createElement("a")
- button.innerText = "Randomize!"
- button.classList.add("option")
- button.classList.add("neato")
- button.addEventListener("click", randomizePrompt)
- div.appendChild(button)
- // Create the label
- const label = document.createElement("label")
- label.innerText = "Randomizes everything!"
- div.appendChild(label)
- const options = document
- .getElementById("menu")
- .getElementsByClassName("subsection")[0]
- options.insertBefore(div, options.lastChild)
- }
- }
- })
- Game.Notify("CCRandomizer loaded!", "Go to the bottom of settings to actually randomize things!", [-1,0])
- Game.UpdateMenu()
Advertisement
Add Comment
Please, Sign In to add comment