mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add herblore unit tests and clean-up plugin code
This commit is contained in:
@@ -19,7 +19,7 @@ enum class CrushableIngredient(val uncrushed: Int, override val id: Int) : Ingre
|
||||
CHOCOLATE_BAR(uncrushed = 1973, id = 1975),
|
||||
BIRDS_NEST(uncrushed = 5075, id = 6693);
|
||||
|
||||
val uncrushedName: String = Definitions.item(uncrushed)!!.name
|
||||
val uncrushedName by lazy { Definitions.item(uncrushed)!!.name }
|
||||
|
||||
companion object {
|
||||
private const val PESTLE_AND_MORTAR = 233
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
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.herblore
|
||||
import java.util.Objects
|
||||
|
||||
class MakeFinishedPotionAction(
|
||||
player: Player,
|
||||
private val potion: FinishedPotion
|
||||
) : AsyncAction<Player>(1, true, player) {
|
||||
|
||||
override fun action(): ActionBlock = {
|
||||
val level = mob.herblore.current
|
||||
|
||||
if (level < potion.level) {
|
||||
mob.sendMessage("You need a Herblore level of ${potion.level} to make this.")
|
||||
stop()
|
||||
}
|
||||
|
||||
val unfinished = potion.unfinished.id
|
||||
val inventory = mob.inventory
|
||||
|
||||
if (inventory.contains(unfinished) && inventory.contains(potion.ingredient)) {
|
||||
inventory.remove(unfinished)
|
||||
inventory.remove(potion.ingredient)
|
||||
|
||||
mob.playAnimation(MIXING_ANIMATION)
|
||||
|
||||
inventory.add(potion.id)
|
||||
mob.herblore.experience += potion.experience
|
||||
|
||||
mob.sendMessage("You mix the ${potion.ingredientName} into your potion.")
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MakeFinishedPotionAction
|
||||
return mob == other.mob && potion == other.potion
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = Objects.hash(mob, potion)
|
||||
|
||||
private companion object {
|
||||
private val MIXING_ANIMATION = Animation(363)
|
||||
}
|
||||
}
|
||||
+37
-10
@@ -2,12 +2,13 @@ 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.model.entity.Skill
|
||||
import org.apollo.game.plugin.api.herblore
|
||||
import java.util.Objects
|
||||
import java.util.*
|
||||
|
||||
class MakeUnfinishedPotionAction(
|
||||
abstract class MakePotionAction(
|
||||
player: Player,
|
||||
private val potion: UnfinishedPotion
|
||||
private val potion: Potion
|
||||
) : AsyncAction<Player>(1, true, player) {
|
||||
|
||||
override fun action(): ActionBlock = {
|
||||
@@ -20,22 +21,26 @@ class MakeUnfinishedPotionAction(
|
||||
|
||||
val inventory = mob.inventory
|
||||
|
||||
if (inventory.contains(VIAL_OF_WATER) && inventory.contains(potion.herb)) {
|
||||
inventory.remove(VIAL_OF_WATER)
|
||||
inventory.remove(potion.herb)
|
||||
if (inventory.containsAll(*ingredients)) {
|
||||
ingredients.forEach { inventory.remove(it) }
|
||||
inventory.add(potion.id)
|
||||
|
||||
mob.playAnimation(MIXING_ANIMATION)
|
||||
|
||||
inventory.add(potion.id)
|
||||
mob.sendMessage("You put the ${potion.herbName} into the vial of water.")
|
||||
mob.sendMessage(message)
|
||||
reward()
|
||||
}
|
||||
}
|
||||
|
||||
abstract val ingredients: IntArray
|
||||
abstract val message: String
|
||||
|
||||
open fun reward() {}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MakeUnfinishedPotionAction
|
||||
other as MakePotionAction
|
||||
return mob == other.mob && potion == other.potion
|
||||
}
|
||||
|
||||
@@ -44,4 +49,26 @@ class MakeUnfinishedPotionAction(
|
||||
private companion object {
|
||||
private val MIXING_ANIMATION = Animation(363)
|
||||
}
|
||||
}
|
||||
|
||||
class MakeFinishedPotionAction(
|
||||
player: Player,
|
||||
private val potion: FinishedPotion
|
||||
) : MakePotionAction(player, potion) {
|
||||
|
||||
override val ingredients = intArrayOf(potion.unfinished.id, potion.ingredient)
|
||||
override val message by lazy { "You mix the ${potion.ingredientName} into your potion." }
|
||||
|
||||
override fun reward() {
|
||||
mob.skillSet.addExperience(Skill.HERBLORE, potion.experience)
|
||||
}
|
||||
}
|
||||
|
||||
class MakeUnfinishedPotionAction(
|
||||
player: Player,
|
||||
private val potion: UnfinishedPotion
|
||||
) : MakePotionAction(player, potion) {
|
||||
|
||||
override val ingredients = intArrayOf(VIAL_OF_WATER, potion.herb)
|
||||
override val message by lazy { "You put the ${potion.herbName} into the vial of water." }
|
||||
}
|
||||
@@ -7,7 +7,12 @@ import org.apollo.game.plugin.api.Definitions
|
||||
|
||||
const val VIAL_OF_WATER = 227
|
||||
|
||||
enum class UnfinishedPotion(val id: Int, herb: Herb, val level: Int) {
|
||||
interface Potion {
|
||||
val id: Int
|
||||
val level: Int
|
||||
}
|
||||
|
||||
enum class UnfinishedPotion(override val id: Int, herb: Herb, override val level: Int) : Potion {
|
||||
GUAM(id = 91, herb = Herb.GUAM_LEAF, level = 1),
|
||||
MARRENTILL(id = 93, herb = Herb.MARRENTILL, level = 5),
|
||||
TARROMIN(id = 95, herb = Herb.TARROMIN, level = 12),
|
||||
@@ -36,12 +41,12 @@ enum class UnfinishedPotion(val id: Int, herb: Herb, val level: Int) {
|
||||
}
|
||||
|
||||
enum class FinishedPotion(
|
||||
val id: Int,
|
||||
override val id: Int,
|
||||
val unfinished: UnfinishedPotion,
|
||||
ingredient: Ingredient,
|
||||
val level: Int,
|
||||
override val level: Int,
|
||||
val experience: Double
|
||||
) {
|
||||
) : Potion {
|
||||
ATTACK(id = 121, unfinished = GUAM, ingredient = EYE_NEWT, level = 1, experience = 25.0),
|
||||
ANTIPOISON(id = 175, unfinished = MARRENTILL, ingredient = UNICORN_HORN, level = 5, experience = 37.5),
|
||||
STRENGTH(id = 115, unfinished = TARROMIN, ingredient = LIMPWURT_ROOT, level = 12, experience = 50.0),
|
||||
|
||||
Reference in New Issue
Block a user