-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroll_tor.sh
More file actions
executable file
·505 lines (443 loc) · 14.8 KB
/
roll_tor.sh
File metadata and controls
executable file
·505 lines (443 loc) · 14.8 KB
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
#!/bin/bash
# Defaults
FEAT_COUNT=1
SUCCESS_COUNT=0
ROLL_MODE="" # adv, disadv, or empty
BONUS_VALUE=0 # bonus/debuff value
# Macro configuration
MACRO_FILE="$HOME/.tor-roller-macros"
# Help function
show_help() {
echo "Usage: $0 [FEAT_DICE] [SUCCESS_DICE] [OPTIONS]"
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 " macro Use a saved macro (see --macro-help)"
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"
echo ""
echo "Macro Examples:"
echo " $0 --macro-help # Show macro usage"
echo " $0 --save-macro hero 1 3 # Save macro named 'hero' with 1d12+3d6"
echo " $0 --save-macro attack 2 4 adv # Save with advantage"
echo " $0 --save-macro spell 1 2 disadv # Save with disadvantage"
echo " $0 --save-macro skill 1 2 +5 # Save with +5 bonus"
echo " $0 --list-macros # List all saved macros"
echo " $0 hero # Use saved macro"
exit 0
}
# Show macro help
show_macro_help() {
echo "Macro Usage:"
echo ""
echo "Save Macros:"
echo " --save-macro NAME FEAT_DICE SUCCESS_DICE [ADV|DISADV] [BONUS]"
echo " NAME: Name for the macro"
echo " FEAT_DICE: Number of d12 dice (1-99)"
echo " SUCCESS_DICE: Number of d6 dice (0-99)"
echo " ADV: Advantage (roll 2 sets, keep highest)"
echo " DISADV: Disadvantage (roll 2 sets, drop highest)"
echo " BONUS: Bonus/debuff value (+5, -3, etc.)"
echo ""
echo "Examples:"
echo " $0 --save-macro hero 1 3"
echo " $0 --save-macro attack 2 4 adv"
echo " $0 --save-macro spell 1 2 disadv"
echo " $0 --save-macro skill 1 2 +5"
echo ""
echo "Use Macros:"
echo " $0 MACRO_NAME"
echo ""
echo "List Macros:"
echo " $0 --list-macros"
echo ""
echo "Delete Macros:"
echo " $0 --delete-macro MACRO_NAME"
echo ""
exit 0
}
# Save a macro
save_macro() {
local name="$1"
local feat="$2"
local success="$3"
local mode="$4"
local bonus="$5"
# Validate inputs
if [[ ! "$feat" =~ ^[0-9]+$ ]] || [ "$feat" -lt 1 ] || [ "$feat" -gt 99 ]; then
echo "Error: FEAT_DICE must be a number between 1 and 99"
exit 1
fi
if [[ ! "$success" =~ ^[0-9]+$ ]] || [ "$success" -gt 99 ]; then
echo "Error: SUCCESS_DICE must be a number between 0 and 99"
exit 1
fi
# Handle mode and bonus arguments
if [[ "$mode" == "adv" ]] || [[ "$mode" == "ADV" ]]; then
mode="adv"
bonus="$5"
elif [[ "$mode" == "disadv" ]] || [[ "$mode" == "DISADV" ]]; then
mode="disadv"
bonus="$5"
elif [[ "$mode" =~ ^[+-]?[0-9]+$ ]]; then
# This is a bonus, mode is empty
mode=""
bonus="$4" # bonus is in the mode position
else
mode=""
bonus="$4" # bonus is in the mode position if provided
fi
# Validate bonus if provided
if [[ "$bonus" != "" ]] && [[ "$bonus" != "0" ]] && [[ ! "$bonus" =~ ^[+-]?[0-9]+$ ]]; then
echo "Error: BONUS must be a number with + or - (e.g., +5, -3)"
exit 1
fi
# If bonus is empty or not a number, set to 0
if [[ "$bonus" == "" ]] || [[ ! "$bonus" =~ ^[+-]?[0-9]+$ ]]; then
bonus="0"
fi
# Create macro entry
local entry="$name|$feat|$success|$mode|$bonus"
# Create directory if it doesn't exist
mkdir -p "$(dirname "$MACRO_FILE")"
# Remove existing macro with same name
if [ -f "$MACRO_FILE" ]; then
grep -v "^$name|" "$MACRO_FILE" > "${MACRO_FILE}.tmp" 2>/dev/null || true
mv "${MACRO_FILE}.tmp" "$MACRO_FILE"
fi
# Add new macro
echo "$entry" >> "$MACRO_FILE"
echo "Macro '$name' saved successfully!"
echo " Feat Dice: $feat d12, Success Dice: $success d6"
if [[ "$mode" == "adv" ]]; then
echo " Mode: Advantage"
elif [[ "$mode" == "disadv" ]]; then
echo " Mode: Disadvantage"
fi
if [[ "$bonus" != "0" ]]; then
echo " Bonus: $bonus"
fi
exit 0
}
# List all macros
list_macros() {
echo "Saved Macros:"
echo ""
if [ ! -f "$MACRO_FILE" ]; then
echo "No macros saved yet."
echo ""
echo "Use --save-macro to create a macro, or --macro-help for examples."
exit 0
fi
printf "%-20s %-10s %-12s %-12s %s\n" "NAME" "FEAT_DICE" "SUCCESS_DICE" "MODE" "BONUS"
printf "%-20s %-10s %-12s %-12s %s\n" "----" "---------" "------------" "----" "-----"
while IFS='|' read -r name feat success mode bonus; do
local mode_display="${mode:-(none)}"
local bonus_display="$bonus"
if [[ "$bonus" == "0" ]]; then
bonus_display="(none)"
fi
printf "%-20s %-10s %-12s %-12s %s\n" "$name" "${feat}d12" "${success}d6" "$mode_display" "$bonus_display"
done < "$MACRO_FILE"
exit 0
}
# Delete a macro
delete_macro() {
local name="$1"
if [ ! -f "$MACRO_FILE" ]; then
echo "No macros saved yet."
exit 1
fi
if ! grep -q "^$name|" "$MACRO_FILE"; then
echo "Macro '$name' not found."
exit 1
fi
# Remove the macro
grep -v "^$name|" "$MACRO_FILE" > "${MACRO_FILE}.tmp"
mv "${MACRO_FILE}.tmp" "$MACRO_FILE"
echo "Macro '$name' deleted successfully!"
exit 0
}
# Load and execute a macro
load_macro() {
local name="$1"
if [ ! -f "$MACRO_FILE" ]; then
echo "No macros saved yet. Use --save-macro to create one."
exit 1
fi
local macro_data=$(grep "^$name|" "$MACRO_FILE")
if [ -z "$macro_data" ]; then
echo "Macro '$name' not found. Use --list-macros to see available macros."
exit 1
fi
# Parse macro data
IFS='|' read -r macro_name feat success mode bonus <<< "$macro_data"
echo "Using macro: $name"
echo ""
# Set global variables for rolling
FEAT_COUNT=$feat
SUCCESS_COUNT=$success
ROLL_MODE=$mode
BONUS_VALUE=$bonus
}
# Check for help flag
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
fi
# Check for macro commands
if [[ "$1" == "--macro-help" ]]; then
show_macro_help
elif [[ "$1" == "--save-macro" ]]; then
if [ "$#" -lt 4 ]; then
echo "Error: --save-macro requires NAME FEAT_DICE SUCCESS_DICE"
echo "Use --macro-help for examples"
exit 1
fi
save_macro "$2" "$3" "$4" "$5" "$6"
elif [[ "$1" == "--list-macros" ]]; then
list_macros
elif [[ "$1" == "--delete-macro" ]]; then
if [ "$#" -lt 2 ]; then
echo "Error: --delete-macro requires MACRO_NAME"
exit 1
fi
delete_macro "$2"
fi
# Check if using a saved macro
if [ "$#" -eq 1 ] && [ "$1" != "" ]; then
# Check if it's a macro name (not numeric)
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
load_macro "$1"
# Macro will set FEAT_COUNT, SUCCESS_COUNT, etc.
else
FEAT_COUNT=$1
fi
elif [[ "$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 ))
}
gum spin --spinner moon --title "🔮 Consulting Palantir..." -- sleep 1
echo ""
# Display macro name if using one
if [ -n "$macro_name" ]; then
if [[ "$ROLL_MODE" == "adv" ]]; then
echo "Mode: Advantage (roll 2 sets, keep highest)"
elif [[ "$ROLL_MODE" == "disadv" ]]; then
echo "Mode: Disadvantage (roll 2 sets, drop highest)"
fi
if [[ "$BONUS_VALUE" != "0" ]]; then
if [[ "$BONUS_VALUE" =~ ^- ]]; then
echo "Effect: $BONUS_VALUE (debuff)"
else
echo "Effect: $BONUS_VALUE (bonus)"
fi
fi
echo ""
fi
TOTAL=0
# Roll Feat Dice (1d12)
if [ "$FEAT_COUNT" -gt 0 ]; then
echo -n -e "Feat Dice (${FEAT_COUNT}d12 ): "
# Handle advantage/disadvantage for Feat Dice
if [[ "$ROLL_MODE" == "adv" ]]; then
echo -n "Set 1: "
total_set1=0
for ((i=0; i<FEAT_COUNT; i++)); do
RESULT=$(roll 12)
total_set1=$((total_set1 + RESULT))
if [ "$RESULT" -eq 1 ]; then
echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
elif [ "$RESULT" -eq 12 ]; then
echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
echo -n -e " | Set 2: "
total_set2=0
for ((i=0; i<FEAT_COUNT; i++)); do
RESULT=$(roll 12)
total_set2=$((total_set2 + RESULT))
if [ "$RESULT" -eq 1 ]; then
echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
elif [ "$RESULT" -eq 12 ]; then
echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
if [ $total_set1 -ge $total_set2 ]; then
TOTAL=$((TOTAL + total_set1))
echo -e " (Kept: $total_set1)"
else
TOTAL=$((TOTAL + total_set2))
echo -e " (Kept: $total_set2)"
fi
elif [[ "$ROLL_MODE" == "disadv" ]]; then
echo -n "Set 1: "
total_set1=0
for ((i=0; i<FEAT_COUNT; i++)); do
RESULT=$(roll 12)
total_set1=$((total_set1 + RESULT))
if [ "$RESULT" -eq 1 ]; then
echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
elif [ "$RESULT" -eq 12 ]; then
echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
echo -n -e " | Set 2: "
total_set2=0
for ((i=0; i<FEAT_COUNT; i++)); do
RESULT=$(roll 12)
total_set2=$((total_set2 + RESULT))
if [ "$RESULT" -eq 1 ]; then
echo -n -e "[ ${BOLD}${RED}1 (EYE)${RESET} ] "
elif [ "$RESULT" -eq 12 ]; then
echo -n -e "[ ${BOLD}${CYAN}12 (GANDALF)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
if [ $total_set1 -le $total_set2 ]; then
TOTAL=$((TOTAL + total_set1))
echo -e " (Kept: $total_set1)"
else
TOTAL=$((TOTAL + total_set2))
echo -e " (Kept: $total_set2)"
fi
else
# Normal rolling
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
fi
echo ""
fi
# Roll Success Dice (1d6)
if [ "$SUCCESS_COUNT" -gt 0 ]; then
echo -n -e "Success Dice (${SUCCESS_COUNT}d6 ): "
# Handle advantage/disadvantage for Success Dice
if [[ "$ROLL_MODE" == "adv" ]]; then
echo -n "Set 1: "
total_set1=0
for ((i=0; i<SUCCESS_COUNT; i++)); do
RESULT=$(roll 6)
total_set1=$((total_set1 + RESULT))
if [ "$RESULT" -eq 6 ]; then
echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
echo -n -e " | Set 2: "
total_set2=0
for ((i=0; i<SUCCESS_COUNT; i++)); do
RESULT=$(roll 6)
total_set2=$((total_set2 + RESULT))
if [ "$RESULT" -eq 6 ]; then
echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
if [ $total_set1 -ge $total_set2 ]; then
TOTAL=$((TOTAL + total_set1))
echo -e " (Kept: $total_set1)"
else
TOTAL=$((TOTAL + total_set2))
echo -e " (Kept: $total_set2)"
fi
elif [[ "$ROLL_MODE" == "disadv" ]]; then
echo -n "Set 1: "
total_set1=0
for ((i=0; i<SUCCESS_COUNT; i++)); do
RESULT=$(roll 6)
total_set1=$((total_set1 + RESULT))
if [ "$RESULT" -eq 6 ]; then
echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
echo -n -e " | Set 2: "
total_set2=0
for ((i=0; i<SUCCESS_COUNT; i++)); do
RESULT=$(roll 6)
total_set2=$((total_set2 + RESULT))
if [ "$RESULT" -eq 6 ]; then
echo -n -e "[ ${BOLD}${GREEN}6 (MAGNIFICENT)${RESET} ] "
else
echo -n "[ $RESULT ] "
fi
done
if [ $total_set1 -le $total_set2 ]; then
TOTAL=$((TOTAL + total_set1))
echo -e " (Kept: $total_set1)"
else
TOTAL=$((TOTAL + total_set2))
echo -e " (Kept: $total_set2)"
fi
else
# Normal rolling
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
fi
echo ""
fi
# Apply bonus/debuff
if [[ "$BONUS_VALUE" != "0" ]]; then
if [[ "$BONUS_VALUE" =~ ^- ]]; then
TOTAL=$((TOTAL + BONUS_VALUE)) # BONUS_VALUE is negative
echo -e "\n${BOLD}Total Face Value (before debuff): $((TOTAL - BONUS_VALUE))${RESET}"
echo -e "${BOLD}Final Total (after ${BONUS_VALUE} debuff): $TOTAL${RESET}"
else
TOTAL=$((TOTAL + BONUS_VALUE))
echo -e "\n${BOLD}Total Face Value (before bonus): $((TOTAL - BONUS_VALUE))${RESET}"
echo -e "${BOLD}Final Total (after ${BONUS_VALUE} bonus): $TOTAL${RESET}"
fi
else
echo -e "\n${BOLD}Total Face Value: $TOTAL${RESET}"
fi