roll_tor.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # Defaults
  3. FEAT_COUNT=1
  4. SUCCESS_COUNT=0
  5. # Help function
  6. show_help() {
  7. echo "Usage: $0 [FEAT_DICE] [SUCCESS_DICE]"
  8. echo ""
  9. echo "Arguments:"
  10. echo " FEAT_DICE Number of 1d12 Feat Dice to roll (default: 1)"
  11. echo " SUCCESS_DICE Number of 1d6 Success Dice to roll (default: 0)"
  12. echo ""
  13. echo "Options:"
  14. echo " -h, --help Show this help message"
  15. echo ""
  16. echo "Examples:"
  17. echo " $0 # Rolls 1 Feat Die"
  18. echo " $0 1 3 # Rolls 1 Feat Die and 3 Success Dice"
  19. echo " $0 2 0 # Rolls 2 Feat Dice"
  20. exit 0
  21. }
  22. # Check for help flag
  23. if [[ "$1" == "-h" || "$1" == "--help" ]]; then
  24. show_help
  25. fi
  26. # Check for arguments
  27. if [[ "$1" =~ ^[0-9]+$ ]]; then
  28. FEAT_COUNT=$1
  29. if [[ "$2" =~ ^[0-9]+$ ]]; then
  30. SUCCESS_COUNT=$2
  31. fi
  32. fi
  33. # Colors and formatting
  34. BOLD='\033[1m'
  35. RED='\033[31m'
  36. GREEN='\033[32m'
  37. CYAN='\033[36m' # Using Cyan for Gandalf as it's bright/distinct
  38. RESET='\033[0m'
  39. # Function to generate a random number between 1 and max
  40. roll() {
  41. local max=$1
  42. # Read 2 bytes from /dev/urandom, convert to decimal, modulo max, add 1
  43. # This provides better randomness than $RANDOM
  44. val=$(od -An -N2 -tu2 /dev/urandom)
  45. echo $(( (val % max) + 1 ))
  46. }
  47. echo -e "${BOLD}Rolling for The One Ring...${RESET}\n"
  48. TOTAL=0
  49. # Roll Feat Dice (1d12)
  50. if [ "$FEAT_COUNT" -gt 0 ]; then
  51. echo -n -e "Feat Dice (${FEAT_COUNT}d12): "
  52. for ((i=0; i<FEAT_COUNT; i++)); do
  53. RESULT=$(roll 12)
  54. ((TOTAL+=RESULT))
  55. if [ "$RESULT" -eq 1 ]; then
  56. # Eye of Mordor
  57. echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
  58. elif [ "$RESULT" -eq 12 ]; then
  59. # Gandalf
  60. echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
  61. else
  62. echo -n "[ $RESULT ] "
  63. fi
  64. done
  65. echo ""
  66. fi
  67. # Roll Success Dice (1d6)
  68. if [ "$SUCCESS_COUNT" -gt 0 ]; then
  69. echo -n -e "Success Dice (${SUCCESS_COUNT}d6): "
  70. for ((i=0; i<SUCCESS_COUNT; i++)); do
  71. RESULT=$(roll 6)
  72. ((TOTAL+=RESULT))
  73. if [ "$RESULT" -eq 6 ]; then
  74. # Magnificent Outcome
  75. echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
  76. else
  77. echo -n "[ $RESULT ] "
  78. fi
  79. done
  80. echo ""
  81. fi
  82. echo -e "\n${BOLD}Total Face Value: $TOTAL${RESET}"