package main import ( "flag" "fmt" "math/rand" "os" "time" "gitlab.com/EternalWanderer/dice-roller/Coin" "gitlab.com/EternalWanderer/dice-roller/Colors" "gitlab.com/EternalWanderer/dice-roller/Dice" ) var ( surfaces, modifier, diceThrows, attacks int advantage, disadvantage, coin bool ) func main() { ParseFlags() rand.Seed(time.Now().Unix()) switch { // 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: Coin.Toss(diceThrows) case advantage: x := Dice.SimpleCast() y := Dice.SimpleCast() result, x_block, y_block := Dice.Advantage(x, y) if modifier != 0 { fmt.Printf("%sRolling 1d20 + %d with advantage...%s\n", Colors.ColorGreen, modifier, Colors.ColorReset) fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "Without modifier...", Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result, Colors.ColorReset, "x:", x_block, "y:", y_block) fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "With modifier...", Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result+modifier, Colors.ColorReset, "x:", x_block+modifier, "y:", y_block+modifier) } else { fmt.Printf("%sRolling 1d20 with advantage...%s\n", Colors.ColorGreen, Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result, Colors.ColorReset, "x:", x_block, "y:", y_block) } case disadvantage: x := Dice.SimpleCast() y := Dice.SimpleCast() result, x_block, y_block := Dice.Disadvantage(x, y) if modifier != 0 { fmt.Printf("%sRolling 1d20 + %d with disadvantage...%s\n", Colors.ColorRed, modifier, Colors.ColorReset) fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "Without modifier...", Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result, Colors.ColorReset, "x:", x_block, "y:", y_block) fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "With modifier...", Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result+modifier, Colors.ColorReset, "x:", x_block+modifier, "y:", y_block+modifier) } else { fmt.Printf("%sRolling 1d20 with disadvantage...%s\n", Colors.ColorRed, Colors.ColorReset) fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result, Colors.ColorReset, "x:", x_block, "y:", y_block) } case attacks > 1: for i := 0; i < attacks; i++ { fmt.Printf("%sAttack %d:%s\n", Colors.ColorBlue, i+1, Colors.ColorReset) Dice.Cast(surfaces, diceThrows, modifier) } default: Dice.Cast(surfaces, diceThrows, modifier) } } func ParseFlags() { 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") flag.BoolVar(&advantage, "advantage", false, "Roll with advantage") flag.BoolVar(&disadvantage, "disadvantage", false, "Roll with disadvantage") flag.BoolVar(&coin, "coin", false, "Toss a coin, same as '-s 2'") flag.Parse() }