Files
Catacombs/ui/class_view.go
tolelom 1563091de1 fix: 13 bugs found via systematic code review and testing
Multiplayer:
- Add WaitingScreen between class select and game start; previously
  selecting a class immediately started the game and locked the room,
  preventing other players from joining
- Add periodic lobby room list refresh (2s interval)
- Add LeaveRoom method for backing out of waiting room

Combat & mechanics:
- Mark invalid attack targets with TargetIdx=-1 to suppress misleading
  "0 dmg" combat log entries
- Make Freeze effect actually skip frozen player's action (was purely
  cosmetic before - expired during tick before action processing)
- Implement Life Siphon relic heal-on-damage effect (was defined but
  never applied in combat)
- Fix combo matching to track used actions and prevent reuse

Game modes:
- Wire up weekly mutations to GameSession via ApplyWeeklyMutation()
- Implement 3 mutation runtime effects: no_shop, glass_cannon, elite_flood
- Pass HardMode toggle from lobby UI through Context to GameSession
- Apply HardMode difficulty multipliers (1.5x monsters, 2x shop, 0.5x heal)

Polish:
- Set starting room (index 0) to always be Empty (safe start)
- Distinguish shop purchase errors: "Not enough gold" vs "Inventory full"
- Record random events in codex for discovery tracking

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 20:45:56 +09:00

115 lines
2.9 KiB
Go

package ui
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/tolelom/catacombs/entity"
"github.com/tolelom/catacombs/game"
)
// ClassSelectScreen lets the player choose a class before entering the game.
type ClassSelectScreen struct {
cursor int
}
func NewClassSelectScreen() *ClassSelectScreen {
return &ClassSelectScreen{}
}
func (s *ClassSelectScreen) Update(msg tea.Msg, ctx *Context) (Screen, tea.Cmd) {
if key, ok := msg.(tea.KeyMsg); ok {
if isUp(key) {
if s.cursor > 0 {
s.cursor--
}
} else if isDown(key) {
if s.cursor < len(classOptions)-1 {
s.cursor++
}
} else if isEnter(key) {
if ctx.Lobby != nil {
selectedClass := classOptions[s.cursor].class
ctx.Lobby.SetPlayerClass(ctx.RoomCode, ctx.Fingerprint, selectedClass.String())
room := ctx.Lobby.GetRoom(ctx.RoomCode)
if room != nil {
if room.Session == nil {
room.Session = game.NewGameSession(ctx.Lobby.Cfg())
room.Session.HardMode = ctx.HardMode
room.Session.ApplyWeeklyMutation()
}
ctx.Session = room.Session
player := entity.NewPlayer(ctx.PlayerName, selectedClass)
player.Fingerprint = ctx.Fingerprint
ctx.Session.AddPlayer(player)
if ctx.Lobby != nil {
ctx.Lobby.RegisterSession(ctx.Fingerprint, ctx.RoomCode)
}
ws := NewWaitingScreen()
return ws, ws.pollWaiting()
}
}
}
}
return s, nil
}
func (s *ClassSelectScreen) View(ctx *Context) string {
state := classSelectState{cursor: s.cursor}
return renderClassSelect(state, ctx.Width, ctx.Height)
}
type classSelectState struct {
cursor int
}
var classOptions = []struct {
class entity.Class
name string
desc string
}{
{entity.ClassWarrior, "Warrior", "HP:120 ATK:12 DEF:8 Skill: Taunt (draw enemy fire)"},
{entity.ClassMage, "Mage", "HP:70 ATK:20 DEF:3 Skill: Fireball (AoE damage)"},
{entity.ClassHealer, "Healer", "HP:90 ATK:8 DEF:5 Skill: Heal (restore 30 HP)"},
{entity.ClassRogue, "Rogue", "HP:85 ATK:15 DEF:4 Skill: Scout (reveal rooms)"},
}
func renderClassSelect(state classSelectState, width, height int) string {
headerStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("205")).
Bold(true)
selectedStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("46")).
Bold(true)
normalStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("255"))
descStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("240"))
header := headerStyle.Render("── Choose Your Class ──")
list := ""
for i, opt := range classOptions {
marker := " "
style := normalStyle
if i == state.cursor {
marker = "> "
style = selectedStyle
}
list += fmt.Sprintf("%s%s\n %s\n\n",
marker, style.Render(opt.name), descStyle.Render(opt.desc))
}
menu := "[Up/Down] Select [Enter] Confirm"
return lipgloss.JoinVertical(lipgloss.Left,
header,
"",
list,
menu,
)
}