Advertisement
Alan72104

Wheel simulator for CrazyCrates

Feb 10th, 2021
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.46 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Change2CUI=y
  3. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  4.  
  5. ; Wheel crate simulator for https://github.com/badbones69/Crazy-Crates
  6.  
  7. #include <Array.au3>
  8. #include <File.au3>
  9. ; #include "..\LibDebug.au3"
  10.  
  11. Global $i = 0
  12. Global $timer = 0
  13. Global $full = 0
  14. Global $slower = 0
  15. Global $slowSpin[10] = [46,37,29,22,16,11,7,4,2,1]
  16. Global $timerRun
  17. If $CmdLine[0] > 0 Then
  18.     Global Const $runCount = $CmdLine[1]
  19. Else
  20.     Global Const $runCount = 50
  21. EndIf
  22. Global $rewards[$runCount]
  23. ; Chance in 100 of every items
  24. Global $item[10] = [10,15,15,8,2,14,12,10,8,6]
  25. ; Global $item = [8,10,6,7,10,12,10,8,2,10,8,5,3,1]
  26. Global $inv[18] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  27. Global $timesRun = 0
  28. Global Const $itemName[UBound($item)] = ["$10000","Supply Crate","Mega Crate","Spawner Crate","Cosmetic Crate", _
  29.                                     "Mystery Box 1*","Mystery Box 2*","Mystery Box 3*","Mystery Box 4*","Mystery Box 5*"]
  30. ; Global Const $itemName[UBound($item)] = ["$10000","Supply Crate","Mega Crate","Spawner Crate","Command Crate","500 Points","1000 Points","2500 Points", _
  31.                                     ; "Cosmetic Crate","Mystery Box 1*","Mystery Box 2*","Mystery Box 3*","Mystery Box 4*","Mystery Box 5*"]
  32. Global $_LD_Debug = True
  33. HotKeySet("{F7}", "Terminate")
  34. HotKeySet("{F8}", "PrintResultAndSleep")
  35.  
  36. Func ArrayAdd(ByRef $a, $v)
  37.     ReDim $a[UBound($a) + 1]
  38.     $a[UBound($a) - 1] = $v
  39. EndFunc
  40.  
  41. Func GetPrize()
  42.     Local $prizes[0]
  43.     Do
  44.         For $i= 0 To UBound($item) - 1
  45.             If Random(1, 100, 1) <= $item[$i] Then
  46.                 ArrayAdd($prizes, $i)
  47.             EndIf
  48.         Next
  49.     Until UBound($prizes) > 0
  50.     Return $prizes[Random(0, UBound($prizes) - 1, 1)]
  51. EndFunc
  52.  
  53. Func GenRewards()
  54.     For $i = 0 To 17
  55.         $inv[$i] = GetPrize()
  56.     Next
  57. EndFunc
  58.  
  59. Func RunOnce(ByRef $ele)
  60.     GenRewards()
  61.     $i = 0
  62.     $timer = Random(42, 68, 1)
  63.     $full = 0
  64.     $slower = 0
  65.     While 1
  66.         If $i > 17 Then $i = 0
  67.         If $full < $timer Then
  68.             $spinSlot = $i
  69.             $i += 1
  70.         EndIf
  71.         If $full >= $timer Then
  72.             If _ArraySearch($slowSpin, $slower) > -1 Then
  73.                 $spinSlot = $i
  74.                 $i += 1
  75.             EndIf
  76.             If $full = $timer + 47 Then
  77.                 ; SoundPlay(@ScriptDir & "\levelup.mp3")
  78.             EndIf
  79.             If $full >= $timer + 55 + 47 Then
  80.                 $rewards[$ele] = $inv[$spinSlot]
  81.                 ExitLoop
  82.             EndIf
  83.             $slower += 1
  84.         EndIf
  85.         $full += 1
  86.     WEnd
  87. EndFunc
  88.  
  89. Func PrintResult(ByRef $timesRun)
  90.     c("Result of $ times running:", 1, $timesRun)
  91.     For $i = 0 To UBound($item) - 1
  92.         Local $count = UBound(_ArrayFindAll($rewards, $i, 0, $timesRun))
  93.         c("Reward [$] - Count: $ Percentage: $", 1, $itemName[$i], $count, Round($count / $timesRun * 100, 1))
  94.     Next
  95. EndFunc
  96.  
  97. Func PrintResultAndSleep()
  98.     PrintResult($timesRun)
  99.     c("Sleeping for 5000 ms")
  100.     Sleep(5000)
  101.     c("Running")
  102. EndFunc
  103.  
  104. Func Main()
  105.     For $i = 0 To $runCount - 1
  106.         $timerRun = TimerInit()
  107.         RunOnce($i)
  108.         c("$ times completed, took $ ms", 1, $i + 1, TimerDiff($timerRun))
  109.         $timesRun += 1
  110.     Next
  111.     c("all completed")
  112.     PrintResult($timesRun)
  113.     c("press F7 to terminate and save the result to rewards.batch.txt")
  114.     While 1
  115.         Sleep(1000)
  116.     WEnd
  117. EndFunc
  118.  
  119. Main()
  120.  
  121. Func Terminate()
  122.     ArrayAdd($rewards, iv("Result of $ times running:", $timesRun))
  123.     For $i = 0 To UBound($item) - 1
  124.         Local $count = UBound(_ArrayFindAll($rewards, $i, 0, $timesRun))
  125.         ArrayAdd($rewards, iv("Reward [$] - Count: $ Percentage: $", $itemName[$i], $count, Round($count / $timesRun * 100, 1)))
  126.     Next
  127.     _FileWriteFromArray(@ScriptDir & "\rewards.batch.txt", $rewards)
  128.     Exit 0
  129. EndFunc
  130.  
  131. #include <StringConstants.au3>
  132.  
  133.  
  134. Func _DebugOff()
  135.     $_LD_Debug = False
  136. EndFunc
  137.  
  138. Func _DebugOn()
  139.     $_LD_Debug = True
  140. EndFunc
  141.  
  142. ; Consoleout
  143. ; Automatically replaces $ to variables given
  144. ; Escape $ using $$
  145. Func c($s = "", $nl = True, $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, _
  146.                             $v4 = 0x0, $v5 = 0x0, $v6 = 0x0, _
  147.                             $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  148.     If Not $_LD_Debug Then
  149.         Return
  150.     EndIf
  151.     If @NumParams > 2 Then
  152.         $s = StringReplace($s, "$$", "@PH@")
  153.         $s = StringReplace($s, "$", "@PH2@")
  154.         For $i = 1 To @NumParams - 2
  155.             $s = StringReplace($s, "@PH2@", Eval("v" & $i), 1)
  156.             If @extended = 0 Then ExitLoop
  157.         Next
  158.         $s = StringReplace($s, "@PH@", "$")
  159.     EndIf
  160.     If $nl Then $s &= @CRLF
  161.     ConsoleWrite($s)
  162.     If @NumParams = 1 Then
  163.         Return $s
  164.     EndIf
  165. EndFunc
  166.  
  167. ; Insert variable
  168. ; Returns a string with all given variables inserted into
  169. Func iv($s = "", $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, _
  170.                 $v4 = 0x0, $v5 = 0x0, $v6 = 0x0, _
  171.                 $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  172.     If @NumParams > 1 Then
  173.         $s = StringReplace($s, "$$", "@PH@")
  174.         $s = StringReplace($s, "$", "@PH2@")
  175.         For $i = 1 To @NumParams - 1
  176.             $s = StringReplace($s, "@PH2@", Eval("v" & $i), 1)
  177.             If @extended = 0 Then ExitLoop
  178.         Next
  179.         $s = StringReplace($s, "@PH@", "$")
  180.     EndIf
  181.     Return $s
  182. EndFunc
  183.  
  184. ; Consoleout Line
  185. Func cl()
  186.     If Not $_LD_Debug Then
  187.         Return
  188.     EndIf
  189.     ConsoleWrite(@CRLF)
  190. EndFunc
  191.  
  192. ; Consoleout Variable
  193. ; Only accepts the name of variable without the $ as string
  194. Func cv($nl = True, $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, $v4 = 0x0, $v5 = 0x0, _
  195.                         $v6 = 0x0, $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  196.     If Not $_LD_Debug Then
  197.         Return
  198.     EndIf
  199.     Local $s = ""
  200.     For $i = 1 To @NumParams - 1
  201.         $s &= "$" & Eval("v" & $i) & " = " & Eval(Eval("v" & $i))
  202.         If $i < @NumParams - 1 Then
  203.             $s &= " | "
  204.         EndIf
  205.     Next
  206.     If $nl Then $s &= @CRLF
  207.     ConsoleWrite($s)
  208. EndFunc
  209.  
  210. Func ce($nl = True)
  211.     $nl ? ConsoleWrite(@ERROR & @CRLF) : ConsoleWrite(@ERROR)
  212. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement