From 4b68b8e47e3303a2af88bc384ac745e179f7204c Mon Sep 17 00:00:00 2001 From: Major Date: Wed, 28 Mar 2018 17:34:38 +0100 Subject: [PATCH] Separate prospecting actions --- .../skills/mining/src/mining.plugin.kts | 101 ++---------------- game/plugin/skills/mining/src/prospecting.kt | 92 ++++++++++++++++ 2 files changed, 101 insertions(+), 92 deletions(-) create mode 100644 game/plugin/skills/mining/src/prospecting.kt diff --git a/game/plugin/skills/mining/src/mining.plugin.kts b/game/plugin/skills/mining/src/mining.plugin.kts index 09ecc88c..83ad0621 100644 --- a/game/plugin/skills/mining/src/mining.plugin.kts +++ b/game/plugin/skills/mining/src/mining.plugin.kts @@ -1,6 +1,5 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.action.DistancedAction import org.apollo.game.message.impl.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.World @@ -36,22 +35,6 @@ on { ObjectActionMessage::class } } } -data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) { - - fun getObject(world: World): GameObject? { - val region = world.regionRepository.fromPosition(position) - return region.findObject(position, objectId).orElse(null) - } - - fun isSuccessful(mob: Player): Boolean { - val offset = if (ore.chanceOffset) 1 else 0 - val percent = (ore.chance * mob.mining.current + offset) * 100 - - return rand(100) < percent - } - -} - class MiningAction( player: Player, private val tool: Pickaxe, @@ -129,86 +112,20 @@ class MiningAction( } -class ExpiredProspectingAction( - mob: Player, - position: Position -) : DistancedAction(DELAY, true, mob, position, ORE_SIZE) { +data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) { - companion object { - private const val DELAY = 0 - private const val ORE_SIZE = 1 - - /** - * Starts a [ExpiredProspectingAction] for the specified [Player], terminating the [Message] that triggered it. - */ - fun start(message: ObjectActionMessage, player: Player) { - val action = ExpiredProspectingAction(player, message.position) - player.startAction(action) - - message.terminate() - } + fun getObject(world: World): GameObject? { + val region = world.regionRepository.fromPosition(position) + return region.findObject(position, objectId).orElse(null) } - override fun executeAction() { - mob.sendMessage("There is currently no ore available in this rock.") - stop() + fun isSuccessful(mob: Player): Boolean { + val offset = if (ore.chanceOffset) 1 else 0 + val percent = (ore.chance * mob.mining.current + offset) * 100 + + return rand(100) < percent } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as ExpiredProspectingAction - return mob == other.mob && position == other.position - } - - override fun hashCode(): Int = Objects.hash(mob, position) - -} - -class ProspectingAction( - player: Player, - position: Position, - private val ore: Ore -) : AsyncDistancedAction(DELAY, true, player, position, ORE_SIZE) { - - companion object { - private const val DELAY = 3 - private const val ORE_SIZE = 1 - - /** - * Starts a [MiningAction] for the specified [Player], terminating the [Message] that triggered it. - */ - fun start(message: ObjectActionMessage, player: Player, ore: Ore) { - val action = ProspectingAction(player, message.position, ore) - player.startAction(action) - - message.terminate() - } - } - - override fun action(): ActionBlock = { - mob.sendMessage("You examine the rock for ores...") - mob.turnTo(position) - - wait() - - val oreName = Definitions.item(ore.id)?.name?.toLowerCase() - mob.sendMessage("This rock contains $oreName.") - - stop() - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as ProspectingAction - return mob == other.mob && position == other.position && ore == other.ore - } - - override fun hashCode(): Int = Objects.hash(mob, position, ore) - } private object Actions { diff --git a/game/plugin/skills/mining/src/prospecting.kt b/game/plugin/skills/mining/src/prospecting.kt new file mode 100644 index 00000000..9b0f3d1c --- /dev/null +++ b/game/plugin/skills/mining/src/prospecting.kt @@ -0,0 +1,92 @@ +import org.apollo.game.action.ActionBlock +import org.apollo.game.action.AsyncDistancedAction +import org.apollo.game.action.DistancedAction +import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.model.Position +import org.apollo.game.model.entity.Player +import org.apollo.game.plugin.api.Definitions +import org.apollo.game.plugin.skills.mining.Ore +import org.apollo.net.message.Message +import java.util.Objects + +class ProspectingAction( + player: Player, + position: Position, + private val ore: Ore +) : AsyncDistancedAction(DELAY, true, player, position, ORE_SIZE) { + + companion object { + private const val DELAY = 3 + private const val ORE_SIZE = 1 + + /** + * Starts a [MiningAction] for the specified [Player], terminating the [Message] that triggered it. + */ + fun start(message: ObjectActionMessage, player: Player, ore: Ore) { + val action = ProspectingAction(player, message.position, ore) + player.startAction(action) + + message.terminate() + } + } + + override fun action(): ActionBlock = { + mob.sendMessage("You examine the rock for ores...") + mob.turnTo(position) + + wait() + + val oreName = Definitions.item(ore.id)?.name?.toLowerCase() + mob.sendMessage("This rock contains $oreName.") + + stop() + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ProspectingAction + return mob == other.mob && position == other.position && ore == other.ore + } + + override fun hashCode(): Int = Objects.hash(mob, position, ore) + +} + +class ExpiredProspectingAction( + mob: Player, + position: Position +) : DistancedAction(DELAY, true, mob, position, ORE_SIZE) { + + companion object { + private const val DELAY = 0 + private const val ORE_SIZE = 1 + + /** + * Starts a [ExpiredProspectingAction] for the specified [Player], terminating the [Message] that triggered it. + */ + fun start(message: ObjectActionMessage, player: Player) { + val action = ExpiredProspectingAction(player, message.position) + player.startAction(action) + + message.terminate() + } + } + + override fun executeAction() { + mob.sendMessage("There is currently no ore available in this rock.") + stop() + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ExpiredProspectingAction + return mob == other.mob && position == other.position + } + + override fun hashCode(): Int = Objects.hash(mob, position) + +} \ No newline at end of file