package game import ( "fmt" "strings" "thehouseoficarus/internal/color" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) promptStr(sess *net.Session) string { prompt := "> " if p := sess.Player; p != nil { prompt = p.Prompt } prompt = g.expandPromptColors(sess, prompt) prompt = g.expandPromptVars(sess, prompt) return prompt } func (g *Game) expandPromptColors(sess *net.Session, text string) string { return color.ExpandTags(g.colorMode(sess), text) } func (g *Game) expandPromptVars(sess *net.Session, text string) string { p := sess.Player if p == nil { return text } text = strings.ReplaceAll(text, "%%", "\x00") text = strings.ReplaceAll(text, "%h", fmt.Sprint(p.HP)) text = strings.ReplaceAll(text, "%H", fmt.Sprint(p.MaxHP())) text = strings.ReplaceAll(text, "%b", fmt.Sprintf("%.1f", p.Battery)) text = strings.ReplaceAll(text, "%B", fmt.Sprintf("%.0f", p.MaxBattery())) text = strings.ReplaceAll(text, "%c", fmt.Sprint(p.Credits)) text = strings.ReplaceAll(text, "%i", fmt.Sprint(p.FreeSlots())) text = strings.ReplaceAll(text, "%s", attackStyleShort(p.AttackStyle)) text = strings.ReplaceAll(text, "%S", attackStyleLong(p.AttackStyle)) mobHP, mobMaxHP := "", "" if cs := g.Combat.Get(p.Name); cs != nil { mob := g.MobStore.GetInstance(cs.MobID) if mob != nil && mob.HP > 0 { mobHP = fmt.Sprint(mob.HP) mobMaxHP = fmt.Sprint(mob.MaxHP) } } text = strings.ReplaceAll(text, "%m", mobHP) text = strings.ReplaceAll(text, "%M", mobMaxHP) for _, sk := range player.AllSkills { tag := string(sk) text = strings.ReplaceAll(text, "%X_"+tag, fmt.Sprint(p.Skills[sk])) text = strings.ReplaceAll(text, "%x_"+tag, fmt.Sprint(xpToLevel(p, sk))) } text = strings.ReplaceAll(text, "\x00", "%") return text } func attackStyleShort(s player.AttackStyle) string { switch s { case player.Accurate: return "acc" case player.Aggressive: return "agg" case player.Defensive: return "def" case player.Balanced: return "bal" } return "acc" } func attackStyleLong(s player.AttackStyle) string { switch s { case player.Accurate: return "accurate" case player.Aggressive: return "aggressive" case player.Defensive: return "defensive" case player.Balanced: return "balanced" } return "accurate" } func xpToLevel(p *player.Player, sk player.SkillName) int { currentXP := p.Skills[sk] currentLevel := p.Level(sk) nextLevelXP := player.XPForLevel(currentLevel + 1) return nextLevelXP - currentXP }