From 1f94135775fc3e2173ae73e48dfcf13f855f9131 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 14 Nov 2014 13:10:18 -0500 Subject: [PATCH] bomb counter goes down again --- commands.go | 13 ++----------- connection.go | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/commands.go b/commands.go index d4f6c1b..adb60e4 100644 --- a/commands.go +++ b/commands.go @@ -201,15 +201,10 @@ var bombCommand = &Command{ name: "bomb", help: "bombs a system, with a big space bomb", handler: func(conn *Connection, args ...string) { - if conn.bombs < 1 { - fmt.Fprintf(conn, "no more bombs left! build more bombs!\n") - return - } - dest_name := strings.Join(args, " ") to, ok := nameIndex[dest_name] if ok { - currentGame.Register(NewBomb(conn, to)) + conn.SendBomb(to) return } @@ -224,11 +219,7 @@ var bombCommand = &Command{ fmt.Fprintf(conn, `oh dear, there doesn't seem to be a system with id %d\n`, id_n) return } - if !conn.CanBomb() { - fmt.Fprintf(conn, "weapons are still reloading. Can bomb again in %v\n", conn.NextBomb()) - return - } - currentGame.Register(NewBomb(conn, to)) + conn.SendBomb(to) }, } diff --git a/connection.go b/connection.go index 291b4a3..ec96758 100644 --- a/connection.go +++ b/connection.go @@ -121,6 +121,22 @@ func (c *Connection) TravelTo(dest *System) { c.state = inTransit // fuck everything about this } +func (c *Connection) SendBomb(target *System) { + if c.bombs <= 0 { + fmt.Fprintln(c, "cannot send bomb: no bombs left") + return + } + if time.Since(c.lastBomb) < 5*time.Second { + fmt.Fprintln(c, "cannod send bomb: bombs are reloading") + return + } + c.bombs -= 1 + c.lastBomb = time.Now() + bomb := NewBomb(c, target) + currentGame.Register(bomb) + fmt.Fprintf(c, "sending bomb to system %v\n", target.Label()) +} + func (c *Connection) land() { fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label()) c.location = c.dest @@ -176,10 +192,6 @@ func (c *Connection) CanScan() bool { return time.Since(c.lastScan) > 1*time.Minute } -func (c *Connection) CanBomb() bool { - return time.Since(c.lastBomb) > 15*time.Second -} - func (c *Connection) NextScan() time.Duration { return -time.Since(c.lastScan.Add(time.Minute)) }