mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Remove KondoKit dependency on XPGlobes
This commit is contained in:
parent
a81b9b46b4
commit
6ec395bbcf
11 changed files with 173 additions and 90 deletions
66
plugin-playground/src/main/kotlin/KondoKit/XPTable.kt
Normal file
66
plugin-playground/src/main/kotlin/KondoKit/XPTable.kt
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package KondoKit
|
||||
|
||||
import plugin.api.API
|
||||
import rt4.IntNode
|
||||
import rt4.Node
|
||||
|
||||
object XPTable {
|
||||
|
||||
const val MAX_LEVEL = 99
|
||||
const val INVALID_LEVEL = -1
|
||||
const val SKILLS_XP_TABLE = 716
|
||||
|
||||
private var xpTable: MutableList<Int> = mutableListOf()
|
||||
|
||||
// Lazily load the XP table from the API if it's empty
|
||||
private fun loadXpTable() {
|
||||
if (xpTable.isEmpty()) {
|
||||
// Add the initial entry for key 1 = 0
|
||||
xpTable.add(0)
|
||||
|
||||
// Fetch XP table from the API
|
||||
API.GetDataMap(SKILLS_XP_TABLE).table.nodes.forEach { bucket ->
|
||||
var currentNode: Node = bucket.nextNode
|
||||
while (currentNode !== bucket) {
|
||||
if (currentNode is IntNode) {
|
||||
xpTable.add(currentNode.value)
|
||||
}
|
||||
currentNode = currentNode.nextNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getXpRequiredForLevel(level: Int): Int {
|
||||
loadXpTable()
|
||||
if (level in 1..xpTable.size) {
|
||||
return xpTable[level - 1]
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fun getLevelForXp(xp: Int): Pair<Int, Int> {
|
||||
loadXpTable()
|
||||
var lowIndex = 0
|
||||
var highIndex = xpTable.size - 1
|
||||
|
||||
if (xp >= xpTable[highIndex]) {
|
||||
return Pair(MAX_LEVEL, xp - xpTable[highIndex]) // Level is max or above, return the highest level
|
||||
}
|
||||
|
||||
while (lowIndex <= highIndex) {
|
||||
val midIndex = (lowIndex + highIndex) / 2
|
||||
when {
|
||||
xp < xpTable[midIndex] -> highIndex = midIndex - 1
|
||||
xp >= xpTable[midIndex + 1] -> lowIndex = midIndex + 1
|
||||
else -> {
|
||||
val currentLevel = midIndex + 1
|
||||
val xpGained = xp - xpTable[midIndex]
|
||||
return Pair(currentLevel, xpGained)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Pair(INVALID_LEVEL, 0) // If xp is below all defined levels
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,6 @@ import KondoKit.plugin.Companion.kondoExposed_playerXPMultiplier
|
|||
import KondoKit.plugin.Companion.primaryColor
|
||||
import KondoKit.plugin.Companion.secondaryColor
|
||||
import KondoKit.plugin.StateManager.totalXPWidget
|
||||
import XPGlobesPlugin.XPTable
|
||||
import plugin.api.API
|
||||
import java.awt.*
|
||||
import java.io.BufferedReader
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import KondoKit.plugin.StateManager.initialXP
|
|||
import KondoKit.plugin.StateManager.totalXPWidget
|
||||
import KondoKit.plugin.StateManager.xpWidgets
|
||||
import plugin.Plugin
|
||||
import plugin.annotations.PluginMeta
|
||||
import plugin.api.*
|
||||
import plugin.api.API.*
|
||||
import plugin.api.FontColor.fromColor
|
||||
|
|
@ -39,6 +38,7 @@ import java.awt.event.MouseAdapter
|
|||
import java.awt.event.MouseEvent
|
||||
import javax.swing.*
|
||||
|
||||
|
||||
class plugin : Plugin() {
|
||||
companion object {
|
||||
val WIDGET_SIZE = Dimension(270, 55)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
AUTHOR='downthecrop'
|
||||
DESCRIPTION='A plugin that adds a right-side panel with custom widgets and navigation.'
|
||||
VERSION=1.0
|
||||
VERSION=1.1
|
||||
|
|
@ -1,22 +1,36 @@
|
|||
package XPGlobesPlugin
|
||||
|
||||
import plugin.api.API
|
||||
import rt4.IntNode
|
||||
import rt4.Node
|
||||
|
||||
object XPTable {
|
||||
|
||||
// source for the experience table: https://oldschool.runescape.wiki/w/Experience#Experience_table
|
||||
private val xpTable = arrayOf(
|
||||
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
|
||||
)
|
||||
const val SKILLS_XP_TABLE = 716
|
||||
|
||||
private var xpTable: MutableList<Int> = mutableListOf()
|
||||
|
||||
// Function to lazily load the XP table from the API if it's not already populated
|
||||
private fun loadXpTable() {
|
||||
if (xpTable.isEmpty()) {
|
||||
// Add the initial entry for key 1 = 0
|
||||
xpTable.add(0)
|
||||
|
||||
// Fetch XP table from the API
|
||||
API.GetDataMap(SKILLS_XP_TABLE).table.nodes.forEach { bucket ->
|
||||
var currentNode: Node = bucket.nextNode
|
||||
while (currentNode !== bucket) {
|
||||
if (currentNode is IntNode) {
|
||||
xpTable.add(currentNode.value)
|
||||
}
|
||||
currentNode = currentNode.nextNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getXpRequiredForLevel(level: Int): Int {
|
||||
loadXpTable()
|
||||
if (level in 1..xpTable.size) {
|
||||
return xpTable[level - 1]
|
||||
}
|
||||
|
|
@ -24,6 +38,7 @@ object XPTable {
|
|||
}
|
||||
|
||||
fun getLevelForXp(xp: Int): Pair<Int, Int> {
|
||||
loadXpTable()
|
||||
var lowIndex = 0
|
||||
var highIndex = xpTable.size - 1
|
||||
|
||||
|
|
@ -46,5 +61,4 @@ object XPTable {
|
|||
|
||||
return Pair(Constants.INVALID_LEVEL, 0) // If xp is below all defined levels
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue