alternate starting rooms

master
Jordan Orelli 4 years ago
parent 1a048f79f7
commit afd17fc6c4

@ -2,6 +2,7 @@ package math
import (
"encoding/json"
"fmt"
)
type Vec struct {
@ -9,6 +10,8 @@ type Vec struct {
Y int
}
func (v Vec) String() string { return fmt.Sprintf("(%d, %d)", v.X, v.Y) }
func (v Vec) MarshalJSON() ([]byte, error) {
return json.Marshal([2]int{v.X, v.Y})
}

@ -180,7 +180,7 @@ func (Move) NetTag() string { return "move" }
func (m *Move) exec(w *world, r *room, p *player, seq int) result {
pos := p.avatar.Position
target := pos.Add(math.Vec(*m))
p.Info("running move for player %s from %v to %v", p.name, *m, target)
p.Info("running move for player %s from %v to %v", p.name, p.avatar.Position, target)
if !r.Contains(target) {
return result{reply: wire.Errorf("target cell (%d, %d) is out of bounds", target.X, target.Y)}
}

@ -60,6 +60,6 @@ func (r *room) getTile(pos math.Vec) *tile {
if !r.Contains(pos) {
return nil
}
n := pos.X*r.Width + pos.Y
n := r.Width*pos.Y + pos.X
return &r.tiles[n]
}

@ -173,8 +173,15 @@ func (w *world) handleRequest(req Request) {
func (w *world) register(c connect) {
w.Info("register: %#v", c.login)
foyer := w.rooms["foyer"]
if len(foyer.players) >= 100 {
r := w.rooms["foyer"]
if hall, ok := w.rooms["hall"]; ok {
if len(hall.players) < len(r.players) {
r = hall
}
}
if len(r.players) >= 100 {
c.failed <- fmt.Errorf("room is full")
close(c.failed)
return
@ -190,11 +197,11 @@ func (w *world) register(c connect) {
Wants: &spawnPlayer{},
},
}
foyer.players[c.login.Name] = &p
r.players[c.login.Name] = &p
w.players[c.login.Name] = &p
w.Info("starting player...")
p.start(w.inbox, c.conn, foyer)
p.start(w.inbox, c.conn, r)
}
func (w *world) stop() error {

Loading…
Cancel
Save