mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
Add XP drop plugin
This commit is contained in:
parent
be61fd1daf
commit
529f741e13
18 changed files with 342 additions and 71 deletions
171
plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt
Normal file
171
plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
package XPDropPlugin;
|
||||
|
||||
import plugin.Plugin
|
||||
import plugin.api.*
|
||||
import java.awt.Color
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
* Displays some simple XP drops.
|
||||
* @author Ceikry
|
||||
*/
|
||||
class plugin : Plugin() {
|
||||
private val displayTimeout = 10000L // 10 seconds
|
||||
private val drawStart = 175
|
||||
private val drawPadding = 25
|
||||
private val drawClear = 60
|
||||
private val lastXp = IntArray(24)
|
||||
private var totalXp = 0
|
||||
private val activeGains = ArrayList<XPGain>()
|
||||
private var lastGain = 0L
|
||||
|
||||
override fun Draw(deltaTime: Long) {
|
||||
if (System.currentTimeMillis() - lastGain >= displayTimeout && activeGains.isEmpty())
|
||||
return
|
||||
|
||||
drawTotalXPBox()
|
||||
|
||||
val removeList = ArrayList<XPGain>()
|
||||
var posX = API.GetWindowDimensions().width / 2
|
||||
|
||||
if (API.GetWindowMode() == WindowMode.FIXED)
|
||||
posX += 60
|
||||
|
||||
for(gain in activeGains) {
|
||||
gain.currentPos -= ceil(deltaTime / 20.0).toInt()
|
||||
if (gain.currentPos <= drawClear) {
|
||||
removeList.add(gain)
|
||||
totalXp += gain.xp
|
||||
} else if (gain.currentPos <= drawStart){
|
||||
val sprite = API.GetSprite(getSpriteArchive(gain.skill))
|
||||
sprite?.render(posX - 25, gain.currentPos - 20)
|
||||
API.DrawText(
|
||||
FontType.SMALL,
|
||||
FontColor.fromColor(Color.WHITE),
|
||||
TextModifier.LEFT,
|
||||
addCommas(gain.xp.toString()),
|
||||
posX,
|
||||
gain.currentPos
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
activeGains.removeAll(removeList.toSet())
|
||||
}
|
||||
|
||||
override fun OnXPUpdate(skill: Int, xp: Int) {
|
||||
if (xp == lastXp[skill]) return
|
||||
|
||||
val gain = xp - lastXp[skill]
|
||||
if (gain <= 0) return
|
||||
|
||||
lastXp[skill] = xp
|
||||
|
||||
val currentTail = try {
|
||||
activeGains.last().currentPos
|
||||
} catch (e: Exception) {
|
||||
drawStart - drawPadding
|
||||
}
|
||||
|
||||
activeGains.add(XPGain(skill, gain, currentTail + drawPadding))
|
||||
lastGain = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
override fun OnLogout() {
|
||||
lastGain = 0L
|
||||
for (i in 0 until 24) lastXp[i] = 0
|
||||
totalXp = 0
|
||||
activeGains.clear()
|
||||
}
|
||||
|
||||
private fun drawTotalXPBox() {
|
||||
var posX = API.GetWindowDimensions().width / 2
|
||||
val posY = API.GetWindowDimensions().height / 4
|
||||
|
||||
if (API.GetWindowMode() == WindowMode.FIXED)
|
||||
posX += 60
|
||||
|
||||
API.ClipRect(0, 0, posX * 2, posY * 4)
|
||||
|
||||
val horizontal = API.GetSprite(822)
|
||||
val horizontalTop = API.GetSprite(820)
|
||||
val tlCorner = API.GetSprite(824)
|
||||
val blCorner = API.GetSprite(826)
|
||||
val trCorner = API.GetSprite(825)
|
||||
val brCorner = API.GetSprite(827)
|
||||
val bg = API.GetSprite(657)
|
||||
|
||||
bg?.render(posX - 77, 10)
|
||||
API.FillRect(posX - 75, 5, 140, 30, 0, 64)
|
||||
|
||||
blCorner?.render(posX - 77, 10)
|
||||
tlCorner?.render(posX - 77, 5)
|
||||
trCorner?.render(posX + 41, 5)
|
||||
brCorner?.render(posX + 41, 10)
|
||||
|
||||
horizontalTop?.render(posX - 45, -8)
|
||||
horizontal?.render(posX - 45, 22)
|
||||
horizontalTop?.render(posX - 15, -8)
|
||||
horizontal?.render(posX - 15, 22)
|
||||
horizontalTop?.render(posX + 9, -8)
|
||||
horizontal?.render(posX + 9, 22)
|
||||
|
||||
API.DrawText(
|
||||
FontType.SMALL,
|
||||
FontColor.fromColor(Color.WHITE),
|
||||
TextModifier.LEFT,
|
||||
"Total Xp: ${addCommas(totalXp.toString())}",
|
||||
posX - 65,
|
||||
28
|
||||
)
|
||||
}
|
||||
|
||||
data class XPGain(val skill: Int, val xp: Int, var currentPos: Int)
|
||||
|
||||
fun addCommas(num: String): String{
|
||||
var newString = ""
|
||||
if(num.length > 9){
|
||||
return "Lots!"
|
||||
}
|
||||
var counter = 1
|
||||
num.reversed().forEach {
|
||||
if(counter % 3 == 0 && counter != num.length){
|
||||
newString += "$it,"
|
||||
} else {
|
||||
newString += it
|
||||
}
|
||||
counter++
|
||||
}
|
||||
return newString.reversed()
|
||||
}
|
||||
|
||||
fun getSpriteArchive(skillId: Int): Int{
|
||||
return when(skillId) {
|
||||
0 -> 197
|
||||
1 -> 199
|
||||
2 -> 198
|
||||
3 -> 203
|
||||
4 -> 200
|
||||
5 -> 201
|
||||
6 -> 202
|
||||
7 -> 212
|
||||
8 -> 214
|
||||
9 -> 208
|
||||
10 -> 211
|
||||
11 -> 213
|
||||
12 -> 207
|
||||
13 -> 210
|
||||
14 -> 209
|
||||
15 -> 205
|
||||
16 -> 204
|
||||
17 -> 206
|
||||
18 -> 216
|
||||
19 -> 217
|
||||
20 -> 215
|
||||
21 -> 220
|
||||
22 -> 221
|
||||
23 -> 222
|
||||
else -> 222
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue