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/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/astro-domu/internal/wire"
"github.com/jordanorelli/blammo"
)
@ -225,19 +226,24 @@ func (p pickup) exec(ui *UI) {
go func() {
res, err := ui.client.Send(sim.Pickup{p.x, p.y})
if err != nil {
ui.Error("look error: %v", err)
return
}
pickedup, ok := res.Body.(*sim.Pickedup)
if !ok {
ui.Error("pickup response is not pickedup: %v", res.Body)
ui.state.detail = textView(err.Error())
return
}
ui.misc <- func(ui *UI) {
ui.state.detail = textView(fmt.Sprintf("you picked up: %s", pickedup.Name))
ui.state.inventory.items = append(ui.state.inventory.items, item{name: pickedup.Name})
switch v := res.Body.(type) {
case *sim.Pickedup:
ui.misc <- func(ui *UI) {
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.state.detail = textView(v.Error())
}
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
solid bool `json:"-"`
overlapped map[int]*entity
pickupable bool
behavior
}

@ -258,6 +258,9 @@ func (pu *Pickup) exec(w *world, r *room, pl *player, seq int) result {
nextTile := r.getTile(target)
if len(nextTile.here) == 1 {
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]
return result{reply: Pickedup{Name: e.name}}
}

@ -40,28 +40,15 @@ func newWorld(log *blammo.Log) *world {
}
foyer.addEntity(&entity{
ID: -1,
Position: math.Vec{5, 4},
Glyph: 'o',
solid: true,
name: "a rock",
behavior: doNothing{},
ID: -1,
Position: math.Vec{5, 4},
Glyph: 'o',
solid: true,
pickupable: true,
name: "a rock",
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{
ID: -4,
Position: math.Vec{9, 5},

Loading…
Cancel
Save