From 62144ce8a1b71cdaeac5bc946d1e735299729b16 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 28 Jun 2019 18:54:32 +0100 Subject: fixes #7 --- build | 2 ++ main.go | 2 +- wat/db.go | 14 +++++++---- wat/game.go | 80 ++++++++++++++++++++++++++++++++++++++++--------------------- 4 files changed, 66 insertions(+), 32 deletions(-) create mode 100755 build diff --git a/build b/build new file mode 100755 index 0000000..fe3ff90 --- /dev/null +++ b/build @@ -0,0 +1,2 @@ +#!/bin/bash +go build -o $HOME/go/bin/watbot main.go diff --git a/main.go b/main.go index 0370b6d..e83f017 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { watConfig := wat.WatConfig{ PermittedChannels: []string{ "##wat", - //"##test", + "##test", "##sweden", "##freedom", }, diff --git a/wat/db.go b/wat/db.go index fb677d8..672d65d 100644 --- a/wat/db.go +++ b/wat/db.go @@ -111,15 +111,21 @@ func (w *WatDb) Act(player *Player, actionType ActionType) { } func (w *WatDb) Strongest() []Player { + return w.GetTopColumn("anarchy") +} + +func (w *WatDb) GetTopColumn(tipe string) []Player { var user = make([]Player, 10) - w.db.Limit(10).Order("anarchy desc").Find(&user) + w.db.Limit(10).Order(tipe + " desc").Find(&user) return user } +func (w *WatDb) Healthiest() []Player { + return w.GetTopColumn("health") +} + func (w *WatDb) TopLost() []Player { - var user = make([]Player, 10) - w.db.Limit(10).Order("coins_lost desc").Find(&user) - return user + return w.GetTopColumn("coins_lost") } func (w *WatDb) TopTen() []Player { diff --git a/wat/game.go b/wat/game.go index 0e17c5c..d986eb3 100644 --- a/wat/game.go +++ b/wat/game.go @@ -12,13 +12,14 @@ import ( ) type WatGame struct { - bot *WatBot - db *WatDb - me Player - commands map[string](func(*Player, []string) string) - aliases map[string](func(*Player, []string) string) - lifeCommands map[string](func(*Player, []string) string) - roid map[string]int + bot *WatBot + db *WatDb + me Player + commands map[string](func(*Player, []string) string) + aliases map[string](func(*Player, []string) string) + lifeCommands map[string](func(*Player, []string) string) + simpleCommands []string + roid map[string]int } var currency = "watcoin" @@ -26,7 +27,7 @@ var currencys = "watcoins" var unconscious = "wat, your hands fumble and fail you. try resting, weakling." func NewWatGame(bot *WatBot, db *WatDb) *WatGame { - g := WatGame{bot, db, Player{}, nil, nil, nil, map[string]int{}} + g := WatGame{bot, db, Player{}, nil, nil, nil, nil, map[string]int{}} g.me = g.db.User(bot.Nick, "tripsit/user/"+bot.Nick, true) g.commands = map[string](func(*Player, []string) string){ //"wat": g.megaWat, @@ -40,6 +41,7 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame { "dice": g.Dice, "mine": g.Mine, "bankrupt": g.Bankrupt, + "heal": g.Heal, } g.aliases = map[string](func(*Player, []string) string){ "sleep": g.Rest, @@ -48,11 +50,17 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame { g.lifeCommands = map[string](func(*Player, []string) string){ "riot": g.Riot, "bench": g.Bench, - "heal": g.Heal, "steal": g.Steal, "frame": g.Frame, "punch": g.Punch, } + g.simpleCommands = []string{ + "ping", + "strongest", + "healthiest", + "losers", + "richest", + } return &g } @@ -72,9 +80,11 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) { reply = g.help() case "strongest": reply = fmt.Sprintf("stronk: %s", g.Strongest()) - case "toplost": + case "healthiest": + reply = fmt.Sprintf("healthy: %s", g.Healthiest()) + case "losers": reply = fmt.Sprintf("%s losers: %s", currency, g.TopLost()) - case "topten": + case "richest": reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen()) case "source": reply = "https://git.circuitco.de/self/watbot" @@ -98,6 +108,7 @@ func (g *WatGame) help() string { } ret += cmd } + ret += strings.Join(g.simpleCommands, ", ") for cmd, _ := range g.lifeCommands { if len(ret) > 0 { ret += ", " @@ -113,7 +124,7 @@ func (g *WatGame) RandInt(max int64) uint64 { } func (g *WatGame) Heal(player *Player, fields []string) string { - multiplier := int64(5) + multiplier := int64(30) if len(fields) < 3 { return "#heal - sacrifice your money to me, peasant! i might heal someone!" } @@ -177,24 +188,25 @@ func (g *WatGame) Int(str string) (uint64, error) { func (g *WatGame) Roll(player *Player, fields []string) string { if len(fields) < 2 { - return fmt.Sprintf("roll <%s> pls - u must score < 50 if u want 2 win", currency) - } - if player.Nick == "vlk" { - return "you've had enough rolling friend. unroll it." + return fmt.Sprintf("roll <%s> pls - u must score < 50 if u want 2 win. u can also pick the dice size", currency) } amount, e := g.Int(fields[1]) if e != nil { return e.Error() } + dieSize := int64(100) + if len(fields) >= 3 { + userDieSize, e := g.Int(fields[2]) + if e == nil && userDieSize >= 2 { + dieSize = int64(userDieSize) + } + } if amount > player.Coins { return "wat? brokeass" } - n := int64(g.RandInt(100)) + 1 - ret := fmt.Sprintf("%s rolls the 100 sided die... %d! ", player.Nick, n) - if player.Nick == "vlk" { - n -= 5 - } - if n < 50 { + n := int64(g.RandInt(dieSize)) + 1 + ret := fmt.Sprintf("%s rolls the %d sided die... %d! ", player.Nick, dieSize, n) + if n < dieSize/2 { player.Coins += amount ret += fmt.Sprintf("You win! ◕ ◡ ◕ total: %d %s", player.Coins, currency) } else { @@ -387,9 +399,14 @@ func (g *WatGame) Rest(player *Player, fields []string) string { ret = fmt.Sprintf("wat were you thinking, sleeping at a time like this (%d until next rest)", minRest-delta) } else { value := g.RandInt(10) + 1 - ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value) + if player.Health < -5 { + player.Health = 1 + ret = fmt.Sprintf("wow ur beat up. i pity u, ur health is now 1.") + } else { + player.Health += int64(value) + ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d, you've got %d hp)", value, player.Health) + } player.LastRested = time.Now().Unix() - player.Health += int64(value) g.db.Update(player) } return ret @@ -528,11 +545,11 @@ func (g *WatGame) Watch(player *Player, fields []string) string { } player = maybePlayer } - return fmt.Sprintf("%s's Strength: %d (%d) / Trickery: %d (%d) / Coins: %d / Health: %d", player.Nick, player.Level(player.Anarchy), player.Anarchy, player.Trickery, player.Trickery, player.Coins, player.Health) + return fmt.Sprintf("%s's Strength: %d (%d) / Coins: %d / Health: %d", player.Nick, player.Level(player.Anarchy), player.Anarchy, player.Coins, player.Health) } func (g *WatGame) Balance(player *Player, fields []string) string { - balStr := "%s's %s balance: %d. Mining time credit: %d. Total lost: %d." + balStr := "%s's %s balance: %d. Mining time credit: %d. Total lost: %d. Bankrupt %d times." balPlayer := player if len(fields) > 1 { var err string @@ -541,7 +558,7 @@ func (g *WatGame) Balance(player *Player, fields []string) string { return err } } - return fmt.Sprintf(balStr, balPlayer.Nick, currency, balPlayer.Coins, time.Now().Unix()-balPlayer.LastMined, balPlayer.CoinsLost) + return fmt.Sprintf(balStr, balPlayer.Nick, currency, balPlayer.Coins, time.Now().Unix()-balPlayer.LastMined, balPlayer.CoinsLost, balPlayer.Bankrupcy) } func (g *WatGame) Strongest() string { @@ -553,6 +570,15 @@ func (g *WatGame) Strongest() string { return ret } +func (g *WatGame) Healthiest() string { + players := g.db.Healthiest() + ret := "" + for _, p := range players { + ret += PrintTwo(p.Nick, uint64(p.Health)) + } + return ret +} + func (g *WatGame) TopLost() string { players := g.db.TopLost() ret := "" -- cgit v1.2.3