From 28681b15a6c0fdc913e0c8083d30cd5c8c531d17 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 8 Nov 2014 15:09:50 -0500 Subject: [PATCH] mining colonies no longer generate revenue when dead --- commands.go | 6 +++--- session.go | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 88af371..39e0948 100644 --- a/commands.go +++ b/commands.go @@ -201,7 +201,7 @@ var colonizeCommand = &Command{ fn = func() { reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate) if system.colonizedBy != nil { - system.colonizedBy.money += reward + system.colonizedBy.Deposit(reward) fmt.Fprintf(system.colonizedBy, "mining colony on %s pays you %d space duckets. total: %d space duckets.\n", system.name, reward, system.colonizedBy.money) } After(5*time.Second, fn) @@ -214,7 +214,7 @@ var colonizeCommand = &Command{ } if conn.money > 2000 { - conn.money -= 2000 + conn.Withdraw(2000) system.colonizedBy = conn fmt.Fprintf(conn, "set up a mining colony on %s\n", conn.System().name) After(5*time.Second, fn) @@ -279,7 +279,7 @@ var mkBombCommand = &Command{ fmt.Fprintf(conn, "not enough money! Bombs cost 800 space duckets to build, you only have %d in the bank.\n", conn.money) return } - conn.money -= 800 + conn.Withdraw(800) conn.bombs += 1 fmt.Fprintf(conn, "built a bomb!\n") fmt.Fprintf(conn, "bombs: %d\n", conn.bombs) diff --git a/session.go b/session.go index 2bf0c20..98500f9 100644 --- a/session.go +++ b/session.go @@ -96,10 +96,16 @@ func (c *Connection) InTransit() bool { func (c *Connection) RecordScan() { c.lastScan = time.Now() + After(1*time.Minute, func() { + fmt.Fprintln(c, "scanner ready") + }) } func (c *Connection) RecordBomb() { c.lastBomb = time.Now() + After(1500*time.Millisecond, func() { + fmt.Fprintln(c, "bomb arsenal reloaded") + }) } func (c *Connection) CanScan() bool { @@ -141,11 +147,25 @@ func (c *Connection) IsMining() bool { } func (c *Connection) Payout() { + if c.dead { + return + } reward := int64(rand.NormFloat64()*5.0 + 100.0*c.System().miningRate) - c.money += reward + c.Deposit(reward) fmt.Fprintf(c, "mined: %d space duckets. total: %d\n", reward, c.money) } +func (c *Connection) Withdraw(n int64) { + c.money -= n +} + +func (c *Connection) Deposit(n int64) { + c.money += n + if c.money >= 25000 { + c.Win() + } +} + func (c *Connection) Win() { for conn, _ := range connected { fmt.Fprintf(conn, "player %s has won.\n", c.PlayerName())