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>
104 lines
2.6 KiB
Go
104 lines
2.6 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"
|
|
)
|
|
|
|
// ShopScreen handles the shop between floors.
|
|
type ShopScreen struct {
|
|
gameState game.GameState
|
|
shopMsg string
|
|
}
|
|
|
|
func NewShopScreen(state game.GameState) *ShopScreen {
|
|
return &ShopScreen{gameState: state}
|
|
}
|
|
|
|
func (s *ShopScreen) Update(msg tea.Msg, ctx *Context) (Screen, tea.Cmd) {
|
|
if key, ok := msg.(tea.KeyMsg); ok {
|
|
switch key.String() {
|
|
case "1", "2", "3":
|
|
if ctx.Session != nil {
|
|
idx := int(key.String()[0] - '1')
|
|
switch ctx.Session.BuyItem(ctx.Fingerprint, idx) {
|
|
case game.BuyOK:
|
|
s.shopMsg = "Purchased!"
|
|
case game.BuyNoGold:
|
|
s.shopMsg = "Not enough gold!"
|
|
case game.BuyInventoryFull:
|
|
s.shopMsg = "Inventory full!"
|
|
default:
|
|
s.shopMsg = "Cannot buy that!"
|
|
}
|
|
s.gameState = ctx.Session.GetState()
|
|
}
|
|
case "q":
|
|
if ctx.Session != nil {
|
|
ctx.Session.LeaveShop()
|
|
gs := NewGameScreen()
|
|
gs.gameState = ctx.Session.GetState()
|
|
return gs, nil
|
|
}
|
|
}
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
func (s *ShopScreen) View(ctx *Context) string {
|
|
return renderShop(s.gameState, ctx.Width, ctx.Height, s.shopMsg)
|
|
}
|
|
|
|
func itemTypeLabel(item entity.Item) string {
|
|
switch item.Type {
|
|
case entity.ItemWeapon:
|
|
return fmt.Sprintf("[ATK+%d]", item.Bonus)
|
|
case entity.ItemArmor:
|
|
return fmt.Sprintf("[DEF+%d]", item.Bonus)
|
|
case entity.ItemConsumable:
|
|
return fmt.Sprintf("[HP+%d]", item.Bonus)
|
|
default:
|
|
return fmt.Sprintf("[+%d]", item.Bonus)
|
|
}
|
|
}
|
|
|
|
func renderShop(state game.GameState, width, height int, shopMsg string) string {
|
|
headerStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("226")).
|
|
Bold(true)
|
|
goldStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("220"))
|
|
msgStyle := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("196")).
|
|
Bold(true)
|
|
|
|
header := headerStyle.Render("── Shop ──")
|
|
|
|
// Show current player's gold
|
|
goldLine := ""
|
|
for _, p := range state.Players {
|
|
inventoryCount := len(p.Inventory)
|
|
goldLine += goldStyle.Render(fmt.Sprintf(" %s — Gold: %d Items: %d/10", p.Name, p.Gold, inventoryCount))
|
|
goldLine += "\n"
|
|
}
|
|
|
|
items := ""
|
|
for i, item := range state.ShopItems {
|
|
label := itemTypeLabel(item)
|
|
items += fmt.Sprintf(" [%d] %s %s — %d gold\n", i+1, item.Name, label, item.Price)
|
|
}
|
|
|
|
menu := "[1-3] Buy [Q] Leave Shop"
|
|
|
|
parts := []string{header, "", goldLine, items, "", menu}
|
|
if shopMsg != "" {
|
|
parts = append(parts, "", msgStyle.Render(shopMsg))
|
|
}
|
|
|
|
return lipgloss.JoinVertical(lipgloss.Left, parts...)
|
|
}
|