1
0
Fork 0
mirror of https://github.com/Luzifer/runemetrics.git synced 2024-12-22 12:11:20 +00:00

Allow displaying remaining XP to target level

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-09-28 21:47:42 +02:00
parent 15d54ac1fd
commit a4ff4c444a
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 50 additions and 11 deletions

17
main.go
View file

@ -173,14 +173,25 @@ func updateUI(player string) error {
levelTable.RowStyles[0] = ui.Style{Fg: ui.ColorWhite, Modifier: ui.ModifierBold} levelTable.RowStyles[0] = ui.Style{Fg: ui.ColorWhite, Modifier: ui.ModifierBold}
levelTable.SetRect(0, 6, termWidth, 6+2+len(playerData.SkillValues)+1) levelTable.SetRect(0, 6, termWidth, 6+2+len(playerData.SkillValues)+1)
levelTable.RowSeparator = false levelTable.RowSeparator = false
levelTable.Rows = [][]string{{"Skill", "Level", "Level %", "XP", "XP to next Level"}} levelTable.Rows = [][]string{{"Skill", "Level", "Level %", "XP", "XP remaining"}}
for i, s := range playerData.SkillValues { for i, s := range playerData.SkillValues {
var (
remaining = strconv.FormatInt(s.ID.Info().XPToNextLevel(s.XP/10), 10)
percentage = strconv.FormatFloat(s.ID.Info().LevelPercentage(s.XP/10), 'f', 1, 64)
)
if s.TargetLevel > 0 {
remaining = strconv.FormatInt(s.ID.Info().XPToTargetLevel(s.TargetLevel, s.XP/10), 10)
percentage = strconv.FormatFloat(s.ID.Info().TargetPercentage(s.TargetLevel, s.XP/10), 'f', 1, 64)
levelTable.RowStyles[i+1] = ui.Style{Fg: ui.ColorYellow}
}
levelTable.Rows = append(levelTable.Rows, []string{ levelTable.Rows = append(levelTable.Rows, []string{
s.ID.String(), s.ID.String(),
strconv.Itoa(s.Level), strconv.Itoa(s.Level),
strconv.FormatFloat(s.ID.Info().LevelPercentage(s.Level, s.XP/10), 'f', 1, 64), percentage,
strconv.FormatInt(s.XP/10, 10), strconv.FormatInt(s.XP/10, 10),
strconv.FormatInt(s.ID.Info().XPToNextLevel(s.Level, s.XP/10), 10), remaining,
}) })
if time.Since(s.Updated) < cfg.MarkerTime { if time.Since(s.Updated) < cfg.MarkerTime {

View file

@ -41,6 +41,7 @@ type skill struct {
Rank int64 `json:"rank"` Rank int64 `json:"rank"`
XP int64 `json:"xp"` XP int64 `json:"xp"`
TargetLevel int
Updated time.Time Updated time.Time
} }
@ -122,6 +123,7 @@ func getPlayerInfo(name string, activities int) (*playerInfo, error) {
for i, nSk := range out.SkillValues { for i, nSk := range out.SkillValues {
if oSk := playerInfoCache.GetSkill(nSk.ID); oSk.XP == nSk.XP { if oSk := playerInfoCache.GetSkill(nSk.ID); oSk.XP == nSk.XP {
out.SkillValues[i].Updated = oSk.Updated out.SkillValues[i].Updated = oSk.Updated
out.SkillValues[i].TargetLevel = oSk.TargetLevel
continue continue
} }

View file

@ -8,26 +8,52 @@ type skillInfo struct {
skillCurve string // ??? skillCurve string // ???
} }
func (s skillInfo) NextLevelXP(level int) int64 { func (s skillInfo) LevelFromXP(xp int64) int {
levelTree := levels levelTree := levels
if s.skillCurve != "" { if s.skillCurve != "" {
levelTree = masterLevels levelTree = masterLevels
} }
return levelTree[level+1] for i := 1; i <= len(levelTree); i++ {
if levelTree[i] > xp {
return i - 1
}
}
return 1
} }
func (s skillInfo) LevelPercentage(level int, xp int64) float64 { func (s skillInfo) LevelXP(level int) int64 {
levelTree := levels
if s.skillCurve != "" {
levelTree = masterLevels
}
return levelTree[level]
}
func (s skillInfo) LevelPercentage(xp int64) float64 {
var ( var (
xpCurr = float64(s.NextLevelXP(level - 1)) level = s.LevelFromXP(xp)
xpNext = float64(s.NextLevelXP(level)) xpCurr = float64(s.LevelXP(level))
xpNext = float64(s.LevelXP(level + 1))
) )
return (float64(xp) - xpCurr) / (xpNext - xpCurr) * 100 return (float64(xp) - xpCurr) / (xpNext - xpCurr) * 100
} }
func (s skillInfo) XPToNextLevel(level int, xp int64) int64 { func (s skillInfo) TargetPercentage(level int, xp int64) float64 {
return s.NextLevelXP(level) - xp var xpNext = float64(s.LevelXP(level))
return float64(xp) / xpNext * 100
}
func (s skillInfo) XPToNextLevel(xp int64) int64 {
level := s.LevelFromXP(xp)
return s.LevelXP(level+1) - xp
}
func (s skillInfo) XPToTargetLevel(level int, xp int64) int64 {
return s.LevelXP(level) - xp
} }
var skillList = []skillInfo{ var skillList = []skillInfo{