Skip to content

Commit

Permalink
feat(types): Avoid unsigned integer type
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Frank <[email protected]>
  • Loading branch information
cfrank committed Dec 1, 2020
1 parent 9107833 commit 7cc78c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/constants/levels.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

// StandardXPTable represents the standard skill XP curve
var StandardXPTable = []uint64{
var StandardXPTable = []int64{
0,
83,
174,
Expand Down Expand Up @@ -131,7 +131,7 @@ var StandardXPTable = []uint64{
}

// EliteXPTable represents the elite skill XP curve
var EliteXPTable = []uint64{
var EliteXPTable = []int64{
0,
830,
1861,
Expand Down
6 changes: 2 additions & 4 deletions pkg/types/skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ const (
)

// GetVirtualLevel gets the virtual level for the given XP
func (s Skill) GetVirtualLevel(XP uint64) uint32 {
func (s Skill) GetVirtualLevel(XP int64) int {
table := constants.StandardXPTable

if s.IsEliteSkill() {
table = constants.EliteXPTable
}

i := sort.Search(len(table), func(i int) bool {
return sort.Search(len(table), func(i int) bool {
return table[i] > XP
})

return uint32(i)
}

// IsStandardSkill determines if the provided skill is a standard skill
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestGetVirtualLevel(t *testing.T) {
cases := []struct {
name string
skill types.Skill
XP uint64
expected uint32
XP int64
expected int
}{
{"standard skill 0 xp", types.Attack, 0, 1},
{"elite skill 0 xp", types.Invention, 0, 1},
Expand Down

0 comments on commit 7cc78c8

Please sign in to comment.