I hope this works out in the end.
parent
a821ab04e4
commit
f4587c18a2
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import ()
|
||||
|
||||
type DeadState struct {
|
||||
CommandSuite
|
||||
start int64
|
||||
}
|
||||
|
||||
func NewDeadState(died int64) ConnectionState {
|
||||
return &DeadState{start: died}
|
||||
}
|
||||
|
||||
func (d *DeadState) Enter(c *Connection) {
|
||||
c.Printf("You are dead.\n")
|
||||
}
|
||||
|
||||
func (d *DeadState) Tick(c *Connection, frame int64) ConnectionState {
|
||||
if frame-d.start > options.respawnFrames {
|
||||
return SpawnRandomly()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *DeadState) Exit(c *Connection) {
|
||||
c.Printf("You're alive again.\n")
|
||||
}
|
||||
|
||||
func (d *DeadState) String() string {
|
||||
return "dead"
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var idleCommands = CommandSet{
|
||||
balCommand,
|
||||
commandsCommand,
|
||||
helpCommand,
|
||||
playersCommand,
|
||||
}
|
||||
|
||||
type IdleState struct {
|
||||
CommandSuite
|
||||
*System
|
||||
}
|
||||
|
||||
func Idle(sys *System) ConnectionState {
|
||||
return &IdleState{idleCommands, sys}
|
||||
}
|
||||
|
||||
func (i *IdleState) String() string {
|
||||
return fmt.Sprintf("idle on %v", i.System)
|
||||
}
|
||||
|
||||
func (i *IdleState) Enter(c *Connection) {
|
||||
c.Printf("You have landed on %v.\n", i.System)
|
||||
}
|
||||
|
||||
func (i *IdleState) Tick(c *Connection, frame int64) ConnectionState {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *IdleState) Exit(c *Connection) {
|
||||
c.Printf("Now leaving %v.\n", i.System)
|
||||
}
|
||||
|
||||
func (i *IdleState) travelTo(c *Connection, args ...string) {
|
||||
dest, err := GetSystem(args[0])
|
||||
if err != nil {
|
||||
c.Printf("%v\n", err)
|
||||
return
|
||||
}
|
||||
c.SetState(NewTravel(c, i.System, dest))
|
||||
}
|
||||
|
||||
func (i *IdleState) GetCommand(name string) *Command {
|
||||
return idleCommands.GetCommand(name)
|
||||
}
|
||||
|
||||
// func (i *IdleState) RunCommand(c *Connection, name string, args ...string) ConnectionState {
|
||||
// switch name {
|
||||
// case "goto":
|
||||
// dest, err := GetSystem(args[0])
|
||||
// if err != nil {
|
||||
// c.Printf("%v\n", err)
|
||||
// break
|
||||
// }
|
||||
// return NewTravel(c, i.System, dest)
|
||||
// case "nearby":
|
||||
// neighbors, err := i.Nearby(25)
|
||||
// if err != nil {
|
||||
// log_error("unable to get neighbors: %v", err)
|
||||
// break
|
||||
// }
|
||||
// c.Printf("--------------------------------------------------------------------------------\n")
|
||||
// c.Printf("%-4s %-20s %s\n", "id", "name", "distance")
|
||||
// c.Printf("--------------------------------------------------------------------------------\n")
|
||||
// for _, neighbor := range neighbors {
|
||||
// other := index[neighbor.id]
|
||||
// c.Printf("%-4d %-20s %v\n", other.id, other.name, neighbor.distance)
|
||||
// }
|
||||
// c.Printf("--------------------------------------------------------------------------------\n")
|
||||
// default:
|
||||
// c.Printf("No such command: %v\n", name)
|
||||
// }
|
||||
// return i
|
||||
// }
|
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type MiningState struct {
|
||||
CommandSuite
|
||||
sys *System
|
||||
mined int
|
||||
}
|
||||
|
||||
func Mine(sys *System) ConnectionState {
|
||||
return &MiningState{sys: sys}
|
||||
}
|
||||
|
||||
func (m *MiningState) Enter(c *Connection) {
|
||||
c.Printf("Mining %v. %v space duckets remaining.\n", m.sys, m.sys.money)
|
||||
}
|
||||
|
||||
func (m *MiningState) Tick(c *Connection, frame int64) ConnectionState {
|
||||
if m.sys.money <= 0 {
|
||||
c.Printf("system %s is all out of space duckets.\n", m.sys)
|
||||
return Idle(m.sys)
|
||||
} else {
|
||||
c.Deposit(1)
|
||||
m.mined += 1
|
||||
m.sys.money -= 1
|
||||
return m
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MiningState) Exit(c *Connection) {
|
||||
if m.sys.money == 0 {
|
||||
c.Printf("Done mining %v. Mined %v space duckets total. %v space duckets remain on %v, and it can be mined again.", m.sys, m.mined, m.sys.money, m.sys)
|
||||
} else {
|
||||
c.Printf("Done mining %v. Mined %v space duckets total. No space duckets remain on %v, and it can't be mined again.", m.sys, m.mined, m.sys)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MiningState) String() string {
|
||||
return fmt.Sprintf("mining %v", m.sys)
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TravelState struct {
|
||||
CommandSuite
|
||||
start *System
|
||||
dest *System
|
||||
travelled float64
|
||||
dist float64
|
||||
}
|
||||
|
||||
func NewTravel(c *Connection, start, dest *System) ConnectionState {
|
||||
return &TravelState{
|
||||
start: start,
|
||||
dest: dest,
|
||||
dist: start.DistanceTo(dest),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TravelState) Enter(c *Connection) {
|
||||
c.Printf("Leaving %v, bound for %v.\n", t.start, t.dest)
|
||||
}
|
||||
|
||||
func (t *TravelState) Tick(c *Connection, frame int64) ConnectionState {
|
||||
t.travelled += options.playerSpeed * options.lightSpeed
|
||||
if t.travelled >= t.dist {
|
||||
return Idle(t.dest)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TravelState) Exit(c *Connection) {
|
||||
c.Printf("You have arrived at %v.\n", t.dest)
|
||||
}
|
||||
|
||||
func (t *TravelState) String() string {
|
||||
return fmt.Sprintf("Traveling from %v to %v", t.start, t.dest)
|
||||
}
|
Loading…
Reference in New Issue