mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Fix kotlin code style issues
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import java.util.*
|
||||
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
|
||||
|
||||
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)
|
||||
}
|
||||
+1
-56
@@ -1,14 +1,12 @@
|
||||
import java.util.*
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncDistancedAction
|
||||
import org.apollo.game.message.impl.ObjectActionMessage
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.api.*
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
import org.apollo.net.message.Message
|
||||
import java.util.*
|
||||
|
||||
class MiningAction(
|
||||
player: Player,
|
||||
@@ -82,57 +80,4 @@ class MiningAction(
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = Objects.hash(mob, target)
|
||||
|
||||
}
|
||||
|
||||
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||
|
||||
/**
|
||||
* Deplete this mining resource from the [World], and schedule it to be respawned
|
||||
* in a number of ticks specified by the [Ore].
|
||||
*/
|
||||
fun deplete(world: World) {
|
||||
val obj = world.findObject(position, objectId)!!
|
||||
|
||||
world.replaceObject(obj, ore.objects[objectId]!!, ore.respawn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [Player] was successful in mining this ore with a random success [chance] value between 0 and 100.
|
||||
*/
|
||||
fun isSuccessful(mob: Player, chance: Int): Boolean {
|
||||
val percent = (ore.chance * mob.mining.current + ore.chanceOffset) * 100
|
||||
return chance < percent
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this target is still valid in the [World] (i.e. has not been [deplete]d).
|
||||
*/
|
||||
fun isValid(world: World) = world.findObject(position, objectId) != null
|
||||
|
||||
/**
|
||||
* Get the normalized name of the [Ore] represented by this target.
|
||||
*/
|
||||
fun oreName() = Definitions.item(ore.id).name.toLowerCase()
|
||||
|
||||
/**
|
||||
* Reward a [player] with experience and ore if they have the inventory capacity to take a new ore.
|
||||
*/
|
||||
fun reward(player: Player): Boolean {
|
||||
val hasInventorySpace = player.inventory.add(ore.id)
|
||||
|
||||
if (hasInventorySpace) {
|
||||
player.mining.experience += ore.exp
|
||||
}
|
||||
|
||||
return hasInventorySpace
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [mob] has met the skill requirements to mine te [Ore] represented by
|
||||
* this [MiningTarget].
|
||||
*/
|
||||
fun skillRequirementsMet(mob: Player) = mob.mining.current < ore.level
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.api.Definitions
|
||||
import org.apollo.game.plugin.api.findObject
|
||||
import org.apollo.game.plugin.api.mining
|
||||
import org.apollo.game.plugin.api.replaceObject
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
|
||||
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||
|
||||
/**
|
||||
* Deplete this mining resource from the [World], and schedule it to be respawned
|
||||
* in a number of ticks specified by the [Ore].
|
||||
*/
|
||||
fun deplete(world: World) {
|
||||
val obj = world.findObject(position, objectId)!!
|
||||
|
||||
world.replaceObject(obj, ore.objects[objectId]!!, ore.respawn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [Player] was successful in mining this ore with a random success [chance] value between 0 and 100.
|
||||
*/
|
||||
fun isSuccessful(mob: Player, chance: Int): Boolean {
|
||||
val percent = (ore.chance * mob.mining.current + ore.chanceOffset) * 100
|
||||
return chance < percent
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this target is still valid in the [World] (i.e. has not been [deplete]d).
|
||||
*/
|
||||
fun isValid(world: World) = world.findObject(position, objectId) != null
|
||||
|
||||
/**
|
||||
* Get the normalized name of the [Ore] represented by this target.
|
||||
*/
|
||||
fun oreName() = Definitions.item(ore.id).name.toLowerCase()
|
||||
|
||||
/**
|
||||
* Reward a [player] with experience and ore if they have the inventory capacity to take a new ore.
|
||||
*/
|
||||
fun reward(player: Player): Boolean {
|
||||
val hasInventorySpace = player.inventory.add(ore.id)
|
||||
|
||||
if (hasInventorySpace) {
|
||||
player.mining.experience += ore.exp
|
||||
}
|
||||
|
||||
return hasInventorySpace
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [mob] has met the skill requirements to mine te [Ore] represented by
|
||||
* this [MiningTarget].
|
||||
*/
|
||||
fun skillRequirementsMet(mob: Player) = mob.mining.current < ore.level
|
||||
}
|
||||
@@ -36,7 +36,6 @@ enum class Ore(
|
||||
|
||||
fun fromRock(id: Int): Ore? = ORE_ROCKS[id]
|
||||
fun fromExpiredRock(id: Int): Ore? = EXPIRED_ORE[id]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-40
@@ -1,13 +1,12 @@
|
||||
import java.util.Objects
|
||||
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,
|
||||
@@ -51,42 +50,4 @@ class ProspectingAction(
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
@@ -87,5 +87,4 @@ class MiningActionTests {
|
||||
@ItemDefinitions
|
||||
fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@ class PickaxeTests {
|
||||
assertEquals(null, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Pickaxe::class)
|
||||
fun `The highest level pickaxe is chosen when available`(pickaxe: Pickaxe) {
|
||||
@@ -43,7 +42,6 @@ class PickaxeTests {
|
||||
assertEquals(Pickaxe.BRONZE, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Pickaxe::class)
|
||||
fun `Pickaxes can be chosen from equipment as well as inventory`(pickaxe: Pickaxe) {
|
||||
@@ -53,7 +51,6 @@ class PickaxeTests {
|
||||
assertEquals(pickaxe, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Pickaxe::class)
|
||||
fun `Pickaxes with a level requirement higher than the player's are ignored`(pickaxe: Pickaxe) {
|
||||
@@ -73,5 +70,4 @@ class PickaxeTests {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,5 +45,4 @@ class ProspectingTests {
|
||||
ItemDefinition(it.id).also { it.name = "<ore_type>" }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import java.util.stream.Stream
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider
|
||||
import java.util.stream.Stream
|
||||
|
||||
data class MiningTestData(val rockId: Int, val expiredRockId: Int, val ore: Ore)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user