Skip to content

Commit b84a737

Browse files
committed
Feature: Experience lamps
1 parent 0b768df commit b84a737

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

src/main/java/io/luna/game/model/mob/varp/PersistentVarp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum PersistentVarp {
1818
CHAT_EFFECTS(171),
1919
AUTO_RETALIATE(172),
2020
RUNNING(173),
21+
XP_LAMP(261),
2122
SPLIT_PRIVATE_CHAT(287),
2223
ACCEPT_AID(427);
2324

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package game.item.experienceLamp
2+
3+
import api.predef.*
4+
import io.luna.game.model.mob.overlay.StandardInterface
5+
6+
/**
7+
* Handles the interface where the player selects which skill to gain experience in,
8+
* from a lamp.
9+
*/
10+
class ExperienceLampInterface : StandardInterface(2808) {
11+
12+
enum class InterfaceSkill(val varpValue: Int, val button: Int) {
13+
ATTACK(1, 2812),
14+
STRENGTH(2, 2813),
15+
RANGED(3, 2814),
16+
MAGIC(4, 2815),
17+
DEFENCE(5, 2816),
18+
HITPOINTS(6, 2817),
19+
PRAYER(7, 2818),
20+
AGILITY(8, 2819),
21+
HERBLORE(9, 2820),
22+
THIEVING(10, 2821),
23+
CRAFTING(11, 2822),
24+
RUNECRAFTING(12, 2823),
25+
MINING(13, 2824),
26+
SMITHING(14, 2825),
27+
FISHING(15, 2826),
28+
COOKING(16, 2827),
29+
FIREMAKING(17, 2828),
30+
WOODCUTTING(18, 2829),
31+
FLETCHING(19, 2830),
32+
SLAYER(20, 12034),
33+
FARMING(21, 13914),
34+
;
35+
36+
companion object {
37+
/**
38+
* Returns the [skill] ID associated with a specific [varpValue].
39+
* Returns null if no match is found.
40+
*/
41+
fun getSkillByVarp(value: Int): Int {
42+
when (value) {
43+
1 -> return SKILL_ATTACK
44+
2 -> return SKILL_STRENGTH
45+
3 -> return SKILL_RANGED
46+
4 -> return SKILL_MAGIC
47+
5 -> return SKILL_DEFENCE
48+
6 -> return SKILL_HITPOINTS
49+
7 -> return SKILL_PRAYER
50+
8 -> return SKILL_AGILITY
51+
9 -> return SKILL_HERBLORE
52+
10 -> return SKILL_THIEVING
53+
11 -> return SKILL_CRAFTING
54+
12 -> return SKILL_RUNECRAFTING
55+
13 -> return SKILL_MINING
56+
14 -> return SKILL_SMITHING
57+
15 -> return SKILL_FISHING
58+
16 -> return SKILL_COOKING
59+
17 -> return SKILL_FIREMAKING
60+
18 -> return SKILL_WOODCUTTING
61+
19 -> return SKILL_FLETCHING
62+
20 -> return SKILL_SLAYER
63+
21 -> return SKILL_FARMING
64+
else -> return SKILL_HITPOINTS
65+
}
66+
}
67+
}
68+
}
69+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package game.item.experienceLamp
2+
3+
import api.plugin.dsl.plugin
4+
5+
plugin {
6+
name = "Experience lamp"
7+
description =
8+
"""
9+
A plugin that enables players to use experience lamps.
10+
"""
11+
version = "1.0"
12+
authors += "hydrozoa"
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package game.item.experienceLamp
2+
3+
import api.predef.*
4+
import api.predef.ext.*
5+
import io.luna.game.model.mob.varp.*
6+
7+
/**
8+
* Rubbing the lamp.
9+
*/
10+
item1(2528) {
11+
plr.overlays.open(ExperienceLampInterface())
12+
}
13+
14+
/**
15+
* Handling the buttons on the interface.
16+
*/
17+
for (skill in ExperienceLampInterface.InterfaceSkill.values()) {
18+
button(skill.button) {
19+
if (ExperienceLampInterface::class in plr.overlays) {
20+
plr.varpManager.setAndSendValue(PersistentVarp.XP_LAMP, skill.varpValue)
21+
}
22+
}
23+
}
24+
25+
/**
26+
* Confirm button.
27+
*/
28+
button(2831) {
29+
if (ExperienceLampInterface::class in plr.overlays) {
30+
plr.overlays.closeWindows()
31+
plr.inventory.remove(2528)
32+
val skillId: Int = ExperienceLampInterface.InterfaceSkill.getSkillByVarp(plr.varpManager.getValue(PersistentVarp.XP_LAMP))
33+
val skill = plr.skills.getSkill(skillId)
34+
val experienceGain = skill.staticLevel * 10.toDouble()
35+
skill.addExperience(experienceGain)
36+
plr.sendMessage("You gained ${experienceGain.toInt()} experience in the ${skill.name} skill.")
37+
}
38+
}

0 commit comments

Comments
 (0)