mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 00:38:46 +00:00
Fix kotlin code style issues
This commit is contained in:
@@ -27,5 +27,4 @@ enum class Fish(val id: Int, val level: Int, val experience: Double, catchSuffix
|
||||
val catchMessage by lazy { "You catch ${catchSuffix ?: "a $catchName."}" }
|
||||
|
||||
private val catchName by lazy { Definitions.item(id).name.toLowerCase().removePrefix("raw ") }
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,10 +1,10 @@
|
||||
package org.apollo.game.plugin.skills.fishing
|
||||
|
||||
import java.util.Objects
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncDistancedAction
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.api.fishing
|
||||
import java.util.Objects
|
||||
|
||||
class FishingAction(
|
||||
player: Player,
|
||||
@@ -82,7 +82,5 @@ class FishingAction(
|
||||
internal fun hasTool(player: Player, tool: FishingTool): Boolean {
|
||||
return tool.id in player.equipment || tool.id in player.inventory
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -106,9 +106,7 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco
|
||||
else -> Pair(tool, secondary, primary)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -119,5 +117,4 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco
|
||||
*/
|
||||
fun lookup(id: Int): FishingSpot? = FISHING_SPOTS[id]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,5 +35,4 @@ data class FishingTarget(val position: Position, val option: FishingSpot.Option)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,5 +29,4 @@ enum class FishingTool(
|
||||
* The name of this tool, formatted so it can be inserted into a message.
|
||||
*/
|
||||
val formattedName by lazy { Definitions.item(id).name.toLowerCase() }
|
||||
|
||||
}
|
||||
-1
@@ -89,5 +89,4 @@ class FishingActionTests {
|
||||
private val spots = FishingSpot.values()
|
||||
.map { NpcDefinition(it.npc).apply { name = "<fishing_spot>" } }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import java.util.Objects
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncAction
|
||||
import org.apollo.game.model.Animation
|
||||
import org.apollo.game.model.entity.Player
|
||||
import java.util.Objects
|
||||
|
||||
class CrushIngredientAction(
|
||||
player: Player,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
import java.util.Objects
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncAction
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.api.herblore
|
||||
import org.apollo.util.LanguageUtil
|
||||
import java.util.Objects
|
||||
|
||||
class IdentifyHerbAction(
|
||||
player: Player,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import java.util.*
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncAction
|
||||
import org.apollo.game.model.Animation
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.Skill
|
||||
import org.apollo.game.plugin.api.herblore
|
||||
import java.util.*
|
||||
|
||||
abstract class MakePotionAction(
|
||||
player: Player,
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
-1
@@ -28,5 +28,4 @@ class BuryBoneAction(
|
||||
public val BURY_BONE_ANIMATION = Animation(827)
|
||||
internal const val BURY_OPTION = 1
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,5 +70,4 @@ class BuryBoneTests {
|
||||
return Bone.values().map { ItemDefinition(it.id) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.apollo.game.plugin.skill.runecrafting
|
||||
|
||||
import org.apollo.game.plugin.skill.runecrafting.Altar.*
|
||||
|
||||
|
||||
interface Rune {
|
||||
/**
|
||||
* The item id of the rune.
|
||||
@@ -29,7 +28,7 @@ interface Rune {
|
||||
*
|
||||
* [playerLevel] - The players current runecrafting level.
|
||||
*/
|
||||
fun getBonusMultiplier(playerLevel: Int) : Double
|
||||
fun getBonusMultiplier(playerLevel: Int): Double
|
||||
}
|
||||
|
||||
enum class DefaultRune(
|
||||
|
||||
@@ -8,11 +8,10 @@ private val changeAltarObjectConfigId = 491
|
||||
|
||||
internal val RUNES = mutableListOf<Rune>()
|
||||
|
||||
fun List<Rune>.findById(id: Int) : Rune? {
|
||||
fun List<Rune>.findById(id: Int): Rune? {
|
||||
return find { rune -> rune.id == id }
|
||||
}
|
||||
|
||||
|
||||
start {
|
||||
RUNES.addAll(DefaultRune.values())
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class RunecraftingAction(val player: Player, val rune: Rune, altar: Altar) : Asy
|
||||
|
||||
wait(1)
|
||||
|
||||
val name = Definitions.item(rune.id).name;
|
||||
val name = Definitions.item(rune.id).name
|
||||
val nameArticle = LanguageUtil.getIndefiniteArticle(name)
|
||||
val essenceAmount = player.inventory.removeAll(runeEssenceId)
|
||||
val runeAmount = essenceAmount * rune.getBonusMultiplier(player.runecraft.current)
|
||||
|
||||
@@ -27,7 +27,6 @@ class RunecraftingActionTests {
|
||||
fun setupPlayer() {
|
||||
player.position = TEST_ALTAR.center
|
||||
player.inventory.add(runeEssenceId, 25)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-3
@@ -1,4 +1,5 @@
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.apollo.game.GameConstants
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncDistancedAction
|
||||
@@ -10,7 +11,6 @@ import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.plugin.api.*
|
||||
import org.apollo.game.plugin.skills.woodcutting.Axe
|
||||
import org.apollo.game.plugin.skills.woodcutting.Tree
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
// TODO Accurate chopping rates, e.g. https://twitter.com/JagexKieren/status/713403124464107520
|
||||
|
||||
@@ -33,7 +33,6 @@ class WoodcuttingTarget(private val objectId: Int, val position: Position, val t
|
||||
* Returns whether or not the tree was cut down.
|
||||
*/
|
||||
fun isCutDown(): Boolean = rand(100) <= tree.chance * 100
|
||||
|
||||
}
|
||||
|
||||
class WoodcuttingAction(
|
||||
@@ -102,5 +101,4 @@ class WoodcuttingAction(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.EnumSource
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class AxeTests {
|
||||
class AxeTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
@@ -70,5 +70,4 @@ class AxeTests {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import java.util.stream.Stream
|
||||
import org.apollo.game.plugin.skills.woodcutting.Tree
|
||||
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 WoodcuttingTestData(val treeId: Int, val stumpId: Int, val tree: Tree)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import java.util.Random
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.Skill
|
||||
@@ -20,7 +21,6 @@ import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource
|
||||
import java.util.Random
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class WoodcuttingTests {
|
||||
|
||||
Reference in New Issue
Block a user