diff --git a/game/plugin/skills/herblore/src/herblore.plugin.kts b/game/plugin/skills/herblore/src/Herblore.plugin.kts similarity index 100% rename from game/plugin/skills/herblore/src/herblore.plugin.kts rename to game/plugin/skills/herblore/src/Herblore.plugin.kts diff --git a/game/plugin/skills/herblore/src/Ingredient.kt b/game/plugin/skills/herblore/src/Ingredient.kt index 3784f090..47543694 100644 --- a/game/plugin/skills/herblore/src/Ingredient.kt +++ b/game/plugin/skills/herblore/src/Ingredient.kt @@ -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 diff --git a/game/plugin/skills/herblore/src/MakeFinishedPotionAction.kt b/game/plugin/skills/herblore/src/MakeFinishedPotionAction.kt deleted file mode 100644 index 37cc56d5..00000000 --- a/game/plugin/skills/herblore/src/MakeFinishedPotionAction.kt +++ /dev/null @@ -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(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) - } -} \ No newline at end of file diff --git a/game/plugin/skills/herblore/src/MakeUnfinishedPotionAction.kt b/game/plugin/skills/herblore/src/MakePotionAction.kt similarity index 50% rename from game/plugin/skills/herblore/src/MakeUnfinishedPotionAction.kt rename to game/plugin/skills/herblore/src/MakePotionAction.kt index 03bbd5a7..46759d79 100644 --- a/game/plugin/skills/herblore/src/MakeUnfinishedPotionAction.kt +++ b/game/plugin/skills/herblore/src/MakePotionAction.kt @@ -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(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." } } \ No newline at end of file diff --git a/game/plugin/skills/herblore/src/Potion.kt b/game/plugin/skills/herblore/src/Potion.kt index 299a8298..ce9053ed 100644 --- a/game/plugin/skills/herblore/src/Potion.kt +++ b/game/plugin/skills/herblore/src/Potion.kt @@ -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),