aboutsummaryrefslogtreecommitdiff
path: root/internal/game/ui_xpdrop.go
blob: a9bff2342b761d46a4ef20825ec9e92609c799fe (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
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
)

// formatXpDrop returns the colored XP-drop suffix for a slice of gains, or ""
// if xp_drops are disabled or there are no gains.
func (g *Game) formatXpDrop(sess *net.Session, p *player.Player, gains []xpGain) string {
	if !p.OptionBool("xp_drops") || len(gains) == 0 {
		return ""
	}
	var parts []string
	for _, gain := range gains {
		parts = append(parts, fmt.Sprintf("+%dxp %s", gain.XP, player.SkillAbbr[player.SkillName(gain.Skill)]))
	}
	return g.colorize(sess, "xp", " ("+strings.Join(parts, ", ")+")")
}

// formatXpDropSingle returns the colored XP-drop suffix for a single skill, or ""
// if xp_drops are disabled or xp is 0.
func (g *Game) formatXpDropSingle(sess *net.Session, p *player.Player, skill player.SkillName, xp int) string {
	if !p.OptionBool("xp_drops") || xp <= 0 {
		return ""
	}
	return g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", xp, player.SkillAbbr[skill]))
}