CursedSliver

Sweet finder (simple)

Jan 21st, 2024 (edited)
7,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //version 1.0: Sweet finder made
  2. //version 1.01: Fixed some minor issues, mainly trailing digits with the sweet finding notification
  3. //version 1.1: Added customization for maximum find distance and allows for skipping of unviable sweets, and finding a spell now plays a sound
  4. //version 1.11: Added option to instead display cast amount in terms of amount of unskippable spells
  5. //version 1.12: Options now save as mod data.
  6. //version 1.13: Added an option that enables saving when a sweet is successfully found. No sweet found message now disappears a lot quicker. Sweet found messages now last a long time.
  7. //version 1.14: Critical patch; now options actually properly save
  8. //version 1.15: Updated description for save on success option to mention bannability
  9. //version 1.2: Updated the unskippable spell count functionality based on updated GFD Skip Skip
  10.  
  11. //I love stealing code from cccem
  12. function getPromptOne() {
  13.     Game.Prompt('<id ImportSave><h3>'+"Input value"+'</h3><div class="block">'+loc("Input to modify the variable.")+'<div id="importError" class="warning" style="font-weight:bold;font-size:11px;"></div></div><div class="block"><textarea id="textareaPrompt" style="width:100%;height:128px;">'+'</textarea></div>',[[loc("Commit"),';Game.ClosePrompt(); Game.prefs.upperBound=Number((l(\'textareaPrompt\').value));'],loc("Cancel")]);
  14.     l('textareaPrompt').focus();
  15. }
  16.  
  17. var sweetFinderVer = "v1.2";
  18. const sweetFinderInitFunction = function() {
  19.     Game.prefs.upperBound = 10000;
  20.     Game.prefs.upperGC = 2;
  21.     Game.prefs.backfireLimEnabled = 0;
  22.     Game.prefs.spellDisplayMode = 0;
  23.     Game.prefs.saveOnSuccess = 0;
  24.     function findFirstSweet() {
  25.         let castCount = (Game.Objects['Wizard tower'].minigame?Game.Objects["Wizard tower"].minigame.spellsCastTotal:0);
  26.         let castA = [];
  27.         for (let i = castCount; i < castCount+Game.prefs.upperBound; i++) {
  28.             castA = findOutcome(i);
  29.             for (let j in castA) { if (castA[j] == 'free sugar lump') {castA[j] = true;} else {castA[j] = false;}}
  30.             castA.push(1-findBackfire(i));
  31.             if (!(castA[0] || castA[1] || castA[2] || castA[3] )) { continue; }
  32.             if (castA[2] || castA[3]) {
  33.                 if (castA[4] < (0.15*1.11+Game.prefs.upperGC*0.15) || !Game.prefs.backfireLimEnabled) {
  34.                     let str = '';
  35.                     if (castA[3]) { str = '.<br>Use Easter or Valentine\'s.'; }
  36.                     if (castA[2]) { str = '.<br>Use any season other than Easter or Valentine\'s'; }
  37.                     if (Game.prefs.saveOnSuccess) { Game.WriteSave(); }
  38.                     if (Game.prefs.spellDisplayMode) {
  39.                         Game.Notify('Sweet found after '+compileUnskippableCasts(castCount,i)+' unskippable casts!', 'At cast <b>'+(i-castCount+1)+'</b>.<br>Backfire; requires a backfire chance of <b>'+(tfwotd(100*castA[4],3))+'%</b>'+str, [29,14],20); PlaySound('snd/squeak'+Math.floor(Math.random()*4+1)+'.mp3'); return true;
  40.                     } else {
  41.                         Game.Notify('Sweet found at cast '+(i-castCount+1)+'!', 'Backfire; requires a backfire chance of <b>'+(tfwotd(100*castA[4],3))+'%</b>'+str, [29,14],20); PlaySound('snd/squeak'+Math.floor(Math.random()*4+1)+'.mp3'); return true;
  42.                     }
  43.                 }
  44.             }
  45.             if (castA[0] || castA[1]) {
  46.                 if (castA[4] < 0.03) {
  47.                     let str = '';
  48.                     if (castA[1]) { str = '.<br>Use Easter or Valentine\'s'; }
  49.                     if (castA[0]) { str = '.<br>Use any season other than Easter or Valentine\'s'; }
  50.                     if (Game.prefs.saveOnSuccess) { Game.WriteSave(); }
  51.                     if (Game.prefs.spellDisplayMode) {
  52.                         Game.Notify('Sweet found after '+compileUnskippableCasts(castCount,i)+' unskippable casts!', 'At cast <b>'+(i-castCount+1)+'</b>.<br>Success; will stop backfiring below <b>'+(tfwotd(100*castA[4],3))+'%</b>'+str, [29,15],20); PlaySound('snd/squeak'+Math.floor(Math.random()*4+1)+'.mp3'); return true;
  53.                     } else {
  54.                         Game.Notify('Sweet found at cast '+(i-castCount+1)+'!', 'Success; will stop backfiring below <b>'+(tfwotd(100*castA[4],3))+'%</b>'+str, [29,15],20); PlaySound('snd/squeak'+Math.floor(Math.random()*4+1)+'.mp3'); return true;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.         Game.Notify('No sweets found.','',0,1); return false;
  60.     }
  61.     AddEvent(document, 'keydown', function(e) { if (e.key.toLowerCase() == 'f') { findFirstSweet(); } });
  62.    
  63.     function compileUnskippableCasts(start, end) {
  64.         let unskippables = 0;
  65.         for (let i = start; i < end; i++) {
  66.             let bb = findBackfire(i);
  67.             if (bb < 0.875) { continue; }
  68.            
  69.             if (i > start && findBackfire(i - 1) >= (3/7) && findBackfire(i - 1) < (1/2)) {
  70.                 unskippables++;
  71.                 continue;
  72.             }
  73.            
  74.             let bbb = findBackfire(i + 1);
  75.             if ((bbb >= (3/7) && bbb < (2/3)) || (bbb >= (6/7))) { unskippables++; }
  76.         }
  77.         return unskippables;
  78.     }
  79.    
  80.     function findOutcome(at) {
  81.         let toReturn = [];
  82.         //success, no change
  83.         Math.seedrandom(Game.seed + '/' + at);
  84.         Math.random(); Math.random(); Math.random();
  85.         let choices = [];
  86.         choices.push('frenzy','multiply cookies');
  87.         if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy');
  88.         if (Math.random()<0.1) choices.push('cookie storm','cookie storm','blab');
  89.         if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special');
  90.         if (Math.random()<0.15) choices=['cookie storm drop'];
  91.         if (Math.random()<0.0001) choices.push('free sugar lump');
  92.         toReturn.push(choose(choices));
  93.        
  94.         //success, has season
  95.         Math.seedrandom(Game.seed + '/' + at);
  96.         Math.random(); Math.random(); Math.random(); Math.random();
  97.         choices = [];
  98.         choices.push('frenzy','multiply cookies');
  99.         if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy');
  100.         if (Math.random()<0.1) choices.push('cookie storm','cookie storm','blab');
  101.         if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special');
  102.         if (Math.random()<0.15) choices=['cookie storm drop'];
  103.         if (Math.random()<0.0001) choices.push('free sugar lump');
  104.         toReturn.push(choose(choices));
  105.            
  106.         //backfire
  107.         Math.seedrandom(Game.seed + '/' + at);
  108.         Math.random(); Math.random(); Math.random();
  109.         choices = [];
  110.         choices.push('clot','ruin cookies');
  111.         if (Math.random()<0.1) choices.push('cursed finger','blood frenzy');
  112.         if (Math.random()<0.003) choices.push('free sugar lump');
  113.         if (Math.random()<0.1) choices=['blab'];
  114.         toReturn.push(choose(choices));
  115.        
  116.         //backfire, has season
  117.         Math.seedrandom(Game.seed + '/' + at);
  118.         Math.random(); Math.random(); Math.random(); Math.random();
  119.         choices = [];
  120.         choices.push('clot','ruin cookies');
  121.         if (Math.random()<0.1) choices.push('cursed finger','blood frenzy');
  122.         if (Math.random()<0.003) choices.push('free sugar lump');
  123.         if (Math.random()<0.1) choices=['blab'];
  124.         toReturn.push(choose(choices));
  125.         return toReturn;
  126.     }    
  127.      
  128.     function findBackfire(at) {
  129.         Math.seedrandom(Game.seed + '/' + at);
  130.         return Math.random();
  131.     }
  132.    
  133.     // toFixed without trailing digits
  134.     function tfwotd(input, digit) {
  135.         //let ad = Math.floor(input).toString().length;
  136.         input = Number(input).toFixed(digit);
  137.        
  138.         //console.log(input);
  139.         //if (input.length>(digit+ad+1)) { console.log('detected'); input = input.slice(0, digit+ad+2); }
  140.         return input;
  141.     }
  142.    
  143.     Game.WriteCycleButton=function(prefName,button,minimum,maximum,name,callback)
  144.             {
  145.                 if (!callback) callback='';
  146.                 callback+='PlaySound(\'snd/tick.mp3\');';
  147.                 callback+='Game.UpdateMenu();'
  148.                 return '<a class="smallFancyButton prefButton option'+'" id="'+button+'" '+Game.clickStr+'="Game.prefs[\''+prefName+'\']++;if(Game.prefs[\''+prefName+'\']>'+maximum+'){Game.prefs[\''+prefName+'\']='+minimum+';}'+callback+'">'+name+Game.prefs[prefName]+'</a>';
  149.             }
  150.    
  151.     eval('Game.UpdateMenu='+Game.UpdateMenu.toString().replace(`game will reload")+')</label><br>'+`,`game will reload")+')</label><br>'+
  152.     Game.WritePrefButton('backfireLimEnabled','backfirelimButton',loc("Backfire detection ")+ON,loc("Backfire detection ")+OFF)+'<label>('+loc("skips unviable sweets that requires too much backfire chance.")+')</label><br>'+
  153.     Game.WriteCycleButton('upperGC','uppergcButton',0,7,loc("Maximum onscreens "))+'<label>('+loc("sets the maximum amount of backfire chance in terms of GCs onscreen.")+')</label><br>'+
  154.     Game.WritePrefButton('spellDisplayMode','spellDisplayButton',loc("Notify as unskippable spells ")+ON,loc("Notify as unskippable spells ")+OFF)+'<label>('+loc("when finding sweets, instead notify as the amount of unskippable spells according to GFD skip skip.")+')</label><br>'+
  155.     Game.WritePrefButton('saveOnSuccess','saveOSButton',loc("Save on success ")+ON,loc("Save on success ")+OFF)+'<label>('+loc("automatically save the game upon finding a successful sweet. BANNABLE IN FINNLESS AND GENERAL LEADERBOARDS")+')</label><br>'+`));
  156.    
  157.     eval('Game.UpdateMenu='+Game.UpdateMenu.toString().replace(`created by mods")+')</label></div>':'')+`,`created by mods")+')</label></div>':'')+
  158.     '<div class="listing"><a class="option smallFancyButton"'+Game.clickStr+'="getPromptOne();">'+loc("Set find depth")+'</a><label>('+loc("set the maximum amount of casts to search.")+')</label></div>'+`));
  159.    
  160.     Game.registerHook('reincarnate',findFirstSweet);
  161. }
  162.  
  163. Game.registerMod('sweetFinder',{
  164.     init:function() {
  165.         if (l('topbarFrenzy')) { return; }
  166.         Game.Notify('Sweet finder '+sweetFinderVer+' initialized!', 'Will attempt to find the nearest Sweet in Grimoire upon reincarnation or upon hitting F.<br>Check options for customization!', [29,16]);
  167.         sweetFinderInitFunction();
  168.     },
  169.     save:function() {
  170.         let str = "";
  171.         str+=Game.prefs.upperBound+'/';
  172.         str+=Game.prefs.upperGC+Game.prefs.backfireLimEnabled+Game.prefs.spellDisplayMode+Game.prefs.saveOnSuccess;
  173.         return str;
  174.     },
  175.     load:function(str) {
  176.         console.log(str);
  177.         if (str == '') { return false; }
  178.         Game.prefs.upperBound = parseInt(str.slice(0,str.indexOf('/')))
  179.         str = str.split('/')[1];
  180.         if (typeof str[0] !== 'undefined') { Game.prefs.upperGC=parseInt(str[0]); }
  181.         if (typeof str[1] !== 'undefined') { Game.prefs.backfireLimEnabled=parseInt(str[1]); }
  182.         if (typeof str[2] !== 'undefined') { Game.prefs.spellDisplayMode=parseInt(str[2]); }
  183.         if (typeof str[3] !== 'undefined') { Game.prefs.saveOnSuccess=parseInt(str[3]); }
  184.     }
  185. });
Advertisement
Add Comment
Please, Sign In to add comment