diff --git a/Server/src/main/content/global/skill/construction/decoration/workshop/SnowscapeWorkbench.kt b/Server/src/main/content/global/skill/construction/decoration/workshop/SnowscapeWorkbench.kt new file mode 100644 index 000000000..86974da72 --- /dev/null +++ b/Server/src/main/content/global/skill/construction/decoration/workshop/SnowscapeWorkbench.kt @@ -0,0 +1,104 @@ +package content.global.skill.construction.decoration.workshop + + + +import core.api.* +import core.game.interaction.IntType +import core.game.interaction.InteractionListener +import core.game.node.Node +import core.game.node.entity.player.Player +import core.game.node.entity.skill.Skills +import core.game.node.scenery.Scenery +import core.game.node.item.Item +import org.rs09.consts.Items +import content.global.skill.construction.BuildingUtils + + +/** + * Simple replacement intil flatpacks are in. Using the workbench will consume planks in exchange for construction exp. + * + * + */ + +class SnowscapeWorkbench : InteractionListener { + + val workbenchIds = intArrayOf(13704,13705,13706,13707,13708) + val plankIds = intArrayOf(Items.PLANK_960, Items.OAK_PLANK_8778, Items.TEAK_PLANK_8780, Items.MAHOGANY_PLANK_8782) + + override fun defineListeners() { + defineInteraction( + IntType.SCENERY, + workbenchIds, + "work-at", + persistent = true, allowedDistance = 1, + handler = ::handlePlankConstruction + ) + } + + private fun handlePlankConstruction(player: Player, node: Node, state: Int) : Boolean { + if (!inInventory(player, Items.SAW_8794) || !inInventory(player, Items.HAMMER_2347)) { + sendMessage(player,"You need a hammer and saw to do that.") + player.scripts.reset() + return false + } + + for (plankId in plankIds) { + if (amountInInventory(player, plankId) > 0) { + if (node.id < getAllowedWorkbench(plankId)) { + sendMessage(player,"You need a better workbench to use ${Item(plankId).getName()}s.") + player.scripts.reset() + return false + } + if (getDynLevel(player, Skills.CONSTRUCTION) < getLevelRequirement(plankId)) { + sendMessage(player,"You need level ${getLevelRequirement(plankId)} construction to use ${Item(plankId).getName()}s.") + player.scripts.reset() + return false + } + + if (removeItem(player, Item(plankId, 1))) { + rewardXP(player, Skills.CONSTRUCTION, getExperience(plankId)) + animate(player, BuildingUtils.BUILD_MID_ANIM) //This animation has a sound effect built in + + return delayScript(player, 1) + } + } + } + + + sendMessage(player,"You have no planks in your inventory.") + player.scripts.reset() + return false + } + + // The following functions really should have been an enum class or something, but I don't know how to do that + + fun getAllowedWorkbench(plankId: Int) : Int { + return when (plankId) { + Items.PLANK_960 -> 13704 + Items.OAK_PLANK_8778 -> 13705 + Items.TEAK_PLANK_8780 -> 13706 + Items.MAHOGANY_PLANK_8782 -> 13707 + else -> 0 + } + } + + fun getExperience(plankId: Int) : Double { + return when (plankId) { + Items.PLANK_960 -> 30.0 + Items.OAK_PLANK_8778 -> 60.0 + Items.TEAK_PLANK_8780 -> 90.0 + Items.MAHOGANY_PLANK_8782 -> 140.0 + else -> 0.0 + } + } + + fun getLevelRequirement(plankId: Int) : Int { + return when (plankId) { + Items.PLANK_960 -> 1 + Items.OAK_PLANK_8778 -> 15 + Items.TEAK_PLANK_8780 -> 35 + Items.MAHOGANY_PLANK_8782 -> 40 + else -> 0 + } + } +} \ No newline at end of file