changed coins to uint64 and started using uints all over the place
added toplost removed an ignore
This commit is contained in:
parent
237d91de16
commit
5c24c985d3
@ -61,7 +61,7 @@ func (w *WatBot) AllowedChannel(c string) bool {
|
|||||||
func (w *WatBot) Msg(m *irc.Message) {
|
func (w *WatBot) Msg(m *irc.Message) {
|
||||||
// bail out if you're not yves, if you're not tripsit or if you're not in an allowed channel
|
// bail out if you're not yves, if you're not tripsit or if you're not in an allowed channel
|
||||||
// but if you're an admin you can do whatever
|
// but if you're an admin you can do whatever
|
||||||
if m.Prefix.Host == "tripsit/user/creatonez" || m.Prefix.Host == "tripsit/user/Yves" || !strings.Contains(m.Prefix.Host, "tripsit") || (!w.AllowedChannel(m.Params[0]) && !w.Admin(m)) {
|
if m.Prefix.Host == "tripsit/user/creatonez" || !strings.Contains(m.Prefix.Host, "tripsit") || (!w.AllowedChannel(m.Params[0]) && !w.Admin(m)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
wat/db.go
12
wat/db.go
@ -15,14 +15,14 @@ type Player struct {
|
|||||||
Watting int64
|
Watting int64
|
||||||
Anarchy int64
|
Anarchy int64
|
||||||
Trickery int64
|
Trickery int64
|
||||||
Coins int64 `gorm:"default:'100'"`
|
Coins uint64 `gorm:"default:'100'"`
|
||||||
Health int64
|
Health int64
|
||||||
LastMined int64
|
LastMined int64
|
||||||
LastRested int64
|
LastRested int64
|
||||||
CoinsLost int64
|
CoinsLost uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) LoseCoins(coins int64) {
|
func (p *Player) LoseCoins(coins uint64) {
|
||||||
p.Coins -= coins
|
p.Coins -= coins
|
||||||
p.CoinsLost += coins
|
p.CoinsLost += coins
|
||||||
}
|
}
|
||||||
@ -97,6 +97,12 @@ func (w *WatDb) Update(upd ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WatDb) TopLost() []Player {
|
||||||
|
var user = make([]Player, 10)
|
||||||
|
w.db.Limit(10).Order("coins_lost desc").Find(&user)
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WatDb) TopTen() []Player {
|
func (w *WatDb) TopTen() []Player {
|
||||||
var user = make([]Player, 10)
|
var user = make([]Player, 10)
|
||||||
w.db.Limit(10).Order("coins desc").Find(&user)
|
w.db.Limit(10).Order("coins desc").Find(&user)
|
||||||
|
75
wat/game.go
75
wat/game.go
@ -33,10 +33,10 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
|
|||||||
"flip": g.Roll,
|
"flip": g.Roll,
|
||||||
"dice": g.Dice,
|
"dice": g.Dice,
|
||||||
"mine": g.Mine,
|
"mine": g.Mine,
|
||||||
"riot": g.Riot,
|
|
||||||
"bench": g.Bench,
|
|
||||||
}
|
}
|
||||||
g.lifeCommands = map[string](func(*Player, []string) string){
|
g.lifeCommands = map[string](func(*Player, []string) string){
|
||||||
|
"riot": g.Riot,
|
||||||
|
"bench": g.Bench,
|
||||||
"heal": g.Heal,
|
"heal": g.Heal,
|
||||||
"steal": g.Steal,
|
"steal": g.Steal,
|
||||||
"frame": g.Frame,
|
"frame": g.Frame,
|
||||||
@ -65,6 +65,8 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) {
|
|||||||
switch strings.ToLower(fields[0]) {
|
switch strings.ToLower(fields[0]) {
|
||||||
case "help":
|
case "help":
|
||||||
reply = helpText
|
reply = helpText
|
||||||
|
case "toplost":
|
||||||
|
reply = fmt.Sprintf("%s losers: %s", currency, g.TopLost())
|
||||||
case "topten":
|
case "topten":
|
||||||
reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen())
|
reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen())
|
||||||
case "source":
|
case "source":
|
||||||
@ -83,9 +85,9 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) {
|
|||||||
g.bot.reply(m, reply)
|
g.bot.reply(m, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) RandInt(max int64) int64 {
|
func (g *WatGame) RandInt(max int64) uint64 {
|
||||||
i, _ := rand.Int(rand.Reader, big.NewInt(max))
|
i, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||||
return i.Int64()
|
return i.Uint64()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Heal(player *Player, fields []string) string {
|
func (g *WatGame) Heal(player *Player, fields []string) string {
|
||||||
@ -97,20 +99,21 @@ func (g *WatGame) Heal(player *Player, fields []string) string {
|
|||||||
if e != "" {
|
if e != "" {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
amount, err := g.Int(fields[2])
|
a, err := g.Int(fields[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
if amount > player.Coins {
|
if a > player.Coins {
|
||||||
return "u poor lol"
|
return "u poor lol"
|
||||||
}
|
}
|
||||||
|
amount := int64(a)
|
||||||
if amount < multiplier {
|
if amount < multiplier {
|
||||||
return fmt.Sprintf("too cheap lol at least %d", multiplier)
|
return fmt.Sprintf("too cheap lol at least %d", multiplier)
|
||||||
}
|
}
|
||||||
target.Health += amount / multiplier
|
target.Health += amount / multiplier
|
||||||
player.Coins -= amount
|
player.Coins -= a
|
||||||
if target.Nick == player.Nick {
|
if target.Nick == player.Nick {
|
||||||
target.Coins -= amount
|
target.Coins -= a
|
||||||
g.db.Update(target)
|
g.db.Update(target)
|
||||||
} else {
|
} else {
|
||||||
g.db.Update(target, player)
|
g.db.Update(target, player)
|
||||||
@ -120,14 +123,14 @@ func (g *WatGame) Heal(player *Player, fields []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Dice(player *Player, fields []string) string {
|
func (g *WatGame) Dice(player *Player, fields []string) string {
|
||||||
roll := int64(6)
|
roll := uint64(6)
|
||||||
if len(fields) > 1 {
|
if len(fields) > 1 {
|
||||||
i, e := g.Int(fields[1])
|
i, e := g.Int(fields[1])
|
||||||
if e == nil {
|
if e == nil {
|
||||||
roll = i
|
roll = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
answer := g.RandInt(roll) + 1
|
answer := g.RandInt(int64(roll)) + 1
|
||||||
return fmt.Sprintf("1d%d - %d", roll, answer)
|
return fmt.Sprintf("1d%d - %d", roll, answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +142,13 @@ type ParseIntError struct {
|
|||||||
func (e PositiveError) Error() string { return "i don't do negative numbers lol" }
|
func (e PositiveError) Error() string { return "i don't do negative numbers lol" }
|
||||||
func (e ParseIntError) Error() string { return fmt.Sprintf("wat kinda number is %s", e.original) }
|
func (e ParseIntError) Error() string { return fmt.Sprintf("wat kinda number is %s", e.original) }
|
||||||
|
|
||||||
func (g *WatGame) Int(str string) (int64, error) {
|
func (g *WatGame) Int(str string) (uint64, error) {
|
||||||
i, e := strconv.ParseInt(str, 10, 64)
|
i, e := strconv.ParseUint(str, 10, 64)
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
return 0, PositiveError{}
|
return 0, PositiveError{}
|
||||||
}
|
}
|
||||||
if e != nil {
|
if e != nil {
|
||||||
e = ParseIntError{}
|
e = ParseIntError{str}
|
||||||
}
|
}
|
||||||
return i, e
|
return i, e
|
||||||
}
|
}
|
||||||
@ -191,16 +194,16 @@ func (g *WatGame) Punch(player *Player, fields []string) string {
|
|||||||
dmg := g.RandInt(6) + 1
|
dmg := g.RandInt(6) + 1
|
||||||
ret := fmt.Sprintf("%s rolls a d6... %s ", player.Nick, player.Nick)
|
ret := fmt.Sprintf("%s rolls a d6... %s ", player.Nick, player.Nick)
|
||||||
if chance > 3 {
|
if chance > 3 {
|
||||||
dmg += player.Level(player.Anarchy)
|
dmg += uint64(player.Level(player.Anarchy))
|
||||||
ret += fmt.Sprintf("hits %s for %d points of damage! ", target.Nick, dmg)
|
ret += fmt.Sprintf("hits %s for %d points of damage! ", target.Nick, dmg)
|
||||||
target.Health -= dmg
|
target.Health -= int64(dmg)
|
||||||
g.db.Update(target)
|
g.db.Update(target)
|
||||||
if target.Health <= 0 {
|
if target.Health <= 0 {
|
||||||
ret += target.Nick + " has fallen unconscious."
|
ret += target.Nick + " has fallen unconscious."
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret += fmt.Sprintf("fumbles, and punches themselves in confusion! %d self-damage. ", dmg)
|
ret += fmt.Sprintf("fumbles, and punches themselves in confusion! %d self-damage. ", dmg)
|
||||||
player.Health -= dmg
|
player.Health -= int64(dmg)
|
||||||
if player.Health <= 0 {
|
if player.Health <= 0 {
|
||||||
ret += player.Nick + " has fallen unconscious."
|
ret += player.Nick + " has fallen unconscious."
|
||||||
}
|
}
|
||||||
@ -253,7 +256,7 @@ func (g *WatGame) Steal(player *Player, fields []string) string {
|
|||||||
return e.Error()
|
return e.Error()
|
||||||
}
|
}
|
||||||
if player.Coins < amount*2 {
|
if player.Coins < amount*2 {
|
||||||
return "wat? you need double your theft or you'd go bankrupt if they steal back..."
|
return "wat? you need double what ur trying 2 steal or you'll go bankrupt..."
|
||||||
}
|
}
|
||||||
target, err := g.GetTarget(player.Nick, fields[1])
|
target, err := g.GetTarget(player.Nick, fields[1])
|
||||||
if target == nil {
|
if target == nil {
|
||||||
@ -292,7 +295,7 @@ func (g *WatGame) GetTarget(player, target string) (*Player, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Leech(player *Player, fields []string) string {
|
func (g *WatGame) Leech(player *Player, fields []string) string {
|
||||||
divisor := int64(10)
|
divisor := uint64(10)
|
||||||
if len(fields) < 3 {
|
if len(fields) < 3 {
|
||||||
return fmt.Sprintf("leech <nick> <%s> - using your wealth, you steal the life force of another player", currency)
|
return fmt.Sprintf("leech <nick> <%s> - using your wealth, you steal the life force of another player", currency)
|
||||||
}
|
}
|
||||||
@ -312,8 +315,8 @@ func (g *WatGame) Leech(player *Player, fields []string) string {
|
|||||||
hpDown := amount / divisor
|
hpDown := amount / divisor
|
||||||
player.Coins -= amount
|
player.Coins -= amount
|
||||||
if r < 5 {
|
if r < 5 {
|
||||||
target.Health -= hpDown
|
target.Health -= int64(hpDown)
|
||||||
player.Health += hpDown
|
player.Health += int64(hpDown)
|
||||||
player.Anarchy += 1
|
player.Anarchy += 1
|
||||||
reply += fmt.Sprintf("The deal is done, you took %d HP from %s. They now have %d HP, you have %d.", hpDown, target.Nick, target.Health, player.Health)
|
reply += fmt.Sprintf("The deal is done, you took %d HP from %s. They now have %d HP, you have %d.", hpDown, target.Nick, target.Health, player.Health)
|
||||||
g.db.Update(target, player)
|
g.db.Update(target, player)
|
||||||
@ -338,13 +341,14 @@ func (g *WatGame) Rest(player *Player, fields []string) string {
|
|||||||
value := g.RandInt(10) + 1
|
value := g.RandInt(10) + 1
|
||||||
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value)
|
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value)
|
||||||
player.LastRested = time.Now().Unix()
|
player.LastRested = time.Now().Unix()
|
||||||
player.Health += value
|
player.Health += int64(value)
|
||||||
g.db.Update(player)
|
g.db.Update(player)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Bench(player *Player, fields []string) string {
|
func (g *WatGame) Bench(player *Player, fields []string) string {
|
||||||
|
return "meh"
|
||||||
weight := g.RandInt(370) + 50
|
weight := g.RandInt(370) + 50
|
||||||
reps := g.RandInt(10)
|
reps := g.RandInt(10)
|
||||||
value := int64(0)
|
value := int64(0)
|
||||||
@ -393,29 +397,30 @@ func (g *WatGame) Send(player *Player, fields []string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
if int64(amount) > player.Coins {
|
if amount > player.Coins {
|
||||||
return "wat? you're too poor!"
|
return "wat? you're too poor!"
|
||||||
}
|
}
|
||||||
target, str := g.GetTarget(player.Nick, fields[1])
|
target, str := g.GetTarget(player.Nick, fields[1])
|
||||||
if target == nil {
|
if target == nil {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
player.Coins -= int64(amount)
|
player.Coins -= amount
|
||||||
target.Coins += int64(amount)
|
target.Coins += amount
|
||||||
g.db.Update(player, target)
|
g.db.Update(player, target)
|
||||||
return fmt.Sprintf("%s sent %s %d %s. %s has %d %s, %s has %d %s", player.Nick, target.Nick, amount, currency, player.Nick, player.Coins, currency, target.Nick, target.Coins, currency)
|
return fmt.Sprintf("%s sent %s %d %s. %s has %d %s, %s has %d %s", player.Nick, target.Nick, amount, currency, player.Nick, player.Coins, currency, target.Nick, target.Coins, currency)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Mine(player *Player, _ []string) string {
|
func (g *WatGame) Mine(player *Player, _ []string) string {
|
||||||
delta := time.Now().Unix() - player.LastMined
|
delta := uint64(time.Now().Unix() - player.LastMined)
|
||||||
if delta < 600 {
|
minDelta := uint64(600)
|
||||||
|
if delta < minDelta {
|
||||||
return fmt.Sprintf("wat? 2 soon. u earn more when u wait long (%d)", delta)
|
return fmt.Sprintf("wat? 2 soon. u earn more when u wait long (%d)", delta)
|
||||||
}
|
}
|
||||||
value := int64(0)
|
value := uint64(0)
|
||||||
if delta < 36000 {
|
if delta < 36000 {
|
||||||
value = delta / 600
|
value = delta / minDelta
|
||||||
} else if delta < 86400 {
|
} else if delta < 86400 {
|
||||||
value = 10
|
value = 25
|
||||||
} else if delta < 2592000 {
|
} else if delta < 2592000 {
|
||||||
value = 50
|
value = 50
|
||||||
} else {
|
} else {
|
||||||
@ -423,7 +428,7 @@ func (g *WatGame) Mine(player *Player, _ []string) string {
|
|||||||
}
|
}
|
||||||
msg := ""
|
msg := ""
|
||||||
if player.LastMined == 0 {
|
if player.LastMined == 0 {
|
||||||
msg = "with wat? you go to get a pickaxe"
|
msg = fmt.Sprintf("u forgot ur pickaxe but it's okay i'll give you one in %d", minDelta)
|
||||||
value = 0
|
value = 0
|
||||||
} else {
|
} else {
|
||||||
player.Coins += value
|
player.Coins += value
|
||||||
@ -458,6 +463,14 @@ func (g *WatGame) Balance(player *Player, fields []string) string {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *WatGame) TopLost() string {
|
||||||
|
players := g.db.TopLost()
|
||||||
|
ret := ""
|
||||||
|
for _, p := range players {
|
||||||
|
ret += PrintTwo(p.Nick, p.CoinsLost)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
func (g *WatGame) TopTen() string {
|
func (g *WatGame) TopTen() string {
|
||||||
players := g.db.TopTen()
|
players := g.db.TopTen()
|
||||||
ret := ""
|
ret := ""
|
||||||
@ -467,7 +480,7 @@ func (g *WatGame) TopTen() string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintTwo(nick string, value int64) string {
|
func PrintTwo(nick string, value uint64) string {
|
||||||
return fmt.Sprintf("%s (%d) ", CleanNick(nick), value)
|
return fmt.Sprintf("%s (%d) ", CleanNick(nick), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user