mirror of
https://github.com/Luzifer/runemetrics.git
synced 2024-12-22 04:01:21 +00:00
Allow displaying remaining XP to target level
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
15d54ac1fd
commit
a4ff4c444a
3 changed files with 50 additions and 11 deletions
17
main.go
17
main.go
|
@ -173,14 +173,25 @@ func updateUI(player string) error {
|
|||
levelTable.RowStyles[0] = ui.Style{Fg: ui.ColorWhite, Modifier: ui.ModifierBold}
|
||||
levelTable.SetRect(0, 6, termWidth, 6+2+len(playerData.SkillValues)+1)
|
||||
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 {
|
||||
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{
|
||||
s.ID.String(),
|
||||
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.ID.Info().XPToNextLevel(s.Level, s.XP/10), 10),
|
||||
remaining,
|
||||
})
|
||||
|
||||
if time.Since(s.Updated) < cfg.MarkerTime {
|
||||
|
|
|
@ -41,6 +41,7 @@ type skill struct {
|
|||
Rank int64 `json:"rank"`
|
||||
XP int64 `json:"xp"`
|
||||
|
||||
TargetLevel int
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
|
@ -122,6 +123,7 @@ func getPlayerInfo(name string, activities int) (*playerInfo, error) {
|
|||
for i, nSk := range out.SkillValues {
|
||||
if oSk := playerInfoCache.GetSkill(nSk.ID); oSk.XP == nSk.XP {
|
||||
out.SkillValues[i].Updated = oSk.Updated
|
||||
out.SkillValues[i].TargetLevel = oSk.TargetLevel
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
40
skill.go
40
skill.go
|
@ -8,26 +8,52 @@ type skillInfo struct {
|
|||
skillCurve string // ???
|
||||
}
|
||||
|
||||
func (s skillInfo) NextLevelXP(level int) int64 {
|
||||
func (s skillInfo) LevelFromXP(xp int64) int {
|
||||
levelTree := levels
|
||||
if s.skillCurve != "" {
|
||||
levelTree = masterLevels
|
||||
}
|
||||
|
||||
return levelTree[level+1]
|
||||
for i := 1; i <= len(levelTree); i++ {
|
||||
if levelTree[i] > xp {
|
||||
return i - 1
|
||||
}
|
||||
}
|
||||
|
||||
func (s skillInfo) LevelPercentage(level int, xp int64) float64 {
|
||||
return 1
|
||||
}
|
||||
|
||||
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 (
|
||||
xpCurr = float64(s.NextLevelXP(level - 1))
|
||||
xpNext = float64(s.NextLevelXP(level))
|
||||
level = s.LevelFromXP(xp)
|
||||
xpCurr = float64(s.LevelXP(level))
|
||||
xpNext = float64(s.LevelXP(level + 1))
|
||||
)
|
||||
|
||||
return (float64(xp) - xpCurr) / (xpNext - xpCurr) * 100
|
||||
}
|
||||
|
||||
func (s skillInfo) XPToNextLevel(level int, xp int64) int64 {
|
||||
return s.NextLevelXP(level) - xp
|
||||
func (s skillInfo) TargetPercentage(level int, xp int64) float64 {
|
||||
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{
|
||||
|
|
Loading…
Reference in a new issue