corpnewt

D&Dice.bat

Dec 13th, 2015
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. @echo off
  2. setlocal enableDelayedExpansion
  3.  
  4. set /a prevRollCount=0
  5. set /a maxRolls=5
  6. set prevRoll[1]=
  7.  
  8.  
  9.  
  10. :main
  11. cls
  12. set input=1d20
  13. echo ### D^&Dice ###
  14. echo.
  15. echo Type "p" to view previous rolls
  16. echo.
  17. echo Please type your dice ^(i.e. 3d8+5):
  18. echo Default is 1d20
  19. echo.
  20. set /p "input= "
  21. set dice=
  22. set sides=
  23. set add=
  24.  
  25. if /i "%input%"=="p" goto previousRolls
  26.  
  27. if /i "%input:~0,1%"=="d" set input=1%input%
  28.  
  29. for /f "usebackq delims=d+ tokens=1,2,3*" %%a in ('%input%') do (
  30. set dice=%%a
  31. set sides=%%b
  32. set add=%%c
  33. )
  34.  
  35. for /f "usebackq delims=- tokens=1,2*" %%a in ('%sides%') do (
  36. if NOT "%%b"=="" (
  37. set sides=%%a
  38. set /a add=%%b*-1
  39. )
  40. )
  41.  
  42. set total=
  43. set str=
  44.  
  45. set tempRollVal=
  46.  
  47. if NOT "%dice%"=="" (
  48. if NOT "%sides%"=="" (
  49. call :roll "%dice%" "%sides%" "%add%" total str
  50. ) else (
  51. goto main
  52. )
  53. ) else (
  54. goto main
  55. )
  56. if NOT "%add%"=="" (
  57. set /a added=!total!+!add!
  58. if %dice% GTR 1 (
  59. echo ============= Roll Total
  60. echo !total!
  61. )
  62. if "%add:~0,1%"=="-" (
  63. echo ============= - %add:~1%
  64. set "str=!str! - !add:~1!"
  65. ) else (
  66. echo ============= + %add%
  67. set "str=!str! + !add!"
  68. )
  69. set "str=!str! = !added!"
  70. echo !added!
  71. ) else (
  72. if %dice% GTR 1 (
  73. echo ============= Roll Total
  74. echo !total!
  75. )
  76. set "str=!str! = !total!"
  77. )
  78.  
  79. REM Let's add this to our previous roll list
  80. if %prevRollCount% LSS %maxRolls% (
  81. set /a prevRollCount+=1
  82. set "prevRoll[!prevRollCount!]=!str!"
  83. ) else (
  84. REM Iterate through the list, deleting the oldest
  85. for /l %%a in (1, 1, %maxRolls%-1) do (
  86. set /a nextRoll=%%a+1
  87. call :repRoll "%%a" "!nextRoll!"
  88. )
  89. set "prevRoll[%maxRolls%]=!str!"
  90. )
  91. echo.
  92. echo Press [enter] to return to the roll screen...
  93. pause > nul
  94.  
  95. goto main
  96.  
  97. :repRoll <num1> <num2>
  98. set "prevRoll[%~1]=!prevRoll[%~2]!"
  99. goto :EOF
  100.  
  101. :roll <dice> <sides> <plus> <return> <string>
  102. setlocal enableDelayedExpansion
  103. set /a dice=%~1
  104. set /a sides=%~2
  105. set plus=
  106. if NOT "%~3"=="" (
  107. set test=%~3
  108. if "!test:~0,1!"=="-" (
  109. set "plus= - !test:~1!"
  110. ) else (
  111. set "plus= + %~3"
  112. )
  113. )
  114. set /a total=0
  115. set "str="
  116. if "%dice%"=="" set /a dice=1
  117. if "%sides%"=="" set /a sides=20
  118. set /a min=1
  119. cls
  120. echo ### Rolling %dice% %sides%-sided dice%plus% ###
  121. echo.
  122. for /l %%a in (1, 1, %dice%) do (
  123. call :random 1 %sides% return
  124. echo !return!
  125. if "!str!"=="" (
  126. set "str=[!return!"
  127. ) else (
  128. set "str=!str!, !return!"
  129. )
  130. set /a total+=!return!
  131. )
  132. set "str=!str!]"
  133. endlocal & (
  134. set total=%total%
  135. set str=%str%
  136. )
  137. set %~4=%total%
  138. set %~5=%str%
  139. exit /b
  140.  
  141. :random <min> <max> <return>
  142. setlocal
  143. set /a rand=%RANDOM% * %~2 / 32768 + %~1
  144. endlocal & set %~3=%rand%
  145. exit /b
  146.  
  147. :previousRolls
  148. cls
  149. echo ### Past Rolls ###
  150. echo.
  151. for /l %%a in (1, 1, %prevRollCount%) do (
  152. echo %%a. !prevRoll[%%a]!
  153. )
  154. echo.
  155. echo Press [enter] to return to the main menu...
  156. pause > nul
  157. goto main
Advertisement
Add Comment
Please, Sign In to add comment