浏览代码

version 0.0.1 of tor-roller

Mitch Donaberger 3 周之前
当前提交
1263fcb397
共有 1 个文件被更改,包括 95 次插入0 次删除
  1. 95 0
      roll_tor.sh

+ 95 - 0
roll_tor.sh

@@ -0,0 +1,95 @@
+#!/bin/bash
+
+# Defaults
+FEAT_COUNT=1
+SUCCESS_COUNT=0
+
+# Help function
+show_help() {
+    echo "Usage: $0 [FEAT_DICE] [SUCCESS_DICE]"
+    echo ""
+    echo "Arguments:"
+    echo "  FEAT_DICE     Number of 1d12 Feat Dice to roll (default: 1)"
+    echo "  SUCCESS_DICE  Number of 1d6 Success Dice to roll (default: 0)"
+    echo ""
+    echo "Options:"
+    echo "  -h, --help    Show this help message"
+    echo ""
+    echo "Examples:"
+    echo "  $0          # Rolls 1 Feat Die"
+    echo "  $0 1 3      # Rolls 1 Feat Die and 3 Success Dice"
+    echo "  $0 2 0      # Rolls 2 Feat Dice"
+    exit 0
+}
+
+# Check for help flag
+if [[ "$1" == "-h" || "$1" == "--help" ]]; then
+    show_help
+fi
+
+# Check for arguments
+if [[ "$1" =~ ^[0-9]+$ ]]; then
+    FEAT_COUNT=$1
+    if [[ "$2" =~ ^[0-9]+$ ]]; then
+        SUCCESS_COUNT=$2
+    fi
+fi
+
+# Colors and formatting
+BOLD='\033[1m'
+RED='\033[31m'
+GREEN='\033[32m'
+CYAN='\033[36m' # Using Cyan for Gandalf as it's bright/distinct
+RESET='\033[0m'
+
+# Function to generate a random number between 1 and max
+roll() {
+    local max=$1
+    # Read 2 bytes from /dev/urandom, convert to decimal, modulo max, add 1
+    # This provides better randomness than $RANDOM
+    val=$(od -An -N2 -tu2 /dev/urandom)
+    echo $(( (val % max) + 1 ))
+}
+
+echo -e "${BOLD}Rolling for The One Ring...${RESET}\n"
+
+TOTAL=0
+
+# Roll Feat Dice (1d12)
+if [ "$FEAT_COUNT" -gt 0 ]; then
+    echo -n -e "Feat Dice (${FEAT_COUNT}d12): "
+    for ((i=0; i<FEAT_COUNT; i++)); do
+        RESULT=$(roll 12)
+        ((TOTAL+=RESULT))
+        
+        if [ "$RESULT" -eq 1 ]; then
+            # Eye of Mordor
+            echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
+        elif [ "$RESULT" -eq 12 ]; then
+            # Gandalf
+            echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
+        else
+            echo -n "[ $RESULT ] "
+        fi
+    done
+    echo ""
+fi
+
+# Roll Success Dice (1d6)
+if [ "$SUCCESS_COUNT" -gt 0 ]; then
+    echo -n -e "Success Dice (${SUCCESS_COUNT}d6): "
+    for ((i=0; i<SUCCESS_COUNT; i++)); do
+        RESULT=$(roll 6)
+        ((TOTAL+=RESULT))
+        
+        if [ "$RESULT" -eq 6 ]; then
+            # Magnificent Outcome
+            echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
+        else
+            echo -n "[ $RESULT ] "
+        fi
+    done
+    echo ""
+fi
+
+echo -e "\n${BOLD}Total Face Value: $TOTAL${RESET}"