1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) promptStr(sess *net.Session) string {
prompt := "> "
if p, ok := sess.Player.(*player.Player); ok && p != nil {
if p.Prompt != "" {
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, ok := sess.Player.(*player.Player)
if !ok || 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, "%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 := combat.GetCombat(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
}
|