rebelderp127

casino minigame with my own icons

Apr 6th, 2020 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(Game.Objects['Chancemaker'].minigame) throw new Error("Casino prevented from loading by already present Chancemaker minigame.");
  2.  
  3. Game.Win('Third-party');
  4. if(typeof CCSE == 'undefined') Game.LoadMod('https://klattmose.github.io/CookieClicker/' + (0 ? 'Beta/' : '') + 'CCSE.js');
  5. var M = {};
  6. M.parent = Game.Objects['Chancemaker'];
  7. M.parent.minigame = M;
  8. M.loadedCount = 0;
  9. M.version = '3.12';
  10. M.GameVersion = '2.022';
  11.  
  12. M.launch = function(){
  13.     var M = this;
  14.    
  15.     M.init = function(div){
  16.         // It's possible that the save data might get lost if entrusted to the game's save
  17.         if(localStorage.getItem(M.savePrefix) != null && !CCSE.save.OtherMods[M.name]) CCSE.save.OtherMods[M.name] = localStorage.getItem(M.savePrefix); // Import old version that doesn't use CCSE if necessary
  18.         if(!M.parent.minigameSave && CCSE.save.OtherMods[M.name]) M.parent.minigameSave = CCSE.save.OtherMods[M.name];
  19.         M.saveString = M.parent.minigameSave;
  20.        
  21.        
  22.         //***********************************
  23.         //    Initial support for multiple games
  24.         //***********************************
  25.         M.games = {
  26.             choice: 0,
  27.             Blackjack: {}
  28.         }
  29.        
  30.         M.cards = [];
  31.         M.cards.push({pip: 0, value:0, suit: 0});
  32.         for(var j = 0; j < 4; j++) for(var i = 1; i <= 13; i++) M.cards.push({pip: i, value: (i < 10 ? i : 10), suit: j});
  33.        
  34.         M.reshuffle = function(){
  35.             M.Deck = [];
  36.             for(var i = 0; i < M.deckCount; i++) for(var j = 1; j < M.cards.length; j++) M.Deck.push(M.cards[j]);
  37.         }
  38.        
  39.         M.cardImage = function(card){
  40.             var left, top;
  41.             if(!card.pip){
  42.                 left = 2 * 79;
  43.                 top = 4 * 123;
  44.             } else {
  45.                 left = (card.pip - 1) * 79;
  46.                 top = (card.suit) * 123;
  47.             }
  48.             var str = '';
  49.             str += '-' + left + 'px ';
  50.             str += '-' + top + 'px ';
  51.             return str;
  52.         }
  53.        
  54.         M.buildSidebar = function(){
  55.             if(M.games.choice == 0) M.games.Blackjack.buildSidebar();
  56.         }
  57.        
  58.         M.buildTable = function(){
  59.             if(M.games.choice == 0) M.games.Blackjack.buildTable();
  60.         }
  61.        
  62.         M.formatPercentage = function(value) {
  63.             if(!M.percentagePrecision) {
  64.                 return value * 100 + '%';
  65.             } else {
  66.                 var sign = (value < 0 ? '-' : '');
  67.                 value = Math.abs(value);
  68.                 if(value < M.minPercentage) {
  69.                     if(sign) {
  70.                         return '-' + M.minPercentageStr + 'to 0%';
  71.                     } else {
  72.                         return '<' + M.minPercentageStr;
  73.                     }
  74.                 } else {
  75.                     // Decided on floor instead of round, it is more similar to the expectations
  76.                     value = Math.round(value * 100 * M.percentagePow10);
  77.                     var low = value % M.percentagePow10;
  78.                     var low_digits = M.percentagePrecision;
  79.                     while(low > 0 && low % 10 === 0) {
  80.                         low /= 10;
  81.                         low_digits -= 1;
  82.                     }
  83.                     if(low) {
  84.                         low = '' + low;
  85.                         while(low.length < low_digits) {
  86.                             low = '0' + low;
  87.                         }
  88.                         low = '.' + low;
  89.                     } else {
  90.                         low = '';
  91.                     }
  92.                     var high = Math.floor(value / M.percentagePow10);
  93.                     return sign + high + low + '%';
  94.                 }
  95.             }
  96.         }
  97.        
  98.         M.setPercentagePrecision = function(precision) {
  99.             if(precision < 0) {
  100.                 throw "In setPercentagePrecision: precision must be >= 0, got " + precision;
  101.             } else {
  102.                 M.percentagePrecision = precision;
  103.                 if(!precision) {
  104.                     M.minPercentage = null;
  105.                     M.minPercentageStr = null;
  106.                     M.percentagePow10 = null;
  107.                } else {
  108.                     M.minPercentage = Math.pow(10, -precision - 2);
  109.                     M.minPercentageStr = '' + Math.pow(10, -precision) + '%';
  110.                     M.percentagePow10 = Math.pow(10, precision);
  111.                }      
  112.             }
  113.         }
  114.        
  115.        
  116.         //***********************************
  117.         //    Blackjack
  118.         //***********************************
  119.         M.games.Blackjack = {
  120.             wins : 0,
  121.             winsT : 0,
  122.             tiesLost : 0,
  123.             ownLuckWins : 0,
  124.             netTotal : 0,
  125.            
  126.             phases : {
  127.                 inactive: 0,
  128.                 deal: 1,
  129.                 firstTurn: 2,
  130.                 playerTurn: 3,
  131.                 dealerTurn: 4,
  132.                 evaluate: 5
  133.             },
  134.            
  135.             getHandValue : function(hand){
  136.                 hand.value = 0;
  137.                 for(var i = 0; i < hand.cards.length; i++) hand.value += hand.cards[i].value;
  138.                 for(var i = 0; i < hand.cards.length; i++) if(hand.value <= 11 && hand.cards[i].value == 1) hand.value += 10;
  139.             },
  140.            
  141.             drawCard : function(deck){
  142.                 var i = Math.floor(Math.random() * deck.length);
  143.                 var res = deck[i];
  144.                 deck.splice(i, 1);
  145.                
  146.                 if(M.Deck.length < (M.minDecks * 52)){
  147.                     Game.Unlock('Counting cards');
  148.                     M.reshuffle();
  149.                     Game.Popup('Decks reshuffled!', Game.mouseX, Game.mouseY);
  150.                 }
  151.                 return res;
  152.             },
  153.            
  154.             hit : function(hand, player){
  155.                 this.getHandValue(hand);
  156.                 var oldValue = hand.value;
  157.                 hand.cards.push(this.drawCard(M.Deck));
  158.                 this.getHandValue(hand);
  159.                
  160.                 if(hand.value > 21){
  161.                     if(player){
  162.                         Game.Unlock('Math lessons');
  163.                         this.stand();
  164.                     }
  165.                 }else if(player && oldValue >= 17 && hand.value > oldValue){
  166.                     Game.Win('I like to live dangerously');
  167.                 }
  168.                
  169.                 this.buildTable();
  170.             },
  171.            
  172.             doubledown : function(){
  173.                 Game.Spend(M.betAmount);
  174.                 M.betAmount *= 2;
  175.                 this.hit(M.hands.player[0], true);
  176.                 this.stand();
  177.             },
  178.            
  179.             split : function(){
  180.                 Game.Spend(M.betAmount);
  181.                
  182.                 M.hands.player.push({value:0, cards:[]});
  183.                 M.hands.player[1].cards.push(M.hands.player[0].cards[1]);
  184.                 M.hands.player[0].cards.splice(1, 1);
  185.                
  186.                 this.hit(M.hands.player[0], true);
  187.                 this.hit(M.hands.player[1], true);
  188.                
  189.                 this.buildSidebar();
  190.                 this.buildTable();
  191.             },
  192.            
  193.             stand : function(){
  194.                 if(M.currentPlayerHand >= (M.hands.player.length - 1)){
  195.                     var allBust = true;
  196.                     for(var i = 0; i < M.hands.player.length; i++) if(M.hands.player[i].value <= 21) allBust = false;
  197.                    
  198.                     if(allBust){
  199.                         M.nextBeat = Date.now() + M.beatLength;
  200.                         this.phase = this.phases.evaluate;
  201.                     }else{
  202.                         M.hands.dealer.cards[1] = this.hiddenCard;
  203.                         this.getHandValue(M.hands.dealer);
  204.                         this.phase = this.phases.dealerTurn;
  205.                         if(M.hands.dealer.value >= 17){
  206.                             M.currentPlayerHand = 0;
  207.                             this.phase = this.phases.evaluate;
  208.                         }
  209.                         M.nextBeat = Date.now() + M.beatLength;
  210.                     }
  211.                    
  212.                 }else{
  213.                     M.currentPlayerHand++;
  214.                 }
  215.                
  216.                 this.buildSidebar()
  217.                 this.buildTable();
  218.             },
  219.            
  220.             instantWinChance : function(){ return (Game.Has('I make my own luck') ? (1 - Math.pow(1 - M.chancemakerChance * (Game.Has('Infinite Improbability Drive') ? 2 : 1), M.parent.amount)) : 0); },
  221.            
  222.             toggleBetMode : function(){
  223.                 if(M.betMode == 1 && Game.Has('Raise the stakes')) M.betMode = 2;
  224.                 else if(M.betMode < 3 && Game.Has('High roller!')) M.betMode = 3;
  225.                 else M.betMode = 1;
  226.                
  227.                 this.buildSidebar();
  228.             },
  229.            
  230.             toggleBetChoice : function(){
  231.                 if(M.betChoice == 1 && Game.Has('Double or nothing')) M.betChoice = 2;
  232.                 else if(M.betChoice < 5 && Game.Has('Stoned cows')) M.betChoice = 5;
  233.                 else M.betChoice = 1;
  234.                
  235.                 this.buildSidebar();
  236.             },
  237.            
  238.             dealProbabilities : function(){
  239.                 var res = '<div style="padding:8px 4px; min-width:125px;">';
  240.                 var iwc = M.games.Blackjack.instantWinChance();
  241.                 var chances = [];
  242.                 var cards = [];
  243.                 var possibles = M.Deck.length * (M.Deck.length - 1) / 2;
  244.                
  245.                 for(var i = 4; i <= 21; i++) chances[i] = 0;
  246.                 for(var i = 1; i <= 10; i++) cards[i] = 0;
  247.                
  248.                 for(var i = 0; i < M.Deck.length; i++){
  249.                     var card = M.Deck[i];
  250.                     cards[card.value]++;
  251.                 }
  252.                
  253.                 for(var i = 1; i <= 10; i++)
  254.                 for(var j = 1; j <= 10; j++){
  255.                     var val = j + i;
  256.                     if(i == 1 || j == 1) val += 10;
  257.                     chances[val] += cards[i] * (cards[j] + (i == j ? -1 : 0)) / possibles / 2;
  258.                 }
  259.                
  260.                 chances[21] = 1 - (1 - chances[21]) * (1 - iwc);
  261.                 for(var i = 4; i <= 20; i++) chances[i] *= 1 - iwc;
  262.                
  263.                 if(chances[21] != 0) res += '<b>Blackjack : </b>' + M.formatPercentage(chances[21]) + '<br/>';
  264.                 for(var i = 20; i >= 4; i--) if(chances[i] != 0) res += '<b>' + i + ' : </b>' + M.formatPercentage(chances[i]) + '<br/>';
  265.                
  266.                 return res + '</div>';
  267.             },
  268.            
  269.             drawProbabilities : function(){
  270.                 var res = '<div style="padding:8px 4px; min-width:125px;">';
  271.                 var cards = [];
  272.                 var outcomes = [];
  273.                 outcomes[22] = 0;
  274.                
  275.                 for(var i = 1; i <= 10; i++) cards[i] = 0;
  276.                 for(var i = 0; i < M.Deck.length; i++){
  277.                     var card = M.Deck[i];
  278.                     cards[card.value]++;
  279.                 }
  280.                 cards[M.games.Blackjack.hiddenCard.value]++;
  281.                
  282.                 for(var i = 1; i <= 10; i++){
  283.                     var prob = cards[i] / (M.Deck.length + 1);
  284.                     var value = 0;
  285.                     var hand = M.hands.player[M.currentPlayerHand];
  286.                    
  287.                     for(var j = 0; j < hand.cards.length; j++) value += hand.cards[j].value;
  288.                     value += i;
  289.                     if(value <= 11 && i == 1) value += 10;
  290.                     for(var j = 0; j < hand.cards.length; j++) if(value <= 11 && hand.cards[j].value == 1) value += 10;
  291.                    
  292.                     if(value > 21) outcomes[22] += prob;
  293.                     else outcomes[value] = prob;
  294.                 }
  295.                
  296.                 if(outcomes[22]) res += '<b>Bust : </b>' + M.formatPercentage(outcomes[22]) + '<br/>';
  297.                 for(var i = 21; i > 5; i--) if(outcomes[i]) res += '<b>' + i + ' : </b>' + M.formatPercentage(outcomes[i]) + '<br/>';
  298.                
  299.                 return res + '</div>';
  300.             },
  301.            
  302.             standProbabilities : function(){
  303.                 var res = '<div style="padding:8px 4px; min-width:125px;">';
  304.                 var cards = [];
  305.                 var outcomes = [];
  306.                 var simHand = [];
  307.                 var winChance = 0;
  308.                 var lossChance = 0;
  309.                
  310.                 for(var i = 0; i < M.hands.dealer.cards.length; i++) if(M.hands.dealer.cards[i].value) simHand.push(M.hands.dealer.cards[i].value);
  311.                 for(var i = 17; i <= 22; i++) outcomes[i] = 0;
  312.                
  313.                 for(var i = 1; i <= 10; i++) cards[i] = 0;
  314.                 for(var i = 0; i < M.Deck.length; i++){
  315.                     var card = M.Deck[i];
  316.                     cards[card.value]++;
  317.                 }
  318.                 cards[M.games.Blackjack.hiddenCard.value]++;
  319.                
  320.                 M.games.Blackjack.recursiveDealerSim(cards, outcomes, simHand, M.Deck.length + 1, 1);
  321.                
  322.                 winChance += outcomes[22];
  323.                 for(var i = 21; i >= 17; i--) if(i >= M.hands.player[M.currentPlayerHand].value + (Game.Has('Tiebreaker') ? 1 : 0)) lossChance += outcomes[i]; else winChance += outcomes[i];
  324.                 if(winChance) res += '<b>Win : </b><span class="green">' + M.formatPercentage(winChance) + '</span><br/>'
  325.                 if(lossChance) res += '<b>Lose : </b><span class="red">' + M.formatPercentage(lossChance) + '</span><br/>'
  326.                
  327.                 if(outcomes[22]) res += '<br/><b>Dealer chances</b><br/><br/><b>Bust : </b>' + M.formatPercentage(outcomes[22]) + '<br/>';
  328.                 for(var i = 21; i >= 17; i--) if(outcomes[i]) res += '<b>' + i + ' : </b>' + M.formatPercentage(outcomes[i]) + '<br/>';
  329.                
  330.                 return res + '</div>';
  331.             },
  332.            
  333.             recursiveDealerSim : function(cards, outcomes, simHand, deckLength, stateChance){
  334.                 for(var i = 1; i <= 10; i++){
  335.                     if(cards[i]){
  336.                         simHand.push(i);
  337.                        
  338.                         var value = 0;
  339.                         var chance = stateChance * cards[i] / deckLength;
  340.                         for(var j = 0; j < simHand.length; j++) value += simHand[j];
  341.                         for(var j = 0; j < simHand.length; j++) if(value <= 11 && simHand[j] == 1) value += 10;
  342.                        
  343.                         if(value > 21) value = 22;
  344.                         if(value >= 17){
  345.                             outcomes[value] += chance;
  346.                         }
  347.                         else{
  348.                             cards[i]--;
  349.                             M.games.Blackjack.recursiveDealerSim(cards, outcomes, simHand, deckLength - 1, chance);
  350.                             cards[i]++;
  351.                         }
  352.                        
  353.                         simHand.splice(simHand.length - 1);
  354.                     }
  355.                 }
  356.             },
  357.            
  358.             buildSidebar : function(){
  359.                 var mode = '';
  360.                
  361.                 if(M.betMode == 1){
  362.                     mode = 'second';
  363.                 }else if(M.betMode == 2){
  364.                     mode = 'minute';
  365.                 }else if(M.betMode == 3){
  366.                     mode = 'hour';
  367.                 }
  368.                 var str = '';
  369.                
  370.                 if(Game.Has('Double or nothing') || Game.Has('Stoned cows')) str += '<div>Bet: <a class="option" id="casinoBetChoiceToggle" >' + Beautify(M.betChoice) + '</a> ';
  371.                 else str += '<div>Bet: ' + Beautify(M.betChoice) + ' ';
  372.                
  373.                 if(Game.Has('Raise the stakes') || Game.Has('High roller!')) str += '<a class="option" id="casinoBetModeToggle" >' + mode + (M.betChoice == 1 ? '' : 's') + '</a> of CPS</div>';
  374.                 else str += mode + (M.betChoice == 1 ? '' : 's') + ' of CPS</div>';
  375.                
  376.                 str += '<div id="casinoCurrentBet">(' + Beautify(M.betAmount) + ' cookies)</div>';
  377.                 M.moneyL.innerHTML = str;
  378.                
  379.                
  380.                 var str = '<table class="casinoActionsTable">';
  381.                 if(this.phase == this.phases.inactive) str += '<tr><td><div class="listing"><a class="option" id="casinoDeal" >Deal</a></div></td></tr>';
  382.                 else str += '<tr><td><div class="listing">Deal</div></td></tr>';
  383.                 if(this.phase == this.phases.firstTurn || this.phase == this.phases.playerTurn) str += '<tr><td><div class="listing"><a class="option" id="casinoHit" >Hit</a></div></td></tr>';
  384.                 else str += '<tr><td><div class="listing">Hit</div></td></tr>';
  385.                 if(this.phase == this.phases.firstTurn && Game.cookies >= M.betAmount) str += '<tr><td><div class="listing"><a class="option" id="casinoDoubledown" >Double Down</a></div></td></tr>';
  386.                 else str += '<tr><td><div class="listing">Double Down</div></td></tr>';
  387.                 if(this.phase == this.phases.firstTurn && Game.cookies >= M.betAmount && M.hands.player[0].cards[0].pip == M.hands.player[0].cards[1].pip) str += '<tr><td><div class="listing"><a class="option" id="casinoSplit" >Split</a></div></td></tr>';
  388.                 else str += '<tr><td><div class="listing">Split</div></td></tr>';
  389.                 if(this.phase == this.phases.firstTurn || this.phase == this.phases.playerTurn) str += '<tr><td><div class="listing"><a class="option" id="casinoStand" >Stand</a></div></td></tr>';
  390.                 else str += '<tr><td><div class="listing">Stand</div></td></tr>';
  391.                 str += '</table>';
  392.                 M.actionsL.innerHTML = str;
  393.                
  394.                
  395.                
  396.                 if(l('casinoBetChoiceToggle')) AddEvent(l('casinoBetChoiceToggle'), 'click', function(){return function(){
  397.                     PlaySound('snd/tick.mp3');
  398.                     M.games.Blackjack.toggleBetChoice();
  399.                 }}());
  400.                 if(l('casinoBetModeToggle')) AddEvent(l('casinoBetModeToggle'), 'click', function(){return function(){
  401.                     PlaySound('snd/tick.mp3');
  402.                     M.games.Blackjack.toggleBetMode();
  403.                 }}());
  404.                 if(l('casinoDeal')) AddEvent(l('casinoDeal'), 'click', function(){return function(){
  405.                     PlaySound('snd/tick.mp3');
  406.                     Game.tooltip.shouldHide = 1;
  407.                     M.games.Blackjack.istep = 0;
  408.                     M.games.Blackjack.phase = M.games.Blackjack.phases.deal;
  409.                     M.nextBeat = Date.now();
  410.                 }}());
  411.                 if(l('casinoHit')) AddEvent(l('casinoHit'), 'click', function(){return function(){
  412.                     PlaySound('snd/tick.mp3');
  413.                     Game.tooltip.shouldHide = 1;
  414.                     M.games.Blackjack.phase = M.games.Blackjack.phases.playerTurn;
  415.                     M.games.Blackjack.hit(M.hands.player[M.currentPlayerHand], true);
  416.                     M.games.Blackjack.buildSidebar();
  417.                 }}());
  418.                 if(l('casinoDoubledown')) AddEvent(l('casinoDoubledown'), 'click', function(){return function(){
  419.                     PlaySound('snd/tick.mp3');
  420.                     Game.tooltip.shouldHide = 1;
  421.                     M.games.Blackjack.phase = M.games.Blackjack.phases.playerTurn;
  422.                     M.games.Blackjack.doubledown();
  423.                 }}());
  424.                 if(l('casinoSplit')) AddEvent(l('casinoSplit'), 'click', function(){return function(){
  425.                     PlaySound('snd/tick.mp3');
  426.                     Game.tooltip.shouldHide = 1;
  427.                     M.games.Blackjack.phase = M.games.Blackjack.phases.playerTurn;
  428.                     M.games.Blackjack.split();
  429.                 }}());
  430.                 if(l('casinoStand')) AddEvent(l('casinoStand'), 'click', function(){return function(){
  431.                     PlaySound('snd/tick.mp3');
  432.                     Game.tooltip.shouldHide = 1;
  433.                     M.games.Blackjack.phase = M.games.Blackjack.phases.playerTurn;
  434.                     M.games.Blackjack.stand();
  435.                 }}());
  436.                
  437.                 if(Game.Has('Actually, do tell me the odds')){
  438.                     if(l('casinoDeal')) Game.attachTooltip(l('casinoDeal'), this.dealProbabilities, 'this');
  439.                     if(l('casinoHit')) Game.attachTooltip(l('casinoHit'), this.drawProbabilities, 'this');
  440.                     if(l('casinoDoubledown')) Game.attachTooltip(l('casinoDoubledown'), this.drawProbabilities, 'this');
  441.                     //if(l('casinoSplit')) Game.attachTooltip(l('casinoSplit'), this.drawProbabilities, 'this');
  442.                     if(l('casinoStand')) Game.attachTooltip(l('casinoStand'), this.standProbabilities, 'this');
  443.                 }
  444.             },
  445.            
  446.             buildTable : function(){
  447.                 this.getHandValue(M.hands.dealer);
  448.                 this.getHandValue(M.hands.player[M.currentPlayerHand]);
  449.                
  450.                 var str = '<table id="casinoBJTable">';
  451.                 str += '<tr><td>Dealer\'s hand:' + (Game.Has('Math lessons') ? ('<br/>Score: ' + M.hands.dealer.value) : '') + '</td>';
  452.                 for(var i = 0; i < M.hands.dealer.cards.length; i++) str += '<td><div class="casinoBJCardImage" style="background-image:url(' + M.cardsImage + '); background-position:' + M.cardImage(M.hands.dealer.cards[i]) + ';" /></td>';
  453.                 str += '</tr>';
  454.                 str += '<tr style="height:75px;"><td></td></tr>';
  455.                 str += '<tr><td>Player\'s hand' + (M.hands.player.length > 1 ? (' (' + (M.currentPlayerHand + 1) + ' of ' + M.hands.player.length + ')') : '') + ':' + (Game.Has('Math lessons') ? ('<br/>Score: ' + M.hands.player[M.currentPlayerHand].value) : '') + '</td>'
  456.                 for(var i = 0; i < M.hands.player[M.currentPlayerHand].cards.length; i++) str += '<td><div class="casinoBJCardImage" style="background-image:url(' + M.cardsImage + '); background-position:' + M.cardImage(M.hands.player[M.currentPlayerHand].cards[i]) + ';" /></td>';
  457.                 str += '</tr>';
  458.                 str += '</table>';
  459.                
  460.                 M.gameL.innerHTML = str;
  461.                
  462.                
  463.                 var cardCount = 0;
  464.                 for(var i = 0; i < M.Deck.length; i++){
  465.                     if(M.Deck[i].value >= 2 && M.Deck[i].value <= 6) cardCount--;
  466.                     else if(M.Deck[i].value == 1 || M.Deck[i].value >= 10) cardCount++;
  467.                 }
  468.                 if(this.hiddenCard && M.hands.dealer.cards[1] && M.hands.dealer.cards[1].value == 0){
  469.                     if(this.hiddenCard.value >= 2 && this.hiddenCard.value <= 6) cardCount--;
  470.                     else if(this.hiddenCard.value == 1 || this.hiddenCard.value >= 10) cardCount++;
  471.                 }
  472.                 M.infoL.innerHTML = 'Hands won : ' + Beautify(this.wins) + ' (total : ' + Beautify(this.winsT) + ')' + (Game.Has('Counting cards') ? ('<br/>Cards left in deck : ' + M.Deck.length + '<br/>Count : ' + cardCount) : '');
  473.                
  474.             },
  475.            
  476.             logic : function(){
  477.                 //run each frame
  478.                 if(M.betMode == 1 && this.phase == this.phases.inactive){
  479.                     M.betAmount = Math.min(Game.cookies, Game.cookiesPs * M.betChoice);
  480.                 }else if(M.betMode == 2 && this.phase == this.phases.inactive){
  481.                     M.betAmount = Math.min(Game.cookies, Game.cookiesPs * M.betChoice * 60);
  482.                 }else if(M.betMode == 3 && this.phase == this.phases.inactive){
  483.                     M.betAmount = Math.min(Game.cookies, Game.cookiesPs * M.betChoice * 60 * 60);
  484.                 }
  485.                
  486.                 if(Date.now() > M.nextBeat){
  487.                     M.nextBeat = Date.now() + M.beatLength;
  488.                     var outcome = 0;
  489.                    
  490.                     if(this.phase == this.phases.inactive){
  491.                        
  492.                     }
  493.                     else if(this.phase == this.phases.deal){
  494.                         if(this.istep == 0){
  495.                             if(M.Deck.length < (M.minDecks * 52)) M.reshuffle();
  496.                             M.hands = {dealer:{value:0, cards:[]}, player:[{value:0, cards:[]}]};
  497.                             M.currentPlayerHand = 0;
  498.                             Game.Spend(M.betAmount);
  499.                            
  500.                             this.hit(M.hands.player[0], true);
  501.                             this.istep = 1;
  502.                         }
  503.                         else if(this.istep == 1){
  504.                             this.hit(M.hands.dealer, false);
  505.                             this.istep = 2;
  506.                         }
  507.                         else if(this.istep == 2){
  508.                             this.hit(M.hands.player[0], true);
  509.                             this.istep = 3;
  510.                         }
  511.                         else if(this.istep == 3){
  512.                             this.hit(M.hands.dealer, false);
  513.                            
  514.                             this.hiddenCard = M.hands.dealer.cards[1];
  515.                             M.hands.dealer.cards[1] = M.cards[0];
  516.                            
  517.                             this.phase = this.phases.firstTurn;
  518.                             if(Math.random() < this.instantWinChance()){
  519.                                 M.hands.dealer.cards[1] = this.hiddenCard;
  520.                                
  521.                                 M.hands.player[0].cards[0] = {pip:choose([10,11,12,13]), value:10, suit:choose([0,1,2,3])};
  522.                                 M.hands.player[0].cards[1] = {pip:1, value:1, suit:choose([0,1,2,3])};
  523.                                
  524.                                 outcome = 'instantWin';
  525.                                 this.phase = this.phases.inactive;
  526.                                
  527.                             } else if(M.hands.player[0].value == 21){
  528.                                 M.hands.dealer.cards[1] = this.hiddenCard;
  529.                                 outcome = 'playerblackjack';
  530.                                 this.phase = this.phases.inactive;
  531.                                
  532.                             } else if(M.hands.dealer.value == 21){
  533.                                 M.hands.dealer.cards[1] = this.hiddenCard;
  534.                                 outcome = 'dealerblackjack';
  535.                                 this.phase = this.phases.inactive;
  536.                                
  537.                             } else{
  538.                                
  539.                             }
  540.                         }
  541.                        
  542.                         this.buildTable();
  543.                         this.buildSidebar();
  544.                     }
  545.                     else if(this.phase == this.phases.playerTurn || this.phase == this.phases.firstTurn){
  546.                        
  547.                     }
  548.                     else if(this.phase == this.phases.dealerTurn){
  549.                         if(M.hands.dealer.value < 17){
  550.                             this.hit(M.hands.dealer, false);
  551.                         }
  552.                         if(M.hands.dealer.value >= 17){
  553.                             M.currentPlayerHand = 0;
  554.                             this.phase = this.phases.evaluate;
  555.                         }
  556.                        
  557.                         this.buildTable();
  558.                         this.buildSidebar();
  559.                     }
  560.                     else if(this.phase == this.phases.evaluate){
  561.                         var playerHand = M.currentPlayerHand;
  562.                         M.hands.dealer.cards[1] = this.hiddenCard;
  563.                         this.buildTable();
  564.                        
  565.                         if(M.hands.player[playerHand].value > 21) outcome = 'bust';
  566.                         else if(M.hands.dealer.value > 21){
  567.                             outcome = 'dealerbust';
  568.                         }
  569.                         else if(M.hands.dealer.value < M.hands.player[playerHand].value){
  570.                             outcome = 'win';
  571.                         }
  572.                         else if(M.hands.dealer.value > M.hands.player[playerHand].value) outcome = 'lose';
  573.                         else if(M.hands.dealer.value == M.hands.player[playerHand].value){
  574.                             outcome = 'push';
  575.                         }
  576.                        
  577.                         playerHand++;
  578.                         if(playerHand < M.hands.player.length){
  579.                             M.currentPlayerHand = playerHand;
  580.                             this.phase = this.phases.evaluate;
  581.                         }
  582.                         else{
  583.                             this.phase = this.phases.inactive;
  584.                         }
  585.                        
  586.                         this.buildTable();
  587.                         this.buildSidebar();
  588.                     }
  589.                    
  590.                     this.getHandValue(M.hands.dealer);
  591.                     this.getHandValue(M.hands.player[M.currentPlayerHand]);
  592.                    
  593.                     if(outcome){
  594.                         var messg = '';
  595.                         var winnings = M.betAmount;
  596.                        
  597.                         switch(outcome){
  598.                             case 'instantWin':
  599.                                 winnings *= 2.5;
  600.                                 messg = 'You make your own luck!';
  601.                                 this.ownLuckWins++;
  602.                                
  603.                                 if(this.ownLuckWins >= 13) Game.Win('Ace up your sleeve');
  604.                                 if(Game.Has('I make my own luck') && this.ownLuckWins >= 52) Game.Unlock('Infinite Improbability Drive');
  605.                                 if(this.ownLuckWins >= (13 * 13)) Game.Win('Paid off the dealer');
  606.                                 if(this.ownLuckWins >= 666) Game.Win('Deal with the Devil');
  607.                                 break;
  608.                                
  609.                             case 'playerblackjack':
  610.                                 winnings *= 2.5;
  611.                                 messg = 'Blackjack!';
  612.                                 Game.Unlock('I make my own luck');
  613.                                 Game.Win('Blackjack!');
  614.                                 break;
  615.                                
  616.                             case 'dealerblackjack':
  617.                                 winnings *= 0;
  618.                                 messg = 'Dealer blackjack';
  619.                                 break;
  620.                            
  621.                             case 'bust':
  622.                                 winnings *= 0;
  623.                                 messg = 'Over 21!';
  624.                                 break;
  625.                            
  626.                             case 'dealerbust':
  627.                                 winnings *= 2;
  628.                                 messg = 'Dealer went over 21!';
  629.                                 break;
  630.                            
  631.                             case 'win':
  632.                                 winnings *= 2;
  633.                                 messg = 'You win!';
  634.                                 break;
  635.                            
  636.                             case 'lose':
  637.                                 winnings *= 0;
  638.                                 messg = 'You lose';
  639.                                 break;
  640.                                
  641.                             case 'push':
  642.                                 if(Game.Has('Tiebreaker')){
  643.                                     winnings *= 2;
  644.                                     messg = 'Tie goes to player!';
  645.                                 }else{
  646.                                     winnings *= 0;
  647.                                     messg = 'Tie goes to dealer';
  648.                                     this.tiesLost++;
  649.                                     if(this.tiesLost >= 7) Game.Unlock('Tiebreaker');
  650.                                 }
  651.                                
  652.                                 break;
  653.                                
  654.                             default:
  655.                                 break;
  656.                         }
  657.                        
  658.                         messg += '<div style="font-size:65%;">';
  659.                         if(winnings > 0){
  660.                             Game.Earn(winnings);
  661.                             this.wins++;
  662.                             this.winsT++;
  663.                             messg += 'Gain ' + Beautify(Math.abs(winnings - M.betAmount)) + ' cookies!';
  664.                             PlaySound('snd/levelPrestige.mp3');
  665.                            
  666.                             if(this.winsT >= 7) Game.Unlock('Raise the stakes');
  667.                             if(Game.Has('Raise the stakes') && this.winsT >= 49) Game.Unlock('High roller!');
  668.                             if(this.winsT >= 21) Game.Win('Card minnow');
  669.                             if(this.winsT >= 210) Game.Win('Card trout');
  670.                             if(this.winsT >= 2100) Game.Win('Card shark');
  671.                            
  672.                             if(M.hands.player[M.currentPlayerHand].cards.length >= 5) Game.Win('Five card stud');
  673.                             if(M.hands.player[M.currentPlayerHand].cards.length >= 6) Game.Win("Why can't I hold all these cards?");
  674.                             if(M.hands.player[M.currentPlayerHand].value <= 5) Game.Win('I also like to live dangerously');
  675.                         }else{
  676.                             messg += 'Lost ' + Beautify(Math.abs(M.betAmount)) + ' cookies';
  677.                         }
  678.                         messg += '</div>';
  679.                        
  680.                         this.netTotal += winnings - M.betAmount;
  681.                         Game.Popup(messg, Game.mouseX, Game.mouseY);
  682.                        
  683.                         this.buildTable();
  684.                         this.buildSidebar();
  685.                     }
  686.                 }
  687.             },
  688.            
  689.             draw : function(){
  690.                 //run each draw frame
  691.                 l('casinoCurrentBet').innerHTML = '(' + Beautify(M.betAmount) + ' cookies)';
  692.             }
  693.        
  694.         }
  695.        
  696.        
  697.        
  698.         var str = '';
  699.         str += '<style>' +
  700.         '#casinoBG{background:url(img/shadedBorders.png), url(' + M.sourceFolder + 'img/BGcasino.jpg); background-size:100% 100%, auto; position:absolute; left:0px; right:0px; top:0px; bottom:16px;}' +
  701.         '#casinoContent{position:relative; box-sizing:border-box; padding:4px 24px; height:450px;}' +
  702.         '#casinoSidebar{text-align:center; margin:0px; padding:0px; position:absolute; left:4px; top:4px; bottom:4px; right:65%; overflow-y:auto; overflow-x:hidden; box-shadow:8px 0px 8px rgba(0,0,0,0.5);}' +
  703.         '#casinoSidebar .listing{text-align:left;}' +
  704.         '#casinoTable{text-align:center; position:absolute; right:0px; top:0px; bottom:0px; overflow-x:auto; overflow:hidden;}' +
  705.         '.casinoBJCardImage{position: relative; width: 79px; height: 123px; left: 0px; top: 0px; overflow: visible;}' +
  706.         '.casinoSpacer{position: relative; width: 79px; height: 123px; left: 0px; top: 0px; overflow: visible;}' +
  707.         '#casinoBJTable td{text-align:center; vertical-align: middle; width:90px;}' +
  708.         '#casinoBJTable tr{height:150px}' +
  709.         '#casinoBJTable{margin-left:auto; margin-right:auto;}' +
  710.         '.casinoSidebarLabel{font-size:12px;width:100%;padding:2px;margin-top:4px;margin-bottom:-4px;}' +
  711.         '.casinoActionsTable tr{height: 40px;}' +
  712.         '#casinoGame{position: relative;}' +
  713.         '#casinoInfo{position: relative;text-align:center; font-size:11px; margin-top:12px; color:rgba(255,255,255,0.75); text-shadow:-1px 1px 0px #000;}' +
  714.         '</style>';
  715.         str += '<div id="casinoBG"></div>';
  716.         str += '<div id="casinoContent">';
  717.             str += '<div id="casinoSidebar" class="framed">';
  718.                 str+='<div class="title casinoSidebarLabel">Cash</div><div class="line"></div>';
  719.                 str += '<div id="casinoMoney"></div>';
  720.                 str+='<div class="title casinoSidebarLabel">Actions</div><div class="line"></div>';
  721.                 str += '<div id="casinoActions"></div>';
  722.             str += '</div>';
  723.             str += '<div id="casinoTable">';
  724.                 str += '<div id="casinoGame"></div>';
  725.                 str += '<div id="casinoInfo">Hello World!</div>';
  726.             str += '</div>';
  727.         str += '</div>';
  728.         div.innerHTML = str;
  729.        
  730.         M.sidebarL = l('casinoSidebar');
  731.         M.moneyL = l('casinoMoney');
  732.         M.actionsL = l('casinoActions');
  733.         M.tableL = l('casinoTable');
  734.         M.gameL = l('casinoGame');
  735.         M.infoL = l('casinoInfo');
  736.        
  737.         M.reset();
  738.        
  739.         M.buildSidebar();
  740.         M.buildTable();
  741.        
  742.         M.loadedCount++;
  743.         if (Game.prefs.popups) Game.Popup('Casino loaded!');
  744.         else Game.Notify('Casino loaded!', '', '', 1, 1);
  745.     }
  746.    
  747.     M.save = function(){
  748.         //output cannot use ",", ";" or "|"
  749.        
  750.         var getMinigameStateSave = function(){
  751.             var res = '';
  752.             res += parseInt(M.parent.onMinigame ? '1' : '0');
  753.             res += '_' + parseInt(M.games.Blackjack.wins);
  754.             res += '_' + parseInt(M.games.Blackjack.winsT);
  755.             res += '_' + parseInt(M.games.Blackjack.ownLuckWins);
  756.             res += '_' + parseInt(M.games.Blackjack.tiesLost);
  757.             res += '_' + parseInt(M.betMode);
  758.             res += '_' + parseInt(M.betChoice);
  759.             res += '_' + parseFloat(M.games.Blackjack.netTotal);
  760.             res += '_' + parseInt(0);
  761.             res += '_' + parseInt(M.beatLength);
  762.            
  763.             return res;
  764.         }
  765.        
  766.         var getGameStateSave = function(){
  767.             var res = '';
  768.             res += parseInt(M.currentPlayerHand);
  769.             res += '_' + parseInt(M.nextBeat);
  770.             res += '_' + parseInt(M.games.Blackjack.phase);
  771.             res += '_' + parseInt(M.games.Blackjack.istep);
  772.             res += '_' + parseFloat(M.betAmount);
  773.             res += '_' + parseInt(M.games.Blackjack.hiddenCard.pip + 13 * M.games.Blackjack.hiddenCard.suit);
  774.            
  775.             return res;
  776.         }
  777.        
  778.         var getCardSave = function(deck){
  779.             var res = '';
  780.             for(var i = 0; i < deck.length; i++) res += (res.length ? '-' : '') + (deck[i].pip + 13 * deck[i].suit);
  781.             return res;
  782.         }
  783.        
  784.         var getPlayerHandsSave = function(){
  785.             var res = '';
  786.             for(var i = 0; i < M.hands.player.length; i++) res += (res.length ? '_' : '') + getCardSave(M.hands.player[i].cards);
  787.             return res;
  788.         }
  789.        
  790.         var getAchievementSave = function(){
  791.             var res = '';
  792.             for(var i = 0; i < M.Achievements.length; i++) res += Math.min(M.Achievements[i].won);
  793.             return res;
  794.         }
  795.        
  796.         var getUpgradeSave = function(){
  797.             var res = '';
  798.             for (var i in M.Upgrades){
  799.                 var me = M.Upgrades[i];
  800.                 res += Math.min(me.unlocked, 1) + '' + Math.min(me.bought, 1);
  801.             }
  802.             return res;
  803.         }
  804.        
  805.        
  806.         var str = getMinigameStateSave();
  807.         str += ' ' + getGameStateSave();
  808.         str += ' ' + getCardSave(M.hands.dealer.cards);
  809.         str += ' ' + getPlayerHandsSave();
  810.         str += ' ' + getCardSave(M.Deck);
  811.         str += ' ' + getAchievementSave();
  812.         str += ' ' + getUpgradeSave();
  813.        
  814.         CCSE.save.OtherMods[M.name] = str;
  815.         M.saveString = str;
  816.         return ''; //str;
  817.     }
  818.    
  819.     M.load = function(str){
  820.         //interpret str; called after .init
  821.         //note : not actually called in the Game's load; see "minigameSave" in main.js
  822.         if(!str) return false;
  823.         M.saveString = str;
  824.        
  825.         var parseMinigameStateSave = function(str){
  826.             var i = 0;
  827.             var spl = str.split('_');
  828.             var on = parseInt(spl[i++] || 0);
  829.             M.games.Blackjack.wins = parseInt(spl[i++] || 0);
  830.             M.games.Blackjack.winsT = parseInt(spl[i++] || 0);
  831.             M.games.Blackjack.ownLuckWins = parseInt(spl[i++] || 0);
  832.             M.games.Blackjack.tiesLost = parseInt(spl[i++] || 0);
  833.             M.betMode = parseInt(spl[i++] || 0);
  834.             M.betChoice = parseInt(spl[i++] || 0);
  835.             M.games.Blackjack.netTotal = parseFloat(spl[i++] || 0);
  836.             var dummy = parseInt(spl[i++] || 0);
  837.             M.beatLength = parseInt(spl[i++] || 750);
  838.            
  839.             if(on && Game.ascensionMode != 1) M.parent.switchMinigame(1);
  840.         }
  841.        
  842.         var parseGameStateSave = function(str){
  843.             var i = 0;
  844.             var spl = str.split('_');
  845.             M.currentPlayerHand = parseInt(spl[i++] || 0);
  846.             M.nextBeat = parseInt(spl[i++] || 0);
  847.             M.games.Blackjack.phase = parseInt(spl[i++] || 0);
  848.             M.games.Blackjack.istep = parseInt(spl[i++] || 0);
  849.             M.betAmount = parseFloat(spl[i++] || 0);
  850.             M.games.Blackjack.hiddenCard = M.cards[parseInt(spl[i++] || 0)];
  851.         }
  852.        
  853.         var parseCardSave = function(str){
  854.             var res = [];
  855.             if(str){
  856.                 var arr = str.split('-');
  857.                 for(var i = 0; i < arr.length; i++){
  858.                     res.push(M.cards[arr[i]]);
  859.                 }
  860.             }
  861.             return res;
  862.         }
  863.        
  864.         var parsePlayerHandsSave = function(str){
  865.             M.hands.player = [];
  866.             if(str){
  867.                 var hands = str.split('_');
  868.                 for(var i = 0; i < hands.length; i++){
  869.                     M.hands.player.push({cards:parseCardSave(hands[i])});
  870.                     M.games.Blackjack.getHandValue(M.hands.player[i]);
  871.                 }
  872.             }else{
  873.                 M.hands.player = [{value:0, cards:[]}];
  874.             }
  875.         }
  876.        
  877.         var parseAchievementSave = function(str){
  878.             var spl = str.split('');
  879.             for (var i in M.Achievements){
  880.                 var me = M.Achievements[i];
  881.                 if(spl[i]){
  882.                     var mestr = [spl[i]];
  883.                     me.won = parseInt(mestr[0]);
  884.                 }else{
  885.                     me.won = 0;
  886.                 }
  887.                 if(me.won && Game.CountsAsAchievementOwned(me.pool)) Game.AchievementsOwned++;
  888.             }
  889.         }
  890.        
  891.         var parseUpgradeSave = function(str){
  892.             var spl = str.split('');
  893.             for (var i in M.Upgrades){
  894.                 var me = M.Upgrades[i];
  895.                 if (spl[i * 2]){
  896.                     var mestr = [spl[i * 2],spl[i * 2 + 1]];
  897.                     me.unlocked = parseInt(mestr[0]);
  898.                     me.bought = parseInt(mestr[1]);
  899.                     if (me.bought && Game.CountsAsUpgradeOwned(me.pool)) Game.UpgradesOwned++;
  900.                 }
  901.                 else{
  902.                     me.unlocked = 0;
  903.                     me.bought = 0;
  904.                 }
  905.             }
  906.         }
  907.        
  908.        
  909.         var i = 0;
  910.         var spl = str.split(' ');
  911.         parseMinigameStateSave(spl[i++] || '');
  912.         parseGameStateSave(spl[i++] || '');
  913.         M.hands.dealer = {cards:parseCardSave(spl[i++] || 0)};
  914.         parsePlayerHandsSave(spl[i++] || 0);
  915.         M.Deck = parseCardSave(spl[i++] || 0);
  916.         parseAchievementSave(spl[i++] || '');
  917.         parseUpgradeSave(spl[i++] || '');
  918.        
  919.         M.games.Blackjack.getHandValue(M.hands.dealer);
  920.         if(M.Deck.length < (M.minDecks * 52)) M.reshuffle();
  921.         if(M.games.Blackjack.phase == M.games.Blackjack.phases.inactive){
  922.             M.hands = {dealer:{value:0, cards:[]}, player:[{value:0, cards:[]}]};
  923.             M.currentPlayerHand = 0;
  924.         }
  925.        
  926.         M.games.Blackjack.buildSidebar();
  927.         M.games.Blackjack.buildTable();
  928.     }
  929.    
  930.     M.reset = function(hard){
  931.         M.deckCount = 4;
  932.         M.Deck = [];
  933.         M.hands = {dealer:{value:0, cards:[]}, player:[{value:0, cards:[]}]};
  934.         M.games.Blackjack.hiddenCard = M.cards[0];
  935.         M.currentPlayerHand = 0;
  936.         M.minDecks = 2;
  937.         M.betAmount = 0;
  938.         M.betChoice = 1;
  939.         M.betMode = 1;
  940.         M.games.Blackjack.wins = 0;
  941.         M.games.Blackjack.ownLuckWins = 0;
  942.         M.games.Blackjack.tiesLost = 0;
  943.         M.games.Blackjack.phase = 0;
  944.         M.games.Blackjack.istep = 0;
  945.         M.nextBeat = Date.now();
  946.        
  947.         M.setPercentagePrecision(1);
  948.        
  949.         if(hard){
  950.             M.saveString = '';
  951.         }
  952.        
  953.         M.reshuffle();
  954.        
  955.         M.buildSidebar();
  956.         M.buildTable();
  957.        
  958.         setTimeout(function(M){return function(){M.onResize();}}(M), 10);
  959.     }
  960.    
  961.     M.logic = function(){
  962.         //run each frame
  963.         if(M.games.choice == 0) M.games.Blackjack.logic();
  964.     }
  965.    
  966.     M.onResize = function(){
  967.         var width = l('casinoContent').offsetWidth;
  968.         var sidebarW = width * 0.20 - 8;
  969.         var tableW = width * 0.80 - 8;
  970.         M.sidebarL.style.width = sidebarW + 'px';
  971.         M.tableL.style.width = tableW + 'px';
  972.     }
  973.    
  974.     M.draw = function(){
  975.         //run each draw frame
  976.         if(M.games.choice == 0) M.games.Blackjack.draw();
  977.        
  978.         l('casinoCurrentBet').innerHTML = '(' + Beautify(M.betAmount) + ' cookies)';
  979.     }
  980.    
  981.     M.init(l('rowSpecial' + M.parent.id));
  982. }
  983.  
  984.  
  985. M.launcher = function(){
  986.     var M = Game.Objects['Chancemaker'].minigame;
  987.    
  988.     // Stuff that needs to wait for CCSE but should only run once goes here
  989.     M.parent.minigameUrl = 'https://klattmose.github.io/CookieClicker/dummyFile.js';
  990.     M.parent.minigameName = 'Casino';
  991.    
  992.     M.name = M.parent.minigameName;
  993.     M.savePrefix = 'minigameCasino';
  994.     M.sourceFolder = 'https://klattmose.github.io/CookieClicker/' + (0 ? 'Beta/' : '');
  995.     M.cardsImage = 'https://cdn.discordapp.com/attachments/529558484208058370/696951472684007534/phantasypantsCards.png';
  996.     M.iconsImage = 'http://cdn.discordapp.com/attachments/529558484208058370/696910427635974257/customIcons.png';
  997.     M.chancemakerChance = 0.0003;
  998.     M.beatLength = 750;
  999.    
  1000.     //***********************************
  1001.     //    Upgrades
  1002.     //***********************************
  1003.     M.Upgrades = [];
  1004.     M.Upgrades.push(CCSE.NewUpgrade('Raise the stakes', "Can bet a minute of CPS at a time.<q>Now we're getting somewhere!</q>", 10, [0, 3, M.iconsImage]));
  1005.     M.Upgrades.push(CCSE.NewUpgrade('High roller!', "Can bet an hour of CPS at a time.<q>If you have to ask, you can't afford it.</q>", 60, [0, 3, M.iconsImage]));
  1006.     M.Upgrades.push(CCSE.NewUpgrade('Math lessons', "Show the value of your current blackjack hand.<q>C'mon, it's not that hard.</q>", 1, [0, 3, M.iconsImage]));
  1007.     M.Upgrades.push(CCSE.NewUpgrade('Counting cards', "Keeps track of which cards have been played. 2-6 increase the count by 1. 10-K and Aces decrease the count by 1. Higher counts give better odds.<q>Technically not cheating, but casinos frown on this sort of thing.</q>", 21, [0, 3, M.iconsImage]));
  1008.     M.Upgrades.push(CCSE.NewUpgrade('Tiebreaker', "Ties push to the player, not the dealer.<q>Look at me. I'm the dealer now.</q>", 15, [0, 3, M.iconsImage]));
  1009.     M.Upgrades.push(CCSE.NewUpgrade('I make my own luck', "Each Chancemaker gives a <b>0.0<span></span>3%</b> chance to instantly win the hand.<q>Wait, that's illegal.</q>", 60, [0, 3, M.iconsImage]));
  1010.     M.Upgrades.push(CCSE.NewUpgrade('Infinite Improbability Drive', "Chancemaker chance to instantly win the hand is <b>doubled</b>.<q>You stole a protoype spaceship just to cheat at cards?</q>", 180, [0, 3, M.iconsImage]));
  1011.     M.Upgrades.push(CCSE.NewUpgrade('Double or nothing', "Multiply your bet by <b>2</b>.<q>The Martingale System sounds good on paper, but one losing streak long enough will bankrupt anyone.</q>", 120, [0, 3, M.iconsImage]));
  1012.     M.Upgrades.push(CCSE.NewUpgrade('Stoned cows', "Multiply your bet by <b>5</b>.<q>The steaks have never been higher!</q>", 300, [0, 3, M.iconsImage]));
  1013.     M.Upgrades.push(CCSE.NewHeavenlyUpgrade('Actually, do tell me the odds', "Display the probabilities of various outcomes of taking an action in the Casino.<q>2 + 2 is 4 minus 1 that's 3 quick maffs.</q>", 21000000, [0, 3, M.iconsImage], 3, -200, []));
  1014.         Game.last.showIf = function(){return Game.HasAchiev('Card shark');}
  1015.    
  1016.     for(var i = 0; i < M.Upgrades.length; i++){
  1017.         M.Upgrades[i].order = 1000000 + i / 100;
  1018.         if(M.Upgrades[i].pool != 'prestige') M.Upgrades[i].priceFunc = function(){return this.basePrice * Game.cookiesPs * 60;};
  1019.     }
  1020.     Game.Upgrades['Double or nothing'].order = Game.Upgrades['High roller!'].order + 0.001;
  1021.     Game.Upgrades['Stoned cows'].order = Game.Upgrades['Double or nothing'].order + 0.001;
  1022.    
  1023.    
  1024.     //***********************************
  1025.     //    Achievements
  1026.     //***********************************
  1027.     M.Achievements = [];
  1028.     M.Achievements.push(CCSE.NewAchievement('Card minnow', 'Win <b>21</b> hands of blackjack.', [0, 3, M.iconsImage]));
  1029.     M.Achievements.push(CCSE.NewAchievement('Card trout', 'Win <b>210</b> hands of blackjack.', [0, 3, M.iconsImage]));
  1030.     M.Achievements.push(CCSE.NewAchievement('Card shark', 'Win <b>2100</b> hands of blackjack.', [0, 3, M.iconsImage]));
  1031.     M.Achievements.push(CCSE.NewAchievement('Five card stud', "Win a hand of blackjack with <b>5</b> cards in your hand.<q>Wait, what game are you playing again?</q>", [0, 3, M.iconsImage]));
  1032.     M.Achievements.push(CCSE.NewAchievement("Why can't I hold all these cards?", 'Win a hand of blackjack with <b>6</b> cards in your hand.', [0, 3, M.iconsImage]));
  1033.         Game.last.pool = 'shadow';
  1034.     M.Achievements.push(CCSE.NewAchievement('Ace up your sleeve', "Win <b>13</b> hands of blackjack through chancemaker intervention in one ascension.<q>I'll tell you what the odds are.</q>", [0, 3, M.iconsImage]));
  1035.     M.Achievements.push(CCSE.NewAchievement('Paid off the dealer', "Win <b>" + (13 * 13) + "</b> hands of blackjack through chancemaker intervention in one ascension.<q>Takes money to make money.</q>", [0, 3, M.iconsImage]));
  1036.     M.Achievements.push(CCSE.NewAchievement('Deal with the Devil', "Win <b>666</b> hands of blackjack through chancemaker intervention in one ascension.<q>Just sign right here.</q>", [0, 3, M.iconsImage]));
  1037.         Game.last.pool = 'shadow';
  1038.     M.Achievements.push(CCSE.NewAchievement('Blackjack!', "Be dealt a hand totaling 21 naturally.", [0, 3, M.iconsImage]));
  1039.     M.Achievements.push(CCSE.NewAchievement('I like to live dangerously', "Hit on <b>17</b> or above without going over <b>21</b>.<q>My name is Number 2. This is my Italian confidential secretary. Her name is Alotta. Alotta Fagina.</q>", [0, 3, M.iconsImage]));
  1040.     M.Achievements.push(CCSE.NewAchievement('I also like to live dangerously', "Win with a score of <b>5</b> or less.<q>Yeah baby!</q>", [0, 3, M.iconsImage]));
  1041.         Game.last.pool = 'shadow';
  1042.    
  1043.     for(var i = 0; i < M.Achievements.length; i++) M.Achievements[i].order = 1000000 + i / 100;
  1044.    
  1045.    
  1046.     //***********************************
  1047.     //    CCSE arrays
  1048.     //***********************************
  1049.     Game.customOptionsMenu.push(function(){
  1050.         var callback = "Game.Objects['Chancemaker'].minigame.beatLength = Math.round(l('beatLengthSlider').value); l('beatLengthSliderRightText').innerHTML = Game.Objects['Chancemaker'].minigame.beatLength;";
  1051.         var str = '<div class="listing">' +
  1052.             '<div class="sliderBox"><div style="float:left;">Beat Length</div><div style="float:right;" id="beatLengthSliderRightText">' + M.beatLength + '</div><input class="slider" style="clear:both;" type="range" min="0" max="1000" step="10" value="' + M.beatLength + '" onchange="' + callback + '" oninput="' + callback + '" onmouseup="PlaySound(\'snd/tick.mp3\');" id="beatLengthSlider"/></div><br/>' +
  1053.             'This is the time in milliseconds between each card deal.</div>';
  1054.        
  1055.         CCSE.AppendCollapsibleOptionsMenu(M.name, str);
  1056.     });
  1057.    
  1058.     Game.customStatsMenu.push(function(){
  1059.         CCSE.AppendStatsVersionNumber(M.name, M.version);
  1060.         if(M.loadedCount){
  1061.             if(M.games.Blackjack.netTotal) CCSE.AppendStatsGeneral('<div class="listing"><b>Blackjack has earned you :</b> <div class="price plain">' + Game.tinyCookie() + Beautify(M.games.Blackjack.netTotal) + '</div></div>');
  1062.             if(M.games.Blackjack.ownLuckWins) CCSE.AppendStatsSpecial('<div class="listing"><b>Made your own luck :</b> ' + M.games.Blackjack.ownLuckWins + ' times</div>');
  1063.         }
  1064.     });
  1065.    
  1066.    
  1067.     CCSE.customLoad.push(function(ret){
  1068.         if(localStorage.getItem(M.savePrefix) != null && !CCSE.save.OtherMods[M.name]) CCSE.save.OtherMods[M.name] = localStorage.getItem(M.savePrefix);
  1069.         if(CCSE.save.OtherMods[M.name]) M.parent.minigameSave = CCSE.save.OtherMods[M.name];
  1070.         M.saveString = M.parent.minigameSave;
  1071.        
  1072.         M.load(M.saveString);
  1073.         return ret;
  1074.     });
  1075.     Game.customChecks.push(function(){
  1076.         if(M.loadedCount){
  1077.             if(M.games.Blackjack.winsT >= 7) Game.Unlock('Raise the stakes');
  1078.             if(Game.Has('Raise the stakes') && M.games.Blackjack.winsT >= 49) Game.Unlock('High roller!');
  1079.             if(Game.Has('High roller!') && Game.cookies >= (4 * Game.cookiesPs * 60 * 60)) Game.Unlock('Double or nothing');
  1080.             if(Game.Has('Double or nothing') && Game.cookies >= (10 * Game.cookiesPs * 60 * 60)) Game.Unlock('Stoned cows');
  1081.             if(Game.Has('I make my own luck') && M.games.Blackjack.ownLuckWins >= 52) Game.Unlock('Infinite Improbability Drive');
  1082.             if(M.games.Blackjack.tiesLost >= 7) Game.Unlock('Tiebreaker');
  1083.            
  1084.             if(M.games.Blackjack.winsT >= 21) Game.Win('Card minnow');
  1085.             if(M.games.Blackjack.winsT >= 210) Game.Win('Card trout');
  1086.             if(M.games.Blackjack.winsT >= 2100) Game.Win('Card shark');
  1087.             if(M.games.Blackjack.ownLuckWins >= 13) Game.Win('Ace up your sleeve');
  1088.             if(M.games.Blackjack.ownLuckWins >= (13 * 13)) Game.Win('Paid off the dealer');
  1089.             if(M.games.Blackjack.ownLuckWins >= 666) Game.Win('Deal with the Devil');
  1090.            
  1091.             if(M.games.choice == 0) M.games.Blackjack.buildSidebar();
  1092.         }
  1093.     });
  1094.    
  1095.    
  1096.     if(typeof CM != 'undefined') CM.Sim.InitData(); // Cookie Monster compatibility
  1097.    
  1098.    
  1099.     Game.LoadMinigames();
  1100. }
  1101.  
  1102. if(CCSE && CCSE.isLoaded){
  1103.     M.launcher();
  1104. }
  1105. else{
  1106.     if(!CCSE) var CCSE = {};
  1107.     if(!CCSE.postLoadHooks) CCSE.postLoadHooks = [];
  1108.     CCSE.postLoadHooks.push(M.launcher);
  1109. }
  1110.  
  1111. var M = 0;
Add Comment
Please, Sign In to add comment