forked from barrenechea/AutoDice
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModePro.xaml.cs
2251 lines (2144 loc) · 94 KB
/
ModePro.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shell;
using AutoDice.Sites;
using MahApps.Metro;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using Newtonsoft.Json;
using Sparrow.Chart;
namespace AutoDice
{
/// <summary>
/// Lógica de interacción para AdvancedMode.xaml
/// </summary>
public partial class ModePro
{
#region Variables
// Variables from Initial Settings
private double _NumStartingBet, _NumStartingChange;
private string _RollOverUnder;
// Variables from Martingale - On loss
private double _NumMultiplierLoss, _NumMaxMultipliesLoss, _NumAfterLoss, _NumMultiplierAfterLoss, _NumAfterXLossesInRowChangeBet, _NumAfterXLossesInRowChangeBetNumber, _NumAfterXLossesInRowChangeChance, _NumAfterXLossesInRowChangeChanceNumber;
private bool _RadMaxLoss, _RadVariableLoss, _RadConstrantLoss, _RadChangeOnceLoss, _ChkMultiplyOnlyOneTimeLoss;
private bool _ChkAfterLossesInRowChangeBet, _ChkAfterLossesInRowChangeChance, _ChkReturnBaseBetAfterFirstLoss;
// Variables from Martingale - On won
private double _NumMultiplierWon, _NumMaxMultipliesWon, _NumAfterWon, _NumMultiplierAfterWon, _NumAfterXWonsInRowChangeBet, _NumAfterXWonsInRowChangeBetNumber, _NumAfterXWonsInRowChangeChance, _NumAfterXWonsInRowChangeChanceNumber;
private bool _RadMaxWon, _RadVariableWon, _RadConstrantWon, _RadChangeOnceWon;
private bool _ChkAfterWonsInRowChangeBet, _ChkAfterWonsInRowChangeChance, _ChkReturnBaseBetAfterFirstWon = true;
// Variables for Fibonacci - On loss
private bool _ChkFibonacciLossIncrease = true, _ChkFibonacciLossRestart = false, _ChkFibonacciLossStop = false;
private int _NumFibonacciIncrementLoss = 1;
// Variables for Fibonacci - On won
private bool _ChkFibonacciWonIncrease = false, _ChkFibonacciWonRestart = true, _ChkFibonacciWonStop = false;
private int _NumFibonacciIncrementWon = -1;
// Other Fibonacci Variables
private bool _ChkFibonacciWhenLevel, _ChkFibonacciWhenLevelReset, _ChkFibonacciWhenLevelStop, _fibonacci;
private int _NumFibonacciWhenLevel = 10, FibonacciLevel = 0;
// Variables for Constructor
private readonly DiceSite _currentSite;
private readonly string _username;
// Winstreak, Losingstreak and Max Winning Streak and Max Losing Streak
private int _WinStreak, _LossStreak, _MaxWinStreak, _MaxLossStreak;
// Variables for Stop Conditions
private bool _ChkBalanceLimit, _ChkBalanceLowerLimit, _ChkStopAfterBTCLoss,
_ChkStopAfterLossesInRow, _ChkResetAfterBTCLoss, _ChkResetAfterLossesInRow,
_ChkStopAfterBTCProfit, _ChkStopAfterWonsInRow, _ChkResetAfterBTCProfit, _ChkResetAfterWonsInRow;
private double _NumBalanceLimit, _NumBalanceLowerLimit, _NumStopBTCLoss,
_NumResetBTCLoss, _NumStopBTCProfit, _NumResetBTCProfit,
_NumStopLosesInRow, _NumResetLosesInRow, _NumStopWonsInRow, _NumResetWonsInRow;
// Variables for measuring the speed of bets
private DateTime _initialDateTime;
private double _delay;
// Variables for Tipping
private string _Payee;
private double _AmountTip;
// Variables for Strategie Database
private readonly BackgroundWorker _cloudWorker = new BackgroundWorker();
private Strats _CloudStrats;
private GenericCheck _CloudLoadConnected;
private int CloudLoadMode;
private string _CloudLoadName;
private string[] CloudDownloadedStrat;
private int _CloudTotalBets, _CloudWinStreak, _CloudLossStreak;
private double _CloudProfit;
private string _CloudUploadName, _CloudUploadDescription, _CloudUploadMinBalance;
private string CloudUploadCode;
// Other variables
private readonly List<GenericDataGrid> _datosRoll = new List<GenericDataGrid>();
private readonly BackgroundWorker _rollWorker = new BackgroundWorker();
readonly BackgroundWorker _tipWorker = new BackgroundWorker();
readonly BackgroundWorker _balanceWorker = new BackgroundWorker();
private GenericBalance _tipData;
readonly IniParser _parser = new IniParser("config.ini");
private bool _HasCleanedGraph;
private ProgressDialogController _controller;
private int _WonsCounter, _LostCounter;
private double _BiggestWon, _BiggestLost, _BiggestBet, _Wagered;
private double _balance;
private bool _martingale, _manuallyStopped;
private bool _DoOneRoll, _StopOnWon, _AutoScroll, _ShowWons, _ShowLosses;
// Variables for Martingale Logic
private double _CurrentMultiplier, _CurrentBet, _CurrentChance;
// Variables for Current roll data
private GenericRoll _roll;
private double _TotalProfit, _CurrentProfit, _AuxProfit;
#endregion
#region Constructor
/// <summary>
/// Constructor for General sites
/// </summary>
/// <param name="site">Current site</param>
/// <param name="username">Current username</param>
/// <param name="balance">Current balance (in BTC)</param>
public ModePro(DiceSite site, string username, double balance)
{
InitializeComponent();
_currentSite = site;
_username = username;
_balance = balance;
InitBackgroundWorkers();
InitThemeSettings();
Title = $"AutoDice Pro: {_username}";
}
#endregion
#region RollWorker Methods
#region DoWork
private void RollWorker_DoWork(object sender, DoWorkEventArgs e)
{
_CurrentProfit = 0;
_AuxProfit = 0;
_CurrentBet = _NumStartingBet;
_CurrentChance = _NumStartingChange;
_CurrentMultiplier = _NumMultiplierLoss;
_manuallyStopped = false;
_WinStreak = 0;
_LossStreak = 0;
var counter = 0;
_initialDateTime = DateTime.Now;
var timelapse = new Stopwatch();
while (!_manuallyStopped)
{
if ((sender as BackgroundWorker).CancellationPending)
{
e.Cancel = true;
break;
}
if (DelayEnabled) timelapse.Start();
_roll = RequestBet();
if (_roll.status)
{
_CloudTotalBets++;
_Wagered += _roll.data.amount;
_CloudProfit += _roll.data.profit;
_TotalProfit += _roll.data.profit;
_CurrentProfit += _roll.data.profit;
_AuxProfit += _roll.data.profit;
if (_DoOneRoll)
{
_manuallyStopped = true;
}
counter++;
_balance = _roll.balance;
if (_roll.data != null && _roll.data.status.Equals("WIN"))
{
if (_StopOnWon)
{
_manuallyStopped = true;
}
_WonsCounter++;
_WinStreak++;
_LossStreak = 0;
if (_WinStreak > _MaxWinStreak)
{
_MaxWinStreak = _WinStreak;
}
if (_BiggestBet < _roll.data.amount)
{
_BiggestBet = _roll.data.amount;
}
if (_BiggestWon < _roll.data.payout)
{
_BiggestWon = _roll.data.payout;
}
if (_martingale)
{
Martingale(true);
}
else if (_fibonacci)
{
Fibonacci(true);
}
}
else if (_roll.data != null && _roll.data.status.Equals("LOSS"))
{
_LostCounter++;
_LossStreak++;
_WinStreak = 0;
if (_LossStreak > _MaxLossStreak)
{
_MaxLossStreak = _LossStreak;
}
if (_BiggestBet < _roll.data.amount)
{
_BiggestBet = _roll.data.amount;
}
if (_BiggestLost < _roll.data.amount)
{
_BiggestLost = _roll.data.amount;
}
if (_martingale)
{
Martingale(false);
}
else if (_fibonacci)
{
Fibonacci(false);
}
}
_CloudWinStreak = _WinStreak;
_CloudLossStreak = _LossStreak;
CheckStopConditions();
}
if (timelapse.IsRunning)
{
if (timelapse.ElapsedMilliseconds < (1000 / _delay))
{
Thread.Sleep((int)(1000 / _delay) - (int)(timelapse.ElapsedMilliseconds));
}
timelapse.Reset();
}
(sender as BackgroundWorker).ReportProgress(counter);
}
}
#endregion
#region ProgressChanged
private void RollWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
UpdateLabels();
#region Update Speed label
var betsPerSecond = Math.Round((e.ProgressPercentage / (DateTime.Now - _initialDateTime).TotalSeconds), 2, MidpointRounding.AwayFromZero);
lblSpeed.Content = $"{betsPerSecond} Bet{(betsPerSecond <= 1 ? string.Empty : "s")}/s";
#endregion
#region Datagrid
if (_roll.status && _roll.data != null)
{
var data = new GenericDataGrid
{
status = _roll.data.status,
amount = _roll.data.amount.ToString("0.00000000", CultureInfo.InvariantCulture),
payout = _roll.data.payout.ToString("0.00000000", CultureInfo.InvariantCulture),
profit = _roll.data.profit.ToString("0.00000000", CultureInfo.InvariantCulture),
result = _roll.data.result,
bet = _roll.data.bet,
chance = $"{_roll.data.chance}%",
id = _roll.data.id,
hour = DateTime.Now.ToString("HH:mm:ss", DateTimeFormatInfo.InvariantInfo)
};
if ((_ShowWons && _roll.data.status.Equals("WIN")) ||
(_ShowLosses && _roll.data.status.Equals("LOSS")))
{
var selected = GridBets.SelectedIndex;
_datosRoll.Add(data);
GridBets.Items.Refresh();
GridBets.SelectedIndex = selected;
}
}
#endregion
#region AutoScroll
if (_AutoScroll && GridBets.Items.Count > 0)
{
GridBets.ScrollIntoView(GridBets.Items[GridBets.Items.Count - 1]);
}
#endregion
#region Status Update
if (_roll.status && _roll.data != null)
{
LblStatus.Content = $"Bet {e.ProgressPercentage}: {_roll.data.status}";
LblStatus.Foreground = _roll.data.status.Equals("WIN") ? Brushes.Green : Brushes.Red;
}
else if (!_roll.error.Equals("Betting too fast. Slow down a bit?"))
{
LblStatus.Content = $"Bet {e.ProgressPercentage + 1}: {_roll.error} [Retrying]";
LblStatus.Foreground = Brushes.Orange;
}
#endregion
#region Update selected item in Fibonacci
if (_fibonacci)
{
lstFibonacci.SelectedIndex = FibonacciLevel;
}
#endregion
#region Graph Update
if (TabGraph.IsSelected && _roll.status)
{
_HasCleanedGraph = false;
Profit.Points.Add(new DoublePoint { Data = e.ProgressPercentage, Value = _CurrentProfit });
if (Profit.Points.Count > 100)
{
Profit.Points.RemoveAt(0);
}
lblAverageProfit.Content =
$"Average Profit: {((_CurrentProfit / e.ProgressPercentage) * betsPerSecond * 600).ToString("0.00000000")} / 10 minutes";
}
else if (!_HasCleanedGraph)
{
RestartGraph();
_HasCleanedGraph = true;
}
#endregion
}
#endregion
#region RunWorkerCompleted
private void RollWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
BtnRefreshBalance.IsEnabled = true;
btnNormalMode.IsEnabled = true;
BtnStartStrategie.IsEnabled = true;
BtnStartOneRoll.IsEnabled = true;
BtnStop.IsEnabled = false;
BtnStopOnWon.IsEnabled = false;
BtnCheckMartingale.IsEnabled = true;
ProgressBetting.IsIndeterminate = false;
if (_martingale)
{
TabFibonacci.IsEnabled = true;
}
else if (_fibonacci)
{
TabMartingale.IsEnabled = true;
}
btnLoadSave.IsEnabled = true;
LblStatus.Content = LblStatus.Content.ToString().Replace(" [Retrying]", String.Empty);
LblStatus.Content =
$"{LblStatus.Content}{(LblStatus.Content.ToString().Contains(".") ? string.Empty : ".")} Bets Stopped.";
}
#endregion
#endregion
#region All other methods (It's full of shit! Expect a lot of reading here :P)
#region Buttons Functionallities
private void BtnStartOneRoll_Click(object sender, RoutedEventArgs e)
{
BtnRefreshBalance.IsEnabled = false;
_NumStartingBet = (double)NumStartingBet.Value;
_NumStartingChange = (double)NumStartingChance.Value;
_NumMultiplierLoss = (double)NumMultiplierLoss.Value;
_DoOneRoll = true;
_StopOnWon = false;
BtnStartStrategie.IsEnabled = false;
BtnStartOneRoll.IsEnabled = false;
BtnStop.IsEnabled = false;
BtnStopOnWon.IsEnabled = false;
BtnCheckMartingale.IsEnabled = false;
_rollWorker.RunWorkerAsync();
ProgressBetting.IsIndeterminate = true;
}
private void BtnStartStrategie_Click(object sender, RoutedEventArgs e)
{
BtnRefreshBalance.IsEnabled = false;
_NumStartingBet = (double)NumStartingBet.Value;
_NumStartingChange = (double)NumStartingChance.Value;
_NumMultiplierLoss = (double)NumMultiplierLoss.Value;
_DoOneRoll = false;
_StopOnWon = false;
BtnStartStrategie.IsEnabled = false;
BtnStartOneRoll.IsEnabled = false;
BtnCheckMartingale.IsEnabled = false;
BtnStop.IsEnabled = true;
BtnStopOnWon.IsEnabled = true;
if (_martingale)
{
TabFibonacci.IsEnabled = false;
}
else if (_fibonacci)
{
TabMartingale.IsEnabled = false;
}
btnLoadSave.IsEnabled = false;
RestartGraph();
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate;
_rollWorker.RunWorkerAsync();
btnNormalMode.IsEnabled = false;
ProgressBetting.IsIndeterminate = true;
}
private void BtnStop_Click(object sender, RoutedEventArgs e)
{
BtnStop.IsEnabled = false;
BtnStopOnWon.IsEnabled = false;
_rollWorker.CancelAsync();
}
private void BtnStopOnWon_Click(object sender, RoutedEventArgs e)
{
_StopOnWon = true;
BtnStopOnWon.IsEnabled = false;
}
#endregion
#region Martingale
#region Martingale Logic
private void Martingale(bool Won)
{
if (Won)
{
if (_RadMaxWon && _WinStreak >= _NumMaxMultipliesWon)
{
_CurrentMultiplier = 1;
}
else if (_RadMaxWon && _WinStreak < _NumMaxMultipliesWon)
{
_CurrentMultiplier = _NumMultiplierWon;
}
else if (_RadVariableWon && _WinStreak >= _NumAfterWon && _WinStreak % (int)_NumAfterWon == 0)
{
_CurrentMultiplier *= _NumMultiplierAfterWon;
}
else if (_RadChangeOnceWon && _WinStreak == (int)_NumAfterWon)
{
_CurrentMultiplier *= _NumMultiplierAfterWon;
}
else if (_RadChangeOnceWon && _WinStreak < (int)_NumAfterWon)
{
_CurrentMultiplier = _NumMultiplierWon;
}
else if (_RadConstrantWon)
{
_CurrentMultiplier = _NumMultiplierWon;
}
_CurrentBet *= _CurrentMultiplier;
if (_CurrentBet < 0.00000001)
{
_CurrentBet = 0.00000001;
}
if (_WinStreak == 1)
{
_CurrentChance = _NumStartingChange;
if (_ChkReturnBaseBetAfterFirstWon)
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierLoss;
}
}
if (_ChkAfterWonsInRowChangeBet && (_WinStreak == (int)_NumAfterXWonsInRowChangeBet))
{
_CurrentBet = _NumAfterXWonsInRowChangeBetNumber;
}
if (_ChkAfterWonsInRowChangeChance && (_WinStreak == (int)_NumAfterXWonsInRowChangeChance))
{
_CurrentChance = _NumAfterXWonsInRowChangeChanceNumber;
}
}
else
{
if (_RadMaxLoss && _LossStreak >= _NumMaxMultipliesLoss)
{
_CurrentMultiplier = 1;
}
else if (_RadMaxLoss && _LossStreak < _NumMaxMultipliesLoss)
{
_CurrentMultiplier = _NumMultiplierLoss;
}
else if (_RadVariableLoss && _LossStreak >= _NumAfterLoss && _LossStreak % (int)_NumAfterLoss == 0)
{
_CurrentMultiplier *= _NumMultiplierAfterLoss;
}
else if (_RadChangeOnceLoss && _LossStreak == (int)_NumAfterLoss)
{
_CurrentMultiplier *= _NumMultiplierAfterLoss;
}
else if (_RadChangeOnceLoss && _LossStreak < (int)_NumAfterLoss)
{
_CurrentMultiplier = _NumMultiplierLoss;
}
else if (_RadConstrantLoss)
{
_CurrentMultiplier = _NumMultiplierLoss;
}
_CurrentBet *= _CurrentMultiplier;
if (_ChkMultiplyOnlyOneTimeLoss && _RadVariableLoss && _LossStreak > 0 && _LossStreak % (int)_NumAfterLoss == 0)
{
_CurrentMultiplier = _NumMultiplierLoss;
}
if (_CurrentBet < 0.00000001)
{
_CurrentBet = 0.00000001;
}
if (_LossStreak == 1)
{
_CurrentChance = _NumStartingChange;
if (_ChkReturnBaseBetAfterFirstLoss)
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierWon;
}
}
if (_ChkAfterLossesInRowChangeBet && (_LossStreak == (int)_NumAfterXLossesInRowChangeBet))
{
_CurrentBet = _NumAfterXLossesInRowChangeBetNumber;
}
if (_ChkAfterLossesInRowChangeChance && (_LossStreak == (int)_NumAfterXLossesInRowChangeChance))
{
_CurrentChance = _NumAfterXLossesInRowChangeChanceNumber;
}
}
}
#endregion
#region Martingale Check Current Settings
private void CheckMartingale()
{
_CurrentMultiplier = _NumMultiplierLoss;
_CurrentBet = _NumStartingBet;
_LossStreak = 0;
var aux = _balance;
var contador = 0;
while (aux > _CurrentBet)
{
_LossStreak++;
aux -= _CurrentBet;
Martingale(false);
contador++;
}
_LossStreak = 0;
_CurrentMultiplier = _NumMultiplierLoss;
_CurrentBet = _NumStartingBet;
ShowNormalDialog("Martingale Check",
$"With your current balance, you can hold on {contador - 1} loses in a row. If you lose at bet number {contador}, your remaining balance will be {aux.ToString("0.00000000").Replace(",", ".")} BTC.");
}
private void BtnCheckMartingale_Click(object sender, RoutedEventArgs e)
{
CheckMartingale();
}
#endregion
#endregion
#region Fibonacci
#region Method to Populate Fibonacci
private readonly List<double> FibonacciList = new List<double>();
private void PopulateFibonacci(double number)
{
double Previous = 0;
var Current = number;
lstFibonacci.Items.Clear();
FibonacciList.Clear();
for (var i = 1; i <= 50; i++)
{
FibonacciList.Add(Current);
lstFibonacci.Items.Add($"{i}. {ToServerString(Current, true)}");
var tmp = Current;
Current += Previous;
Previous = tmp;
}
NumFibonacciWhenLevel.Maximum = FibonacciList.Count;
}
#endregion
#region Fibonacci Logic
private void Fibonacci(bool Won)
{
if (Won)
{
_LossStreak = 0;
_WinStreak ++;
if (_ChkFibonacciWonIncrease)
{
FibonacciLevel += _NumFibonacciIncrementWon;
}
else if (_ChkFibonacciWonRestart)
{
FibonacciLevel = 0;
}
else if (_ChkFibonacciWonStop)
{
FibonacciLevel = 0;
_manuallyStopped = true;
}
}
else
{
_WinStreak = 0;
_LossStreak++;
if (_ChkFibonacciLossIncrease)
{
FibonacciLevel += _NumFibonacciIncrementLoss;
}
else if (_ChkFibonacciLossRestart)
{
FibonacciLevel = 0;
}
else if (_ChkFibonacciLossStop)
{
FibonacciLevel = 0;
_manuallyStopped = true;
}
}
if (FibonacciLevel < 0)
{
FibonacciLevel = 0;
}
else if (FibonacciLevel > 49)
{
FibonacciLevel = 49;
}
if (_ChkFibonacciWhenLevel && FibonacciLevel >= _NumFibonacciWhenLevel)
{
if (_ChkFibonacciWhenLevelReset)
FibonacciLevel = 0;
else if (_ChkFibonacciWhenLevelStop)
{
FibonacciLevel = 0;
_manuallyStopped = true;
}
}
_CurrentBet = FibonacciList[FibonacciLevel];
}
#endregion
#endregion
#region Simulation
private void Simulate()
{
_CurrentMultiplier = _NumMultiplierLoss;
_CurrentBet = _NumStartingBet;
_LossStreak = 0;
var aux = _balance;
var contador = 0;
while (aux > _CurrentBet)
{
_LossStreak++;
aux -= _CurrentBet;
Martingale(false);
contador++;
}
_LossStreak = 0;
_CurrentMultiplier = _NumMultiplierLoss;
_CurrentBet = _NumStartingBet;
ShowNormalDialog("Martingale Check",
$"With your current balance, you can hold on {contador - 1} loses in a row. If you lose at bet number {contador}, your remaining balance will be {aux.ToString("0.00000000").Replace(",", ".")} BTC.");
while (true)
{
var number = new Random().NextDouble() * 99.99;
break;
}
}
#endregion
#region Stop Conditions
private void CheckStopConditions()
{
#region Balance Limits
if (_ChkBalanceLimit && _NumBalanceLimit < _balance)
{
_manuallyStopped = true;
}
if (_ChkBalanceLowerLimit && _balance < _NumBalanceLowerLimit)
{
_manuallyStopped = true;
}
#endregion
#region On Losses Conditions
if (_ChkStopAfterBTCLoss && ((-_AuxProfit) >= _NumStopBTCLoss))
{
_manuallyStopped = true;
}
if (_ChkStopAfterLossesInRow && _LossStreak >= _NumStopLosesInRow)
{
_manuallyStopped = true;
}
if (_ChkResetAfterBTCLoss && ((-_AuxProfit) >= _NumResetBTCLoss))
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierWon;
FibonacciLevel = 0;
_AuxProfit = 0;
}
if (_ChkResetAfterLossesInRow && _LossStreak >= _NumResetLosesInRow)
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierWon;
FibonacciLevel = 0;
_LossStreak = 0;
}
#endregion
#region On Wons Conditions
if (_ChkStopAfterBTCProfit && (_AuxProfit >= _NumStopBTCProfit))
{
_manuallyStopped = true;
}
if (_ChkStopAfterWonsInRow && _WinStreak >= _NumStopWonsInRow)
{
_manuallyStopped = true;
}
if (_ChkResetAfterBTCProfit && (_AuxProfit >= _NumResetBTCProfit))
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierWon;
_AuxProfit = 0;
}
if (_ChkResetAfterWonsInRow && _WinStreak >= _NumResetWonsInRow)
{
_CurrentBet = _NumStartingBet;
_CurrentMultiplier = _NumMultiplierWon;
_WinStreak = 0;
}
#endregion
}
#endregion
#region Methods to avoid closing window if betting
private bool avoidClosing = true;
protected override void OnClosing(CancelEventArgs e)
{
if (_rollWorker.IsBusy && avoidClosing)
{
e.Cancel = true;
ShowCloseMessage();
}
else
{
_currentSite.Disconnect();
e.Cancel = false;
}
}
private async void ShowCloseMessage()
{
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "Yes",
NegativeButtonText = "No",
ColorScheme = MetroDialogOptions.ColorScheme
};
var result = await this.ShowMessageAsync("Betting", "You are betting right now. ¿Are you sure do you want to quit?",
MessageDialogStyle.AffirmativeAndNegative, mySettings);
if (result != MessageDialogResult.Affirmative) return;
avoidClosing = false;
_currentSite.Disconnect();
Close();
}
#endregion
#region Initialize BackgroundWorkers
private void InitBackgroundWorkers()
{
_rollWorker.WorkerReportsProgress = true;
_rollWorker.WorkerSupportsCancellation = true;
_rollWorker.DoWork += RollWorker_DoWork;
_rollWorker.ProgressChanged += RollWorker_ProgressChanged;
_rollWorker.RunWorkerCompleted += RollWorker_RunWorkerCompleted;
_tipWorker.DoWork += tipWorker_DoWork;
_tipWorker.RunWorkerCompleted += tipWorker_RunWorkerCompleted;
_balanceWorker.DoWork += balanceWorker_DoWork;
_balanceWorker.RunWorkerCompleted += balanceWorker_RunWorkerCompleted;
_cloudWorker.DoWork += cloudWorker_DoWork;
_cloudWorker.RunWorkerCompleted += cloudWorker_RunWorkerCompleted;
}
#endregion
#region TipWorker Methods
#region DoWork
private void tipWorker_DoWork(object sender, DoWorkEventArgs e)
{
_tipData = null;
_tipData = _currentSite.Tip(_Payee, _AmountTip);
if (_tipData.status)
{
_balance = _tipData.balance;
}
}
#endregion
#region RunWorkerCompleted
private void tipWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
UpdateLabels();
FlyoutProcessExecution.IsOpen = true;
ProgressTip.IsIndeterminate = false;
ProgressTip.Visibility = Visibility.Hidden;
if (_tipData.status)
{
lblStatusTip.Content = $"Tip sent to {_Payee}.";
LblBalance.Content = _balance.ToString("0.00000000 BTC").Replace(",", ".");
}
else
{
lblStatusTip.Content = _tipData.error;
}
#region Generates a delay for autoclosing the Flyout
using (var bG = new BackgroundWorker())
{
bG.DoWork += (s, j) =>
{
var aux = Stopwatch.StartNew();
while (true) { if (aux.Elapsed.Seconds >= 5) { aux.Stop(); break; } }
};
bG.RunWorkerCompleted += (s, j) => { FlyoutProcessExecution.IsOpen = false; };
bG.RunWorkerAsync();
}
#endregion
}
#endregion
#endregion
#region BalanceWorker Methods
#region Event of clicking Refresh button
private void BtnRefreshBalance_Click(object sender, RoutedEventArgs e)
{
BtnRefreshBalance.IsEnabled = false;
_balanceWorker.RunWorkerAsync();
}
#endregion
#region DoWork
private GenericBalance _balanceAux;
private void balanceWorker_DoWork(object sender, DoWorkEventArgs e)
{
_balanceAux = _currentSite.Balance();
}
#endregion
#region RunWorkerCompleted
private void balanceWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
BtnRefreshBalance.IsEnabled = true;
if (_balanceAux.status)
{
_balance = _balanceAux.balance;
UpdateLabels();
LblStatus.Content = "Balance updated successfully";
LblStatus.Foreground = Brushes.Green;
}
else
{
LblStatus.Content = "Unable to fetch balance";
LblStatus.Foreground = Brushes.Red;
}
}
#endregion
#endregion
#region Method to format the data sent to Da Dice
private static string ToServerString(double value, bool mode)
{
return mode ? value.ToString("0.00000000").Replace(",", ".") : value.ToString("0.00").Replace(",", ".");
}
#endregion
#region Method to request a bet
private GenericRoll RequestBet()
{
return _currentSite.Roll(_CurrentBet, _CurrentChance, _RollOverUnder.Equals("over"));
}
#endregion
#region Window Loaded Method
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
GridBets.ItemsSource = _datosRoll;
UpdateLabels();
PopulateFibonacci(_NumStartingBet);
lblVersion.Content =
$"Version {Assembly.GetExecutingAssembly().GetName().Version.ToString().Remove(5)} by @sbarrenechea";
if (File.Exists("default.ini"))
{
LoadStratConfig("default.ini");
}
chkDelay.IsChecked = DelayEnabled = bool.Parse(_parser.GetSetting("AUTODICE", "DELAYENABLED"));
NumDelay.Value = _delay = double.Parse(_parser.GetSetting("AUTODICE", "DELAYTIME"), CultureInfo.InvariantCulture);
NumStartingChance.Maximum = _currentSite.MaxMultiplier;
NumStartingChance.Minimum = _currentSite.MinMultiplier;
btnTip.IsEnabled = _currentSite.CanTip;
numAmountTip.Minimum = _currentSite.MinTipAmount;
numAmountTip.Interval = _currentSite.TipAmountInterval;
}
#endregion
#region Strat System Changer Method
private void TabStrategies_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_martingale = TabMartingale.IsSelected;
_fibonacci = TabFibonacci.IsSelected;
if (TabMartingale.IsSelected)
{
BtnStartStrategie.Content = "Start Martingale";
}
else if (TabFibonacci.IsSelected)
{
BtnStartStrategie.Content = "Start Fibonacci";
}
}
#endregion
#region Values changed
#region Initial Settings
private void NumDelay_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
try
{
_delay = (double)NumDelay.Value;
_parser.AddSetting("AUTODICE", "DELAYTIME", ((double)NumDelay.Value).ToString("0.00", CultureInfo.InvariantCulture));
_parser.SaveSettings();
}
catch
{
// ignored
}
}
private bool DelayEnabled;
private void chkDelay_CheckedChanged(object sender, RoutedEventArgs e)
{
try
{
DelayEnabled = (bool)chkDelay.IsChecked;
_parser.AddSetting("AUTODICE", "DELAYENABLED", chkDelay.IsChecked.ToString());
_parser.SaveSettings();
}
catch
{
// ignored
}
}
private void NumStartingBet_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
try
{
_NumStartingBet = (double)NumStartingBet.Value;
if (TabFibonacci.IsSelected)
{
PopulateFibonacci(_NumStartingBet);
}
}
catch
{
// ignored
}
}
private void NumStartingChance_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
try
{
_CloudTotalBets = 0;
_CloudWinStreak = 0;
_CloudLossStreak = 0;
_CloudProfit = 0;
NumStartingChance.Value = Math.Round((double)NumStartingChance.Value, 2);
_NumStartingChange = (double)NumStartingChance.Value;
_CurrentChance = _NumStartingChange;
txtNextBetPayout.Text = $"{CalculatePayout(_NumStartingChange)}x";
RadRollOver.Content = $"Over {(99.99 - _NumStartingChange).ToString("0.00").Replace(",", ".")}";
RadRollUnder.Content = $"Under {_NumStartingChange.ToString("0.00").Replace(",", ".")}";
}
catch
{
// ignored
}
}
private void RadRollOver_CheckedChanged(object sender, RoutedEventArgs e)
{
try
{
_RollOverUnder = (bool)RadRollOver.IsChecked ? "over" : "under";
}
catch
{
// ignored
}
}
#endregion
#region Martingale - On loss
private void NumMultiplierLoss_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{