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
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
"thehouseoficarus/internal/world"
)
// taskWorkVerb returns the flavor verb for working on a task worksite. Designers
// set `verb:` on the mob (e.g. "survey", "prospect", "build"); the default is
// "work on". The player-facing command is always `work` (or `attack`).
func taskWorkVerb(mob *world.MobInstance) string {
if mob != nil && mob.Verb != "" {
return mob.Verb
}
return "work on"
}
// progressBar renders a bar that fills as progress rises toward max — the
// inverse of hpBar. It is used for task worksites whose internal HP drains to 0
// to complete the work (progress = MaxHP - HP).
func (g *Game) progressBar(sess *net.Session, progress, max int) string {
if max <= 0 {
max = 1
}
if progress < 0 {
progress = 0
}
if progress > max {
progress = max
}
pct := float64(progress) / float64(max) * 100.0
var fgColor int
switch {
case pct >= 70:
fgColor = 82
case pct >= 40:
fgColor = 220
default:
fgColor = 39
}
unicode := sess.Player != nil && sess.Player.OptionBool("unicode")
style := &BarStyle{FilledColor: fgColor, EmptyColor: 238, EmptyDim: true}
bar := RenderColoredBar(progress, max, 10, unicode, style, g.colorMode(sess))
return "[" + bar + "]"
}
// writeTaskProgress prints the per-tick progress line for a task worksite,
// mirroring the combat hit line but framed as labor instead of damage.
func (g *Game) writeTaskProgress(sess *net.Session, p *player.Player, mob *world.MobInstance, dmg int, gains []xpGain) {
progress := mob.MaxHP - mob.HP
if progress < 0 {
progress = 0
}
pct := 0
if mob.MaxHP > 0 {
pct = progress * 100 / mob.MaxHP
}
noun := mob.ProgressNoun
if noun == "" {
noun = "work"
}
prefix := fmt.Sprintf("You advance the %s on %s.", noun, g.colorize(sess, "mob", mobDisplayName(mob, true)))
line := fmt.Sprintf("%s %s %3d%%", prefix, g.progressBar(sess, progress, mob.MaxHP), pct)
if p.OptionBool("xp_drops") && len(gains) > 0 {
var parts []string
for _, gain := range gains {
parts = append(parts, fmt.Sprintf("+%dxp %s", gain.XP, player.SkillAbbr[player.SkillName(gain.Skill)]))
}
line += g.colorize(sess, "xp", " ("+strings.Join(parts, ", ")+")")
}
sess.WriteLine(line)
}
|