aboutsummaryrefslogtreecommitdiff
path: root/internal/game/exit_discovery_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-07 00:22:32 -0400
committerhistoria <[not public]>2026-07-07 00:22:32 -0400
commita51f7a53aa2c487ebf94ba0363038574ae8bb590 (patch)
treeb393a8f9e4732b40f6fe8058d086bd631537ad3b /internal/game/exit_discovery_test.go
parent9292634f2f8d71a53879ff07e1330c671b207d51 (diff)
downloadthehouseoficarus-a51f7a53aa2c487ebf94ba0363038574ae8bb590.tar.gz
feat: hidden exits (and related flags) work with commands that change room ids. exit code simplified and unified between impassable and blocked exits.
Diffstat (limited to 'internal/game/exit_discovery_test.go')
-rw-r--r--internal/game/exit_discovery_test.go75
1 files changed, 59 insertions, 16 deletions
diff --git a/internal/game/exit_discovery_test.go b/internal/game/exit_discovery_test.go
index 58177de..3c0b360 100644
--- a/internal/game/exit_discovery_test.go
+++ b/internal/game/exit_discovery_test.go
@@ -3,6 +3,8 @@ package game
import (
"testing"
+ "thehouseoficarus/internal/behavior"
+ "thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
"thehouseoficarus/internal/world"
)
@@ -51,22 +53,6 @@ func TestExitDiscoveredGodMode(t *testing.T) {
}
}
-func TestExitHiddenFiltered(t *testing.T) {
- g := &Game{Flags: NewFlagStore()}
- p := &player.Player{}
-
- if !g.exitHiddenFiltered(p, 1, world.North, false) {
- t.Error("non-hidden exit should pass filter")
- }
- if g.exitHiddenFiltered(p, 1, world.North, true) {
- t.Error("hidden undiscovered exit should be filtered")
- }
- g.markExitDiscovered(p, 1, world.North)
- if !g.exitHiddenFiltered(p, 1, world.North, true) {
- t.Error("hidden discovered exit should pass filter")
- }
-}
-
func TestExitDiscoveredDifferentRoom(t *testing.T) {
g := &Game{Flags: NewFlagStore()}
p := &player.Player{}
@@ -79,3 +65,60 @@ func TestExitDiscoveredDifferentRoom(t *testing.T) {
t.Error("discovering room 10 north should not mark room 20 north")
}
}
+
+func TestExitDisplayState(t *testing.T) {
+ g := &Game{Flags: NewFlagStore()}
+ const roomID = 7
+ dir := world.North
+
+ // {player_flag: open} — passes when "open" is set, fails otherwise.
+ openCond := &behavior.Condition{PlayerFlag: "open"}
+ hiddenDiscoveredSess := sessWithFlags(map[string]any{discoveredExitFlag(roomID, dir): 1})
+ openSess := sessWithFlags(map[string]any{"open": true})
+ closedSess := sessWithFlags(map[string]any{})
+ godSess := sessWithFlags(map[string]any{})
+
+ assertDisp := func(name string, sess *net.Session, exit world.ExitDef, wantVisible, wantBlocked, wantTagHidden bool) {
+ t.Helper()
+ ed := g.exitDisplayState(sess, roomID, dir, exit)
+ if ed.Visible != wantVisible || ed.Blocked != wantBlocked || ed.TagHidden != wantTagHidden {
+ t.Errorf("%s: got {Visible:%v Blocked:%v TagHidden:%v}, want {Visible:%v Blocked:%v TagHidden:%v}",
+ name, ed.Visible, ed.Blocked, ed.TagHidden, wantVisible, wantBlocked, wantTagHidden)
+ }
+ }
+
+ // Plain open exit: visible, not blocked, not hidden.
+ assertDisp("plain", openSess, world.ExitDef{Room: 1}, true, false, false)
+
+ // Hidden + undiscovered: absent.
+ assertDisp("hidden-undiscovered", closedSess, world.ExitDef{Room: 1, Hidden: true}, false, false, false)
+ // Hidden + discovered: visible, tagged hidden, not blocked.
+ assertDisp("hidden-discovered", hiddenDiscoveredSess, world.ExitDef{Room: 1, Hidden: true}, true, false, true)
+ // Hidden + god: god discovers — visible, tagged hidden.
+ godSess.Player.GodMode = true
+ assertDisp("hidden-god", godSess, world.ExitDef{Room: 1, Hidden: true}, true, false, true)
+ godSess.Player.GodMode = false
+
+ // always_blocked (non-god): visible, blocked, condition ignored.
+ assertDisp("always-blocked", closedSess, world.ExitDef{Room: 1, AlwaysBlocked: true}, true, true, false)
+ // always_blocked + a PASSING condition still blocks (condition not evaluated).
+ assertDisp("always-blocked-over-passing-cond", openSess, world.ExitDef{Room: 1, AlwaysBlocked: true, Condition: openCond}, true, true, false)
+ // always_blocked + god: not blocked (god bypass).
+ godSess.Player.GodMode = true
+ assertDisp("always-blocked-god", godSess, world.ExitDef{Room: 1, AlwaysBlocked: true}, true, false, false)
+ godSess.Player.GodMode = false
+
+ // Condition failing (no always_blocked): blocked.
+ assertDisp("cond-failing", closedSess, world.ExitDef{Room: 1, Condition: openCond}, true, true, false)
+ // Condition passing: not blocked.
+ assertDisp("cond-passing", openSess, world.ExitDef{Room: 1, Condition: openCond}, true, false, false)
+ // Condition failing + god: not blocked (god bypass).
+ godSess.Player.GodMode = true
+ assertDisp("cond-failing-god", godSess, world.ExitDef{Room: 1, Condition: openCond}, true, false, false)
+ godSess.Player.GodMode = false
+
+ // nil session (background render): non-hidden visible & not blocked;
+ // hidden absent (no player to have discovered it).
+ assertDisp("nil-sess-plain", nil, world.ExitDef{Room: 1}, true, false, false)
+ assertDisp("nil-sess-hidden", nil, world.ExitDef{Room: 1, Hidden: true}, false, false, false)
+}