package game import ( "fmt" "thehouseoficarus/internal/color" "thehouseoficarus/internal/net" "thehouseoficarus/internal/ui" ) func (g *Game) dmgDisplay(sess *net.Session, dmg int) string { if sess.Player != nil && sess.Player.OptionBool("unicode") { return fmt.Sprintf("\U0001FB38 %d \U0001FB34", dmg) } return fmt.Sprintf("> %d <", dmg) } // renderBarGeneric renders a high/med/low tiered bar at width 10 using the // named constant-color family (prefix: "hp_bar" or "task_bar"). The empty // cells are painted with hp_bar_empty. func (g *Game) renderBarGeneric(sess *net.Session, current, max int, prefix string) string { if max <= 0 { max = 1 } if current < 0 { current = 0 } if current > max { current = max } pct := float64(current) / float64(max) var spec color.ColorSpec switch { case pct >= 0.7: spec = g.resolveConstant(sess, prefix+"_high") case pct >= 0.4: spec = g.resolveConstant(sess, prefix+"_med") default: spec = g.resolveConstant(sess, prefix+"_low") } empty := g.resolveConstant(sess, "hp_bar_empty") unicode := sess.Player != nil && sess.Player.OptionBool("unicode") style := &ui.BarStyle{FilledColor: spec.Fg, EmptyColor: empty.Fg, EmptyDim: empty.Dim} bar := ui.RenderColoredBar(current, max, 10, unicode, style, g.colorMode(sess)) return "[" + bar + "]" } // hpBarStyle returns the per-tier fill/empty color spec for an HP bar at the // given ratio (high>=70%, med>=40%, low<40%). Colors come from the // constant_colors map (hp_bar_high/med/low/empty). func (g *Game) hpBarStyle(sess *net.Session, current, max int) *ui.BarStyle { if max <= 0 { max = 1 } pct := float64(current) / float64(max) spec := g.resolveConstant(sess, "hp_bar_low") switch { case pct >= 0.7: spec = g.resolveConstant(sess, "hp_bar_high") case pct >= 0.4: spec = g.resolveConstant(sess, "hp_bar_med") } empty := g.resolveConstant(sess, "hp_bar_empty") return &ui.BarStyle{FilledColor: spec.Fg, EmptyColor: empty.Fg, EmptyDim: empty.Dim} } func (g *Game) hpBar(sess *net.Session, current, max int) string { return g.renderBarGeneric(sess, current, max, "hp_bar") }