2018-10-21 13:57:23 +02:00
package wat
import (
2018-10-26 13:40:02 +02:00
"crypto/rand"
2018-11-08 11:40:08 +01:00
"fmt"
2018-10-26 13:40:02 +02:00
"math/big"
2018-11-08 11:40:08 +01:00
"strconv"
"strings"
"time"
2018-10-21 13:57:23 +02:00
"github.com/go-irc/irc"
)
type WatGame struct {
2019-06-28 19:54:32 +02:00
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
2018-10-21 13:57:23 +02:00
}
2018-11-15 03:11:45 +01:00
var currency = "watcoin"
var currencys = "watcoins"
var unconscious = "wat, your hands fumble and fail you. try resting, weakling."
2018-10-21 13:57:23 +02:00
func NewWatGame ( bot * WatBot , db * WatDb ) * WatGame {
2019-06-28 19:54:32 +02:00
g := WatGame { bot , db , Player { } , nil , nil , nil , nil , map [ string ] int { } }
2018-10-23 03:36:02 +02:00
g . me = g . db . User ( bot . Nick , "tripsit/user/" + bot . Nick , true )
2018-11-08 11:40:08 +01:00
g . commands = map [ string ] ( func ( * Player , [ ] string ) string ) {
2018-12-04 00:21:11 +01:00
//"wat": g.megaWat,
2019-01-04 10:20:39 +01:00
"steroid" : g . Steroid ,
"watch" : g . Watch ,
"coins" : g . Balance ,
"send" : g . Send ,
"rest" : g . Rest ,
"leech" : g . Leech ,
"roll" : g . Roll ,
"dice" : g . Dice ,
"mine" : g . Mine ,
"bankrupt" : g . Bankrupt ,
2019-06-28 19:54:32 +02:00
"heal" : g . Heal ,
2019-01-04 10:20:39 +01:00
}
g . aliases = map [ string ] ( func ( * Player , [ ] string ) string ) {
"sleep" : g . Rest ,
2018-11-08 11:40:08 +01:00
"flip" : g . Roll ,
}
g . lifeCommands = map [ string ] ( func ( * Player , [ ] string ) string ) {
2018-11-14 23:38:32 +01:00
"riot" : g . Riot ,
"bench" : g . Bench ,
2018-10-23 01:15:28 +02:00
"steal" : g . Steal ,
"frame" : g . Frame ,
"punch" : g . Punch ,
}
2019-06-28 19:54:32 +02:00
g . simpleCommands = [ ] string {
"ping" ,
"strongest" ,
"healthiest" ,
"losers" ,
"richest" ,
}
2018-10-23 01:15:28 +02:00
return & g
2018-10-21 13:57:23 +02:00
}
func ( g * WatGame ) Msg ( m * irc . Message , player * Player , fields [ ] string ) {
2018-11-15 03:11:45 +01:00
command := strings . ToLower ( fields [ 0 ] )
2018-10-21 13:57:23 +02:00
reply := ""
2018-11-15 03:11:45 +01:00
if g . commands [ command ] != nil {
reply = g . commands [ command ] ( player , fields )
2019-01-04 10:20:39 +01:00
} else if g . aliases [ command ] != nil {
reply = g . aliases [ command ] ( player , fields )
2018-10-23 01:15:28 +02:00
} else {
2018-10-25 02:04:35 +02:00
// one liners
2018-11-15 03:11:45 +01:00
switch strings . ToLower ( command ) {
2019-01-04 10:20:39 +01:00
case "ping" :
reply = ",beef"
2018-10-23 01:15:28 +02:00
case "help" :
2018-11-15 03:11:45 +01:00
reply = g . help ( )
2019-01-04 10:20:39 +01:00
case "strongest" :
reply = fmt . Sprintf ( "stronk: %s" , g . Strongest ( ) )
2019-06-28 19:54:32 +02:00
case "healthiest" :
reply = fmt . Sprintf ( "healthy: %s" , g . Healthiest ( ) )
case "losers" :
2018-11-14 23:38:32 +01:00
reply = fmt . Sprintf ( "%s losers: %s" , currency , g . TopLost ( ) )
2019-06-28 19:54:32 +02:00
case "richest" :
2018-10-23 01:15:28 +02:00
reply = fmt . Sprintf ( "%s holders: %s" , currency , g . TopTen ( ) )
2018-11-08 11:40:08 +01:00
case "source" :
reply = "https://git.circuitco.de/self/watbot"
2018-10-23 01:15:28 +02:00
}
}
2018-11-15 03:11:45 +01:00
if g . lifeCommands [ command ] != nil {
2018-10-21 13:57:23 +02:00
if ! player . Conscious ( ) {
reply = unconscious
} else {
2018-11-15 03:11:45 +01:00
reply = g . lifeCommands [ command ] ( player , fields )
2018-10-21 13:57:23 +02:00
}
}
g . bot . reply ( m , reply )
}
2018-11-15 03:11:45 +01:00
func ( g * WatGame ) help ( ) string {
ret := ""
for cmd , _ := range g . commands {
if len ( ret ) > 0 {
ret += ", "
}
ret += cmd
}
2019-06-28 19:54:32 +02:00
ret += strings . Join ( g . simpleCommands , ", " )
2018-11-15 03:11:45 +01:00
for cmd , _ := range g . lifeCommands {
if len ( ret ) > 0 {
ret += ", "
}
ret += cmd
}
return ret
}
2018-11-14 23:38:32 +01:00
func ( g * WatGame ) RandInt ( max int64 ) uint64 {
2018-10-26 13:40:02 +02:00
i , _ := rand . Int ( rand . Reader , big . NewInt ( max ) )
2018-11-14 23:38:32 +01:00
return i . Uint64 ( )
2018-10-26 13:40:02 +02:00
}
2018-11-08 11:40:08 +01:00
func ( g * WatGame ) Heal ( player * Player , fields [ ] string ) string {
2019-06-28 19:54:32 +02:00
multiplier := int64 ( 30 )
2018-11-08 11:40:08 +01:00
if len ( fields ) < 3 {
return "#heal <player> <coins> - sacrifice your money to me, peasant! i might heal someone!"
}
target , e := g . GetTarget ( "" , fields [ 1 ] )
if e != "" {
return e
}
2018-11-14 23:38:32 +01:00
a , err := g . Int ( fields [ 2 ] )
2018-11-08 11:40:08 +01:00
if err != nil {
return err . Error ( )
}
2018-11-14 23:38:32 +01:00
if a > player . Coins {
2018-11-08 11:40:08 +01:00
return "u poor lol"
}
2018-11-14 23:38:32 +01:00
amount := int64 ( a )
2018-11-08 11:40:08 +01:00
if amount < multiplier {
return fmt . Sprintf ( "too cheap lol at least %d" , multiplier )
}
target . Health += amount / multiplier
2018-11-14 23:38:32 +01:00
player . Coins -= a
2018-11-08 11:40:08 +01:00
if target . Nick == player . Nick {
2018-11-14 23:38:32 +01:00
target . Coins -= a
2018-11-08 11:40:08 +01:00
g . db . Update ( target )
} else {
g . db . Update ( target , player )
}
fmtStr := "%s throws %d on the dirt. %s picks it up and waves their hand across %s, healing them. %s now has %d health."
return fmt . Sprintf ( fmtStr , player . Nick , amount , g . bot . Nick , target . Nick , target . Nick , target . Health )
}
2018-10-23 03:36:02 +02:00
func ( g * WatGame ) Dice ( player * Player , fields [ ] string ) string {
2018-11-14 23:38:32 +01:00
roll := uint64 ( 6 )
2018-10-23 03:36:02 +02:00
if len ( fields ) > 1 {
i , e := g . Int ( fields [ 1 ] )
if e == nil {
roll = i
}
}
2018-11-14 23:38:32 +01:00
answer := g . RandInt ( int64 ( roll ) ) + 1
2018-10-23 03:36:02 +02:00
return fmt . Sprintf ( "1d%d - %d" , roll , answer )
}
2018-11-08 11:40:08 +01:00
type PositiveError struct { }
type ParseIntError struct {
original string
}
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 ) }
2018-10-23 01:15:28 +02:00
2018-11-14 23:38:32 +01:00
func ( g * WatGame ) Int ( str string ) ( uint64 , error ) {
i , e := strconv . ParseUint ( str , 10 , 64 )
2018-10-23 01:15:28 +02:00
if i < 0 {
return 0 , PositiveError { }
2018-10-21 13:57:23 +02:00
}
2018-11-08 11:40:08 +01:00
if e != nil {
2018-11-14 23:38:32 +01:00
e = ParseIntError { str }
2018-11-08 11:40:08 +01:00
}
2018-10-23 01:15:28 +02:00
return i , e
2018-10-21 13:57:23 +02:00
}
func ( g * WatGame ) Roll ( player * Player , fields [ ] string ) string {
if len ( fields ) < 2 {
2019-06-28 19:54:32 +02:00
return fmt . Sprintf ( "roll <%s> pls - u must score < 50 if u want 2 win. u can also pick the dice size" , currency )
2019-01-04 10:20:39 +01:00
}
2018-10-23 01:15:28 +02:00
amount , e := g . Int ( fields [ 1 ] )
2018-10-21 13:57:23 +02:00
if e != nil {
2018-11-08 11:40:08 +01:00
return e . Error ( )
2018-10-21 13:57:23 +02:00
}
2019-06-28 19:54:32 +02:00
dieSize := int64 ( 100 )
if len ( fields ) >= 3 {
userDieSize , e := g . Int ( fields [ 2 ] )
if e == nil && userDieSize >= 2 {
dieSize = int64 ( userDieSize )
}
}
2018-10-21 13:57:23 +02:00
if amount > player . Coins {
return "wat? brokeass"
}
2019-06-28 19:54:32 +02:00
n := int64 ( g . RandInt ( dieSize ) ) + 1
ret := fmt . Sprintf ( "%s rolls the %d sided die... %d! " , player . Nick , dieSize , n )
if n < dieSize / 2 {
2018-10-23 01:15:28 +02:00
player . Coins += amount
2018-12-04 00:21:11 +01:00
ret += fmt . Sprintf ( "You win! ◕ ◡ ◕ total: %d %s" , player . Coins , currency )
2018-10-21 13:57:23 +02:00
} else {
2018-10-26 13:40:02 +02:00
player . LoseCoins ( amount )
g . me . Coins += amount
g . db . Update ( g . me )
2018-12-04 00:21:11 +01:00
ret += fmt . Sprintf ( "You lose! ≧ヮ≦ %d %s left..." , player . Coins , currency )
2018-10-21 13:57:23 +02:00
}
g . db . Update ( player )
return ret
}
2019-01-04 10:20:39 +01:00
func ( g * WatGame ) Bankrupt ( player * Player , fields [ ] string ) string {
if player . Coins > 10 {
return fmt . Sprintf ( "hmm, with %d %s, you're too rich. go get poor." , player . Coins , currency )
}
minTime := int64 ( 14400 )
if ! g . CanAct ( player , Action_Bankrupt , minTime ) {
return "pity is only valid once every 4 hours"
}
player . Coins += 50
player . Bankrupcy += 1
g . db . Act ( player , Action_Bankrupt )
g . db . Update ( player )
return fmt . Sprintf ( "here's some pity money. you've been bankrupt %d times." , player . Bankrupcy )
}
2018-10-21 13:57:23 +02:00
func ( g * WatGame ) Punch ( player * Player , fields [ ] string ) string {
if len ( fields ) < 2 {
return "punch <target> pls"
}
target , err := g . GetTarget ( player . Nick , fields [ 1 ] )
if err != "" {
return err
}
2018-11-08 11:40:08 +01:00
if ! target . Conscious ( ) {
return "wat? you're punching someone who is already unconscious. u crazy?"
}
chance := g . RandInt ( 6 ) + 1
dmg := g . RandInt ( 6 ) + 1
2018-10-25 02:04:35 +02:00
ret := fmt . Sprintf ( "%s rolls a d6... %s " , player . Nick , player . Nick )
2018-11-15 03:11:45 +01:00
dmg += uint64 ( player . Level ( player . Anarchy ) )
2018-10-25 02:04:35 +02:00
if chance > 3 {
2018-10-27 15:05:12 +02:00
ret += fmt . Sprintf ( "hits %s for %d points of damage! " , target . Nick , dmg )
2018-11-14 23:38:32 +01:00
target . Health -= int64 ( dmg )
2018-10-21 13:57:23 +02:00
g . db . Update ( target )
2018-10-25 02:04:35 +02:00
if target . Health <= 0 {
ret += target . Nick + " has fallen unconscious."
2018-11-15 03:11:45 +01:00
} else {
ret += fmt . Sprintf ( "%s has %dHP left" , target . Nick , target . Health )
2018-10-25 02:04:35 +02:00
}
2018-10-21 13:57:23 +02:00
} else {
2018-10-25 02:04:35 +02:00
ret += fmt . Sprintf ( "fumbles, and punches themselves in confusion! %d self-damage. " , dmg )
2018-11-15 03:11:45 +01:00
player . Health -= int64 ( dmg * 2 )
player . Anarchy -= 1
2018-10-21 13:57:23 +02:00
if player . Health <= 0 {
ret += player . Nick + " has fallen unconscious."
2018-11-15 03:11:45 +01:00
} else {
ret += fmt . Sprintf ( "%s has %dHP left" , player . Nick , player . Health )
2018-10-21 13:57:23 +02:00
}
g . db . Update ( player )
}
return ret
}
func ( g * WatGame ) Frame ( player * Player , fields [ ] string ) string {
if len ( fields ) < 3 {
2018-10-23 03:36:02 +02:00
return fmt . Sprintf ( "frame <nick> <%s> - d6 roll. Sneaky? You force the target to pay me. Clumsy? You pay a fine to the target and myself." , currency )
2018-10-21 13:57:23 +02:00
}
2018-10-23 01:15:28 +02:00
amount , e := g . Int ( fields [ 2 ] )
2018-11-08 11:40:08 +01:00
if e != nil {
return e . Error ( )
2018-10-21 13:57:23 +02:00
}
if player . Coins < amount {
return "wat? you too poor for that."
}
target , err := g . GetTarget ( player . Nick , fields [ 1 ] )
if err != "" {
return err
}
if target . Coins < amount {
return fmt . Sprintf ( "wat? %s is too poor for this." , target . Nick )
}
2018-11-08 11:40:08 +01:00
n := g . RandInt ( 6 ) + 1
2018-10-21 13:57:23 +02:00
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 {
2018-10-23 03:36:02 +02:00
ret += fmt . Sprintf ( "You frame %s for a minor crime. They pay me %d." , target . Nick , amount )
2018-10-21 13:57:23 +02:00
player . Anarchy += 1
target . Coins -= amount
} else {
2018-11-08 11:40:08 +01:00
ret += fmt . Sprintf ( "You were caught and pay them %d. %s gets the rest." , ( amount / 2 ) , g . bot . Nick )
2018-10-26 13:40:02 +02:00
player . LoseCoins ( amount )
2018-11-08 11:40:08 +01:00
target . Coins += amount / 2
g . me . Coins += amount / 2
2018-10-23 03:36:02 +02:00
g . db . Update ( g . me )
2018-10-21 13:57:23 +02:00
}
2018-11-08 11:40:08 +01:00
g . db . Update ( player , target )
2018-10-21 13:57:23 +02:00
return ret
}
func ( g * WatGame ) Steal ( player * Player , fields [ ] string ) string {
if len ( fields ) < 3 {
2018-10-23 03:36:02 +02:00
return fmt . Sprintf ( "steal <nick> <%s> - d6 roll. If you fail, you pay double the %s to %s" , currency , currency , g . bot . Nick )
2018-10-21 13:57:23 +02:00
}
2018-10-23 01:15:28 +02:00
amount , e := g . Int ( fields [ 2 ] )
2018-11-08 11:40:08 +01:00
if e != nil {
return e . Error ( )
2018-10-21 13:57:23 +02:00
}
if player . Coins < amount * 2 {
2018-11-14 23:38:32 +01:00
return "wat? you need double what ur trying 2 steal or you'll go bankrupt..."
2018-10-21 13:57:23 +02:00
}
target , err := g . GetTarget ( player . Nick , fields [ 1 ] )
if target == nil {
return err
}
if target . Coins < amount {
2018-10-25 02:04:35 +02:00
return fmt . Sprintf ( "wat? %s is poor and doesn't have that much to steal. (%d %s)" , target . Nick , target . Coins , currency )
2018-10-21 13:57:23 +02:00
}
2018-11-08 11:40:08 +01:00
n := g . RandInt ( 6 ) + 1
2018-10-23 03:36:02 +02:00
ret := fmt . Sprintf ( "%s is trying to steal %d %s from %s... " , player . Nick , amount , currency , target . Nick )
2018-10-21 13:57:23 +02:00
if n < 3 {
2018-10-25 02:04:35 +02:00
ret += "You did it! Sneaky bastard!"
2018-10-21 13:57:23 +02:00
player . Coins += amount
player . Anarchy += 1
target . Coins -= amount
g . db . Update ( target )
} else {
2018-11-08 11:40:08 +01:00
ret += fmt . Sprintf ( "You were caught and I took %d %s from your pocket." , ( amount * 2 ) , currency )
player . LoseCoins ( amount * 2 )
g . me . Coins += amount * 2
2018-10-25 02:04:35 +02:00
g . db . Update ( g . me )
2018-10-21 13:57:23 +02:00
}
g . db . Update ( player )
return ret
}
func ( g * WatGame ) GetTarget ( player , target string ) ( * Player , string ) {
2018-10-23 01:15:28 +02:00
t := g . db . User ( strings . ToLower ( target ) , "" , false )
2018-10-21 13:57:23 +02:00
if t . Nick == "" {
2018-10-23 01:15:28 +02:00
return nil , "Who? wat?"
2018-10-21 13:57:23 +02:00
}
if t . Nick == player {
2018-10-25 02:04:35 +02:00
return nil , "You can't do that to yourself, silly."
2018-10-21 13:57:23 +02:00
}
return & t , ""
}
2018-10-23 03:36:02 +02:00
func ( g * WatGame ) Leech ( player * Player , fields [ ] string ) string {
2018-11-14 23:38:32 +01:00
divisor := uint64 ( 10 )
2018-10-23 03:36:02 +02:00
if len ( fields ) < 3 {
2018-10-25 02:04:35 +02:00
return fmt . Sprintf ( "leech <nick> <%s> - using your wealth, you steal the life force of another player" , currency )
2018-10-23 03:36:02 +02:00
}
amount , er := g . Int ( fields [ 2 ] )
if amount < divisor {
2018-10-25 02:04:35 +02:00
return fmt . Sprintf ( "wat? its %d %s for 1 hp" , divisor , currency )
2018-10-23 03:36:02 +02:00
}
if player . Coins < amount || er != nil {
return "wat great fortune do you think you have? poor wats shouldn't be doing this, wat a waste..."
}
target , err := g . GetTarget ( player . Nick , fields [ 1 ] )
if err != "" {
return err
}
2018-11-08 11:40:08 +01:00
r := g . RandInt ( 10 ) + 1
2018-10-23 03:36:02 +02:00
reply := fmt . Sprintf ( "You muster your wealth and feed it to %s. " , g . bot . Nick )
2018-11-08 11:40:08 +01:00
hpDown := amount / divisor
2018-10-23 03:36:02 +02:00
player . Coins -= amount
if r < 5 {
2018-11-14 23:38:32 +01:00
target . Health -= int64 ( hpDown )
player . Health += int64 ( hpDown )
2018-10-25 02:04:35 +02:00
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 )
2018-11-08 11:40:08 +01:00
g . db . Update ( target , player )
2018-10-23 03:36:02 +02:00
} else {
reply += "The gods do not smile upon you this waturday. Your money vanishes and nothing happens."
}
return reply
}
func ( g * WatGame ) Rest ( player * Player , fields [ ] string ) string {
2018-10-25 02:04:35 +02:00
minRest := int64 ( 43200 )
2018-10-23 03:36:02 +02:00
delta := time . Now ( ) . Unix ( ) - player . LastRested
ret := ""
if player . LastRested == 0 {
ret = "you've never slept before - you sleep so well, your injuries are cured and your health is restored to 10"
player . Health = 10
2018-10-26 13:40:02 +02:00
player . LastRested = time . Now ( ) . Unix ( )
g . db . Update ( player )
2018-10-23 03:36:02 +02:00
} else if delta < minRest {
ret = fmt . Sprintf ( "wat were you thinking, sleeping at a time like this (%d until next rest)" , minRest - delta )
} else {
2018-11-08 11:40:08 +01:00
value := g . RandInt ( 10 ) + 1
2019-06-28 19:54:32 +02:00
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 )
}
2018-10-26 13:40:02 +02:00
player . LastRested = time . Now ( ) . Unix ( )
g . db . Update ( player )
2018-10-23 03:36:02 +02:00
}
return ret
}
2018-11-16 02:01:29 +01:00
func ( g * WatGame ) CanAct ( player * Player , action ActionType , minTime int64 ) bool {
delta := g . db . LastActed ( player , action )
if minTime != 0 && delta != 0 && time . Now ( ) . Unix ( ) - delta < minTime {
return false
}
return true
}
2018-11-08 11:40:08 +01:00
func ( g * WatGame ) Bench ( player * Player , fields [ ] string ) string {
2019-01-04 10:20:39 +01:00
minTime := int64 ( 115200 )
2018-11-16 02:01:29 +01:00
if ! g . CanAct ( player , Action_Lift , minTime ) {
2018-11-15 03:11:45 +01:00
return "you're tired. no more lifting for now."
}
2018-11-08 11:40:08 +01:00
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 {
reply += "do u even lift bro?"
return reply
} else if weight < 250 {
value = 1
} else if weight < 420 {
value = 2
} else if weight == 420 {
value = 10
reply += "four twenty blaze it bro! "
}
2019-01-04 10:20:39 +01:00
if g . roid [ player . Nick ] != 0 {
delete ( g . roid , player . Nick )
success := g . RandInt ( 2 )
if success != 0 {
player . Health = 0
player . Anarchy -= 10
g . db . Act ( player , Action_Lift )
g . db . Update ( player )
return fmt . Sprintf ( "%s tried to lift %d but halfway through their %d reps, their heart literally exploded from steroid use. They are now unconscious." , player . Nick , weight , reps )
} else {
reply += fmt . Sprintf ( "roid rage increased the effectiveness! " )
value *= 2
}
}
2018-11-15 03:11:45 +01:00
g . db . Act ( player , Action_Lift )
2018-11-08 11:40:08 +01:00
player . Anarchy += value
g . db . Update ( player )
reply += fmt . Sprintf ( "ur %d stronger lol" , value )
return reply
}
func ( g * WatGame ) Riot ( player * Player , fields [ ] string ) string {
2018-11-16 02:01:29 +01:00
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)"
}
2018-11-08 11:40:08 +01:00
r := g . RandInt ( 100 )
reply := ""
2018-12-04 00:21:11 +01:00
if r > 40 {
player . Anarchy += 3
reply = fmt . Sprintf ( "%s has successfully smashed the state! The brogeoise have been toppled. You feel stronger..." , player . Nick )
2018-11-08 11:40:08 +01:00
} else {
player . Health -= 3
reply = fmt . Sprintf ( "The proletariat have been hunted down by the secret police and had their faces smashed in! Your rebellion fails and you lose 3HP." )
}
2018-11-16 02:01:29 +01:00
g . db . Act ( player , Action_Riot )
2018-11-08 11:40:08 +01:00
g . db . Update ( player )
return reply
}
2018-10-21 13:57:23 +02:00
func ( g * WatGame ) Send ( player * Player , fields [ ] string ) string {
if len ( fields ) < 3 {
return fmt . Sprintf ( "You forgot somethin'. send <nick> <%s>" , currency )
}
2018-11-08 11:40:08 +01:00
amount , err := g . Int ( fields [ 2 ] )
2018-10-21 13:57:23 +02:00
if err != nil {
2018-11-08 11:40:08 +01:00
return err . Error ( )
2018-10-21 13:57:23 +02:00
}
2018-11-14 23:38:32 +01:00
if amount > player . Coins {
2018-10-25 02:04:35 +02:00
return "wat? you're too poor!"
2018-10-21 13:57:23 +02:00
}
target , str := g . GetTarget ( player . Nick , fields [ 1 ] )
if target == nil {
return str
}
2018-11-14 23:38:32 +01:00
player . Coins -= amount
target . Coins += amount
2018-11-08 11:40:08 +01:00
g . db . Update ( player , target )
2018-10-26 13:40:02 +02:00
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 )
2018-10-21 13:57:23 +02:00
}
2018-10-25 02:04:35 +02:00
func ( g * WatGame ) Mine ( player * Player , _ [ ] string ) string {
2018-11-14 23:38:32 +01:00
delta := uint64 ( time . Now ( ) . Unix ( ) - player . LastMined )
minDelta := uint64 ( 600 )
if delta < minDelta {
2018-11-08 11:40:08 +01:00
return fmt . Sprintf ( "wat? 2 soon. u earn more when u wait long (%d)" , delta )
2018-10-21 13:57:23 +02:00
}
2018-11-14 23:38:32 +01:00
value := uint64 ( 0 )
2018-10-21 13:57:23 +02:00
if delta < 36000 {
2018-11-14 23:38:32 +01:00
value = delta / minDelta
2018-10-21 13:57:23 +02:00
} else if delta < 86400 {
2018-11-14 23:38:32 +01:00
value = 25
2018-10-21 13:57:23 +02:00
} else if delta < 2592000 {
value = 50
} else {
value = 1000
}
msg := ""
if player . LastMined == 0 {
2018-11-14 23:38:32 +01:00
msg = fmt . Sprintf ( "u forgot ur pickaxe but it's okay i'll give you one in %d" , minDelta )
2018-10-21 13:57:23 +02:00
value = 0
} else {
2018-10-23 01:15:28 +02:00
player . Coins += value
2018-10-21 13:57:23 +02:00
msg = fmt . Sprintf ( "%s mined %d %s for %d and has %d %s" , player . Nick , value , currency , delta , player . Coins , currency )
}
player . LastMined = time . Now ( ) . Unix ( )
g . db . Update ( player )
return msg
}
2019-01-04 10:20:39 +01:00
func ( g * WatGame ) Steroid ( player * Player , fields [ ] string ) string {
if g . roid [ player . Nick ] != 0 {
return "Taking more than the recommended amount of steroids is, well, not recommended."
}
g . roid [ player . Nick ] = 1
return fmt . Sprintf ( "%s has eaten anabolic steroids. While they're good for building strength, it's dangerous to lift heavy weights. I hope you know what you're doing..." , player . Nick )
}
2018-10-23 01:15:28 +02:00
func ( g * WatGame ) Watch ( player * Player , fields [ ] string ) string {
if len ( fields ) > 1 {
maybePlayer , err := g . GetTarget ( "" , fields [ 1 ] )
if err != "" {
return err
}
player = maybePlayer
}
2019-06-28 19:54:32 +02:00
return fmt . Sprintf ( "%s's Strength: %d (%d) / Coins: %d / Health: %d" , player . Nick , player . Level ( player . Anarchy ) , player . Anarchy , player . Coins , player . Health )
2018-10-23 01:15:28 +02:00
}
2018-10-21 13:57:23 +02:00
func ( g * WatGame ) Balance ( player * Player , fields [ ] string ) string {
2019-06-28 19:54:32 +02:00
balStr := "%s's %s balance: %d. Mining time credit: %d. Total lost: %d. Bankrupt %d times."
2018-11-08 11:40:08 +01:00
balPlayer := player
if len ( fields ) > 1 {
var err string
balPlayer , err = g . GetTarget ( "" , fields [ 1 ] )
if err != "" {
return err
2018-10-26 13:40:02 +02:00
}
2018-11-08 11:40:08 +01:00
}
2019-06-28 19:54:32 +02:00
return fmt . Sprintf ( balStr , balPlayer . Nick , currency , balPlayer . Coins , time . Now ( ) . Unix ( ) - balPlayer . LastMined , balPlayer . CoinsLost , balPlayer . Bankrupcy )
2018-10-21 13:57:23 +02:00
}
2019-01-04 10:20:39 +01:00
func ( g * WatGame ) Strongest ( ) string {
players := g . db . Strongest ( )
ret := ""
for _ , p := range players {
ret += PrintTwo ( p . Nick , uint64 ( p . Anarchy ) )
}
return ret
}
2019-06-28 19:54:32 +02:00
func ( g * WatGame ) Healthiest ( ) string {
players := g . db . Healthiest ( )
ret := ""
for _ , p := range players {
ret += PrintTwo ( p . Nick , uint64 ( p . Health ) )
}
return ret
}
2018-11-14 23:38:32 +01:00
func ( g * WatGame ) TopLost ( ) string {
players := g . db . TopLost ( )
ret := ""
for _ , p := range players {
ret += PrintTwo ( p . Nick , p . CoinsLost )
}
return ret
}
2019-01-04 10:20:39 +01:00
2018-10-21 13:57:23 +02:00
func ( g * WatGame ) TopTen ( ) string {
players := g . db . TopTen ( )
ret := ""
for _ , p := range players {
ret += PrintTwo ( p . Nick , p . Coins )
}
return ret
}
2018-11-14 23:38:32 +01:00
func PrintTwo ( nick string , value uint64 ) string {
2018-10-21 13:57:23 +02:00
return fmt . Sprintf ( "%s (%d) " , CleanNick ( nick ) , value )
}
2018-10-23 01:15:28 +02:00
func ( g * WatGame ) megaWat ( player * Player , _ [ ] string ) string {
2018-11-08 11:40:08 +01:00
mega := g . RandInt ( 1000000 ) + 1
kilo := g . RandInt ( 1000 ) + 1
ten := g . RandInt ( 100 ) + 1
2018-10-21 13:57:23 +02:00
reply := ""
if mega == 23 {
player . Coins += 1000000
reply = fmt . Sprintf ( "OMGWATWATWAT!!!! %s has won the MegaWat lottery and gains 1000000 %s!" , player . Nick , currency )
}
if kilo == 5 {
player . Coins += 1000
reply = fmt . Sprintf ( "OMGWAT! %s has won the KiloWat lottery and gains 1000 %s!" , player . Nick , currency )
}
2018-10-25 02:04:35 +02:00
if ten == 10 {
player . Coins += 10
reply = fmt . Sprintf ( "%s won the regular wattery. This one only pays 10 %s." , player . Nick , currency )
}
2018-10-21 13:57:23 +02:00
player . Watting += 1
g . db . Update ( player )
return reply
}