2021-08-23 18:53:20 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-08-19 12:04:04 +02:00
|
|
|
"math/rand"
|
2021-09-16 13:52:38 +02:00
|
|
|
"os"
|
2022-08-19 12:04:04 +02:00
|
|
|
"time"
|
2022-08-19 10:15:31 +02:00
|
|
|
|
|
|
|
"gitlab.com/EternalWanderer/dice-roller/Coin"
|
|
|
|
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
|
|
|
"gitlab.com/EternalWanderer/dice-roller/Dice"
|
2021-08-23 18:53:20 +02:00
|
|
|
)
|
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
var (
|
|
|
|
surfaces, modifier, diceThrows, attacks int
|
2022-08-07 01:42:35 +02:00
|
|
|
advantage, disadvantage, coin bool
|
2021-09-16 13:52:38 +02:00
|
|
|
)
|
|
|
|
|
2021-08-23 18:53:20 +02:00
|
|
|
func main() {
|
2021-09-16 13:52:38 +02:00
|
|
|
ParseFlags()
|
2022-08-19 12:04:04 +02:00
|
|
|
rand.Seed(time.Now().Unix())
|
2021-09-16 11:59:45 +02:00
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
switch {
|
2022-08-07 01:42:35 +02:00
|
|
|
|
|
|
|
// few basic checks
|
|
|
|
case attacks < 1:
|
|
|
|
fmt.Println("Attack amount cannot be below 1")
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
case surfaces < 2:
|
|
|
|
fmt.Println("Die surfaces cannot be below 2")
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
case diceThrows < 1:
|
|
|
|
fmt.Println("Dice thrown cannot be below 1")
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
// die with 2 sides might as well be a coin
|
|
|
|
case surfaces == 2 || coin:
|
2022-08-19 10:15:31 +02:00
|
|
|
Coin.Toss(diceThrows)
|
2022-08-07 01:42:35 +02:00
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
case advantage:
|
2022-08-07 01:42:35 +02:00
|
|
|
if modifier > 0 {
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("%sRolling 1d20 + %d with advantage...%s\n", Colors.ColorGreen, modifier, Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
} else {
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("%sRolling 1d20 with advantage...%s\n", Colors.ColorGreen, Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
}
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("\t%s%d%s\n", Colors.ColorGreen, Dice.Advantage(Dice.SimpleCast(modifier), Dice.SimpleCast(modifier)), Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
case disadvantage:
|
2022-07-29 15:04:24 +02:00
|
|
|
if modifier != 0 {
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("%sRolling 1d20 + %d with disadvantage...%s\n", Colors.ColorRed, modifier, Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
} else {
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("%sRolling 1d20 with disadvantage...%s\n", Colors.ColorRed, Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
}
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("\t%s%d%s\n", Colors.ColorRed, Dice.Disadvantage(Dice.SimpleCast(modifier), Dice.SimpleCast(modifier)), Colors.ColorReset)
|
2022-07-29 15:04:24 +02:00
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
case attacks > 1:
|
|
|
|
for i := 0; i < attacks; i++ {
|
2022-08-19 10:15:31 +02:00
|
|
|
fmt.Printf("%sAttack %d:%s\n", Colors.ColorBlue, i+1, Colors.ColorReset)
|
|
|
|
Dice.Cast(surfaces, diceThrows, modifier)
|
2021-09-16 11:59:45 +02:00
|
|
|
}
|
2021-09-16 13:52:38 +02:00
|
|
|
default:
|
2022-08-19 10:15:31 +02:00
|
|
|
Dice.Cast(surfaces, diceThrows, modifier)
|
2021-08-28 12:36:16 +02:00
|
|
|
}
|
2021-08-23 18:53:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
func ParseFlags() {
|
2022-07-29 12:26:50 +02:00
|
|
|
flag.IntVar(&surfaces, "surfaces", 20, "Use to specify die surfaces, does not apply to advantage and disadvantage")
|
|
|
|
flag.IntVar(&surfaces, "s", 20, "Use to specify die surfaces, defaults to 20")
|
|
|
|
|
|
|
|
flag.IntVar(&diceThrows, "throws", 1, "Specify amount of dice to cast")
|
|
|
|
flag.IntVar(&diceThrows, "c", 1, "Specify amount of dice to cast")
|
|
|
|
|
|
|
|
flag.IntVar(&modifier, "modifier", 0, "Add modifier to result of rolls")
|
|
|
|
flag.IntVar(&modifier, "m", 0, "Add modifier to result of rolls")
|
|
|
|
|
|
|
|
flag.IntVar(&attacks, "attacks", 1, "Roll a set rules multiple times, does not apply to advantage and disadvantage")
|
|
|
|
flag.IntVar(&attacks, "a", 1, "Roll a set rules multiple times, does not apply to advantage and disadvantage")
|
2021-09-16 13:52:38 +02:00
|
|
|
|
2022-07-29 12:26:50 +02:00
|
|
|
flag.BoolVar(&advantage, "advantage", false, "Roll with advantage")
|
|
|
|
flag.BoolVar(&disadvantage, "disadvantage", false, "Roll with disadvantage")
|
2021-09-16 13:52:38 +02:00
|
|
|
|
2022-08-07 01:42:35 +02:00
|
|
|
flag.BoolVar(&coin, "coin", false, "Toss a coin, same as '-s 2'")
|
|
|
|
|
2021-09-16 13:52:38 +02:00
|
|
|
flag.Parse()
|
|
|
|
}
|