2022-08-19 10:15:31 +02:00
|
|
|
package Dice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
surfaces, diceThrows, modidier int
|
|
|
|
)
|
|
|
|
|
2022-08-19 12:01:07 +02:00
|
|
|
func Cast(surfaces, diceThrows, modifier int) {
|
2022-08-19 10:15:31 +02:00
|
|
|
var (
|
|
|
|
casts []int
|
|
|
|
cast, total int
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := 0; i < diceThrows; i++ {
|
|
|
|
cast = rand.Intn(surfaces) + 1
|
|
|
|
casts = append(casts, cast)
|
|
|
|
total += cast
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case modifier != 0:
|
|
|
|
fmt.Printf("%sRolling %dd%d + %d...\n%s", Colors.ColorYellow, diceThrows, surfaces, modifier, Colors.ColorReset)
|
|
|
|
default:
|
|
|
|
fmt.Printf("%sRolling %dd%d...\n%s", Colors.ColorYellow, diceThrows, surfaces, Colors.ColorReset)
|
|
|
|
}
|
|
|
|
|
|
|
|
if diceThrows > 1 {
|
|
|
|
fmt.Println(Colors.ColorMagenta, "\tIndividual rolls:",
|
|
|
|
strings.Trim(fmt.Sprint(casts), "[]"),
|
|
|
|
Colors.ColorReset)
|
|
|
|
}
|
|
|
|
|
|
|
|
if modifier != 0 {
|
|
|
|
fmt.Println("\tWithout modifier:", total)
|
|
|
|
fmt.Println(Colors.ColorGreen, "\tWith modifier:", total+modifier, Colors.ColorReset)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s\t%d%s\n", Colors.ColorGreen, total, Colors.ColorReset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:19:53 +02:00
|
|
|
func SimpleCast() int {
|
2022-08-19 10:15:31 +02:00
|
|
|
|
|
|
|
var cast = rand.Intn(20) + 1
|
|
|
|
|
2022-08-19 15:19:53 +02:00
|
|
|
return cast
|
2022-08-19 10:15:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-19 15:19:53 +02:00
|
|
|
func Advantage(x, y int) (int, int, int) {
|
2022-08-19 10:15:31 +02:00
|
|
|
if x > y {
|
2022-08-19 15:19:53 +02:00
|
|
|
return x, x, y
|
2022-08-19 10:15:31 +02:00
|
|
|
} else {
|
2022-08-19 15:19:53 +02:00
|
|
|
return y, x, y
|
2022-08-19 10:15:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:19:53 +02:00
|
|
|
func Disadvantage(x, y int) (int, int, int) {
|
2022-08-19 10:15:31 +02:00
|
|
|
if x < y {
|
2022-08-19 15:19:53 +02:00
|
|
|
return x, x, y
|
2022-08-19 10:15:31 +02:00
|
|
|
} else {
|
2022-08-19 15:19:53 +02:00
|
|
|
return y, x, y
|
2022-08-19 10:15:31 +02:00
|
|
|
}
|
|
|
|
}
|