mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Fix nitpicks in prayer plugin
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
enum class Bone(val id: Int, val xp: Double) {
|
||||
REGULAR_BONES(id = 526, xp = 5.0),
|
||||
BURNT_BONES(id = 528, xp = 5.0),
|
||||
BAT_BONES(id = 530, xp = 4.0),
|
||||
BIG_BONES(id = 532, xp = 45.0),
|
||||
BABY_DRAGON_BONES(id = 534, xp = 30.0),
|
||||
DRAGON_BONES(id = 536, xp = 72.0),
|
||||
WOLF_BONES(id = 2859, xp = 14.0),
|
||||
SHAIKAHAN_BONES(id = 3123, xp = 25.0),
|
||||
JOGRE_BONES(id = 3125, xp = 15.0),
|
||||
BURNT_ZOGRE_BONES(id = 3127, xp = 25.0),
|
||||
MONKEY_BONES_SMALL_0(id = 3179, xp = 14.0),
|
||||
MONKEY_BONES_MEDIUM(id = 3180, xp = 14.0),
|
||||
MONKEY_BONES_LARGE_0(id = 3181, xp = 14.0),
|
||||
MONKEY_BONES_LARGE_1(id = 3182, xp = 14.0),
|
||||
MONKEY_BONES_SMALL_1(id = 3183, xp = 14.0),
|
||||
SHAKING_BONES(id = 3187, xp = 14.0),
|
||||
FAYRG_BONES(id = 4830, xp = 84.0),
|
||||
RAURG_BONES(id = 4832, xp = 96.0),
|
||||
OURG_BONES(id = 4834, xp = 140.0);
|
||||
|
||||
companion object {
|
||||
private val BONES = Bone.values().associateBy(Bone::id)
|
||||
|
||||
operator fun get(id: Int) = BONES[id]
|
||||
internal fun Int.isBone(): Boolean = this in BONES
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncAction
|
||||
import org.apollo.game.model.Animation
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.api.prayer
|
||||
|
||||
class BuryBoneAction(
|
||||
player: Player,
|
||||
private val slot: Int,
|
||||
private val bone: Bone
|
||||
) : AsyncAction<Player>(0, true, player) {
|
||||
|
||||
override fun action(): ActionBlock = {
|
||||
if (mob.inventory.removeSlot(slot, 1) > 0) {
|
||||
mob.sendMessage("You dig a hole in the ground...")
|
||||
mob.playAnimation(BURY_BONE_ANIMATION)
|
||||
|
||||
wait(pulses = 1)
|
||||
|
||||
mob.sendMessage("You bury the bones.")
|
||||
mob.prayer.experience += bone.xp
|
||||
}
|
||||
|
||||
stop()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val BURY_BONE_ANIMATION = Animation(827)
|
||||
internal const val BURY_OPTION = 1
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +1,8 @@
|
||||
import com.google.common.collect.MultimapBuilder
|
||||
import com.google.common.collect.SetMultimap
|
||||
import org.apollo.game.message.impl.ConfigMessage
|
||||
import org.apollo.game.model.Animation
|
||||
import org.apollo.game.model.entity.Player
|
||||
|
||||
val BURY_BONE_ANIMATION = Animation(827)
|
||||
|
||||
val PLAYER_PRAYERS: SetMultimap<Player, Prayer> = MultimapBuilder.hashKeys()
|
||||
.enumSetValues(Prayer::class.java)
|
||||
.build<Player, Prayer>()
|
||||
|
||||
val Player.currentPrayers: Set<Prayer>
|
||||
get() = PLAYER_PRAYERS[this]
|
||||
|
||||
enum class Bone(val id: Int, val xp: Double) {
|
||||
REGULAR_BONES(id = 526, xp = 5.0),
|
||||
BURNT_BONES(id = 528, xp = 5.0),
|
||||
BAT_BONES(id = 530, xp = 4.0),
|
||||
BIG_BONES(id = 532, xp = 45.0),
|
||||
BABY_DRAGON_BONES(id = 534, xp = 30.0),
|
||||
DRAGON_BONES(id = 536, xp = 72.0),
|
||||
WOLF_BONES(id = 2859, xp = 14.0),
|
||||
SHAIKAHAN_BONES(id = 3123, xp = 25.0),
|
||||
JOGRE_BONES(id = 3125, xp = 15.0),
|
||||
BURNT_ZOGRE_BONES(id = 3127, xp = 25.0),
|
||||
MONKEY_BONES_SMALL_0(id = 3179, xp = 14.0),
|
||||
MONKEY_BONES_MEDIUM(id = 3180, xp = 14.0),
|
||||
MONKEY_BONES_LARGE_0(id = 3181, xp = 14.0),
|
||||
MONKEY_BONES_LARGE_1(id = 3182, xp = 14.0),
|
||||
MONKEY_BONES_SMALL_1(id = 3183, xp = 14.0),
|
||||
SHAKING_BONES(id = 3187, xp = 14.0),
|
||||
FAYRG_BONES(id = 4830, xp = 84.0),
|
||||
RAURG_BONES(id = 4832, xp = 96.0),
|
||||
OURG_BONES(id = 4834, xp = 140.0);
|
||||
|
||||
companion object {
|
||||
private val BONES = Bone.values().associateBy { it.id }
|
||||
|
||||
operator fun get(id: Int) = BONES[id]
|
||||
}
|
||||
}
|
||||
|
||||
enum class Prayer(val button: Int, val level: Int, val setting: Int, val drain: Double) {
|
||||
THICK_SKIN(button = 5609, level = 1, setting = 83, drain = 0.01),
|
||||
BURST_OF_STRENGTH(button = 5610, level = 4, setting = 84, drain = 0.01),
|
||||
@@ -62,18 +24,21 @@ enum class Prayer(val button: Int, val level: Int, val setting: Int, val drain:
|
||||
SMITE(button = 685, level = 52, setting = 100, drain = 0.2);
|
||||
|
||||
companion object {
|
||||
private val PRAYERS = Prayer.values().associateBy { it.button }
|
||||
private val prayers = Prayer.values().associateBy(Prayer::button)
|
||||
|
||||
fun forButton(button: Int) = PRAYERS[button]
|
||||
fun forButton(button: Int) = prayers[button]
|
||||
internal fun Int.isPrayerButton(): Boolean = this in prayers
|
||||
}
|
||||
}
|
||||
|
||||
fun updatePrayer(player: Player, prayer: Prayer) {
|
||||
val prayerSettingValue = if (player.currentPrayers.contains(prayer)) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
val Player.currentPrayers: Set<Prayer>
|
||||
get() = playerPrayers[this]
|
||||
|
||||
player.send(ConfigMessage(prayer.setting, prayerSettingValue))
|
||||
}
|
||||
fun Player.updatePrayer(prayer: Prayer) {
|
||||
val value = if (currentPrayers.contains(prayer)) 1 else 0
|
||||
send(ConfigMessage(prayer.setting, value))
|
||||
}
|
||||
|
||||
internal val playerPrayers: SetMultimap<Player, Prayer> = MultimapBuilder.hashKeys()
|
||||
.enumSetValues(Prayer::class.java)
|
||||
.build<Player, Prayer>()
|
||||
@@ -1,49 +1,37 @@
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncAction
|
||||
import Bone.Companion.isBone
|
||||
import Prayer.Companion.isPrayerButton
|
||||
import org.apollo.game.message.impl.ButtonMessage
|
||||
import org.apollo.game.message.impl.ItemOptionMessage
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.event.impl.LogoutEvent
|
||||
import org.apollo.game.plugin.api.prayer
|
||||
|
||||
//Clear the player prayer on logout
|
||||
// Clear the player's prayer(s) on logout
|
||||
on_player_event { LogoutEvent::class }
|
||||
.then {
|
||||
PLAYER_PRAYERS.removeAll(it)
|
||||
playerPrayers.removeAll(it)
|
||||
}
|
||||
|
||||
on { ButtonMessage::class }
|
||||
.then {
|
||||
val prayer = Prayer.forButton(widgetId) ?: return@then
|
||||
if (prayer.level > it.prayer.current) {
|
||||
.where { widgetId.isPrayerButton() }
|
||||
.then { player ->
|
||||
val prayer = Prayer.forButton(widgetId)!!
|
||||
val level = prayer.level
|
||||
|
||||
if (level > player.prayer.current) {
|
||||
player.sendMessage("You need a prayer level of $level to use this prayer.")
|
||||
terminate()
|
||||
return@then
|
||||
}
|
||||
updatePrayer(it, prayer)
|
||||
|
||||
player.updatePrayer(prayer)
|
||||
terminate()
|
||||
}
|
||||
|
||||
on { ItemOptionMessage::class }
|
||||
.where { option == 1 }
|
||||
.then {
|
||||
val bone = Bone[id] ?: return@then
|
||||
.where { option == BuryBoneAction.BURY_OPTION && id.isBone() }
|
||||
.then { player ->
|
||||
val bone = Bone[id]!!
|
||||
|
||||
it.startAction(BuryBoneAction(it, slot, bone))
|
||||
player.startAction(BuryBoneAction(player, slot, bone))
|
||||
terminate()
|
||||
}
|
||||
|
||||
class BuryBoneAction(val player: Player, val slot: Int, val bone: Bone) : AsyncAction<Player>(0, true, player) {
|
||||
override fun action(): ActionBlock = {
|
||||
if (player.inventory.removeSlot(slot, 1) > 0) {
|
||||
player.sendMessage("You dig a hole in the ground...")
|
||||
player.playAnimation(BURY_BONE_ANIMATION)
|
||||
|
||||
wait(1) //Wait for animation
|
||||
|
||||
player.sendMessage("You bury the bones.")
|
||||
player.prayer.experience += bone.xp
|
||||
}
|
||||
|
||||
stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user