mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Separate prospecting actions
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import org.apollo.game.action.ActionBlock
|
import org.apollo.game.action.ActionBlock
|
||||||
import org.apollo.game.action.AsyncDistancedAction
|
import org.apollo.game.action.AsyncDistancedAction
|
||||||
import org.apollo.game.action.DistancedAction
|
|
||||||
import org.apollo.game.message.impl.ObjectActionMessage
|
import org.apollo.game.message.impl.ObjectActionMessage
|
||||||
import org.apollo.game.model.Position
|
import org.apollo.game.model.Position
|
||||||
import org.apollo.game.model.World
|
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(
|
class MiningAction(
|
||||||
player: Player,
|
player: Player,
|
||||||
private val tool: Pickaxe,
|
private val tool: Pickaxe,
|
||||||
@@ -129,86 +112,20 @@ class MiningAction(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExpiredProspectingAction(
|
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||||
mob: Player,
|
|
||||||
position: Position
|
|
||||||
) : DistancedAction<Player>(DELAY, true, mob, position, ORE_SIZE) {
|
|
||||||
|
|
||||||
companion object {
|
fun getObject(world: World): GameObject? {
|
||||||
private const val DELAY = 0
|
val region = world.regionRepository.fromPosition(position)
|
||||||
private const val ORE_SIZE = 1
|
return region.findObject(position, objectId).orElse(null)
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
fun isSuccessful(mob: Player): Boolean {
|
||||||
mob.sendMessage("There is currently no ore available in this rock.")
|
val offset = if (ore.chanceOffset) 1 else 0
|
||||||
stop()
|
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<Player>(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 {
|
private object Actions {
|
||||||
|
|||||||
@@ -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<Player>(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<Player>(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)
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user