Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function(global) {
- /* for setting */
- var refleshInterval = 1000;
- /* internal variables */
- var randCounter = 0;
- var M = (Game.Objects['Wizard tower'] || Game.ObjectsById[7]).minigame;
- var localMath = Object.create(Math);
- /* functions */
- var choose = function(arr) {
- return arr[localMath.floor(localMath.random() * arr.length)];
- };
- var succeeds = function(spell, failChanceMax = 0, goldenCookies = 0) {
- var failChance = Math.max(M.getFailChance(spell) + 0.15 * goldenCookies, failChanceMax);
- return !spell.fail || localMath.random() < 1 - failChance;
- };
- var gamble = {
- win: function() {
- var selfCost = M.getSpellCost(M.spells['gambler\'s fever dream']);
- var spells = [];
- for (var s in M.spells) {
- if (s != 'gambler\'s fever dream' && M.getSpellCost(M.spells[s]) * 0.5 <= M.magic - selfCost) {
- spells.push(M.spells[s]);
- }
- }
- if (spells.length == 0) {
- return ('no magics can cast');
- }
- var selected = choose(spells);
- var result = '';
- localMath.seedrandom(Game.seed + '/' + (M.spellsCastTotal + 1));
- if (selected.name == 'Force the Hand of Fate') {
- result = succeeds(selected, 0.5) ? hand.win(randCounter) : hand.fail(randCounter);
- return 'will cast <b>Force the Hand of Fate</b> and ' + result;
- } else {
- result = succeeds(selected, 0.5) ? 'win' : 'fail';
- return 'will cast <b>' + selected.name + '</b> and <b>' + result + '</b>';
- }
- }
- };
- var hand = {
- win: function(cycle) {
- /* by shimmer.initFunc */
- localMath.random();
- localMath.random();
- /* by PlaySound or season shimmer */
- for (i = 0; i < cycle; i++) {
- localMath.random();
- }
- var choices = [];
- choices.push('Frenzy', 'Lucky');
- if (!Game.hasBuff('Dragonflight')) {
- choices.push('Click frenzy');
- }
- if (localMath.random() < 0.1) {
- choices.push('Cookie storm', 'Cookie storm', 'Blab');
- }
- if (Game.BuildingsOwned >= 10 && localMath.random() < 0.25) {
- choices.push('Building special');
- }
- if (localMath.random() < 0.15) {
- choices = ['Cookie storm drop'];
- }
- if (localMath.random() < 0.0001) {
- choices.push('Sweet');
- }
- return choose(choices);
- },
- fail: function(cycle) {
- /* by shimmer.initFunc */
- localMath.random();
- localMath.random();
- /* by PlaySound or season */
- for (var i = 0; i < cycle; i++) {
- localMath.random();
- }
- var choices = [];
- choices.push('Clot', 'Ruin');
- if (localMath.random() < 0.1) {
- choices.push('Cursed finger', 'Elder frenzy');
- }
- if (localMath.random() < 0.003) {
- choices.push('Sweet');
- }
- if (localMath.random() < 0.1) {
- choices = ['Blab'];
- }
- return choose(choices);
- }
- };
- var testSpell = function() {
- var ret = '';
- var spellTotal = M.spellsCastTotal;
- randCounter = 0;
- if (Game.season == 'easter' || Game.season == 'valentines') {
- randCounter++;
- }
- if (Game.chimeType == 1 && Game.ascensionMode != 1) {
- randCounter++;
- }
- /* Gamblers Fever Dream */
- ret += '<p><h3>Gamblers Dream</h3>';
- localMath.seedrandom(Game.seed + '/' + spellTotal);
- spellResult = succeeds(gamble) ? gamble.win() : gamble.fail();
- ret += '<h5 style="padding-left:1em">' + spellResult + '</h5></p>';
- /* Hand of Fate */
- ret += '<p><h3>Hand of Fate</h3><table style="margin:auto;width:90%">';
- ret += '<thead><tr><th></th><th>0 change</th><th>1 change</th><th>2 change</th></tr></thead><tbody>';
- var nextBS = false;
- for (var i = 0; i < 10; i++) {
- ret += '<tr><td style="padding:1px 5px 0px;text-align:right;">' + (i + 1) + '</td>';
- for (var j = 0; j < 3; j++) {
- localMath.seedrandom(Game.seed + '/' + (spellTotal + i));
- var spellSucceed = succeeds(hand);
- var spellResult = spellSucceed ? hand.win(j) : hand.fail(j);
- localMath.seedrandom(Game.seed + '/' + (spellTotal + i));
- ret += '<td style="';
- if (spellSucceed) {
- if (spellResult == 'Building special' || spellResult == 'Sweet') {
- ret += succeeds(hand, 0, 1) ? 'color:cyan;' : 'color:magenta;';
- } else if (!succeeds(hand, 0, 1)) {
- ret += 'color:orange;';
- }
- } else {
- ret += 'color:red;';
- }
- if (randCounter == j) {
- ret += 'font-weight:bold;">' + spellResult + '</td>';
- } else {
- ret += '">' + spellResult + '</td>';
- }
- nextBS |= i == 0 && (spellResult == 'Building special' || spellResult == 'Sweet');
- }
- ret += '</tr>';
- }
- ret += '</tbody></table></p>';
- Math.seedrandom();
- if (M.magic == M.magicM && !nextBS) {
- document.querySelector('#grimoireSpell4').click();
- }
- return ret;
- };
- /* panel creation */
- var panel = document.createElement('div');
- panel.setAttribute('id', 'grimoireNext');
- panel.setAttribute('class', 'framed note');
- panel.style.cssText = 'margin:3px auto; width:80%';
- document.getElementById('grimoireContent').appendChild(panel);
- panel.innerHTML = testSpell();
- /* auto refresh */
- setInterval(function() {
- panel.innerHTML = testSpell();
- }, refleshInterval);
- })(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement