CursedSliver

Sweet finder (simple)

Jan 21st, 2024 (edited)
9,568
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. //version 1.21: Updated for game version v2.058
  11.  
  12. //I love stealing code from cccem
  13. function getPromptOne() {
  14.     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")]);
  15.     l('textareaPrompt').focus();
  16. }
  17.  
  18. var oneChangeHint = ((Game.version >= 2.057)?'Use any non-Christmas season.':'Use Easter or Valentine\'s.');
  19. var noChangeHint = ((Game.version >= 2.057)?'Use no season or Christmas.':'Use any season other than Easter or Valentine\'s.');
  20.  
  21. var sweetFinderVer = "v1.21";
  22. const sweetFinderInitFunction = function() {
  23.     Game.prefs.upperBound = 10000;
  24.     Game.prefs.upperGC = 2;
  25.     Game.prefs.backfireLimEnabled = 0;
  26.     Game.prefs.spellDisplayMode = 0;
  27.     Game.prefs.saveOnSuccess = 0;
  28.     function findFirstSweet() {
  29.         let castCount = (Game.Objects['Wizard tower'].minigame?Game.Objects["Wizard tower"].minigame.spellsCastTotal:0);
  30.         let castA = [];
  31.         for (let i = castCount; i < castCount+Game.prefs.upperBound; i++) {
  32.             castA = findOutcome(i);
  33.             for (let j in castA) { if (castA[j] == 'free sugar lump') {castA[j] = true;} else {castA[j] = false;}}
  34.             castA.push(1-findBackfire(i));
  35.             if (!(castA[0] || castA[1] || castA[2] || castA[3] )) { continue; }
  36.             if (castA[2] || castA[3]) {
  37.                 if (castA[4] < (0.15*1.11+Game.prefs.upperGC*0.15) || !Game.prefs.backfireLimEnabled) {
  38.                     let str = '';
  39.                     if (castA[3]) { str = '.<br>'+oneChangeHint; }
  40.                     if (castA[2]) { str = '.<br>'+noChangeHint; }
  41.                     if (Game.prefs.saveOnSuccess) { Game.WriteSave(); }
  42.                     if (Game.prefs.spellDisplayMode) {
  43.                         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;
  44.                     } else {
  45.                         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;
  46.                     }
  47.                 }
  48.             }
  49.             if (castA[0] || castA[1]) {
  50.                 if (castA[4] < 0.03) {
  51.                     let str = '';
  52.                     if (castA[1]) { str = '.<br>'+oneChangeHint; }
  53.                     if (castA[0]) { str = '.<br>'+noChangeHint; }
  54.                     if (Game.prefs.saveOnSuccess) { Game.WriteSave(); }
  55.                     if (Game.prefs.spellDisplayMode) {
  56.                         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;
  57.                     } else {
  58.                         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;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.         Game.Notify('No sweets found.','',0,1); return false;
  64.     }
  65.     AddEvent(document, 'keydown', function(e) { if (e.key.toLowerCase() == 'f') { findFirstSweet(); } });
  66.    
  67.     function compileUnskippableCasts(start, end) {
  68.         let unskippables = 0;
  69.         for (let i = start; i < end; i++) {
  70.             let bb = findBackfire(i);
  71.             if (bb < 0.875) { continue; }
  72.            
  73.             if (i > start && findBackfire(i - 1) >= (3/7) && findBackfire(i - 1) < (1/2)) {
  74.                 unskippables++;
  75.                 continue;
  76.             }
  77.            
  78.             let bbb = findBackfire(i + 1);
  79.             if ((bbb >= (3/7) && bbb < (2/3)) || (bbb >= (6/7))) { unskippables++; }
  80.         }
  81.         return unskippables;
  82.     }
  83.    
  84.     function findOutcome(at) {
  85.         let toReturn = [];
  86.         //success, no change
  87.         Math.seedrandom(Game.seed + '/' + at);
  88.         Math.random(); Math.random(); Math.random();
  89.         let choices = [];
  90.         choices.push('frenzy','multiply cookies');
  91.         if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy');
  92.         if (Math.random()<0.1) choices.push('cookie storm','cookie storm','blab');
  93.         if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special');
  94.         if (Math.random()<0.15) choices=['cookie storm drop'];
  95.         if (Math.random()<0.0001) choices.push('free sugar lump');
  96.         toReturn.push(choose(choices));
  97.        
  98.         //success, has season
  99.         Math.seedrandom(Game.seed + '/' + at);
  100.         Math.random(); Math.random(); Math.random(); Math.random();
  101.         choices = [];
  102.         choices.push('frenzy','multiply cookies');
  103.         if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy');
  104.         if (Math.random()<0.1) choices.push('cookie storm','cookie storm','blab');
  105.         if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special');
  106.         if (Math.random()<0.15) choices=['cookie storm drop'];
  107.         if (Math.random()<0.0001) choices.push('free sugar lump');
  108.         toReturn.push(choose(choices));
  109.            
  110.         //backfire
  111.         Math.seedrandom(Game.seed + '/' + at);
  112.         Math.random(); Math.random(); Math.random();
  113.         choices = [];
  114.         choices.push('clot','ruin cookies');
  115.         if (Math.random()<0.1) choices.push('cursed finger','blood frenzy');
  116.         if (Math.random()<0.003) choices.push('free sugar lump');
  117.         if (Math.random()<0.1) choices=['blab'];
  118.         toReturn.push(choose(choices));
  119.        
  120.         //backfire, has season
  121.         Math.seedrandom(Game.seed + '/' + at);
  122.         Math.random(); Math.random(); Math.random(); Math.random();
  123.         choices = [];
  124.         choices.push('clot','ruin cookies');
  125.         if (Math.random()<0.1) choices.push('cursed finger','blood frenzy');
  126.         if (Math.random()<0.003) choices.push('free sugar lump');
  127.         if (Math.random()<0.1) choices=['blab'];
  128.         toReturn.push(choose(choices));
  129.         return toReturn;
  130.     }    
  131.      
  132.     function findBackfire(at) {
  133.         Math.seedrandom(Game.seed + '/' + at);
  134.         return Math.random();
  135.     }
  136.    
  137.     // toFixed without trailing digits
  138.     function tfwotd(input, digit) {
  139.         //let ad = Math.floor(input).toString().length;
  140.         input = Number(input).toFixed(digit);
  141.        
  142.         //console.log(input);
  143.         //if (input.length>(digit+ad+1)) { console.log('detected'); input = input.slice(0, digit+ad+2); }
  144.         return input;
  145.     }
  146.    
  147.     Game.WriteCycleButton=function(prefName,button,minimum,maximum,name,callback)
  148.             {
  149.                 if (!callback) callback='';
  150.                 callback+='PlaySound(\'snd/tick.mp3\');';
  151.                 callback+='Game.UpdateMenu();'
  152.                 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>';
  153.             }
  154.    
  155.     eval('Game.UpdateMenu='+Game.UpdateMenu.toString().replace(`game will reload")+')</label><br>'+`,`game will reload")+')</label><br>'+
  156.     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>'+
  157.     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>'+
  158.     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>'+
  159.     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>'+`));
  160.    
  161.     eval('Game.UpdateMenu='+Game.UpdateMenu.toString().replace(`created by mods")+')</label></div>':'')+`,`created by mods")+')</label></div>':'')+
  162.     '<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>'+`));
  163.    
  164.     Game.registerHook('reincarnate',findFirstSweet);
  165. }
  166.  
  167. Game.registerMod('sweetFinder',{
  168.     init:function() {
  169.         if (l('topbarFrenzy')) { return; }
  170.         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]);
  171.         sweetFinderInitFunction();
  172.     },
  173.     save:function() {
  174.         let str = "";
  175.         str+=Game.prefs.upperBound+'/';
  176.         str+=Game.prefs.upperGC+Game.prefs.backfireLimEnabled+Game.prefs.spellDisplayMode+Game.prefs.saveOnSuccess;
  177.         return str;
  178.     },
  179.     load:function(str) {
  180.         console.log(str);
  181.         if (str == '') { return false; }
  182.         Game.prefs.upperBound = parseInt(str.slice(0,str.indexOf('/')))
  183.         str = str.split('/')[1];
  184.         if (typeof str[0] !== 'undefined') { Game.prefs.upperGC=parseInt(str[0]); }
  185.         if (typeof str[1] !== 'undefined') { Game.prefs.backfireLimEnabled=parseInt(str[1]); }
  186.         if (typeof str[2] !== 'undefined') { Game.prefs.spellDisplayMode=parseInt(str[2]); }
  187.         if (typeof str[3] !== 'undefined') { Game.prefs.saveOnSuccess=parseInt(str[3]); }
  188.     }
  189. });
Advertisement
Add Comment
Please, Sign In to add comment