aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_labor.go
blob: 43f7bb29cf011da225b7ccbc6f86422da427949c (plain)
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
package game

import (
	"fmt"

	"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 {
	return g.renderBar(sess, progress, max, 39)
}

// 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)
	line += g.formatXpDrop(sess, p, gains)
	sess.WriteLine(line)
}