mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +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),
|
CHOCOLATE_BAR(uncrushed = 1973, id = 1975),
|
||||||
BIRDS_NEST(uncrushed = 5075, id = 6693);
|
BIRDS_NEST(uncrushed = 5075, id = 6693);
|
||||||
|
|
||||||
val uncrushedName: String = Definitions.item(uncrushed)!!.name
|
val uncrushedName by lazy { Definitions.item(uncrushed)!!.name }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PESTLE_AND_MORTAR = 233
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+38
-11
@@ -2,12 +2,13 @@ import org.apollo.game.action.ActionBlock
|
|||||||
import org.apollo.game.action.AsyncAction
|
import org.apollo.game.action.AsyncAction
|
||||||
import org.apollo.game.model.Animation
|
import org.apollo.game.model.Animation
|
||||||
import org.apollo.game.model.entity.Player
|
import org.apollo.game.model.entity.Player
|
||||||
|
import org.apollo.game.model.entity.Skill
|
||||||
import org.apollo.game.plugin.api.herblore
|
import org.apollo.game.plugin.api.herblore
|
||||||
import java.util.Objects
|
import java.util.*
|
||||||
|
|
||||||
class MakeUnfinishedPotionAction(
|
abstract class MakePotionAction(
|
||||||
player: Player,
|
player: Player,
|
||||||
private val potion: UnfinishedPotion
|
private val potion: Potion
|
||||||
) : AsyncAction<Player>(1, true, player) {
|
) : AsyncAction<Player>(1, true, player) {
|
||||||
|
|
||||||
override fun action(): ActionBlock = {
|
override fun action(): ActionBlock = {
|
||||||
@@ -20,22 +21,26 @@ class MakeUnfinishedPotionAction(
|
|||||||
|
|
||||||
val inventory = mob.inventory
|
val inventory = mob.inventory
|
||||||
|
|
||||||
if (inventory.contains(VIAL_OF_WATER) && inventory.contains(potion.herb)) {
|
if (inventory.containsAll(*ingredients)) {
|
||||||
inventory.remove(VIAL_OF_WATER)
|
ingredients.forEach { inventory.remove(it) }
|
||||||
inventory.remove(potion.herb)
|
inventory.add(potion.id)
|
||||||
|
|
||||||
mob.playAnimation(MIXING_ANIMATION)
|
mob.playAnimation(MIXING_ANIMATION)
|
||||||
|
mob.sendMessage(message)
|
||||||
|
reward()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inventory.add(potion.id)
|
abstract val ingredients: IntArray
|
||||||
mob.sendMessage("You put the ${potion.herbName} into the vial of water.")
|
abstract val message: String
|
||||||
}
|
|
||||||
}
|
open fun reward() {}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (javaClass != other?.javaClass) return false
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
other as MakeUnfinishedPotionAction
|
other as MakePotionAction
|
||||||
return mob == other.mob && potion == other.potion
|
return mob == other.mob && potion == other.potion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,3 +50,25 @@ class MakeUnfinishedPotionAction(
|
|||||||
private val MIXING_ANIMATION = Animation(363)
|
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
|
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),
|
GUAM(id = 91, herb = Herb.GUAM_LEAF, level = 1),
|
||||||
MARRENTILL(id = 93, herb = Herb.MARRENTILL, level = 5),
|
MARRENTILL(id = 93, herb = Herb.MARRENTILL, level = 5),
|
||||||
TARROMIN(id = 95, herb = Herb.TARROMIN, level = 12),
|
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(
|
enum class FinishedPotion(
|
||||||
val id: Int,
|
override val id: Int,
|
||||||
val unfinished: UnfinishedPotion,
|
val unfinished: UnfinishedPotion,
|
||||||
ingredient: Ingredient,
|
ingredient: Ingredient,
|
||||||
val level: Int,
|
override val level: Int,
|
||||||
val experience: Double
|
val experience: Double
|
||||||
) {
|
) : Potion {
|
||||||
ATTACK(id = 121, unfinished = GUAM, ingredient = EYE_NEWT, level = 1, experience = 25.0),
|
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),
|
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),
|
STRENGTH(id = 115, unfinished = TARROMIN, ingredient = LIMPWURT_ROOT, level = 12, experience = 50.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user