Skip to content

Commit

Permalink
Merge pull request #3 from alog-rs/feature/skill-methods
Browse files Browse the repository at this point in the history
feat(types): Add XP tables and skill methods
  • Loading branch information
cfrank authored Dec 1, 2020
2 parents 8fd3f85 + c8b241a commit 9107833
Show file tree
Hide file tree
Showing 3 changed files with 448 additions and 0 deletions.
297 changes: 297 additions & 0 deletions pkg/constants/levels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
package constants

// StandardXPTable represents the standard skill XP curve
var StandardXPTable = []uint64{
0,
83,
174,
276,
388,
512,
650,
801,
969,
1154,
1358,
1584,
1833,
2107,
2411,
2746,
3115,
3523,
3973,
4470,
5018,
5624,
6291,
7028,
7842,
8740,
9730,
10824,
12031,
13363,
14833,
16456,
18247,
20224,
22406,
24815,
27473,
30408,
33648,
37224,
41171,
45529,
50339,
55649,
61512,
67983,
75127,
83014,
91721,
101333,
111945,
123660,
136594,
150872,
166636,
184040,
203254,
224466,
247886,
273742,
302288,
333804,
368599,
407015,
449428,
496254,
547953,
605032,
668051,
737627,
814445,
899257,
992895,
1096278,
1210421,
1336443,
1475581,
1629200,
1798808,
1986068,
2192818,
2421087,
2673114,
2951373,
3258594,
3597792,
3972294,
4385776,
4842295,
5346332,
5902831,
6517253,
7195629,
7944614,
8771558,
9684577,
10692629,
11805606,
13034431,
14391160,
15889109,
17542976,
19368992,
21385073,
23611006,
26068632,
28782069,
31777943,
35085654,
38737661,
42769801,
47221641,
52136869,
57563718,
63555443,
70170840,
77474828,
85539082,
94442737,
104273167,
115126838,
127110260,
140341028,
154948977,
171077457,
188884740,
}

// EliteXPTable represents the elite skill XP curve
var EliteXPTable = []uint64{
0,
830,
1861,
2902,
3980,
5126,
6390,
7787,
9400,
11275,
13605,
16372,
19656,
23546,
28138,
33520,
39809,
47109,
55535,
64802,
77190,
90811,
106221,
123573,
143025,
164742,
188893,
215651,
245196,
277713,
316311,
358547,
404634,
454796,
509259,
568254,
632019,
700797,
774834,
854383,
946227,
1044569,
1149696,
1261903,
1381488,
1508756,
1644015,
1787581,
1939773,
2100917,
2283490,
2476369,
2679907,
2894505,
3120508,
3358307,
3608290,
3870846,
4146374,
4435275,
4758122,
5096111,
5449685,
5819299,
6205407,
6608473,
7028964,
7467354,
7924122,
8399751,
8925664,
9472665,
10041285,
10632061,
11245538,
11882262,
12542789,
13227679,
13937496,
14672812,
15478994,
16313404,
17176661,
18069395,
18992239,
19945833,
20930821,
21947856,
22997593,
24080695,
25259906,
26475754,
27728955,
29020233,
30350318,
31719944,
33129852,
34580790,
36073511,
37608773,
39270442,
40978509,
42733789,
44537107,
46389292,
48291180,
50243611,
52247435,
54303504,
56412678,
58575823,
60793812,
63067521,
65397835,
67785643,
70231841,
72737330,
75303019,
77929820,
80618654,
83370445,
86186124,
89066630,
92012904,
95025896,
98106559,
101255855,
104474750,
107764216,
111125230,
114558777,
118065845,
121647430,
125304532,
129038159,
132849323,
136739041,
140708338,
144758242,
148889790,
153104021,
157401983,
161784728,
166253312,
170808801,
175452262,
180184770,
185007406,
189921255,
194927409,
}

// SkillMastery is the maximum level for a standard non-120 skill
const SkillMastery uint32 = 99

// TrueSkillMastery is the maximum level for a 120 skill
const TrueSkillMastery uint32 = 120

// VirtualStandardTrueSkillMastery is the virtual maxium level for a standard skill
const VirtualStandardTrueSkillMastery uint32 = 126

// VirtualEliteTrueSkillMastery is the maxium virtual level for an elite skill
const VirtualEliteTrueSkillMastery uint32 = 150
71 changes: 71 additions & 0 deletions pkg/types/skills.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package types

import (
"sort"

"github.com/alog-rs/shared-packages/pkg/constants"
)

// Skill represents one of the Runescape skills
type Skill int

// Runescape skills
const (
Attack Skill = iota
Defence
Strength
Constitution
Ranged
Prayer
Magic
Cooking
Woodcutting
Fletching
Fishing
Firemaking
Crafting
Smithing
Mining
Herblore
Agility
Thieving
Slayer
Farming
Runecrafting
Hunter
Construction
Summoning
Dungeoneering
Divination
Invention
Archaeology
)

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

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

i := 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
func (s Skill) IsStandardSkill() bool {
if s == Invention {
return false
}

return true
}

// IsEliteSkill determines if the provided skill is a elite skill
func (s Skill) IsEliteSkill() bool {
return !s.IsStandardSkill()
}
Loading

0 comments on commit 9107833

Please sign in to comment.