Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.89 KB | None | 0 0
  1. var config = {
  2. betBalance: { type: 'multiplier', label: 'Max portion of balance to start bet with.', value: 0.0001 },
  3. baseBet: { type: 'balance', label: 'Extra amount added to base bet', value: 0 },
  4. averageVariation: { type: 'multiplier', label: 'Average variation for min/max payout', value: 0.5 },
  5. maxPayout: { type: 'multiplier', label: 'Upper bound limit on payout', value: 3.5 },
  6. minPayout: { type: 'multiplier', label: 'Lower bound limit on payout', value: 1.3 },
  7. cargo: { type: 'number', label: 'Cargo of history length to use for build median', value: 20 },
  8. minProfit: { type: 'balance', label: 'Minimal profit', value: -50000 },
  9. maxProfit: { type: 'balance', label: 'Maximal profit', value: 10000 },
  10. skips_freq: { type: 'number', label: 'Skips after restart', value: 0 },
  11. reset_profits: { type: 'checkbox', label: 'Reset profit at hitting limit of min/max profits', value: true },
  12. reset_seed_at_restart: { type: 'checkbox', label: 'On bust seed also will be reset', value: true },
  13. reset_seed_target_at_restart: { type: 'checkbox', label: 'Reset seed on profit goal complete', value: false },
  14. stop_on_double_loss: { type: 'checkbox', label: 'Stop on double loss of minProfit', value: true },
  15. betSpeed: { type: 'number', label: 'Bet Speed(ms)', value: 1 },
  16. maxBalance: { type: 'number', label: 'Stop script @ Balance bits', value: 6000 },
  17. };
  18. var config_hided = {
  19. fast: false,
  20. reset_browser_stats_at_begin: true,
  21. nosound: true,
  22. play_intro: true,
  23. debug: true,
  24. };
  25. var engine = this
  26. var locked_balance = this.balance
  27. var startingBalance = this.balance
  28.  
  29. var findStreak = 0
  30. var streakRolls = 0
  31. var streakLossCount = 0
  32. var maxBalance = config.maxBalance.value
  33.  
  34. var results = [], loses = [], vectorApex = 0, nextBet = 0, nonce = 1, total_profit = 0;
  35. var min_Profit = config.minProfit.value, max_Profit = config.maxProfit.value , profit = 0, baseBet = config.baseBet.value, losses = 0, reached = false, total_profit = 0;
  36. var wagered = 0, gross_profit = 0;
  37. var minPayout = config.minPayout.value, maxPayout = config.maxPayout.value;
  38.  
  39. var normal_bettable = config.betBalance.value;
  40. var ripped = false
  41. var hitter_counter = 0, recovery_rolls = 0, defence_rolls = 0;
  42.  
  43. var result, profit_risk = 0, wins = 0;
  44.  
  45. Array.prototype.median = function (span) {
  46. let arr = results.slice(0, (span ? Math.max(1, Math.min(50, span)) : 50)).map(a => a.bust).sort((a, b) => { return a - b })
  47. let mid = arr.length / 2, med = mid % 1 ? arr[mid - 0.5] : (arr[mid - 1] + arr[mid]) / 2;
  48. return med;
  49. };
  50.  
  51. /***************************************************************** */
  52.  
  53. function recovery_mode (state, effect = 0){
  54. switch (state) {
  55. case true:
  56. console.log(`Recovery started!`)
  57. recovery_rolls = effect;
  58. case false:
  59. console.log(`Recovery ended!`)
  60. hitter_counter = 0;
  61. }
  62. }
  63.  
  64. function defence_mode (state, effect = 0){
  65. switch (state) {
  66. case true:
  67. console.log(`Defence started!`)
  68. defence_rolls = effect;
  69. case false:
  70. console.log(`Defence ended!`)
  71. defence_rolls = 0;
  72.  
  73. }
  74. }
  75.  
  76. /********************* - Assign to betting - ************************ */
  77.  
  78. const origBet = this.bet;
  79. this.bet = async function () {
  80. await updateLog()
  81. nonce++
  82. return origBet.apply(this, arguments);
  83. };
  84. const origSkip = this.skip;
  85. this.skip = async function () {
  86. await updateLog()
  87. nonce++
  88. return origSkip.apply(this, arguments);
  89. };
  90.  
  91. /************************** - Effects - ************************* */
  92.  
  93. function recovery_effect(multiplier_modificator){
  94. if (hitter_counter < 2) return
  95.  
  96. let recovery_multiplier = multiplier_modificator
  97. let recovery_bettable = config.betBalance.value * recovery_multiplier
  98.  
  99. if (recovery_rolls > 0){
  100. normal_bettable = recovery_bettable;
  101. recovery_rolls--;
  102. console.log(`Recovery mode will lasts more ${recovery_rolls} rolls`)
  103. }
  104. if (recovery_rolls <= 0) {
  105. normal_bettable = config.betBalance.value;
  106. recovery_rolls = 0
  107. }
  108. }
  109.  
  110. function defence_effect(multiplier_modificator){
  111. if (hitter_counter < 3) return
  112. let defence_multiplier = multiplier_modificator
  113. let defence_bettable = config.betBalance.value / defence_multiplier
  114.  
  115. if (defence_rolls > 0){
  116. //normal_bettable = defence_bettable;
  117. minPayout = config.minPayout.value + config.averageVariation.value
  118. maxPayout = config.maxPayout.value + config.averageVariation.value
  119. defence_rolls--;
  120. console.log(`Defence mode will lasts more ${recovery_rolls} rolls`)
  121. } else {
  122. //normal_bettable = config.betBalance.value;
  123. minPayout = config.minPayout.value
  124. maxPayout = config.maxPayout.value
  125. defence_rolls = 0;
  126. }
  127. }
  128.  
  129. /*************************** - Targets - **************************** */
  130.  
  131. function clampTarget(target) { return Math.max(minPayout, Math.min(maxPayout, target)); }
  132.  
  133. function calcTarget(results) {
  134. const pLen = results.length
  135. if ( pLen < config.cargo.value) { return; } /* Not enough input to slice. Returning.*/
  136. const r = results.slice(-config.cargo.value).sort((a, b) => a - b), len = r.length, mid = Math.floor(len / 2)
  137. return clampTarget((len % 2 ? r[mid] : ((r[mid - 1] + r[mid]) / 2)));
  138. }
  139.  
  140. /************************** - Bets - ************************** */
  141.  
  142. function roundBit(bet) { return Math.max(100, Math.round(bet / 100) * 100);}
  143.  
  144. const calcBet = () => {
  145. const betBalPerc = normal_bettable, lossCount = loses.length || 0;
  146.  
  147. baseBet = roundBit(config.baseBet.value + (engine.balance * (betBalPerc / (200 - lossCount))));
  148. vectorApex = calcTarget(results);
  149.  
  150. if (!lossCount) { return baseBet; }
  151.  
  152. losses = (loses.reduce((a, b) => a + b) * 100);
  153. nextBet = roundBit((baseBet + losses) / (vectorApex - 1));
  154.  
  155. return nextBet;
  156. };
  157.  
  158. /*************************** - Methods - *********************** */
  159.  
  160.  
  161. async function updateLog(){
  162. var maximum_lose = ` Maximum lose: ${session_win() / 100} `
  163. let extra = ` Extra base bet ${(baseBet / 100).toFixed()} + `
  164. let rolls_amount = `Nonce: ${nonce} `
  165. let Dmode = `[D]`
  166. let Rmode = `[R]`
  167. let Bbet = `[B = ${Math.round(normal_bettable).toFixed()}]`
  168. let HC = `[HC = ${hitter_counter}]`
  169.  
  170. if (recovery_rolls > 0){Rmode = `[R = ${recovery_rolls}]`} else {Rmode = ``}
  171. if (defence_rolls > 0){Dmode = `[D = ${defence_rolls}]`} else {Dmode = ``}
  172. if (hitter_counter > 0){HC = `[HC = ${hitter_counter}]`} else {HC = ``}
  173. if (config.baseBet.value == 0){ extra = `` }
  174.  
  175. engine.clearLog()
  176. engine.log(`${rolls_amount}|${extra} | NextBet: ${(losses / 100).toFixed()} / ${vectorApex.toFixed(2)}x = ${( nextBet / 100)} bits | Start Bal: ${startingBalance} | streakRolls: ${streakRolls} | Streak Loss: ${streakLossCount}`)
  177. if (reached){
  178. engine.log(`${HC}${Dmode}${Rmode}${Bbet}${maximum_lose}| PROFIT: ${(profit / 100).toFixed(2)} | ${(getTotalProfit())} bits`)
  179. } else {
  180. engine.log(`${HC}${Dmode}${Rmode}${Bbet}${maximum_lose}| profit goal: ${max_Profit / 100} | PROFIT: ${(profit / 100).toFixed(2)} | ${(getTotalProfit())} bits`)
  181. }
  182. if (config_hided.debug){engine.log(`${min_Profit / 100} | ${config.minProfit.value / 100} | ${session_win() / 100} | ${wins}`)}
  183. await sleep(config.betSpeed.value);
  184. }
  185.  
  186. function get_random(rnd = 10) { return Math.round(Math.random() * rnd) + 1 }
  187.  
  188. function sleep(ms = config.betSpeed.value) { if(ms != 0) { return new Promise(resolve => setTimeout(resolve, ms)) }};
  189.  
  190. async function skip_games(context, skips){
  191. //if (config.skips_freq.value > 0){
  192. for (let i = 0; i < get_random(skips); i++){
  193. const { multiplier } = await context.skip();
  194. }
  195. //}
  196. }
  197.  
  198. function getProfit(){
  199. let current_profit = (((wagered + gross_profit) - wagered) / 100).toFixed(2)
  200. return current_profit
  201. }
  202. function getTotalProfit(){
  203. return (total_profit / 100).toFixed(2)
  204. }
  205. function updateProfit(value){
  206. if (value > 0){
  207. gross_profit += value
  208. }
  209. wagered += Math.abs(value)
  210. profit += value
  211. total_profit += value
  212. }
  213.  
  214. async function checkConditions(){
  215. let _minProfit;
  216.  
  217. if (wins == 0) {_minProfit = config.minProfit.value }
  218. if ((wins * (config.maxProfit.value / 2)) - nextBet < session_win()) {
  219.  
  220. loses = []
  221. wins = 0
  222. profit = 0
  223. nextBet = roundBit(calcBet())
  224.  
  225. if (config.reset_seed_target_at_restart.value){
  226. //await generateSeed(engine)
  227. // findStreak = 0
  228. // await streakFinder()
  229.  
  230. }
  231. }
  232. //await getBuffs()
  233. }
  234. function session_win(){
  235. let give_cost = config.maxProfit.value
  236.  
  237.  
  238. if (profit > config.maxProfit.value){
  239. profit -= give_cost // |> buy
  240. // </> trade
  241. wins = wins + 1 // <| receive item
  242. }
  243. //nextBet = roundBit(calcBet())
  244.  
  245. let formula = 0
  246. if (wins > 0){
  247. formula = (wins * config.maxProfit.value) / 2
  248. } else if (wins <= 0) {
  249. formula = config.minProfit.value
  250. }
  251. return formula
  252. }
  253.  
  254. async function getBuffs() {
  255. if (engine.balance < locked_balance + config.minProfit.value) {
  256. await get_initial_data(engine)
  257. if (config.stop_on_double_loss.value) {
  258. // engine.log(`Stopped script due loss`)
  259. // engine.stop()
  260. findStreak = 0
  261. await streakFinder(1)
  262. } else {
  263. hitter_counter++
  264. if (hitter_counter >= 1 && recovery_rolls <= 0) {
  265. recovery_mode(true, 30)
  266. }
  267. if (hitter_counter >= 2 && defence_rolls <= 0) {
  268. defence_mode(true, 50)
  269. }
  270. }
  271. }
  272. }
  273.  
  274. // CHECK FOR ACTIVE EFFECTS
  275. function checkBuffs() {
  276. defence_effect(3)
  277. recovery_effect(3)
  278. }
  279.  
  280. async function generateSeed(context) {
  281. try {
  282. const { server_seed_hash } = await context.newSeedPair()
  283. await context.setClientSeed(server_seed_hash)
  284. nonce = 1
  285. }
  286. catch (e) { console.log(`Seed Pair is already was set and still not used.`) }
  287. }
  288.  
  289. async function play_tick_sound(sound, delay = true){
  290. let second = 1000
  291. if (!delay) second = 0
  292. if (config_hided.fast == false) await sleep(second)
  293. if (!config_hided.nosound) SE.play_raw(SE.song(sound))
  294. }
  295.  
  296. async function count_down(context){
  297. let _nextBet = nextBet / 100
  298. context.log(`Game is restarting!`)
  299. play_tick_sound(0)
  300. context.clearLog()
  301.  
  302. context.log(`Starts in...3 seconds!`)
  303. play_tick_sound(0)
  304. context.log(`NEXT BET: ${_nextBet} bits`)
  305. context.clearLog()
  306.  
  307. context.log(`Starts in...2 seconds!`)
  308. play_tick_sound(0)
  309. context.log(`NEXT BET: ${_nextBet} bits`)
  310. context.clearLog()
  311.  
  312. context.log(`Starts in...1 seconds!`)
  313. play_tick_sound(0)
  314. context.log(`NEXT BET: ${_nextBet} bits`)
  315. context.clearLog()
  316.  
  317. context.log(`-------STARTED-------`)
  318. play_tick_sound(1)
  319. context.log(`NEXT BET: ${_nextBet} bits`)
  320. context.clearLog()
  321.  
  322. if (config.skips_freq.value > 0) await skip_games(context, config.skips_freq.value)
  323. }
  324.  
  325. class SoundEngine{
  326. constructor() {
  327. this.id = -1
  328. this.url = ``
  329. this.host = `https://raw.githubusercontent.com/ruzli/misc/master/`
  330. this.format = `.wav`
  331. this.name = ``
  332. this.library = []
  333. this.sound_track = [ `cl_hihat`, `claves`, `conga1`, `cowbell`, `hi_conga`, `hightom`, `rimshot`, `snare`, `tom1`, `sc` ]
  334. this.muted = false
  335.  
  336. this.default_sound_betting = 8
  337.  
  338. this.save(`https://freesound.org/data/previews/274/274178_5123851-lq.mp3`)
  339. this.save(`https://freesound.org/data/previews/411/411639_5121236-lq.mp3`)
  340. if (config_hided.play_intro ) this.play_raw(this.song(1))
  341. }
  342. get song_library(){
  343. return this.library
  344. }
  345.  
  346. /* Playing sound loop by number or by name from sound track listed below. */
  347. async sound_loop(sound_number = default_sound_betting(), name){
  348. await this.play(sound_number, name)
  349. }
  350.  
  351. async sound_beat(multiplier, beat_mode = false, beat_target = undefined) {
  352. if (multiplier == undefined) {
  353. console.log(`Something is wrong with sound engine.`)
  354. await sleep(3000)
  355. return
  356. }
  357. if (beat_mode) {
  358. if (multiplier < 5) {
  359. SoundEngine.prototype.sound_loop(8)
  360. } else if (multiplier < 10) {
  361. SoundEngine.prototype.sound_loop(1)
  362. } else if (multiplier < 15) {
  363. SoundEngine.prototype.sound_loop(2)
  364. } else if (multiplier < 20) {
  365. SoundEngine.prototype.sound_loop(5)
  366. } else if (multiplier < 25) {
  367. SoundEngine.prototype.sound_loop(4)
  368. } else if (multiplier < 30) {
  369. SoundEngine.prototype.sound_loop(6)
  370. } else if (multiplier < 35) {
  371. SoundEngine.prototype.sound_loop(7)
  372. } else if (multiplier < 40) {
  373. SoundEngine.prototype.sound_loop(0)
  374. } else {
  375. SoundEngine.prototype.sound_loop(3)
  376. }
  377. } else {
  378. if (multiplier >= beat_target || beat_target != undefined) {
  379. SoundEngine.prototype.sound_loop(8)
  380. } else {
  381. SoundEngine.prototype.sound_loop(3)
  382. }
  383. }
  384. }
  385.  
  386. set default_sound_betting(default_sound_number){
  387. this.default_sound = default_sound_number
  388. }
  389. link(){
  390. if (this.name != ``){
  391. return this.url + this.name + this.format
  392. }
  393. }
  394. song(song_number){
  395. return this.library[song_number]
  396. }
  397. save(url){
  398. this.library.push(url)
  399. }
  400. async play(sound_number, name){
  401. let sound_track = this.sound_track
  402. let url = this.host
  403. let format = this.format
  404.  
  405. let full_string = url + name + format
  406.  
  407. if (name != undefined) {
  408. full_string = url + name + format
  409. } else if (sound_number != undefined) {
  410. full_string = url + sound_track[ sound_number ] + format
  411. } else {
  412. console.log(`Sound ${sound_number} not found.`)
  413. }
  414. const audio = new Audio(full_string)
  415.  
  416. if (!this.muted) await audio.play()
  417.  
  418. return new Promise(resolve => audio.onended = resolve)
  419. }
  420. async play_raw(url){
  421. const audio = new Audio(url)
  422.  
  423. if (!this.muted) await audio.play()
  424.  
  425. return new Promise(resolve => audio.onended = resolve)
  426. }
  427. }
  428. var SE = new SoundEngine;
  429.  
  430. async function get_initial_data(context, rolls_to_gather = config.cargo.value){
  431. results = []
  432. while(results.length < rolls_to_gather) {
  433. const { multiplier } = await context.skip();
  434.  
  435. results.push(multiplier);
  436. if (!config_hided.nosound) SE.sound_loop(8)
  437. }
  438. }
  439.  
  440. async function streakFinder(s=0) {
  441. if(findStreak == 1){
  442. return
  443. }
  444. findStreak = 1
  445. profit = 0
  446. const streakToWait = 7
  447. const streakTofind = 1.5
  448. let RETRY = true
  449. nonce = 0
  450. streakRolls = 0
  451. streakLossCount = 0
  452. var streakskipStep = 1 /* 0 = skip | 1 = bet */
  453. var streakskip_enabled = true
  454. var stengine = engine
  455. if(s==1)await engine.newSeedPair()
  456. while (RETRY) {
  457. if(nonce > 100){
  458. RETRY = false
  459. await get_initial_data(engine)
  460. gong()
  461. }
  462. console.log(`In a row: ${streakLossCount}`)
  463. streakRolls++
  464. const {
  465. multiplier
  466. } = await analyzeBet()
  467.  
  468. if (multiplier < streakTofind) {
  469. streakLossCount++
  470. } else {
  471. streakLossCount = 0
  472. }
  473. if (streakLossCount == streakToWait) {
  474. console.log(`${streakRolls} streakRolls has pasted to catch streak. Good luck!`)
  475. await get_initial_data(engine)
  476. gong()
  477. RETRY = false
  478. // await this.stop()
  479. }
  480. }
  481. async function betSize(streakLossCount) {
  482. if (streakLossCount == streakToWait) {
  483. console.log(`${streakRolls} streakRolls has pasted to catch streak. Good luck!`)
  484. await get_initial_data(engine)
  485. gong()
  486. RETRY = false
  487. // await this.stop()
  488. }
  489. return 100
  490. }
  491.  
  492. function gong() {
  493. const audio = new Audio("https://bustadice.com/5bb187b7ef764e76fb519939f77288c1.mp3")
  494. audio.play()
  495. return new Promise(resolve => audio.onended = resolve)
  496. }
  497.  
  498. async function analyzeBet() {
  499. const streakresult = streakskip_enabled ? streakskipStep ? await engine.bet(100, 1.01) : await engine.skip() : await engine.bet(100, 1.01);
  500. streakskipStep = !streakskipStep;
  501.  
  502. return streakresult;
  503. }
  504. }
  505.  
  506. var RUNNING = true
  507.  
  508. var main = async () => {
  509. if (config_hided.reset_browser_stats_at_begin) this.resetStatistics()
  510.  
  511. await get_initial_data(this)
  512. while(RUNNING){
  513.  
  514. //checkBuffs()
  515. //await streakFinder(1)
  516.  
  517.  
  518. nextBet = roundBit(calcBet())
  519. vectorApex = calcTarget(results) // Get target
  520.  
  521. await checkConditions()
  522.  
  523. result = await this.bet(roundBit(nextBet),vectorApex.toFixed(2));
  524.  
  525. if (!config_hided.nosound) SE.sound_loop(8)
  526. results.push(result.multiplier);
  527.  
  528. if (result.multiplier < result.target) { // LOSE
  529. updateProfit(-result.value)
  530.  
  531. loses.push(nextBet / 100);
  532. const loss = loses.reduce((a, b) => a + b);
  533. if((engine.balance-startingBalance) <= min_Profit/2){
  534. //engine.stop()
  535. startingBalance = engine.balance
  536. findStreak = 0
  537. //loses = []
  538.  
  539. await streakFinder(1)
  540.  
  541. await get_initial_data(this)
  542.  
  543. }
  544.  
  545. } else { // WIN
  546. loses = []
  547. updateProfit((result.value * result.target) - result.value);
  548. if(engine.balance/100 > maxBalance) engine.stop()
  549. if((engine.balance-startingBalance) >= max_Profit){
  550. startingBalance = engine.balance
  551. // findStreak = 0
  552. // await streakFinder(1)
  553.  
  554. await get_initial_data(this)
  555.  
  556. }
  557.  
  558. }
  559. }
  560. };
  561.  
  562. async function restart_game(){
  563. if (engine.balance < locked_balance + config.minProfit.value ){
  564. locked_balance = engine.balance
  565. console.log(`Restarting game`)
  566. await engine.stop()
  567. //await skip_games(context, config.cargo.value)
  568. }
  569. }
  570. /* Prevent script from lost connection to server */
  571. while (true) {
  572. // WATCH FOR ERROR IN MAIN LOOP
  573. try {await main()} // MAIN LOOP
  574. catch (error) {
  575. // ERROR EVENTS TO HANDLE
  576. if (error.message === "connection closed") {
  577. await this.log("Connection closed. Restarting script");
  578. RUNNING = true
  579. continue;
  580. } else if (error.message === "insufficient balance") {
  581. await this.log("Not enough balance to bet");
  582. } else {
  583. throw error;
  584. };
  585. };
  586. };
  587. var config = {
  588. betBalance: { type: 'multiplier', label: 'Max portion of balance to start bet with.', value: 0.0001 },
  589. baseBet: { type: 'balance', label: 'Extra amount added to base bet', value: 0 },
  590. averageVariation: { type: 'multiplier', label: 'Average variation for min/max payout', value: 0.5 },
  591. maxPayout: { type: 'multiplier', label: 'Upper bound limit on payout', value: 3.5 },
  592. minPayout: { type: 'multiplier', label: 'Lower bound limit on payout', value: 1.3 },
  593. cargo: { type: 'number', label: 'Cargo of history length to use for build median', value: 20 },
  594. minProfit: { type: 'balance', label: 'Minimal profit', value: -50000 },
  595. maxProfit: { type: 'balance', label: 'Maximal profit', value: 10000 },
  596. skips_freq: { type: 'number', label: 'Skips after restart', value: 0 },
  597. reset_profits: { type: 'checkbox', label: 'Reset profit at hitting limit of min/max profits', value: true },
  598. reset_seed_at_restart: { type: 'checkbox', label: 'On bust seed also will be reset', value: true },
  599. reset_seed_target_at_restart: { type: 'checkbox', label: 'Reset seed on profit goal complete', value: false },
  600. stop_on_double_loss: { type: 'checkbox', label: 'Stop on double loss of minProfit', value: true },
  601. betSpeed: { type: 'number', label: 'Bet Speed(ms)', value: 1 },
  602. maxBalance: { type: 'number', label: 'Stop script @ Balance bits', value: 6000 },
  603. };
  604. var config_hided = {
  605. fast: false,
  606. reset_browser_stats_at_begin: true,
  607. nosound: true,
  608. play_intro: true,
  609. debug: true,
  610. };
  611. var engine = this
  612. var locked_balance = this.balance
  613. var startingBalance = this.balance
  614.  
  615. var findStreak = 0
  616. var streakRolls = 0
  617. var streakLossCount = 0
  618. var maxBalance = config.maxBalance.value
  619.  
  620. var results = [], loses = [], vectorApex = 0, nextBet = 0, nonce = 1, total_profit = 0;
  621. var min_Profit = config.minProfit.value, max_Profit = config.maxProfit.value , profit = 0, baseBet = config.baseBet.value, losses = 0, reached = false, total_profit = 0;
  622. var wagered = 0, gross_profit = 0;
  623. var minPayout = config.minPayout.value, maxPayout = config.maxPayout.value;
  624.  
  625. var normal_bettable = config.betBalance.value;
  626. var ripped = false
  627. var hitter_counter = 0, recovery_rolls = 0, defence_rolls = 0;
  628.  
  629. var result, profit_risk = 0, wins = 0;
  630.  
  631. Array.prototype.median = function (span) {
  632. let arr = results.slice(0, (span ? Math.max(1, Math.min(50, span)) : 50)).map(a => a.bust).sort((a, b) => { return a - b })
  633. let mid = arr.length / 2, med = mid % 1 ? arr[mid - 0.5] : (arr[mid - 1] + arr[mid]) / 2;
  634. return med;
  635. };
  636.  
  637. /***************************************************************** */
  638.  
  639. function recovery_mode (state, effect = 0){
  640. switch (state) {
  641. case true:
  642. console.log(`Recovery started!`)
  643. recovery_rolls = effect;
  644. case false:
  645. console.log(`Recovery ended!`)
  646. hitter_counter = 0;
  647. }
  648. }
  649.  
  650. function defence_mode (state, effect = 0){
  651. switch (state) {
  652. case true:
  653. console.log(`Defence started!`)
  654. defence_rolls = effect;
  655. case false:
  656. console.log(`Defence ended!`)
  657. defence_rolls = 0;
  658.  
  659. }
  660. }
  661.  
  662. /********************* - Assign to betting - ************************ */
  663.  
  664. const origBet = this.bet;
  665. this.bet = async function () {
  666. await updateLog()
  667. nonce++
  668. return origBet.apply(this, arguments);
  669. };
  670. const origSkip = this.skip;
  671. this.skip = async function () {
  672. await updateLog()
  673. nonce++
  674. return origSkip.apply(this, arguments);
  675. };
  676.  
  677. /************************** - Effects - ************************* */
  678.  
  679. function recovery_effect(multiplier_modificator){
  680. if (hitter_counter < 2) return
  681.  
  682. let recovery_multiplier = multiplier_modificator
  683. let recovery_bettable = config.betBalance.value * recovery_multiplier
  684.  
  685. if (recovery_rolls > 0){
  686. normal_bettable = recovery_bettable;
  687. recovery_rolls--;
  688. console.log(`Recovery mode will lasts more ${recovery_rolls} rolls`)
  689. }
  690. if (recovery_rolls <= 0) {
  691. normal_bettable = config.betBalance.value;
  692. recovery_rolls = 0
  693. }
  694. }
  695.  
  696. function defence_effect(multiplier_modificator){
  697. if (hitter_counter < 3) return
  698. let defence_multiplier = multiplier_modificator
  699. let defence_bettable = config.betBalance.value / defence_multiplier
  700.  
  701. if (defence_rolls > 0){
  702. //normal_bettable = defence_bettable;
  703. minPayout = config.minPayout.value + config.averageVariation.value
  704. maxPayout = config.maxPayout.value + config.averageVariation.value
  705. defence_rolls--;
  706. console.log(`Defence mode will lasts more ${recovery_rolls} rolls`)
  707. } else {
  708. //normal_bettable = config.betBalance.value;
  709. minPayout = config.minPayout.value
  710. maxPayout = config.maxPayout.value
  711. defence_rolls = 0;
  712. }
  713. }
  714.  
  715. /*************************** - Targets - **************************** */
  716.  
  717. function clampTarget(target) { return Math.max(minPayout, Math.min(maxPayout, target)); }
  718.  
  719. function calcTarget(results) {
  720. const pLen = results.length
  721. if ( pLen < config.cargo.value) { return; } /* Not enough input to slice. Returning.*/
  722. const r = results.slice(-config.cargo.value).sort((a, b) => a - b), len = r.length, mid = Math.floor(len / 2)
  723. return clampTarget((len % 2 ? r[mid] : ((r[mid - 1] + r[mid]) / 2)));
  724. }
  725.  
  726. /************************** - Bets - ************************** */
  727.  
  728. function roundBit(bet) { return Math.max(100, Math.round(bet / 100) * 100);}
  729.  
  730. const calcBet = () => {
  731. const betBalPerc = normal_bettable, lossCount = loses.length || 0;
  732.  
  733. baseBet = roundBit(config.baseBet.value + (engine.balance * (betBalPerc / (200 - lossCount))));
  734. vectorApex = calcTarget(results);
  735.  
  736. if (!lossCount) { return baseBet; }
  737.  
  738. losses = (loses.reduce((a, b) => a + b) * 100);
  739. nextBet = roundBit((baseBet + losses) / (vectorApex - 1));
  740.  
  741. return nextBet;
  742. };
  743.  
  744. /*************************** - Methods - *********************** */
  745.  
  746.  
  747. async function updateLog(){
  748. var maximum_lose = ` Maximum lose: ${session_win() / 100} `
  749. let extra = ` Extra base bet ${(baseBet / 100).toFixed()} + `
  750. let rolls_amount = `Nonce: ${nonce} `
  751. let Dmode = `[D]`
  752. let Rmode = `[R]`
  753. let Bbet = `[B = ${Math.round(normal_bettable).toFixed()}]`
  754. let HC = `[HC = ${hitter_counter}]`
  755.  
  756. if (recovery_rolls > 0){Rmode = `[R = ${recovery_rolls}]`} else {Rmode = ``}
  757. if (defence_rolls > 0){Dmode = `[D = ${defence_rolls}]`} else {Dmode = ``}
  758. if (hitter_counter > 0){HC = `[HC = ${hitter_counter}]`} else {HC = ``}
  759. if (config.baseBet.value == 0){ extra = `` }
  760.  
  761. engine.clearLog()
  762. engine.log(`${rolls_amount}|${extra} | NextBet: ${(losses / 100).toFixed()} / ${vectorApex.toFixed(2)}x = ${( nextBet / 100)} bits | Start Bal: ${startingBalance} | streakRolls: ${streakRolls} | Streak Loss: ${streakLossCount}`)
  763. if (reached){
  764. engine.log(`${HC}${Dmode}${Rmode}${Bbet}${maximum_lose}| PROFIT: ${(profit / 100).toFixed(2)} | ${(getTotalProfit())} bits`)
  765. } else {
  766. engine.log(`${HC}${Dmode}${Rmode}${Bbet}${maximum_lose}| profit goal: ${max_Profit / 100} | PROFIT: ${(profit / 100).toFixed(2)} | ${(getTotalProfit())} bits`)
  767. }
  768. if (config_hided.debug){engine.log(`${min_Profit / 100} | ${config.minProfit.value / 100} | ${session_win() / 100} | ${wins}`)}
  769. await sleep(config.betSpeed.value);
  770. }
  771.  
  772. function get_random(rnd = 10) { return Math.round(Math.random() * rnd) + 1 }
  773.  
  774. function sleep(ms = config.betSpeed.value) { if(ms != 0) { return new Promise(resolve => setTimeout(resolve, ms)) }};
  775.  
  776. async function skip_games(context, skips){
  777. //if (config.skips_freq.value > 0){
  778. for (let i = 0; i < get_random(skips); i++){
  779. const { multiplier } = await context.skip();
  780. }
  781. //}
  782. }
  783.  
  784. function getProfit(){
  785. let current_profit = (((wagered + gross_profit) - wagered) / 100).toFixed(2)
  786. return current_profit
  787. }
  788. function getTotalProfit(){
  789. return (total_profit / 100).toFixed(2)
  790. }
  791. function updateProfit(value){
  792. if (value > 0){
  793. gross_profit += value
  794. }
  795. wagered += Math.abs(value)
  796. profit += value
  797. total_profit += value
  798. }
  799.  
  800. async function checkConditions(){
  801. let _minProfit;
  802.  
  803. if (wins == 0) {_minProfit = config.minProfit.value }
  804. if ((wins * (config.maxProfit.value / 2)) - nextBet < session_win()) {
  805.  
  806. loses = []
  807. wins = 0
  808. profit = 0
  809. nextBet = roundBit(calcBet())
  810.  
  811. if (config.reset_seed_target_at_restart.value){
  812. //await generateSeed(engine)
  813. // findStreak = 0
  814. // await streakFinder()
  815.  
  816. }
  817. }
  818. //await getBuffs()
  819. }
  820. function session_win(){
  821. let give_cost = config.maxProfit.value
  822.  
  823.  
  824. if (profit > config.maxProfit.value){
  825. profit -= give_cost // |> buy
  826. // </> trade
  827. wins = wins + 1 // <| receive item
  828. }
  829. //nextBet = roundBit(calcBet())
  830.  
  831. let formula = 0
  832. if (wins > 0){
  833. formula = (wins * config.maxProfit.value) / 2
  834. } else if (wins <= 0) {
  835. formula = config.minProfit.value
  836. }
  837. return formula
  838. }
  839.  
  840. async function getBuffs() {
  841. if (engine.balance < locked_balance + config.minProfit.value) {
  842. await get_initial_data(engine)
  843. if (config.stop_on_double_loss.value) {
  844. // engine.log(`Stopped script due loss`)
  845. // engine.stop()
  846. findStreak = 0
  847. await streakFinder(1)
  848. } else {
  849. hitter_counter++
  850. if (hitter_counter >= 1 && recovery_rolls <= 0) {
  851. recovery_mode(true, 30)
  852. }
  853. if (hitter_counter >= 2 && defence_rolls <= 0) {
  854. defence_mode(true, 50)
  855. }
  856. }
  857. }
  858. }
  859.  
  860. // CHECK FOR ACTIVE EFFECTS
  861. function checkBuffs() {
  862. defence_effect(3)
  863. recovery_effect(3)
  864. }
  865.  
  866. async function generateSeed(context) {
  867. try {
  868. const { server_seed_hash } = await context.newSeedPair()
  869. await context.setClientSeed(server_seed_hash)
  870. nonce = 1
  871. }
  872. catch (e) { console.log(`Seed Pair is already was set and still not used.`) }
  873. }
  874.  
  875. async function play_tick_sound(sound, delay = true){
  876. let second = 1000
  877. if (!delay) second = 0
  878. if (config_hided.fast == false) await sleep(second)
  879. if (!config_hided.nosound) SE.play_raw(SE.song(sound))
  880. }
  881.  
  882. async function count_down(context){
  883. let _nextBet = nextBet / 100
  884. context.log(`Game is restarting!`)
  885. play_tick_sound(0)
  886. context.clearLog()
  887.  
  888. context.log(`Starts in...3 seconds!`)
  889. play_tick_sound(0)
  890. context.log(`NEXT BET: ${_nextBet} bits`)
  891. context.clearLog()
  892.  
  893. context.log(`Starts in...2 seconds!`)
  894. play_tick_sound(0)
  895. context.log(`NEXT BET: ${_nextBet} bits`)
  896. context.clearLog()
  897.  
  898. context.log(`Starts in...1 seconds!`)
  899. play_tick_sound(0)
  900. context.log(`NEXT BET: ${_nextBet} bits`)
  901. context.clearLog()
  902.  
  903. context.log(`-------STARTED-------`)
  904. play_tick_sound(1)
  905. context.log(`NEXT BET: ${_nextBet} bits`)
  906. context.clearLog()
  907.  
  908. if (config.skips_freq.value > 0) await skip_games(context, config.skips_freq.value)
  909. }
  910.  
  911. class SoundEngine{
  912. constructor() {
  913. this.id = -1
  914. this.url = ``
  915. this.host = `https://raw.githubusercontent.com/ruzli/misc/master/`
  916. this.format = `.wav`
  917. this.name = ``
  918. this.library = []
  919. this.sound_track = [ `cl_hihat`, `claves`, `conga1`, `cowbell`, `hi_conga`, `hightom`, `rimshot`, `snare`, `tom1`, `sc` ]
  920. this.muted = false
  921.  
  922. this.default_sound_betting = 8
  923.  
  924. this.save(`https://freesound.org/data/previews/274/274178_5123851-lq.mp3`)
  925. this.save(`https://freesound.org/data/previews/411/411639_5121236-lq.mp3`)
  926. if (config_hided.play_intro ) this.play_raw(this.song(1))
  927. }
  928. get song_library(){
  929. return this.library
  930. }
  931.  
  932. /* Playing sound loop by number or by name from sound track listed below. */
  933. async sound_loop(sound_number = default_sound_betting(), name){
  934. await this.play(sound_number, name)
  935. }
  936.  
  937. async sound_beat(multiplier, beat_mode = false, beat_target = undefined) {
  938. if (multiplier == undefined) {
  939. console.log(`Something is wrong with sound engine.`)
  940. await sleep(3000)
  941. return
  942. }
  943. if (beat_mode) {
  944. if (multiplier < 5) {
  945. SoundEngine.prototype.sound_loop(8)
  946. } else if (multiplier < 10) {
  947. SoundEngine.prototype.sound_loop(1)
  948. } else if (multiplier < 15) {
  949. SoundEngine.prototype.sound_loop(2)
  950. } else if (multiplier < 20) {
  951. SoundEngine.prototype.sound_loop(5)
  952. } else if (multiplier < 25) {
  953. SoundEngine.prototype.sound_loop(4)
  954. } else if (multiplier < 30) {
  955. SoundEngine.prototype.sound_loop(6)
  956. } else if (multiplier < 35) {
  957. SoundEngine.prototype.sound_loop(7)
  958. } else if (multiplier < 40) {
  959. SoundEngine.prototype.sound_loop(0)
  960. } else {
  961. SoundEngine.prototype.sound_loop(3)
  962. }
  963. } else {
  964. if (multiplier >= beat_target || beat_target != undefined) {
  965. SoundEngine.prototype.sound_loop(8)
  966. } else {
  967. SoundEngine.prototype.sound_loop(3)
  968. }
  969. }
  970. }
  971.  
  972. set default_sound_betting(default_sound_number){
  973. this.default_sound = default_sound_number
  974. }
  975. link(){
  976. if (this.name != ``){
  977. return this.url + this.name + this.format
  978. }
  979. }
  980. song(song_number){
  981. return this.library[song_number]
  982. }
  983. save(url){
  984. this.library.push(url)
  985. }
  986. async play(sound_number, name){
  987. let sound_track = this.sound_track
  988. let url = this.host
  989. let format = this.format
  990.  
  991. let full_string = url + name + format
  992.  
  993. if (name != undefined) {
  994. full_string = url + name + format
  995. } else if (sound_number != undefined) {
  996. full_string = url + sound_track[ sound_number ] + format
  997. } else {
  998. console.log(`Sound ${sound_number} not found.`)
  999. }
  1000. const audio = new Audio(full_string)
  1001.  
  1002. if (!this.muted) await audio.play()
  1003.  
  1004. return new Promise(resolve => audio.onended = resolve)
  1005. }
  1006. async play_raw(url){
  1007. const audio = new Audio(url)
  1008.  
  1009. if (!this.muted) await audio.play()
  1010.  
  1011. return new Promise(resolve => audio.onended = resolve)
  1012. }
  1013. }
  1014. var SE = new SoundEngine;
  1015.  
  1016. async function get_initial_data(context, rolls_to_gather = config.cargo.value){
  1017. results = []
  1018. while(results.length < rolls_to_gather) {
  1019. const { multiplier } = await context.skip();
  1020.  
  1021. results.push(multiplier);
  1022. if (!config_hided.nosound) SE.sound_loop(8)
  1023. }
  1024. }
  1025.  
  1026. async function streakFinder(s=0) {
  1027. if(findStreak == 1){
  1028. return
  1029. }
  1030. findStreak = 1
  1031. profit = 0
  1032. const streakToWait = 7
  1033. const streakTofind = 1.5
  1034. let RETRY = true
  1035. nonce = 0
  1036. streakRolls = 0
  1037. streakLossCount = 0
  1038. var streakskipStep = 1 /* 0 = skip | 1 = bet */
  1039. var streakskip_enabled = true
  1040. var stengine = engine
  1041. if(s==1)await engine.newSeedPair()
  1042. while (RETRY) {
  1043. if(nonce > 100){
  1044. RETRY = false
  1045. await get_initial_data(engine)
  1046. gong()
  1047. }
  1048. console.log(`In a row: ${streakLossCount}`)
  1049. streakRolls++
  1050. const {
  1051. multiplier
  1052. } = await analyzeBet()
  1053.  
  1054. if (multiplier < streakTofind) {
  1055. streakLossCount++
  1056. } else {
  1057. streakLossCount = 0
  1058. }
  1059. if (streakLossCount == streakToWait) {
  1060. console.log(`${streakRolls} streakRolls has pasted to catch streak. Good luck!`)
  1061. await get_initial_data(engine)
  1062. gong()
  1063. RETRY = false
  1064. // await this.stop()
  1065. }
  1066. }
  1067. async function betSize(streakLossCount) {
  1068. if (streakLossCount == streakToWait) {
  1069. console.log(`${streakRolls} streakRolls has pasted to catch streak. Good luck!`)
  1070. await get_initial_data(engine)
  1071. gong()
  1072. RETRY = false
  1073. // await this.stop()
  1074. }
  1075. return 100
  1076. }
  1077.  
  1078. function gong() {
  1079. const audio = new Audio("https://bustadice.com/5bb187b7ef764e76fb519939f77288c1.mp3")
  1080. audio.play()
  1081. return new Promise(resolve => audio.onended = resolve)
  1082. }
  1083.  
  1084. async function analyzeBet() {
  1085. const streakresult = streakskip_enabled ? streakskipStep ? await engine.bet(100, 1.01) : await engine.skip() : await engine.bet(100, 1.01);
  1086. streakskipStep = !streakskipStep;
  1087.  
  1088. return streakresult;
  1089. }
  1090. }
  1091.  
  1092. var RUNNING = true
  1093.  
  1094. var main = async () => {
  1095. if (config_hided.reset_browser_stats_at_begin) this.resetStatistics()
  1096.  
  1097. await get_initial_data(this)
  1098. while(RUNNING){
  1099.  
  1100. //checkBuffs()
  1101. //await streakFinder(1)
  1102.  
  1103.  
  1104. nextBet = roundBit(calcBet())
  1105. vectorApex = calcTarget(results) // Get target
  1106.  
  1107. await checkConditions()
  1108.  
  1109. result = await this.bet(roundBit(nextBet),vectorApex.toFixed(2));
  1110.  
  1111. if (!config_hided.nosound) SE.sound_loop(8)
  1112. results.push(result.multiplier);
  1113.  
  1114. if (result.multiplier < result.target) { // LOSE
  1115. updateProfit(-result.value)
  1116.  
  1117. loses.push(nextBet / 100);
  1118. const loss = loses.reduce((a, b) => a + b);
  1119. if((engine.balance-startingBalance) <= min_Profit/2){
  1120. //engine.stop()
  1121. startingBalance = engine.balance
  1122. findStreak = 0
  1123. //loses = []
  1124.  
  1125. await streakFinder(1)
  1126.  
  1127. await get_initial_data(this)
  1128.  
  1129. }
  1130.  
  1131. } else { // WIN
  1132. loses = []
  1133. updateProfit((result.value * result.target) - result.value);
  1134. if(engine.balance/100 > maxBalance) engine.stop()
  1135. if((engine.balance-startingBalance) >= max_Profit){
  1136. startingBalance = engine.balance
  1137. // findStreak = 0
  1138. // await streakFinder(1)
  1139.  
  1140. await get_initial_data(this)
  1141.  
  1142. }
  1143.  
  1144. }
  1145. }
  1146. };
  1147.  
  1148. async function restart_game(){
  1149. if (engine.balance < locked_balance + config.minProfit.value ){
  1150. locked_balance = engine.balance
  1151. console.log(`Restarting game`)
  1152. await engine.stop()
  1153. //await skip_games(context, config.cargo.value)
  1154. }
  1155. }
  1156. /* Prevent script from lost connection to server */
  1157. while (true) {
  1158. // WATCH FOR ERROR IN MAIN LOOP
  1159. try {await main()} // MAIN LOOP
  1160. catch (error) {
  1161. // ERROR EVENTS TO HANDLE
  1162. if (error.message === "connection closed") {
  1163. await this.log("Connection closed. Restarting script");
  1164. RUNNING = true
  1165. continue;
  1166. } else if (error.message === "insufficient balance") {
  1167. await this.log("Not enough balance to bet");
  1168. } else {
  1169. throw error;
  1170. };
  1171. };
  1172. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement