Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const WHEEL1RNG = [5, 2, 6, 5, 6, 30, 30, 10, 3, 3];
  2. const WHEEL2RNG = [8, 2, 0, 25, 10, 10, 7, 20, 12, 6];
  3. const WHEEL3RNG = [5, 2, 6, 30, 30, 5, 6, 5, 6, 5];        // Bonus (third in) should be 6, bumped up to 25 for testing. Applicable to wheels 1, 3 and 5.
  4. const WHEEL4RNG = [2, 2, 0, 11, 20, 25, 15, 15, 5, 5];
  5. const WHEEL5RNG = [1, 2, 6, 10, 25, 10, 11, 10, 15, 10];
  6. const FREESPINCHANCE = 0.5;
  7.  
  8. const DEBUGMODE = false;
  9.  
  10. const PAYOUTS = {
  11.     1: [0, 0, 0, 2000],
  12.     2: [4, 10, 20, 80],
  13.     3: [0, 0, 0, 0],
  14.     4: [1, 5, 10, 50],
  15.     5: [1, 7, 15, 75],
  16.     6: [2, 10, 30, 120],
  17.     7: [2, 10, 50, 150],
  18.     8: [3, 20, 75, 200],
  19.     9: [4, 35, 350, 1500],
  20.     10: [5, 50, 500, 2000]
  21. };
  22.  
  23. const LINES = {
  24.     1: [1, 1, 1, 1, 1],
  25.     2: [2, 2, 2, 2, 2],
  26.     3: [0, 0, 0, 0, 0],
  27.     4: [2, 1, 0, 1, 2],
  28.     5: [0, 1, 2, 1, 0],
  29.     6: [1, 2, 2, 2, 1],
  30.     7: [1, 0, 0, 0, 1],
  31.     8: [2, 2, 1, 0, 0],
  32.     9: [0, 0, 1, 2, 2],
  33.     10: [1, 0, 1, 2, 1],
  34.     11: [1, 2, 1, 0, 1],
  35.     12: [2, 1, 1, 1, 2],
  36.     13: [0, 1, 1, 1, 0],
  37.     14: [2, 1, 2, 1, 2],
  38.     15: [0, 1, 0, 1, 0],
  39.     16: [1, 1, 2, 1, 1],
  40.     17: [1, 1, 0, 1, 1],
  41.     18: [2, 2, 0, 2, 2],
  42.     19: [0, 0, 2, 0, 0],
  43.     20: [2, 0, 0, 0, 2],
  44.     21: [0, 2, 2, 2, 0],
  45.     22: [1, 0, 2, 0, 1],
  46.     23: [1, 2, 0, 2, 1],
  47.     24: [2, 0, 2, 0, 2],
  48.     25: [0, 2, 0, 2, 0]
  49. };
  50.  
  51. const FREESPINSQUANTITY = [5, 10, 25];
  52. const FREESPINSQUANTITYCHANCE = [60, 30, 10];
  53. const FREESPINSMULTIPLIER = [2, 3, 5];
  54. const FREESPINSMULTIPLIERCHANCE = [60, 30, 10];
  55.  
  56. const BONUSGAMESETAMIN = 5;
  57. const BONUSGAMESETAMAX = 75;
  58. const BONUSGAMESETANUMBER = 6;
  59. const BONUSGAMESETBMIN = 75;
  60. const BONUSGAMESETBMAX = 200;
  61. const BONUSGAMESETBNUMBER = 8;
  62. const BONUSGAMESETCMIN = 200;
  63. const BONUSGAMESETCMAX = 500;
  64. const BONUSGAMESETCNUMBER = 11;
  65. const BONUSGAMEPICKS = [3, 4, 5];
  66. const BONUSGAMEPICKSCHANCE = [60, 30, 10];
  67.  
  68. const POSSIBLEBETSPERLINE = [1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000, 250000, 500000, 1000000];
  69. const AUTOSPINSPERHOUR = 30;
  70.  
  71. handlers.OnSpin = function(args)
  72. {
  73.     var RetObj = {};
  74.  
  75.     var GetUserInventoryRequest =
  76.     {
  77.         "PlayFabId": currentPlayerId
  78.     };
  79.     var GetUserInventoryResult = server.GetUserInventory(GetUserInventoryRequest);
  80.  
  81.     if (GetUserInventoryResult.VirtualCurrency.hasOwnProperty("CO") && GetUserInventoryResult.VirtualCurrency.CO >= args.BetPerLine * 25)
  82.     {
  83.         RetObj["Wheel1"] = SetWheel(WHEEL1RNG, false);
  84.         RetObj["Wheel2"] = SetWheel(WHEEL2RNG, false);
  85.         RetObj["Wheel3"] = SetWheel(WHEEL3RNG, false);
  86.         RetObj["Wheel4"] = SetWheel(WHEEL4RNG, false);
  87.         RetObj["Wheel5"] = SetWheel(WHEEL5RNG, false);
  88.  
  89.         // Debug Bonus
  90.         if (DEBUGMODE)
  91.         {
  92.             RetObj["Wheel1"][0] = 3;
  93.             RetObj["Wheel3"][0] = 3;
  94.             RetObj["Wheel5"][0] = 3;
  95.         }
  96.  
  97.         RetObj = CalculateWins(RetObj, args.BetPerLine, false);
  98.  
  99.         var NetValue = RetObj["TotalWin"] - args.BetPerLine * 25;
  100.  
  101.         // Add / Subtract Currency
  102.         if (DEBUGMODE)
  103.         {
  104.             RetObj["Coins"] = GetUserInventoryResult.VirtualCurrency.CO;
  105.         }
  106.         else
  107.         {
  108.             if (NetValue > 0) {
  109.                 var AddUserVirtualCurrencyRequest =
  110.                 {
  111.                     "PlayFabId": currentPlayerId,
  112.                     "VirtualCurrency": "CO",
  113.                     "Amount": NetValue
  114.                 };
  115.                 var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
  116.  
  117.                 RetObj["Coins"] = AddUserVirtualCurrencyResult.Balance;
  118.             }
  119.             else if (NetValue < 0) {
  120.                 var SubtractUserVirtualCurrencyRequest =
  121.                 {
  122.                     "PlayFabId": currentPlayerId,
  123.                     "VirtualCurrency": "CO",
  124.                     "Amount": -NetValue
  125.                 };
  126.                 var SubtractUserVirtualCurrencyResult = server.SubtractUserVirtualCurrency(SubtractUserVirtualCurrencyRequest);
  127.  
  128.                 RetObj["Coins"] = SubtractUserVirtualCurrencyResult.Balance;
  129.             }
  130.             else {
  131.                 RetObj["Coins"] = GetUserInventoryResult.VirtualCurrency.CO;
  132.             }
  133.         }
  134.  
  135.         //SpinWonNothing
  136.         var SWN = 0;
  137.         if (RetObj["TotalWin"] == 0)
  138.         {
  139.             SWN = 1;
  140.         }
  141.         //SpinWonButLost
  142.         var SWBL = 0;
  143.         if (RetObj["TotalWin"] > 0 && RetObj["TotalWin"] < args.BetPerLine * 25)
  144.         {
  145.             SWBL = 1;
  146.         }
  147.         //SpinBreakEven
  148.         var SBE = 0;
  149.         if (RetObj["TotalWin"] == args.BetPerLine * 25) {
  150.             SBE = 1;
  151.         }
  152.         //FreeSpins
  153.         var FS = 0;
  154.         if (RetObj["FreeSpinsEntered"] != null)
  155.         {
  156.             FS = 1;
  157.         }
  158.         //BonusGame
  159.         var BG = 0;
  160.         if (RetObj["BonusGameEntered"] != null)
  161.         {
  162.             BG = 1;
  163.         }
  164.  
  165.         // Update Player Statistics
  166.         if (!DEBUGMODE)
  167.         {
  168.             server.UpdatePlayerStatistics(
  169.             {
  170.                 PlayFabId: currentPlayerId,
  171.                 Statistics:
  172.                 [{
  173.                     StatisticName: "Spins",
  174.                     Value: 1
  175.                 }, {
  176.                     StatisticName: "BiggestWin",
  177.                     Value: RetObj["TotalWin"] / args.BetPerLine
  178.                 }, {
  179.                     StatisticName: "SpinWonNothing",
  180.                     Value: SWN
  181.                 }, {
  182.                     StatisticName: "SpinWonButLost",
  183.                     Value: SWBL
  184.                 }, {
  185.                     StatisticName: "SpinBreakEven",
  186.                     Value: SBE
  187.                 }, {
  188.                     StatisticName: "MinCoins",
  189.                     Value: RetObj["Coins"]
  190.                 }, {
  191.                     StatisticName: "FreeSpinsPlayed",
  192.                     Value: FS
  193.                 }, {
  194.                     StatisticName: "BonusGamesPlayed",
  195.                     Value: BG
  196.                 }]
  197.             });
  198.         }
  199.  
  200.         RetObj["Success"] = true;
  201.     }
  202.     else
  203.     {
  204.         RetObj["Success"] = false;
  205.     }
  206.  
  207.     return RetObj;
  208. }
  209.  
  210. function SetWheel(RNG, Bonus)
  211. {
  212.     var Icon1 = Math.round(Math.random() * 100);
  213.     var Icon2 = Math.round(Math.random() * 100);
  214.     var Icon3 = Math.round(Math.random() * 100);
  215.    
  216.     var Icon1Result = 0;
  217.     var Icon2Result = 0;
  218.     var Icon3Result = 0;
  219.    
  220.     var j = 0;
  221.     for (var i = 0; i < 10; i++)
  222.     {
  223.         if(j <= Icon1)
  224.         {
  225.             Icon1Result++;
  226.         }
  227.         if(j <= Icon2)
  228.         {
  229.             Icon2Result++;
  230.         }
  231.         if(j <= Icon3)
  232.         {
  233.             Icon3Result++;
  234.         }
  235.         j += RNG[i];
  236.     }
  237.  
  238.     if (Bonus)
  239.     {
  240.         if(Icon1Result == 3)
  241.         {
  242.             Icon1Result = 1;
  243.         }
  244.         if (Icon2Result == 3)
  245.         {
  246.             Icon2Result = 1;
  247.         }
  248.         if (Icon3Result == 3)
  249.         {
  250.             Icon3Result = 1;
  251.         }
  252.     }
  253.    
  254.     var Ret = [Icon1Result, Icon2Result, Icon3Result];
  255.    
  256.     if((Icon1Result == 2 && Icon2Result == 2) || (Icon1Result == 2 && Icon3Result == 2) || (Icon2Result == 2 && Icon3Result == 2) || (Icon1Result == 3 && Icon2Result == 3) || (Icon1Result == 3 && Icon3Result == 3) || (Icon2Result == 3 && Icon3Result == 3))
  257.     {
  258.         Ret = SetWheel(RNG);
  259.     }
  260.    
  261.     return Ret;
  262. }
  263.  
  264. function CalculateWins(RetObj, BetPerLine, Bonus, Auto)
  265. {
  266.     var Lines = {};
  267.     var TotalWin = 0;
  268.     for (var i = 1; i < 26; i++)
  269.     {
  270.         var Sequence = [];
  271.  
  272.         Sequence.push(RetObj["Wheel1"][LINES[i][0]]);
  273.         Sequence.push(RetObj["Wheel2"][LINES[i][1]]);
  274.         Sequence.push(RetObj["Wheel3"][LINES[i][2]]);
  275.         Sequence.push(RetObj["Wheel4"][LINES[i][3]]);
  276.         Sequence.push(RetObj["Wheel5"][LINES[i][4]]);
  277.  
  278.         Lines["Line" + i] = Sequence;
  279.  
  280.         if(Sequence[0] == 1)
  281.         {
  282.             if(Sequence[1] == 1)
  283.             {
  284.                 if(Sequence[2] == 1)
  285.                 {
  286.                     if(Sequence[3] == 1)
  287.                     {
  288.                         if(Sequence[4] == 1)
  289.                         {
  290.                             for (var j = 0; j < 5; j++)
  291.                             {
  292.                                 if(Sequence[j] == 1)
  293.                                 {
  294.                                     Sequence[j] = 10;
  295.                                 }
  296.                             }
  297.                         }
  298.                         else
  299.                         {
  300.                             for (var j = 0; j < 5; j++)
  301.                             {
  302.                                 if (Sequence[j] == 1)
  303.                                 {
  304.                                     Sequence[j] = Sequence[4];
  305.                                 }
  306.                             }
  307.                         }
  308.                     }
  309.                     else
  310.                     {
  311.                         for (var j = 0; j < 5; j++)
  312.                         {
  313.                             if (Sequence[j] == 1)
  314.                             {
  315.                                 Sequence[j] = Sequence[3];
  316.                             }
  317.                         }
  318.                     }
  319.                 }
  320.                 else
  321.                 {
  322.                     for (var j = 0; j < 5; j++)
  323.                     {
  324.                         if (Sequence[j] == 1)
  325.                         {
  326.                             Sequence[j] = Sequence[2];
  327.                         }
  328.                     }
  329.                 }
  330.             }
  331.             else
  332.             {
  333.                 for (var j = 0; j < 5; j++)
  334.                 {
  335.                     if(Sequence[j] == 1)
  336.                     {
  337.                         Sequence[j] = Sequence[1];
  338.                     }
  339.                 }
  340.             }
  341.         }
  342.         else
  343.         {
  344.             for (var j = 0; j < 5; j++)
  345.             {
  346.                 if(Sequence[j] == 1)
  347.                 {
  348.                     Sequence[j] = Sequence[0];
  349.                 }
  350.             }
  351.         }
  352.  
  353.         if(Sequence[0] > 3)
  354.         {
  355.             var RunningCount = 1;
  356.  
  357.             if(Sequence[0] == Sequence[1])
  358.             {
  359.                 RunningCount++;
  360.                 if(Sequence[1] == Sequence[2])
  361.                 {
  362.                     RunningCount++;
  363.                     if(Sequence[2] == Sequence[3])
  364.                     {
  365.                         RunningCount++;
  366.                         if(Sequence[3] == Sequence[4])
  367.                         {
  368.                             RunningCount++;
  369.                         }
  370.                     }
  371.                 }
  372.             }
  373.  
  374.             if(RunningCount == 1)
  375.             {
  376.                 //if (!Bonus)
  377.                 {
  378.                     RetObj["Line" + i] = 0;
  379.                 }
  380.             }
  381.             else
  382.             {
  383.                 //if (!Bonus)
  384.                 {
  385.                     RetObj["Line" + i] = PAYOUTS[Sequence[0]][RunningCount - 2] * BetPerLine;
  386.                 }
  387.                 TotalWin += PAYOUTS[Sequence[0]][RunningCount - 2] * BetPerLine;
  388.             }
  389.         }
  390.         else
  391.         {
  392.             if (!Bonus)
  393.             {
  394.                 RetObj["Line" + i] = 0;
  395.             }
  396.         }
  397.     }
  398.  
  399.     var Scatters = 0;
  400.     if (RetObj["Wheel1"].indexOf(2) > -1)
  401.     {
  402.         Scatters++;
  403.     }
  404.     if (RetObj["Wheel2"].indexOf(2) > -1)
  405.     {
  406.         Scatters++;
  407.     }
  408.     if (RetObj["Wheel3"].indexOf(2) > -1)
  409.     {
  410.         Scatters++;
  411.     }
  412.     if (RetObj["Wheel4"].indexOf(2) > -1)
  413.     {
  414.         Scatters++;
  415.     }
  416.     if (RetObj["Wheel5"].indexOf(2) > -1)
  417.     {
  418.         Scatters++;
  419.     }
  420.  
  421.     if (Scatters >= 2)
  422.     {
  423.         if (!Bonus)
  424.         {
  425.             RetObj["ScatterPayout"] = PAYOUTS[2][Scatters - 2] * BetPerLine * 25;
  426.         }
  427.         TotalWin += PAYOUTS[2][Scatters - 2] * BetPerLine * 25;
  428.     }
  429.     else
  430.     {
  431.         if (!Bonus)
  432.         {
  433.             RetObj["ScatterPayout"] = 0;
  434.         }
  435.     }
  436.  
  437.     RetObj["TotalWin"] = TotalWin;
  438.  
  439.     if (RetObj["Wheel1"].indexOf(3) > -1 && RetObj["Wheel3"].indexOf(3) > -1 && RetObj["Wheel5"].indexOf(3) > -1 && !Bonus)
  440.     {
  441.         RetObj = EnterBonusGame(RetObj, BetPerLine, Auto);
  442.     }
  443.  
  444.     return RetObj;
  445. }
  446.  
  447. function EnterBonusGame(RetObj, BetPerLine, Auto)
  448. {
  449.     if(Math.random() <= FREESPINCHANCE)
  450.     {
  451.         RetObj["FreeSpinsEntered"] = true;
  452.  
  453.         var QuantityIndex = 0;
  454.         var QuantityRNG = Math.round(Math.random() * 100);
  455.         var X = 0;
  456.  
  457.         for (var i = 0; i < FREESPINSQUANTITYCHANCE.length; i++)
  458.         {
  459.             X += FREESPINSQUANTITYCHANCE[i];
  460.             if(QuantityRNG > X)
  461.             {
  462.                 QuantityIndex++;
  463.             }
  464.         }
  465.  
  466.         var Quantity = FREESPINSQUANTITY[QuantityIndex];
  467.         RetObj["FreeSpinsQuantity"] = Quantity;
  468.  
  469.         var MultiplierIndex = 0;
  470.         var MultiplierRNG = Math.round(Math.random() * 100);
  471.         X = 0;
  472.  
  473.         for (var i = 0; i < FREESPINSMULTIPLIERCHANCE.length; i++)
  474.         {
  475.             X += FREESPINSMULTIPLIERCHANCE[i];
  476.             if (MultiplierRNG > X)
  477.             {
  478.                 MultiplierIndex++;
  479.             }
  480.         }
  481.  
  482.         var Multiplier = FREESPINSMULTIPLIER[MultiplierIndex];
  483.         RetObj["FreeSpinsMultiplier"] = Multiplier;
  484.  
  485.         RetObj["FreeSpinData"] = [];
  486.  
  487.         var RunningTotal = 0;
  488.         for (var i = 0; i < Quantity; i++)
  489.         {
  490.             var Data = {};
  491.  
  492.             Data["Wheel1"] = SetWheel(WHEEL1RNG, true);
  493.             Data["Wheel2"] = SetWheel(WHEEL2RNG, true);
  494.             Data["Wheel3"] = SetWheel(WHEEL3RNG, true);
  495.             Data["Wheel4"] = SetWheel(WHEEL4RNG, true);
  496.             Data["Wheel5"] = SetWheel(WHEEL5RNG, true);
  497.  
  498.             Data = CalculateWins(Data, BetPerLine, true);
  499.  
  500.             Data["TotalWin"] = Data["TotalWin"] * Multiplier;
  501.  
  502.             RunningTotal += Data["TotalWin"];
  503.  
  504.             RetObj.FreeSpinData.push(Data);
  505.         }
  506.  
  507.         // Add Currency
  508.         if (!DEBUGMODE && Auto != true)
  509.         {
  510.             var AddUserVirtualCurrencyRequest =
  511.                 {
  512.                     "PlayFabId": currentPlayerId,
  513.                     "VirtualCurrency": "CO",
  514.                     "Amount": RunningTotal
  515.                 };
  516.             var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
  517.         }
  518.  
  519.         RetObj["FreeSpinTotalWin"] = RunningTotal;
  520.     }
  521.     else
  522.     {
  523.         RetObj["BonusGameEntered"] = true;
  524.  
  525.         RetObj["BonusValues"] = [];
  526.  
  527.         // Set A
  528.         for (var i = 0; i < BONUSGAMESETANUMBER; i++)
  529.         {
  530.             var X = Math.floor(Math.random() * (BONUSGAMESETAMAX - BONUSGAMESETAMIN) + BONUSGAMESETAMIN) * BetPerLine;
  531.  
  532.             RetObj.BonusValues.push(X);
  533.         }
  534.  
  535.         // Set B
  536.         for (var i = 0; i < BONUSGAMESETBNUMBER; i++)
  537.         {
  538.             var X = Math.floor(Math.random() * (BONUSGAMESETBMAX - BONUSGAMESETBMIN) + BONUSGAMESETBMIN) * BetPerLine;
  539.  
  540.             RetObj.BonusValues.push(X);
  541.         }
  542.  
  543.         // Set C
  544.         for (var i = 0; i < BONUSGAMESETCNUMBER; i++)
  545.         {
  546.             var X = Math.floor(Math.random() * (BONUSGAMESETCMAX - BONUSGAMESETCMIN) + BONUSGAMESETCMIN) * BetPerLine;
  547.  
  548.             RetObj.BonusValues.push(X);
  549.         }
  550.  
  551.         var PicksIndex = 0;
  552.         var PicksRNG = Math.round(Math.random() * 100);
  553.         var X = 0;
  554.  
  555.         for (var i = 0; i < BONUSGAMEPICKSCHANCE.length; i++)
  556.         {
  557.             X += BONUSGAMEPICKSCHANCE[i];
  558.             if (PicksRNG > X) {
  559.                 PicksIndex++;
  560.             }
  561.         }
  562.  
  563.         var Picks = BONUSGAMEPICKS[PicksIndex];
  564.         RetObj["BonusPicks"] = Picks;
  565.  
  566.         var PickIndexes = [];
  567.         var RunningTotal = 0;
  568.  
  569.         for (var i = 0; i < Picks; i++)
  570.         {
  571.             var Y = Math.floor(Math.random() * RetObj["BonusValues"].length);
  572.            
  573.             while(PickIndexes.indexOf(Y) != -1)
  574.             {
  575.                 Y = Math.floor(Math.random() * RetObj["BonusValues"].length);
  576.             }
  577.  
  578.             RunningTotal += RetObj.BonusValues[Y];
  579.            
  580.             PickIndexes.push(Y);
  581.         }
  582.  
  583.         RetObj["BonusPickIndexes"] = PickIndexes;
  584.  
  585.         RetObj["BonusTotalWin"] = RunningTotal;
  586.  
  587.         // Add Currency
  588.         if (!DEBUGMODE && Auto != true)
  589.         {
  590.             var AddUserVirtualCurrencyRequest =
  591.             {
  592.                 "PlayFabId": currentPlayerId,
  593.                 "VirtualCurrency": "CO",
  594.                 "Amount": RunningTotal
  595.             };
  596.             var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
  597.         }
  598.     }
  599.  
  600.     return RetObj;
  601. }
  602.  
  603. handlers.OnGetPlayerStatus = function(args)
  604. {
  605.     var RetObj = {};
  606.  
  607.     var PlayerStats = server.GetPlayerStatistics(
  608.     {
  609.         PlayFabId: currentPlayerId,
  610.         StatisticNames: ["IdleCoins"]
  611.     });
  612.  
  613.     var IC = 0;
  614.  
  615.     for (var i = 0; i < PlayerStats.Statistics.length; i++) {
  616.         if (PlayerStats.Statistics[i].StatisticName == "IdleCoins") {
  617.             IC = PlayerStats.Statistics[i].Value;
  618.         }
  619.     }
  620.  
  621.     RetObj["IdleCoins"] = IC;
  622.  
  623.     server.UpdatePlayerStatistics(
  624.     {
  625.         PlayFabId: currentPlayerId,
  626.         Statistics:
  627.         [{
  628.             StatisticName: "IdleCoins",
  629.             Value: 0
  630.         }],
  631.         ForceUpdate: true
  632.     });
  633.  
  634.     if (IC > 0) {
  635.         var AddUserVirtualCurrencyRequest =
  636.         {
  637.             "PlayFabId": currentPlayerId,
  638.             "VirtualCurrency": "CO",
  639.             "Amount": IC
  640.         };
  641.         var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
  642.     }
  643.     else if (IC < 0) {
  644.         var SubtractUserVirtualCurrencyRequest =
  645.         {
  646.             "PlayFabId": currentPlayerId,
  647.             "VirtualCurrency": "CO",
  648.             "Amount": -IC
  649.         };
  650.         var SubtractUserVirtualCurrencyResult = server.SubtractUserVirtualCurrency(SubtractUserVirtualCurrencyRequest);
  651.     }
  652.  
  653.     var GetUserInventoryRequest =
  654.     {
  655.         "PlayFabId": currentPlayerId
  656.     };
  657.     var GetUserInventoryResult = server.GetUserInventory(GetUserInventoryRequest);
  658.  
  659.     if (GetUserInventoryResult.VirtualCurrency.hasOwnProperty("CO")) {
  660.         RetObj["Coins"] = GetUserInventoryResult.VirtualCurrency.CO;
  661.         RetObj["Success"] = true;
  662.     }
  663.     else {
  664.         RetObj["Success"] = false;
  665.     }
  666.  
  667.     return RetObj;
  668. }
  669.  
  670. handlers.OnPlayerIdleRun = function(args)
  671. {
  672.     var GetUserInventoryRequest =
  673.     {
  674.         "PlayFabId": currentPlayerId
  675.     };
  676.     var GetUserInventoryResult = server.GetUserInventory(GetUserInventoryRequest);
  677.  
  678.     if (GetUserInventoryResult.VirtualCurrency.hasOwnProperty("CO"))
  679.     {
  680.         var CoinsOwned = GetUserInventoryResult.VirtualCurrency.CO;
  681.  
  682.         var Bet = GetDefaultBet(CoinsOwned);
  683.  
  684.         var RunningTotal = 0;
  685.  
  686.         for (var i = 0; i < AUTOSPINSPERHOUR; i++)
  687.         {
  688.             var SpinObj = {};
  689.  
  690.             SpinObj["Wheel1"] = SetWheel(WHEEL1RNG, false);
  691.             SpinObj["Wheel2"] = SetWheel(WHEEL2RNG, false);
  692.             SpinObj["Wheel3"] = SetWheel(WHEEL3RNG, false);
  693.             SpinObj["Wheel4"] = SetWheel(WHEEL4RNG, false);
  694.             SpinObj["Wheel5"] = SetWheel(WHEEL5RNG, false);
  695.  
  696.             SpinObj = CalculateWins(SpinObj, Bet, false, true);
  697.  
  698.             var Total = SpinObj.TotalWin;
  699.  
  700.             if(SpinObj.hasOwnProperty("FreeSpinTotalWin"))
  701.             {
  702.                 Total += SpinObj.FreeSpinTotalWin;
  703.             }
  704.  
  705.             if (SpinObj.hasOwnProperty("BonusTotalWin"))
  706.             {
  707.                 Total += SpinObj.BonusTotalWin;
  708.             }
  709.  
  710.             RunningTotal += Total;
  711.         }
  712.  
  713.         //if (RunningTotal > 0)
  714.         //{
  715.         //    var AddUserVirtualCurrencyRequest =
  716.         //    {
  717.         //        "PlayFabId": currentPlayerId,
  718.         //        "VirtualCurrency": "CO",
  719.         //        "Amount": RunningTotal
  720.         //    };
  721.         //    var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
  722.         //}
  723.         //else if (RunningTotal < 0)
  724.         //{
  725.         //    var SubtractUserVirtualCurrencyRequest =
  726.         //    {
  727.         //        "PlayFabId": currentPlayerId,
  728.         //        "VirtualCurrency": "CO",
  729.         //        "Amount": -RunningTotal
  730.         //    };
  731.         //    var SubtractUserVirtualCurrencyResult = server.SubtractUserVirtualCurrency(SubtractUserVirtualCurrencyRequest);
  732.         //}
  733.  
  734.         server.UpdatePlayerStatistics(
  735.         {
  736.             PlayFabId: currentPlayerId,
  737.             Statistics:
  738.             [{
  739.                 StatisticName: "IdleCoins",
  740.                 Value: RunningTotal
  741.             }]
  742.         });
  743.  
  744.         return RunningTotal;
  745.     }
  746. }
  747.  
  748. function GetDefaultBet(Coins)
  749. {
  750.     var Distances = [];
  751.  
  752.     for (var i = 0; i < POSSIBLEBETSPERLINE.length; i++)
  753.     {
  754.         Distances.push(Math.abs(Coins - (POSSIBLEBETSPERLINE[i] * 25 * 40)));
  755.     }
  756.  
  757.     return Distances.indexOf(Math.min.apply(null, Distances));
  758. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement