THE BEST DICE FUNCTION ON THE PLANET

This commit is contained in:
Elliott Pardee 2015-02-10 09:06:59 -05:00
parent d4a83ffab1
commit 8d7f9036ad

40
bot.go
View File

@ -18,7 +18,8 @@ type Bot struct {
} }
var ( var (
admins = []string{"vypr", "bajr"} admins = []string{"vypr", "bajr", "kirby"}
dieopt = []string{"4", "6", "8", "10", "12", "20"}
dunmas = "" dunmas = ""
rulemod = make([]string, len(modeopt)) rulemod = make([]string, len(modeopt))
@ -50,7 +51,7 @@ var dict = map[string]string{
var argmap = map[string]int{ var argmap = map[string]int{
".set": 4, ".set": 4,
".print": 3, ".print": 3,
".die": 2, ".roll": 1,
".mode": 1, ".mode": 1,
".rmmode": 1, ".rmmode": 1,
".dm": 1, ".dm": 1,
@ -68,23 +69,24 @@ func fillCharmap(nick string, cat string, item string, val string) {
} }
} }
func die(side int, amount int) { func roll(amount int, side int) int {
// TODO: Works, just not correctly. var numbers = make([]int, amount)
var numbers = make([]int, amount + 1) var finaln = 0;
var tmpnum = make([]int, amount)
for i := 0; i < amount; i++ { for i := 0; i < amount; i++ {
r1 := rand.NewSource(0) number := rand.Intn(side) + 1
r2 := rand.New(r1)
number := r2.Intn(side)
numbers[i] = number numbers[i] = number
if amount > i {
tmpnum[i] = numbers[i + 1] + number
} }
fmt.Println(tmpnum[i]) for i := 0; i < len(numbers); i++ {
if i == len(numbers) {
return finaln
} }
finaln = finaln + numbers[i]
}
return finaln
} }
// TODO: Create functions related to character import/export. // TODO: Create functions related to character import/export.
@ -136,10 +138,14 @@ func (b *Bot) Command(nick string, msg string) {
} }
break break
case ".die": case ".roll":
arg1, _ := strconv.Atoi(args[0]) amount, _ := strconv.Atoi(strings.Split(args[0], "d")[0])
arg2, _ := strconv.Atoi(args[1]) side, _ := strconv.Atoi(strings.Split(args[0], "d")[1])
die(arg1, arg2)
if stringInSlice(strconv.Itoa(side), dieopt) && amount > 0 && amount <= 20 {
fmt.Println("[cmd] rolling " + args[0])
b.Say(nick + " rolled a " + strconv.Itoa(roll(amount, side)))
}
break break
case ".mode": case ".mode":