diff --git a/Server/src/main/content/global/skill/construction/decoration/workshop/EaselListeners.kt b/Server/src/main/content/global/skill/construction/decoration/workshop/EaselListeners.kt index 18240f419..aa3fcd8e9 100644 --- a/Server/src/main/content/global/skill/construction/decoration/workshop/EaselListeners.kt +++ b/Server/src/main/content/global/skill/construction/decoration/workshop/EaselListeners.kt @@ -3,6 +3,7 @@ package content.global.skill.construction.decoration.workshop import content.global.skill.crafting.HeraldicProduct import core.api.* import core.game.interaction.InteractionListener +import core.game.node.entity.player.Player import core.game.node.entity.skill.Skills import org.rs09.consts.Items import org.rs09.consts.Scenery @@ -14,12 +15,65 @@ import org.rs09.consts.Scenery class EaselListener : InteractionListener { - private val easels = intArrayOf(Scenery.HELMET_PLUMING_STAND_13716, Scenery.PAINTING_STAND_13717, Scenery.BANNER_MAKING_STAND_13718) + private val easels = intArrayOf( + Scenery.HELMET_PLUMING_STAND_13716, + Scenery.PAINTING_STAND_13717, + Scenery.BANNER_MAKING_STAND_13718 + ) + private val buttonsToProducts = mapOf( + 2 to HeraldicProduct.STEEL_HELM, + 3 to HeraldicProduct.RUNE_HELM, + 4 to HeraldicProduct.STEEL_SHIELD, + 5 to HeraldicProduct.RUNE_SHIELD, + 6 to HeraldicProduct.BANNER + ) private val heraldryAnimation = 3654 + private fun checkRequirements(player: Player, product: HeraldicProduct) : Boolean { + when { + (!inInventory(player, product.primaryMaterialId)) -> { + sendDialogue(player, "You need a ${product.primaryMaterialId.asItem().name.toLowerCase()} to make this.") + return false + } + (product.secondaryMaterialId != null && !inInventory(player, product.secondaryMaterialId)) -> { + sendDialogue(player, "You need a ${product.secondaryMaterialId.asItem().name.toLowerCase()} to make this.") + return false + } + (!hasLevelDyn(player, Skills.CONSTRUCTION, product.constructionReq)) -> { + sendDialogue(player, "You need a Construction level of ${product.constructionReq} to make this.") + return false + } + (!hasLevelDyn(player, Skills.CRAFTING, product.craftingReq)) -> { + sendDialogue(player, "You need a Crafting level of ${product.craftingReq} to make this.") + return false + } + else -> { + return true + } + } + } + + private fun giveProduct(player: Player, product: HeraldicProduct) { + val crest = player.houseManager.crest + if (removeItem(player, product.primaryMaterialId)) { + if (product.secondaryMaterialId == null || removeItem(player, product.secondaryMaterialId)) { + addItemOrDrop(player, product.productForCrest(crest)) + rewardXP(player, Skills.CRAFTING, product.craftingXp) + animate(player, heraldryAnimation) + when (product) { + HeraldicProduct.STEEL_HELM, HeraldicProduct.RUNE_HELM -> + sendMessage(player, "You make a helmet in your colours.") + HeraldicProduct.STEEL_SHIELD, HeraldicProduct.RUNE_SHIELD -> + sendMessage(player, "You make a shield with your symbol on.") + HeraldicProduct.BANNER -> + sendMessage(player, "You make a banner with your symbol on.") + } + } + } + } + override fun defineListeners() { on(easels, SCENERY, "use") { player, node -> - val crest = player.houseManager.crest val options = when (node.id) { Scenery.HELMET_PLUMING_STAND_13716 -> arrayOf("Plumed steel helmet", "Plumed rune helmet") @@ -32,132 +86,16 @@ class EaselListener : InteractionListener { } sendDialogueOptions(player, "What do you want to make?", *options) addDialogueAction(player) { player, button -> - when (button) { - 2,3 -> { - when { - (!hasLevelDyn(player, Skills.CONSTRUCTION, HeraldicProduct.STEEL_HELM.constructionReq)) -> { - sendDialogue(player, "You need a Construction level of ${HeraldicProduct.STEEL_HELM.constructionReq} to make this.") - return@addDialogueAction - } - (!hasLevelDyn(player, Skills.CRAFTING, HeraldicProduct.STEEL_HELM.craftingReq)) -> { - sendDialogue(player, "You need a Crafting level of ${HeraldicProduct.STEEL_HELM.craftingReq} to make this.") - return@addDialogueAction - } - (button == 2) -> { - if (removeItem(player, HeraldicProduct.STEEL_HELM.primaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.STEEL_HELM.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.STEEL_HELM.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a helmet in your colours.") - return@addDialogueAction - } else { - sendDialogue(player, "You need a steel full helm in order to do this.") - return@addDialogueAction - } - } - else -> { - if (removeItem(player, HeraldicProduct.RUNE_HELM.primaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.RUNE_HELM.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.RUNE_HELM.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a helmet in your colours.") - return@addDialogueAction - } else { - sendDialogue(player, "You need a rune full helm in order to do this.") - return@addDialogueAction - } - } - } - } - 4,5 -> { - when { - (!hasLevelDyn(player, Skills.CONSTRUCTION, HeraldicProduct.STEEL_SHIELD.constructionReq)) -> { - sendDialogue(player, "You need a Construction level of ${HeraldicProduct.STEEL_SHIELD.constructionReq} to make this.") - return@addDialogueAction - } - (!hasLevelDyn(player, Skills.CRAFTING, HeraldicProduct.STEEL_SHIELD.craftingReq)) -> { - sendDialogue(player, "You need a Crafting level of ${HeraldicProduct.STEEL_SHIELD.craftingReq} to make this.") - return@addDialogueAction - } - (button == 4) -> { - if (removeItem(player, HeraldicProduct.STEEL_SHIELD.primaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.STEEL_SHIELD.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.STEEL_SHIELD.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a shield with your symbol on.") - return@addDialogueAction - } else { - sendDialogue(player, "You need a steel kiteshield in order to do this.") - return@addDialogueAction - } - } - else -> { - if (removeItem(player, HeraldicProduct.RUNE_SHIELD.primaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.RUNE_SHIELD.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.RUNE_SHIELD.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a shield with your symbol on.") - return@addDialogueAction - } else { - sendDialogue(player, "You need a rune kiteshield in order to do this.") - return@addDialogueAction - } - } - } - } - 6 -> { - when { - (!hasLevelDyn(player, Skills.CONSTRUCTION, HeraldicProduct.BANNER.constructionReq)) -> { - sendDialogue(player, "You need a Construction level of ${HeraldicProduct.BANNER.constructionReq} to make this.") - return@addDialogueAction - } - (!hasLevelDyn(player, Skills.CRAFTING, HeraldicProduct.BANNER.craftingReq)) -> { - sendDialogue(player, "You need a Crafting level of ${HeraldicProduct.BANNER.craftingReq} to make this.") - return@addDialogueAction - } - (!inInventory(player, HeraldicProduct.BANNER.primaryMaterialId) || !inInventory(player, HeraldicProduct.BANNER.secondaryMaterialId!!)) -> { - sendDialogue(player, "You need a bolt of cloth and a plank in order to do this.") - } - else -> { - if (removeItem(player, HeraldicProduct.BANNER.primaryMaterialId) && removeItem(player, HeraldicProduct.BANNER.secondaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.BANNER.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.BANNER.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a banner with your symbol on.") - } - return@addDialogueAction - } - } - } + if (checkRequirements(player, buttonsToProducts[button] ?: return@addDialogueAction)) { + giveProduct(player, buttonsToProducts[button] ?: return@addDialogueAction) } + return@addDialogueAction } return@on true } onUseWith(SCENERY, Items.BOLT_OF_CLOTH_8790, Scenery.BANNER_MAKING_STAND_13718) { player, _, _ -> - val crest = player.houseManager.crest - when { - (!hasLevelDyn(player, Skills.CONSTRUCTION, HeraldicProduct.BANNER.constructionReq)) -> { - sendDialogue(player, "You need a Construction level of ${HeraldicProduct.BANNER.constructionReq} to make this.") - return@onUseWith false - } - (!hasLevelDyn(player, Skills.CRAFTING, HeraldicProduct.BANNER.craftingReq)) -> { - sendDialogue(player, "You need a Crafting level of ${HeraldicProduct.BANNER.craftingReq} to make this.") - return@onUseWith false - } - (!inInventory(player, HeraldicProduct.BANNER.primaryMaterialId) || !inInventory(player, HeraldicProduct.BANNER.secondaryMaterialId!!)) -> { - sendDialogue(player, "You need a bolt of cloth and a plank in order to do this.") - } - else -> { - if (removeItem(player, HeraldicProduct.BANNER.primaryMaterialId) && removeItem(player, HeraldicProduct.BANNER.secondaryMaterialId)) { - addItemOrDrop(player, HeraldicProduct.BANNER.productForCrest(crest)) - rewardXP(player, Skills.CRAFTING, HeraldicProduct.BANNER.craftingXp) - animate(player, heraldryAnimation) - sendMessage(player, "You make a banner with your symbol on.") - return@onUseWith true - } else { - return@onUseWith false - } - } + if (checkRequirements(player, HeraldicProduct.BANNER)) { + giveProduct(player, HeraldicProduct.BANNER) } return@onUseWith true }