can no longer pick up doors

master
Jordan Orelli 4 years ago
parent 068eb26d38
commit 84a92c28f5

@ -6,6 +6,7 @@ import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math" "github.com/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/astro-domu/internal/sim" "github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/astro-domu/internal/wire"
"github.com/jordanorelli/blammo" "github.com/jordanorelli/blammo"
) )
@ -225,19 +226,24 @@ func (p pickup) exec(ui *UI) {
go func() { go func() {
res, err := ui.client.Send(sim.Pickup{p.x, p.y}) res, err := ui.client.Send(sim.Pickup{p.x, p.y})
if err != nil { if err != nil {
ui.Error("look error: %v", err) ui.state.detail = textView(err.Error())
return return
} }
pickedup, ok := res.Body.(*sim.Pickedup) switch v := res.Body.(type) {
if !ok { case *sim.Pickedup:
ui.Error("pickup response is not pickedup: %v", res.Body) ui.misc <- func(ui *UI) {
return ui.state.detail = textView(fmt.Sprintf("you picked up: %s", v.Name))
ui.state.inventory.items = append(ui.state.inventory.items, item{name: v.Name})
} }
case wire.Error:
ui.misc <- func(ui *UI) { ui.misc <- func(ui *UI) {
ui.state.detail = textView(fmt.Sprintf("you picked up: %s", pickedup.Name)) ui.state.detail = textView(v.Error())
ui.state.inventory.items = append(ui.state.inventory.items, item{name: pickedup.Name}) }
default:
ui.misc <- func(ui *UI) {
ui.state.detail = textView(fmt.Sprintf("unexpected pickup response type: %T", res.Body))
}
} }
}() }()
} }

@ -14,6 +14,7 @@ type entity struct {
description string description string
solid bool `json:"-"` solid bool `json:"-"`
overlapped map[int]*entity overlapped map[int]*entity
pickupable bool
behavior behavior
} }

@ -258,6 +258,9 @@ func (pu *Pickup) exec(w *world, r *room, pl *player, seq int) result {
nextTile := r.getTile(target) nextTile := r.getTile(target)
if len(nextTile.here) == 1 { if len(nextTile.here) == 1 {
e := nextTile.here[0] e := nextTile.here[0]
if !e.pickupable {
return result{reply: wire.Errorf("the %s cannot be picked up", e.name)}
}
nextTile.here = nextTile.here[0:0] nextTile.here = nextTile.here[0:0]
return result{reply: Pickedup{Name: e.name}} return result{reply: Pickedup{Name: e.name}}
} }

@ -44,24 +44,11 @@ func newWorld(log *blammo.Log) *world {
Position: math.Vec{5, 4}, Position: math.Vec{5, 4},
Glyph: 'o', Glyph: 'o',
solid: true, solid: true,
pickupable: true,
name: "a rock", name: "a rock",
behavior: doNothing{}, behavior: doNothing{},
}) })
// foyer.addEntity(&entity{
// ID: -2,
// Position: math.Vec{9, 0},
// Glyph: '+',
// behavior: doNothing{},
// })
// foyer.addEntity(&entity{
// ID: -3,
// Position: math.Vec{9, 1},
// Glyph: '-',
// behavior: doNothing{},
// })
foyer.addEntity(&entity{ foyer.addEntity(&entity{
ID: -4, ID: -4,
Position: math.Vec{9, 5}, Position: math.Vec{9, 5},

Loading…
Cancel
Save