Compare commits

..

No commits in common. "67ef6fec1b6b4ca6b99701109b15f60a853dc5a2" and "91b0e21b7ac29d11d7c6774c92c99f4640a1a8d1" have entirely different histories.

2 changed files with 21 additions and 110 deletions

View File

@ -121,17 +121,9 @@ func (g *WatGame) help() string {
return ret
}
func (g *WatGame) RandInt(maxx int64) (uint64, error) {
bi := big.NewInt(maxx)
// prevent panic of rand.Int on big numbers
if bi.BitLen() < 2 {
return 0, fmt.Errorf("overflow, got %d", bi)
}
i, err := rand.Int(rand.Reader, bi)
if err != nil {
return 0, err
}
return i.Uint64(), nil
func (g *WatGame) RandInt(max int64) uint64 {
i, _ := rand.Int(rand.Reader, big.NewInt(max))
return i.Uint64()
}
func (g *WatGame) Heal(player *Player, fields []string) string {
@ -174,11 +166,8 @@ func (g *WatGame) Dice(player *Player, fields []string) string {
roll = i
}
}
answer, err := g.RandInt(int64(roll))
if e := handleError(err); e != "" {
return e
}
return fmt.Sprintf("1d%d - %d", roll + 1, answer)
answer := g.RandInt(int64(roll)) + 1
return fmt.Sprintf("1d%d - %d", roll, answer)
}
type PositiveError struct{}
@ -217,20 +206,12 @@ func (g *WatGame) Roll(player *Player, fields []string) string {
}
lotteryNum := int64(-1)
if dieSize > 100 {
lotteryNumRand, randErr := g.RandInt(dieSize)
if e := handleError(randErr); e != "" {
return e
}
lotteryNum = int64(lotteryNumRand) + 1
lotteryNum = int64(g.RandInt(dieSize)) + 1
}
if amount > player.Coins {
return "wat? brokeass"
}
nRand, randErr := g.RandInt(dieSize)
if e := handleError(randErr); e != "" {
return e
}
n := int64(nRand) + 1
n := int64(g.RandInt(dieSize)) + 1
ret := fmt.Sprintf("%s rolls the %d sided die... %d! ", player.Nick, dieSize, n)
if n == lotteryNum {
player.Coins += player.Coins
@ -274,18 +255,11 @@ func (g *WatGame) Punch(player *Player, fields []string) string {
if !target.Conscious() {
return "wat? you're punching someone who is already unconscious. u crazy?"
}
chance, randErr := g.RandInt(6)
if e := handleError(randErr); e != "" {
return e
}
dmg, randErr := g.RandInt(6)
if e := handleError(randErr); e != "" {
return e
}
dmg = dmg + 1
chance := g.RandInt(6) + 1
dmg := g.RandInt(6) + 1
ret := fmt.Sprintf("%s rolls a d6... %s ", player.Nick, player.Nick)
dmg += uint64(player.Level(player.Anarchy))
if chance + 1 > 3 {
if chance > 3 {
ret += fmt.Sprintf("hits %s for %d points of damage! ", target.Nick, dmg)
target.Health -= int64(dmg)
g.db.Update(target)
@ -326,11 +300,7 @@ func (g *WatGame) Frame(player *Player, fields []string) string {
if target.Coins < amount {
return fmt.Sprintf("wat? %s is too poor for this.", target.Nick)
}
n, randErr := g.RandInt(6)
if e := handleError(randErr); e != "" {
return e
}
n = n + 1
n := g.RandInt(6) + 1
ret := fmt.Sprintf("%s rolls a d6 to frame %s with %d %s: It's a %d! (<3 wins). ", player.Nick, target.Nick, amount, currency, n)
if n < 3 {
ret += fmt.Sprintf("You frame %s for a minor crime. They pay me %d.", target.Nick, amount)
@ -365,11 +335,7 @@ func (g *WatGame) Steal(player *Player, fields []string) string {
if target.Coins < amount {
return fmt.Sprintf("wat? %s is poor and doesn't have that much to steal. (%d %s)", target.Nick, target.Coins, currency)
}
n, randErr := g.RandInt(6)
if e := handleError(randErr); e != "" {
return e
}
n = n + 1
n := g.RandInt(6) + 1
ret := fmt.Sprintf("%s is trying to steal %d %s from %s... ", player.Nick, amount, currency, target.Nick)
if n < 3 {
ret += "You did it! Sneaky bastard!"
@ -414,11 +380,7 @@ func (g *WatGame) Leech(player *Player, fields []string) string {
if err != "" {
return err
}
r, randErr := g.RandInt(10)
if e := handleError(randErr); e != "" {
return e
}
r = r + 1
r := g.RandInt(10) + 1
reply := fmt.Sprintf("You muster your wealth and feed it to %s. ", g.bot.Nick)
hpDown := amount / divisor
player.Coins -= amount
@ -446,11 +408,7 @@ func (g *WatGame) Rest(player *Player, fields []string) string {
} else if delta < minRest {
ret = fmt.Sprintf("wat were you thinking, sleeping at a time like this (%d until next rest)", minRest-delta)
} else {
value, randErr := g.RandInt(10)
if e := handleError(randErr); e != "" {
return e
}
value = value + 1
value := g.RandInt(10) + 1
if player.Health < -5 {
player.Health = 1
ret = fmt.Sprintf("wow ur beat up. i pity u, ur health is now 1.")
@ -477,15 +435,8 @@ func (g *WatGame) Bench(player *Player, fields []string) string {
if !g.CanAct(player, Action_Lift, minTime) {
return "you're tired. no more lifting for now."
}
weight, randErr := g.RandInt(370)
if e := handleError(randErr); e != "" {
return e
}
weight = weight + 50
reps, randErr := g.RandInt(10)
if e := handleError(randErr); e != "" {
return e
}
weight := g.RandInt(370) + 50
reps := g.RandInt(10)
value := int64(0)
reply := fmt.Sprintf("%s benches %dwatts for %d reps, ", player.Nick, weight, reps)
if weight < 150 {
@ -501,10 +452,7 @@ func (g *WatGame) Bench(player *Player, fields []string) string {
}
if g.roid[player.Nick] != 0 {
delete(g.roid, player.Nick)
success, randErr := g.RandInt(2)
if e := handleError(randErr); e != "" {
return e
}
success := g.RandInt(2)
if success != 0 {
player.Health = 0
player.Anarchy -= 10
@ -527,10 +475,7 @@ func (g *WatGame) Riot(player *Player, fields []string) string {
if !g.CanAct(player, Action_Riot, int64((48 * time.Hour).Seconds())) {
return "Planning a riot takes time and the right circumstances. Be prepared. (nothing happens)"
}
r, randErr := g.RandInt(100)
if e := handleError(randErr); e != "" {
return e
}
r := g.RandInt(100)
reply := ""
if r > 40 {
player.Anarchy += 3
@ -676,21 +621,9 @@ func PrintTwo(nick string, value uint64) string {
}
func (g *WatGame) megaWat(player *Player, _ []string) string {
mega, randErr := g.RandInt(1000000)
if e := handleError(randErr); e != "" {
return e + " mega fail"
}
mega = mega + 1
kilo, randErr := g.RandInt(1000)
if e := handleError(randErr); e != "" {
return e + " kilo fail"
}
kilo = kilo + 1
ten, randErr := g.RandInt(100)
if e := handleError(randErr); e != "" {
return e + " ten fail"
}
ten = ten + 1
mega := g.RandInt(1000000) + 1
kilo := g.RandInt(1000) + 1
ten := g.RandInt(100) + 1
reply := ""
if mega == 23 {
player.Coins += 1000000

View File

@ -1,22 +0,0 @@
package wat
import (
"fmt"
"runtime"
)
func handleError(err error) string {
if err != nil {
pc, _, _, ok := runtime.Caller(1)
details := runtime.FuncForPC(pc)
var cFun string
if ok && details != nil {
cFun = details.Name()
} else {
cFun = "???"
}
fmt.Printf("caught error in %s: %v\n", cFun, err)
return "u wat"
}
return ""
}