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>
120 lines
2.7 KiB
Go
120 lines
2.7 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
// WaitingScreen shows room members and lets players ready up before starting.
|
|
type WaitingScreen struct {
|
|
ready bool
|
|
}
|
|
|
|
func NewWaitingScreen() *WaitingScreen {
|
|
return &WaitingScreen{}
|
|
}
|
|
|
|
func (s *WaitingScreen) pollWaiting() tea.Cmd {
|
|
return tea.Tick(time.Second, func(t time.Time) tea.Msg {
|
|
return tickMsg{}
|
|
})
|
|
}
|
|
|
|
func (s *WaitingScreen) startGame(ctx *Context) (Screen, tea.Cmd) {
|
|
room := ctx.Lobby.GetRoom(ctx.RoomCode)
|
|
if room != nil && room.Session != nil {
|
|
ctx.Session = room.Session
|
|
ctx.Session.StartGame()
|
|
ctx.Lobby.StartRoom(ctx.RoomCode)
|
|
gs := NewGameScreen()
|
|
gs.gameState = ctx.Session.GetState()
|
|
return gs, gs.pollState()
|
|
}
|
|
return s, s.pollWaiting()
|
|
}
|
|
|
|
func (s *WaitingScreen) Update(msg tea.Msg, ctx *Context) (Screen, tea.Cmd) {
|
|
switch msg.(type) {
|
|
case tickMsg:
|
|
// Check if all players are ready → start game
|
|
if ctx.Lobby != nil && ctx.Lobby.AllReady(ctx.RoomCode) {
|
|
return s.startGame(ctx)
|
|
}
|
|
return s, s.pollWaiting()
|
|
}
|
|
|
|
if key, ok := msg.(tea.KeyMsg); ok {
|
|
if isEnter(key) && !s.ready {
|
|
s.ready = true
|
|
if ctx.Lobby != nil {
|
|
ctx.Lobby.SetPlayerReady(ctx.RoomCode, ctx.Fingerprint, true)
|
|
// Solo: if only 1 player in room, start immediately
|
|
room := ctx.Lobby.GetRoom(ctx.RoomCode)
|
|
if room != nil && len(room.Players) == 1 {
|
|
return s.startGame(ctx)
|
|
}
|
|
}
|
|
} else if isKey(key, "esc") || key.Type == tea.KeyEsc {
|
|
// Leave room — unready and go back to lobby
|
|
if ctx.Lobby != nil {
|
|
ctx.Lobby.SetPlayerReady(ctx.RoomCode, ctx.Fingerprint, false)
|
|
ctx.Lobby.LeaveRoom(ctx.RoomCode, ctx.Fingerprint)
|
|
}
|
|
ctx.RoomCode = ""
|
|
ls := NewLobbyScreen()
|
|
ls.refreshLobby(ctx)
|
|
return ls, nil
|
|
}
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
func (s *WaitingScreen) View(ctx *Context) string {
|
|
headerStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("205")).
|
|
Bold(true)
|
|
|
|
readyStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("46"))
|
|
|
|
notReadyStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("240"))
|
|
|
|
header := headerStyle.Render(fmt.Sprintf("── Waiting Room [%s] ──", ctx.RoomCode))
|
|
|
|
playerList := ""
|
|
if ctx.Lobby != nil {
|
|
room := ctx.Lobby.GetRoom(ctx.RoomCode)
|
|
if room != nil {
|
|
for _, p := range room.Players {
|
|
status := notReadyStyle.Render("...")
|
|
if p.Ready {
|
|
status = readyStyle.Render("READY")
|
|
}
|
|
cls := p.Class
|
|
if cls == "" {
|
|
cls = "?"
|
|
}
|
|
playerList += fmt.Sprintf(" %s (%s) %s\n", p.Name, cls, status)
|
|
}
|
|
}
|
|
}
|
|
|
|
menu := "[Enter] Ready"
|
|
if s.ready {
|
|
menu = "Waiting for other players..."
|
|
}
|
|
menu += " [Esc] Leave"
|
|
|
|
return lipgloss.JoinVertical(lipgloss.Left,
|
|
header,
|
|
"",
|
|
playerList,
|
|
"",
|
|
menu,
|
|
)
|
|
}
|