Add physical hub portals and shared housing entrances

This commit is contained in:
dingo
2026-09-11 05:31:18 -04:00
parent 9b01ee38e3
commit ca571577ad
22 changed files with 366 additions and 37 deletions
@@ -31,6 +31,7 @@ func TestHouseVisitorsAcrossHubOwners(t *testing.T) {
_ = w.Connect(c.View.Entity.ID)
w.Kind = "hub"
w.Phase = "hub"
c.View.Entity.Position = w.HousingEntrancePosition()
l, _, e := db.Acquire(ctx, w)
if e != nil {
t.Fatal(e)
@@ -27,6 +27,7 @@ func TestHouseDeathTravelAndRecovery(t *testing.T) {
_ = hub.Connect(c.View.Entity.ID)
hub.Kind = "hub"
hub.Phase = "hub"
c.View.Entity.Position = hub.HousingEntrancePosition()
hl, _, e := db.Acquire(ctx, hub)
if e != nil {
t.Fatal(e)
@@ -62,6 +63,7 @@ func TestHouseDeathTravelAndRecovery(t *testing.T) {
t.Fatal(e)
}
// Traveling cancels the action, retains the exact key, and never creates another owner copy.
c.View.Entity.Position = hub.PortalPosition()
act(hl, hub, c, HouseRequest{Op: "destroy-key", Item: key})
oldWorld := *hub
oldWorld.Characters = map[string]*game.Character{c.View.Entity.ID: c}
@@ -140,6 +142,7 @@ func TestHouseDeathTravelAndRecovery(t *testing.T) {
if v := state(hub, replacement); v.Houses[0].Keys != 2 {
t.Fatal("creator recovery invalidated corpse key")
}
replacement.View.Entity.Position = hub.HousingEntrancePosition()
act(hl, hub, replacement, HouseRequest{Op: "enter", HouseID: house})
if state(hub, replacement).Room.Floor.Inventory["wood"] != 7 {
t.Fatal("recovery recreated or lost contents")
+15
View File
@@ -301,6 +301,21 @@ func (d *DB) mutateHouse(ctx context.Context, tx *sql.Tx, w *game.World, c *game
return houseError("a carried key or invitation is required")
}
if r.Op == "enter" {
if !w.NearEntrance(c, w.HousingEntrancePosition()) {
return houseError("stand next to the housing entrance in this hub")
}
if r.Item != "" {
// Explicit key use must name a carried, active key for this exact house;
// an invitation cannot make a wrong or destroyed key usable.
carried := slices.ContainsFunc(c.View.Items, func(i p.ItemInstance) bool { return i.ID == r.Item && i.HouseID != nil && *i.HouseID == h.View.ID })
var active int
if e := tx.QueryRowContext(ctx, d.q(`SELECT COUNT(*) FROM house_keys WHERE id=? AND house_id=? AND state='active'`), r.Item, h.View.ID).Scan(&active); e != nil {
return e
}
if !carried || active != 1 {
return houseError("use a carried key for this house")
}
}
if c.WorldsSurvived < 1 {
return houseError("survive a world before entering housing")
}
+10 -1
View File
@@ -51,6 +51,9 @@ func testHousingLifecycle(t *testing.T, dsn string) {
// Seed arrivals before making this fixture a hub; travel itself has separate coverage.
w.Kind = "hub"
w.Phase = "hub"
for _, c := range []*game.Character{owner, guest, coowner} {
c.View.Entity.Position = w.HousingEntrancePosition()
}
save := func() {
t.Helper()
if e := l.Save(ctx, w, ""); e != nil {
@@ -109,7 +112,13 @@ func testHousingLifecycle(t *testing.T, dsn string) {
key := owner.View.Items[len(owner.View.Items)-1].ID
reject(owner, HouseRequest{Op: "create", Name: "Duplicate"})
reject(guest, HouseRequest{Op: "enter", HouseID: house})
act(owner, HouseRequest{Op: "enter", HouseID: house})
owner.View.Entity.Position.X += 100
reject(owner, HouseRequest{Op: "enter", HouseID: house, Item: key})
owner.View.Entity.Position = w.HousingEntrancePosition()
reject(owner, HouseRequest{Op: "enter", HouseID: house, Item: "unowned-key"})
entry := HouseRequest{RequestID: game.ID(), Op: "enter", HouseID: house, Item: key}
act(owner, entry)
act(owner, entry) // Replaying an entry from inside the room must not enter twice.
if e := w.Intent(owner.View.Entity.ID, p.Intent{Seq: 1, Op: "attack"}); e == nil {
t.Fatal("world action inside house")
}
+16 -1
View File
@@ -203,7 +203,22 @@ func runTravelTests(t *testing.T, dsn string) {
if current == hub {
switchTo, switchLease = other, ol
}
switched, e := lease.PrepareTravel(ctx, current, c.Account, game.ID(), switchTo.ID, "hub")
traveler := current.ForAccount(c.Account)
traveler.View.Entity.Position.X += 100
beforePortal, _ := json.Marshal(current)
requestAtPortal := game.ID()
if _, e = lease.PrepareTravel(ctx, current, c.Account, requestAtPortal, switchTo.ID, "hub"); !errors.Is(e, ErrTravel) {
t.Fatal("remote hub travel accepted", e)
}
afterPortal, _ := json.Marshal(current)
if string(beforePortal) != string(afterPortal) {
t.Fatal("remote portal rejection mutated source")
}
if pending, e := db.PendingTransfer(ctx, c.Account); e != nil || pending != nil {
t.Fatal("remote portal rejection created transit escrow", e)
}
traveler.View.Entity.Position = current.PortalPosition()
switched, e := lease.PrepareTravel(ctx, current, c.Account, requestAtPortal, switchTo.ID, "hub")
if e != nil {
t.Fatal(e)
}