aboutsummaryrefslogtreecommitdiff
path: root/internal/game/exit_discovery.go
blob: cf09252fd5b82f968e0ff0f3df022305f3b567e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/player"
	"thehouseoficarus/internal/world"
)

// hiddenExitFlagPrefix is the canonical prefix for discovered-exit player flags
// ("hidden_exit_<roomID>_<dir>"). Shared by discoveredExitFlag, the
// hideallexits admin command, and the room-ID migration in exit_migrate.go so
// the format never drifts between writers and readers.
const hiddenExitFlagPrefix = "hidden_exit_"

func discoveredExitFlag(roomID int, dir world.ExitDir) string {
	return fmt.Sprintf("%s%d_%s", hiddenExitFlagPrefix, roomID, strings.ToLower(string(dir)))
}

func (g *Game) exitDiscovered(p *player.Player, roomID int, dir world.ExitDir) bool {
	if p.GodMode {
		return true
	}
	return getPlayerFlagInt(p, discoveredExitFlag(roomID, dir)) != 0
}

func (g *Game) markExitDiscovered(p *player.Player, roomID int, dir world.ExitDir) {
	g.setPlayerFlag(p, discoveredExitFlag(roomID, dir), 1)
}