Fix kotlin code style issues

This commit is contained in:
Gary Tierney
2018-09-04 04:43:34 +01:00
parent b6086d57b8
commit 475c7ac741
89 changed files with 338 additions and 435 deletions
@@ -4,7 +4,6 @@ import io.mockk.MockKVerificationScope
import io.mockk.verify import io.mockk.verify
import org.apollo.game.plugin.testing.junit.api.ActionCaptureCallbackRegistration import org.apollo.game.plugin.testing.junit.api.ActionCaptureCallbackRegistration
/** /**
* Verify some expectations on a [mock] after a delayed event (specified by [DelayMode]). * Verify some expectations on a [mock] after a delayed event (specified by [DelayMode]).
*/ */
@@ -3,6 +3,7 @@ package org.apollo.game.plugin.testing.junit
import io.mockk.every import io.mockk.every
import io.mockk.slot import io.mockk.slot
import io.mockk.spyk import io.mockk.spyk
import kotlin.reflect.KClass
import org.apollo.game.action.Action import org.apollo.game.action.Action
import org.apollo.game.message.handler.MessageHandlerChainSet import org.apollo.game.message.handler.MessageHandlerChainSet
import org.apollo.game.model.World import org.apollo.game.model.World
@@ -12,7 +13,6 @@ import org.apollo.game.plugin.testing.junit.mocking.StubPrototype
import org.apollo.game.plugin.testing.junit.stubs.PlayerStubInfo import org.apollo.game.plugin.testing.junit.stubs.PlayerStubInfo
import org.apollo.net.message.Message import org.apollo.net.message.Message
import org.apollo.util.security.PlayerCredentials import org.apollo.util.security.PlayerCredentials
import kotlin.reflect.KClass
data class ApolloTestState(val handlers: MessageHandlerChainSet, val world: World) { data class ApolloTestState(val handlers: MessageHandlerChainSet, val world: World) {
val players = mutableListOf<Player>() val players = mutableListOf<Player>()
@@ -4,6 +4,14 @@ import io.mockk.every
import io.mockk.slot import io.mockk.slot
import io.mockk.spyk import io.mockk.spyk
import io.mockk.staticMockk import io.mockk.staticMockk
import kotlin.reflect.KCallable
import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.createType
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.jvm.isAccessible
import kotlin.reflect.jvm.jvmErasure
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition import org.apollo.cache.def.ObjectDefinition
@@ -20,22 +28,6 @@ import org.apollo.game.plugin.testing.junit.api.annotations.NpcDefinitions
import org.apollo.game.plugin.testing.junit.api.annotations.ObjectDefinitions import org.apollo.game.plugin.testing.junit.api.annotations.ObjectDefinitions
import org.apollo.game.plugin.testing.junit.mocking.StubPrototype import org.apollo.game.plugin.testing.junit.mocking.StubPrototype
import org.junit.jupiter.api.extension.* import org.junit.jupiter.api.extension.*
import kotlin.reflect.KCallable
import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.createType
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.jvm.isAccessible
import kotlin.reflect.jvm.jvmErasure
internal val supportedTestDoubleTypes = setOf(
Player::class.createType(),
Npc::class.createType(),
GameObject::class.createType(),
World::class.createType(),
ActionCapture::class.createType()
)
class ApolloTestingExtension : class ApolloTestingExtension :
AfterTestExecutionCallback, AfterTestExecutionCallback,
@@ -168,6 +160,13 @@ class ApolloTestingExtension :
} }
companion object { companion object {
internal val supportedTestDoubleTypes = setOf(
Player::class.createType(),
Npc::class.createType(),
GameObject::class.createType(),
World::class.createType(),
ActionCapture::class.createType()
)
inline fun <reified D : Any, reified A : Annotation> findTestDefinitions( inline fun <reified D : Any, reified A : Annotation> findTestDefinitions(
callables: Collection<KCallable<*>>, callables: Collection<KCallable<*>>,
@@ -185,7 +184,5 @@ class ApolloTestingExtension :
method.call(companionObjectInstance) method.call(companionObjectInstance)
} }
} }
} }
} }
@@ -1,10 +1,10 @@
package org.apollo.game.plugin.testing.junit.api package org.apollo.game.plugin.testing.junit.api
import kotlin.reflect.KClass
import kotlin.reflect.full.isSuperclassOf
import org.apollo.game.action.Action import org.apollo.game.action.Action
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import kotlin.reflect.KClass
import kotlin.reflect.full.isSuperclassOf
class ActionCapture(val type: KClass<out Action<*>>) { class ActionCapture(val type: KClass<out Action<*>>) {
private var action: Action<*>? = null private var action: Action<*>? = null
@@ -62,7 +62,6 @@ class ActionCapture(val type: KClass<out Action<*>>) {
}) })
} }
/** /**
* Create a callback registration that triggers after exactly [count] ticks. * Create a callback registration that triggers after exactly [count] ticks.
*/ */
@@ -1,6 +0,0 @@
package org.apollo.game.plugin.testing.junit.api.annotations
import org.apollo.game.action.Action
import kotlin.reflect.KClass
annotation class ActionTest(val value: KClass<out Action<*>> = Action::class)
@@ -18,7 +18,6 @@ fun World.spawnObject(id: Int, position: Position): GameObject {
return obj return obj
} }
/** /**
* Spawns a new NPC with the minimum set of dependencies required to function correctly in the world. * Spawns a new NPC with the minimum set of dependencies required to function correctly in the world.
*/ */
@@ -1,5 +1,10 @@
package org.apollo.game.plugin.testing.junit.params package org.apollo.game.plugin.testing.junit.params
import java.util.stream.Stream
import kotlin.reflect.KCallable
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition import org.apollo.cache.def.ObjectDefinition
@@ -11,11 +16,6 @@ import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.support.AnnotationConsumer import org.junit.jupiter.params.support.AnnotationConsumer
import java.util.stream.Stream
import kotlin.reflect.KCallable
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
/** /**
* An [ArgumentsProvider] for a definition of type `D`. * An [ArgumentsProvider] for a definition of type `D`.
@@ -64,7 +64,6 @@ object ItemDefinitionsProvider : DefinitionsProvider<ItemDefinition>(
override fun accept(source: ItemDefinitionSource) { override fun accept(source: ItemDefinitionSource) {
sourceNames = source.sourceNames.toHashSet() sourceNames = source.sourceNames.toHashSet()
} }
} }
/** /**
@@ -80,7 +79,6 @@ object NpcDefinitionsProvider : DefinitionsProvider<NpcDefinition>(
override fun accept(source: NpcDefinitionSource) { override fun accept(source: NpcDefinitionSource) {
sourceNames = source.sourceNames.toHashSet() sourceNames = source.sourceNames.toHashSet()
} }
} }
/** /**
@@ -96,5 +94,4 @@ object ObjectDefinitionsProvider : DefinitionsProvider<ObjectDefinition>(
override fun accept(source: ObjectDefinitionSource) { override fun accept(source: ObjectDefinitionSource) {
sourceNames = source.sourceNames.toHashSet() sourceNames = source.sourceNames.toHashSet()
} }
} }
@@ -1,2 +1 @@
package org.apollo.game.plugin.testing.junit.stubs package org.apollo.game.plugin.testing.junit.stubs
@@ -1,2 +1 @@
package org.apollo.game.plugin.testing.junit.stubs package org.apollo.game.plugin.testing.junit.stubs
@@ -18,10 +18,8 @@ class PlayerStubInfo {
return info return info
} }
} }
var position = Position(3222, 3222) var position = Position(3222, 3222)
var name = "test" var name = "test"
} }
@@ -1,9 +1,9 @@
package org.apollo.game.plugin.api package org.apollo.game.plugin.api
import java.lang.IllegalArgumentException
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition import org.apollo.cache.def.ObjectDefinition
import java.lang.IllegalArgumentException
/** /**
* Provides plugins with access to item, npc, and object definitions * Provides plugins with access to item, npc, and object definitions
@@ -101,5 +101,4 @@ object Definitions {
val normalizedName = name.replace('_', ' ') val normalizedName = name.replace('_', ' ')
return definitions.firstOrNull { it.nameSupplier().equals(normalizedName, ignoreCase = true) } return definitions.firstOrNull { it.nameSupplier().equals(normalizedName, ignoreCase = true) }
} }
} }
@@ -86,5 +86,4 @@ class SkillProxy(private val skills: SkillSet, private val skill: Int) {
val new = Math.min(current + amount, maximum) val new = Math.min(current + amount, maximum)
skills.setCurrentLevel(skill, new) skills.setCurrentLevel(skill, new)
} }
} }
@@ -100,5 +100,4 @@ private class ExpireObjectTask(
stop() stop()
} }
} }
} }
@@ -88,7 +88,5 @@ class DefinitionsTests {
@ObjectDefinitions @ObjectDefinitions
val objs = listOf("obj zero", "obj one", "obj two", "obj duplicate name", "obj duplicate name") val objs = listOf("obj zero", "obj one", "obj two", "obj duplicate name", "obj duplicate name")
.mapIndexed { id, name -> ObjectDefinition(id).also { it.name = name } } .mapIndexed { id, name -> ObjectDefinition(id).also { it.name = name } }
} }
} }
@@ -119,5 +119,4 @@ class PlayerTests {
assertEquals(10, hitpoints.maximum) assertEquals(10, hitpoints.maximum)
} }
} }
} }
@@ -22,5 +22,4 @@ class PositionTests {
assertEquals(y, y2) { "y coordinate mismatch in Position destructuring." } assertEquals(y, y2) { "y coordinate mismatch in Position destructuring." }
assertEquals(z, z2) { "z coordinate mismatch in Position destructuring." } assertEquals(z, z2) { "z coordinate mismatch in Position destructuring." }
} }
} }
-2
View File
@@ -14,7 +14,6 @@ interface Area {
* Returns whether or not the specified [Position] is inside this [Area]. * Returns whether or not the specified [Position] is inside this [Area].
*/ */
operator fun contains(position: Position): Boolean operator fun contains(position: Position): Boolean
} }
internal class RectangularArea(private val x: IntRange, private val y: IntRange, private val height: Int) : Area { internal class RectangularArea(private val x: IntRange, private val y: IntRange, private val height: Int) : Area {
@@ -23,5 +22,4 @@ internal class RectangularArea(private val x: IntRange, private val y: IntRange,
val (x, y, z) = position val (x, y, z) = position
return x in this.x && y in this.y && z == height return x in this.x && y in this.y && z == height
} }
} }
@@ -38,5 +38,4 @@ class AreaActionBuilder internal constructor(val name: String, val area: Area) {
fun exit(listener: AreaListener) { fun exit(listener: AreaListener) {
this.exit = listener this.exit = listener
} }
} }
@@ -55,5 +55,4 @@ class AreaActionTests {
assertTrue(triggered) { "exit_test_action was not triggered." } assertTrue(triggered) { "exit_test_action was not triggered." }
} }
} }
-3
View File
@@ -9,7 +9,6 @@ import org.apollo.net.message.Message
val BANK_BOOTH_ID = 2213 val BANK_BOOTH_ID = 2213
/** /**
* Hook into the [ObjectActionMessage] and listen for when a bank booth's second action ("Open Bank") is selected. * Hook into the [ObjectActionMessage] and listen for when a bank booth's second action ("Open Bank") is selected.
*/ */
@@ -56,7 +55,6 @@ class BankAction(player: Player, position: Position) : DistancedAction<Player>(0
player.startAction(BankAction(player, position)) player.startAction(BankAction(player, position))
message.terminate() message.terminate()
} }
} }
override fun executeAction() { override fun executeAction() {
@@ -72,5 +70,4 @@ class BankAction(player: Player, position: Position) : DistancedAction<Player>(0
override fun hashCode(): Int { override fun hashCode(): Int {
return position.hashCode() return position.hashCode()
} }
} }
-1
View File
@@ -49,5 +49,4 @@ class OpenBankTest {
verifyAfter(action.complete()) { player.openBank() } verifyAfter(action.complete()) { player.openBank() }
} }
} }
@@ -104,7 +104,6 @@ on_command("teleto", PrivilegeLevel.ADMINISTRATOR)
} }
} }
internal val TELEPORT_DESTINATIONS = listOf( internal val TELEPORT_DESTINATIONS = listOf(
"alkharid" to Position(3292, 3171), "alkharid" to Position(3292, 3171),
"ardougne" to Position(2662, 3304), "ardougne" to Position(2662, 3304),
@@ -36,5 +36,4 @@ class AnimateCommandTests {
player.sendMessage(contains("Invalid syntax")) player.sendMessage(contains("Invalid syntax"))
} }
} }
} }
@@ -93,5 +93,4 @@ class LookupCommandTests {
length = 1 length = 1
}) })
} }
} }
+1 -1
View File
@@ -37,7 +37,7 @@ class SpawnCommandTests {
verify { verify {
world.register(match<Npc> { world.register(match<Npc> {
it.id == 1 && it.position == Position(3, 3,0) it.id == 1 && it.position == Position(3, 3, 0)
}) })
} }
} }
@@ -49,5 +49,4 @@ class TeleportToPlayerCommandTests {
player.sendMessage(contains("Invalid syntax")) player.sendMessage(contains("Invalid syntax"))
} }
} }
} }
@@ -18,7 +18,6 @@ abstract class Consumable(val name: String, val id: Int, val sound: Int, val del
player.inventory.add(replacement) player.inventory.add(replacement)
} }
} }
} }
private val consumables = mutableMapOf<Int, Consumable>() private val consumables = mutableMapOf<Int, Consumable>()
@@ -64,7 +63,6 @@ class FoodOrDrink : Consumable {
player.skillSet.setCurrentLevel(Skill.HITPOINTS, newHitpointsLevel) player.skillSet.setCurrentLevel(Skill.HITPOINTS, newHitpointsLevel)
} }
} }
/** /**
@@ -34,5 +34,4 @@ class ConsumeAction(val consumable: Consumable, player: Player, val slot: Int) :
wait(consumable.delay) wait(consumable.delay)
stop() stop()
} }
} }
@@ -1,13 +1,13 @@
import org.apollo.plugin.consumables.drink import org.apollo.plugin.consumables.drink
//# Wine // # Wine
drink(name = "jug_of_wine", id = 1993, restoration = 11) drink(name = "jug_of_wine", id = 1993, restoration = 11)
//# Hot Drinks // # Hot Drinks
drink(name = "nettle_tea", id = 4239, restoration = 3) drink(name = "nettle_tea", id = 4239, restoration = 3)
drink(name = "nettle_tea", id = 4240, restoration = 3) drink(name = "nettle_tea", id = 4240, restoration = 3)
//# Gnome Cocktails // # Gnome Cocktails
drink(name = "fruit_blast", id = 2034, restoration = 9) drink(name = "fruit_blast", id = 2034, restoration = 9)
drink(name = "fruit_blast", id = 2084, restoration = 9) drink(name = "fruit_blast", id = 2084, restoration = 9)
drink(name = "pineapple_punch", id = 2036, restoration = 9) drink(name = "pineapple_punch", id = 2036, restoration = 9)
+13 -13
View File
@@ -32,12 +32,12 @@ food(name = "shark", id = 385, restoration = 20)
food(name = "sea_turtle", id = 397, restoration = 21) food(name = "sea_turtle", id = 397, restoration = 21)
food(name = "manta_ray", id = 391, restoration = 22) food(name = "manta_ray", id = 391, restoration = 22)
//# Breads/Wraps // # Breads/Wraps
food(name = "bread", id = 2309, restoration = 5) food(name = "bread", id = 2309, restoration = 5)
food(name = "oomlie_wrap", id = 2343, restoration = 14) food(name = "oomlie_wrap", id = 2343, restoration = 14)
food(name = "ugthanki_kebab", id = 1883, restoration = 19) food(name = "ugthanki_kebab", id = 1883, restoration = 19)
//# Fruits // # Fruits
food(name = "banana", id = 1963, restoration = 2) food(name = "banana", id = 1963, restoration = 2)
food(name = "sliced_banana", id = 3162, restoration = 2) food(name = "sliced_banana", id = 3162, restoration = 2)
food(name = "lemon", id = 2102, restoration = 2) food(name = "lemon", id = 2102, restoration = 2)
@@ -54,8 +54,8 @@ food(name = "orange", id = 2108, restoration = 2)
food(name = "orange_rings", id = 2110, restoration = 2) food(name = "orange_rings", id = 2110, restoration = 2)
food(name = "orange_slices", id = 2112, restoration = 2) food(name = "orange_slices", id = 2112, restoration = 2)
//# Pies // # Pies
//# TODO: pie special effects (e.g. fish pie raises fishing level) // # TODO: pie special effects (e.g. fish pie raises fishing level)
food(name = "redberry_pie", id = 2325, restoration = 5, replacement = 2333, delay = 1) food(name = "redberry_pie", id = 2325, restoration = 5, replacement = 2333, delay = 1)
food(name = "redberry_pie", id = 2333, restoration = 5, delay = 1) food(name = "redberry_pie", id = 2333, restoration = 5, delay = 1)
@@ -77,12 +77,12 @@ food(name = "wild_pie", id = 7210, restoration = 11, delay = 1)
food(name = "summer_pie", id = 7218, restoration = 11, replacement = 7220, delay = 1) food(name = "summer_pie", id = 7218, restoration = 11, replacement = 7220, delay = 1)
food(name = "summer_pie", id = 7220, restoration = 11, delay = 1) food(name = "summer_pie", id = 7220, restoration = 11, delay = 1)
//# Stews // # Stews
food(name = "stew", id = 2003, restoration = 11) food(name = "stew", id = 2003, restoration = 11)
food(name = "banana_stew", id = 4016, restoration = 11) food(name = "banana_stew", id = 4016, restoration = 11)
food(name = "curry", id = 2011, restoration = 19) food(name = "curry", id = 2011, restoration = 19)
//# Pizzas // # Pizzas
food(name = "plain_pizza", id = 2289, restoration = 7, replacement = 2291) food(name = "plain_pizza", id = 2289, restoration = 7, replacement = 2291)
food(name = "plain_pizza", id = 2291, restoration = 7) food(name = "plain_pizza", id = 2291, restoration = 7)
@@ -95,7 +95,7 @@ food(name = "anchovy_pizza", id = 2299, restoration = 9)
food(name = "pineapple_pizza", id = 2301, restoration = 11, replacement = 2303) food(name = "pineapple_pizza", id = 2301, restoration = 11, replacement = 2303)
food(name = "pineapple_pizza", id = 2303, restoration = 11) food(name = "pineapple_pizza", id = 2303, restoration = 11)
//# Cakes // # Cakes
food(name = "fishcake", id = 7530, restoration = 11) food(name = "fishcake", id = 7530, restoration = 11)
food(name = "cake", id = 1891, restoration = 4, replacement = 1893) food(name = "cake", id = 1891, restoration = 4, replacement = 1893)
@@ -106,7 +106,7 @@ food(name = "chocolate_cake", id = 1897, restoration = 5, replacement = 1899)
food(name = "chocolate_cake", id = 1899, restoration = 5, replacement = 1901) food(name = "chocolate_cake", id = 1899, restoration = 5, replacement = 1901)
food(name = "chocolate_cake", id = 1901, restoration = 5) food(name = "chocolate_cake", id = 1901, restoration = 5)
//# Vegetables // # Vegetables
food(name = "potato", id = 1942, restoration = 1) food(name = "potato", id = 1942, restoration = 1)
food(name = "spinach_roll", id = 1969, restoration = 2) food(name = "spinach_roll", id = 1969, restoration = 2)
food(name = "baked_potato", id = 6701, restoration = 4) food(name = "baked_potato", id = 6701, restoration = 4)
@@ -119,14 +119,14 @@ food(name = "egg_potato", id = 7056, restoration = 16)
food(name = "mushroom_potato", id = 7058, restoration = 20) food(name = "mushroom_potato", id = 7058, restoration = 20)
food(name = "tuna_potato", id = 7060, restoration = 22) food(name = "tuna_potato", id = 7060, restoration = 22)
//# Dairy // # Dairy
food(name = "cheese", id = 1985, restoration = 2) food(name = "cheese", id = 1985, restoration = 2)
food(name = "pot_of_cream", id = 2130, restoration = 1) food(name = "pot_of_cream", id = 2130, restoration = 1)
//# Gnome Food // # Gnome Food
food(name = "toads_legs", id = 2152, restoration = 3) food(name = "toads_legs", id = 2152, restoration = 3)
//# Gnome Bowls // # Gnome Bowls
food(name = "worm_hole", id = 2191, restoration = 12) food(name = "worm_hole", id = 2191, restoration = 12)
food(name = "worm_hole", id = 2233, restoration = 12) food(name = "worm_hole", id = 2233, restoration = 12)
food(name = "vegetable_ball", id = 2195, restoration = 12) food(name = "vegetable_ball", id = 2195, restoration = 12)
@@ -136,7 +136,7 @@ food(name = "tangled_toads_legs", id = 2231, restoration = 15)
food(name = "chocolate_bomb", id = 2185, restoration = 15) food(name = "chocolate_bomb", id = 2185, restoration = 15)
food(name = "chocolate_bomb", id = 2229, restoration = 15) food(name = "chocolate_bomb", id = 2229, restoration = 15)
//# Gnome Crunchies // # Gnome Crunchies
food(name = "toad_crunchies", id = 2217, restoration = 7) food(name = "toad_crunchies", id = 2217, restoration = 7)
food(name = "toad_crunchies", id = 2243, restoration = 7) food(name = "toad_crunchies", id = 2243, restoration = 7)
food(name = "spicy_crunchies", id = 2213, restoration = 7) food(name = "spicy_crunchies", id = 2213, restoration = 7)
@@ -146,7 +146,7 @@ food(name = "worm_crunchies", id = 2237, restoration = 8)
food(name = "chocchip_crunchies", id = 2209, restoration = 7) food(name = "chocchip_crunchies", id = 2209, restoration = 7)
food(name = "chocchip_crunchies", id = 2239, restoration = 7) food(name = "chocchip_crunchies", id = 2239, restoration = 7)
//# Gnome Battas // # Gnome Battas
food(name = "fruit_batta", id = 2225, restoration = 11) food(name = "fruit_batta", id = 2225, restoration = 11)
food(name = "fruit_batta", id = 2277, restoration = 11) food(name = "fruit_batta", id = 2277, restoration = 11)
food(name = "toad_batta", id = 2221, restoration = 11) food(name = "toad_batta", id = 2221, restoration = 11)
@@ -3,8 +3,8 @@ package org.apollo.plugin.consumables
import io.mockk.verify import io.mockk.verify
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.testing.assertions.contains
import org.apollo.game.plugin.testing.assertions.after import org.apollo.game.plugin.testing.assertions.after
import org.apollo.game.plugin.testing.assertions.contains
import org.apollo.game.plugin.testing.assertions.verifyAfter import org.apollo.game.plugin.testing.assertions.verifyAfter
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
import org.apollo.game.plugin.testing.junit.api.ActionCapture import org.apollo.game.plugin.testing.junit.api.ActionCapture
@@ -81,15 +81,13 @@ class FoodOrDrinkTests {
fun `A message should be sent saying the player has drank an item when consuming a drink`() { fun `A message should be sent saying the player has drank an item when consuming a drink`() {
player.interactWithItem(TEST_DRINK_ID, option = 1, slot = 1) player.interactWithItem(TEST_DRINK_ID, option = 1, slot = 1)
verifyAfter(action.complete()) { player.sendMessage("You drink the ${TEST_DRINK_NAME}.") } verifyAfter(action.complete()) { player.sendMessage("You drink the $TEST_DRINK_NAME.") }
} }
@Test @Test
fun `A message should be sent saying the player has eaten an item when consuming food`() { fun `A message should be sent saying the player has eaten an item when consuming food`() {
player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1) player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1)
verifyAfter(action.complete()) { player.sendMessage("You eat the ${TEST_FOOD_NAME}.") } verifyAfter(action.complete()) { player.sendMessage("You eat the $TEST_FOOD_NAME.") }
} }
} }
-6
View File
@@ -1,9 +1,6 @@
import kotlinx.coroutines.experimental.* import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.selects.select
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.Animation import org.apollo.game.model.Animation
import org.apollo.game.model.Position import org.apollo.game.model.Position
@@ -50,10 +47,8 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction
player.startAction(DummyAction(player, position)) player.startAction(DummyAction(player, position))
message.terminate() message.terminate()
} }
} }
override fun action(): ActionBlock = { override fun action(): ActionBlock = {
mob.sendMessage("You hit the dummy.") mob.sendMessage("You hit the dummy.")
mob.turnTo(position) mob.turnTo(position)
@@ -68,5 +63,4 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction
skills.addExperience(Skill.ATTACK, EXP_PER_HIT) skills.addExperience(Skill.ATTACK, EXP_PER_HIT)
} }
} }
} }
+1 -2
View File
@@ -5,12 +5,12 @@ import org.apollo.game.model.World
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.testing.assertions.after import org.apollo.game.plugin.testing.assertions.after
import org.apollo.game.plugin.testing.assertions.contains
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
import org.apollo.game.plugin.testing.junit.api.ActionCapture import org.apollo.game.plugin.testing.junit.api.ActionCapture
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
import org.apollo.game.plugin.testing.junit.api.interactions.interactWith import org.apollo.game.plugin.testing.junit.api.interactions.interactWith
import org.apollo.game.plugin.testing.junit.api.interactions.spawnObject import org.apollo.game.plugin.testing.junit.api.interactions.spawnObject
import org.apollo.game.plugin.testing.assertions.contains
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@@ -60,5 +60,4 @@ class TrainingDummyTest {
assertEquals(beforeExp, skills.getExperience(Skill.ATTACK)) assertEquals(beforeExp, skills.getExperience(Skill.ATTACK))
} }
} }
} }
@@ -0,0 +1,6 @@
package org.apollo.game.plugin.entity.actions
import org.apollo.game.model.entity.Player
import org.apollo.game.model.event.PlayerEvent
class PlayerActionEvent(player: Player, val target: Player, val action: PlayerActionType) : PlayerEvent(player)
@@ -1,11 +1,8 @@
package org.apollo.game.plugin.entity.actions package org.apollo.game.plugin.entity.actions
import java.util.*
import org.apollo.game.message.impl.SetPlayerActionMessage import org.apollo.game.message.impl.SetPlayerActionMessage
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.event.PlayerEvent
import java.util.*
class PlayerActionEvent(player: Player, val target: Player, val action: PlayerActionType) : PlayerEvent(player)
fun Player.enableAction(action: PlayerActionType) { fun Player.enableAction(action: PlayerActionType) {
send(SetPlayerActionMessage(action.displayName, action.slot, action.primary)) send(SetPlayerActionMessage(action.displayName, action.slot, action.primary))
@@ -30,5 +30,4 @@ class PlayerActionTests {
verify { player.send(eq(SetPlayerActionMessage("null", type.slot, type.primary))) } verify { player.send(eq(SetPlayerActionMessage("null", type.slot, type.primary))) }
assertFalse(player.actionEnabled(type)) { "Action $type should not have been enabled, but was." } assertFalse(player.actionEnabled(type)) { "Action $type should not have been enabled, but was." }
} }
} }
@@ -46,5 +46,4 @@ class FollowAction(player: Player, private val target: Player) : Action<Player>(
lastPosition = target.position lastPosition = target.position
} }
} }
} }
@@ -2,7 +2,6 @@ package org.apollo.plugin.entity.following
import org.apollo.game.plugin.entity.actions.PlayerActionEvent import org.apollo.game.plugin.entity.actions.PlayerActionEvent
import org.apollo.game.plugin.entity.actions.PlayerActionType import org.apollo.game.plugin.entity.actions.PlayerActionType
import org.apollo.plugin.entity.following.FollowAction
on_player_event { PlayerActionEvent::class } on_player_event { PlayerActionEvent::class }
.where { action == PlayerActionType.FOLLOW } .where { action == PlayerActionType.FOLLOW }
@@ -139,5 +139,4 @@ class SpawnTests {
} }
} }
} }
} }
@@ -45,7 +45,6 @@ spawnNpc("oziach", x = 3067, y = 3518, facing = Direction.EAST)
spawnNpc("shop_keeper", id = 528, x = 3079, y = 3509) spawnNpc("shop_keeper", id = 528, x = 3079, y = 3509)
spawnNpc("shop_assistant", id = 529, x = 3082, y = 3513) spawnNpc("shop_assistant", id = 529, x = 3082, y = 3513)
spawnNpc("banker", x = 3096, y = 3489, facing = Direction.WEST) spawnNpc("banker", x = 3096, y = 3489, facing = Direction.WEST)
spawnNpc("banker", x = 3096, y = 3491, facing = Direction.WEST) spawnNpc("banker", x = 3096, y = 3491, facing = Direction.WEST)
spawnNpc("banker", x = 3096, y = 3492) spawnNpc("banker", x = 3096, y = 3492)
@@ -56,7 +56,6 @@ spawnNpc("woman", x = 3221, y = 3396)
spawnNpc("woman", id = 5, x = 3279, y = 3497) spawnNpc("woman", id = 5, x = 3279, y = 3497)
spawnNpc("woman", id = 25, x = 3278, y = 3492) spawnNpc("woman", id = 25, x = 3278, y = 3492)
spawnNpc("thief", x = 3285, y = 3500) spawnNpc("thief", x = 3285, y = 3500)
spawnNpc("thief", x = 3234, y = 3389) spawnNpc("thief", x = 3234, y = 3389)
spawnNpc("thief", x = 3188, y = 3383) spawnNpc("thief", x = 3188, y = 3383)
@@ -130,7 +129,6 @@ spawnNpc("warrior_woman", x = 3205, y = 3493)
spawnNpc("swan", x = 3261, y = 3354) spawnNpc("swan", x = 3261, y = 3354)
spawnNpc("swan", x = 3260, y = 3356) spawnNpc("swan", x = 3260, y = 3356)
spawnNpc("ram", id = 3673, x = 3238, y = 3346) spawnNpc("ram", id = 3673, x = 3238, y = 3346)
spawnNpc("ram", id = 3673, x = 3248, y = 3352) spawnNpc("ram", id = 3673, x = 3248, y = 3352)
spawnNpc("ram", id = 3673, x = 3260, y = 3348) spawnNpc("ram", id = 3673, x = 3260, y = 3348)
-2
View File
@@ -1,4 +1,3 @@
import io.mockk.verify import io.mockk.verify
import org.apollo.game.message.impl.ButtonMessage import org.apollo.game.message.impl.ButtonMessage
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
@@ -23,5 +22,4 @@ class LogoutTests {
verify { player.logout() } verify { player.logout() }
} }
} }
+1 -6
View File
@@ -1,5 +1,6 @@
package org.apollo.plugin.navigation.door package org.apollo.plugin.navigation.door
import java.util.*
import org.apollo.game.action.DistancedAction import org.apollo.game.action.DistancedAction
import org.apollo.game.model.Direction import org.apollo.game.model.Direction
import org.apollo.game.model.Position import org.apollo.game.model.Position
@@ -10,7 +11,6 @@ import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.model.event.PlayerEvent import org.apollo.game.model.event.PlayerEvent
import org.apollo.game.plugin.api.findObject import org.apollo.game.plugin.api.findObject
import org.apollo.net.message.Message import org.apollo.net.message.Message
import java.util.*
enum class DoorType { enum class DoorType {
LEFT, RIGHT, NOT_SUPPORTED LEFT, RIGHT, NOT_SUPPORTED
@@ -59,7 +59,6 @@ class Door(private val gameObject: GameObject) {
return type() !== DoorType.NOT_SUPPORTED return type() !== DoorType.NOT_SUPPORTED
} }
/** /**
* Computes the given door type by which id exists in * Computes the given door type by which id exists in
* the supported left and right hinged doors * the supported left and right hinged doors
@@ -97,7 +96,6 @@ class Door(private val gameObject: GameObject) {
toggledDoors.remove(gameObject) toggledDoors.remove(gameObject)
regionRepository.fromPosition(originalDoor.position).addEntity(originalDoor) regionRepository.fromPosition(originalDoor.position).addEntity(originalDoor)
} }
} }
/** /**
@@ -120,7 +118,6 @@ class Door(private val gameObject: GameObject) {
DoorType.NOT_SUPPORTED -> null DoorType.NOT_SUPPORTED -> null
} }
} }
} }
class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction<Player>( class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction<Player>(
@@ -140,7 +137,6 @@ class OpenDoorAction(private val player: Player, private val door: Door, positio
player.startAction(OpenDoorAction(player, door, position)) player.startAction(OpenDoorAction(player, door, position))
message.terminate() message.terminate()
} }
} }
override fun executeAction() { override fun executeAction() {
@@ -156,7 +152,6 @@ class OpenDoorAction(private val player: Player, private val door: Door, positio
} }
override fun hashCode(): Int = Objects.hash(position, player) override fun hashCode(): Int = Objects.hash(position, player)
} }
class OpenDoorEvent(player: Player) : PlayerEvent(player) class OpenDoorEvent(player: Player) : PlayerEvent(player)
-2
View File
@@ -50,7 +50,6 @@ class OpenShopAction(
shop.removeListener(shopListener) shop.removeListener(shopListener)
} }
} }
} }
/** /**
@@ -64,5 +63,4 @@ class PlayerInventorySupplier : InventorySupplier {
else -> null else -> null
} }
} }
} }
+6 -10
View File
@@ -45,8 +45,12 @@ class ShopBuilder(val name: String) {
* @param depluralise Whether or not the category name should have the "s". * @param depluralise Whether or not the category name should have the "s".
* @param builder The builder used to add items to the category. * @param builder The builder used to add items to the category.
*/ */
fun category(name: String, affix: Affix = Affix.Suffix, depluralise: Boolean = true, fun category(
builder: CategoryWrapper.() -> Unit) { name: String,
affix: Affix = Affix.Suffix,
depluralise: Boolean = true,
builder: CategoryWrapper.() -> Unit
) {
val items = mutableListOf<Pair<String, Int>>() val items = mutableListOf<Pair<String, Int>>()
builder.invoke(CategoryWrapper(items)) builder.invoke(CategoryWrapper(items))
@@ -118,7 +122,6 @@ class ShopBuilder(val name: String) {
* Gets the [List] of shop operator ids. * Gets the [List] of shop operator ids.
*/ */
internal fun operators(): MutableList<Int> = operated.operators internal fun operators(): MutableList<Int> = operated.operators
} }
@ShopDslMarker @ShopDslMarker
@@ -148,14 +151,12 @@ class CategoryWrapper(private val items: MutableList<Pair<String, Int>>) {
* Joins the item and category name in the expected manner. * Joins the item and category name in the expected manner.
*/ */
fun join(item: String, category: String): String = joiner(item, category) fun join(item: String, category: String): String = joiner(item, category)
} }
/** /**
* Creates a [SellBuilder] with the specified [amount]. * Creates a [SellBuilder] with the specified [amount].
*/ */
fun sell(amount: Int): SellBuilder = SellBuilder(amount, items) fun sell(amount: Int): SellBuilder = SellBuilder(amount, items)
} }
/** /**
@@ -210,7 +211,6 @@ class OperatorBuilder internal constructor() {
* `"Shopkeeper"(500) vs `"Shopkeeper"(501)`). Use [by(String][by] if the npc name is unambiguous. * `"Shopkeeper"(500) vs `"Shopkeeper"(501)`). Use [by(String][by] if the npc name is unambiguous.
*/ */
operator fun plus(pair: Pair<String, Int>): OperatorBuilder = by(pair) operator fun plus(pair: Pair<String, Int>): OperatorBuilder = by(pair)
} }
/** /**
@@ -270,7 +270,6 @@ class ActionBuilder {
*/ */
override fun hashCode(): Int = throw UnsupportedOperationException("ActionBuilder is a utility class for a DSL " + override fun hashCode(): Int = throw UnsupportedOperationException("ActionBuilder is a utility class for a DSL " +
"and improperly implements equals() - it should not be used anywhere outside of the DSL.") "and improperly implements equals() - it should not be used anywhere outside of the DSL.")
} }
/** /**
@@ -288,7 +287,6 @@ class CurrencyBuilder {
builder.currency = this builder.currency = this
return true return true
} }
} }
/** /**
@@ -312,7 +310,6 @@ class PurchasesBuilder {
infix fun any(@Suppress("UNUSED_PARAMETER") items: Unit) { infix fun any(@Suppress("UNUSED_PARAMETER") items: Unit) {
policy = Shop.PurchasePolicy.ANY policy = Shop.PurchasePolicy.ANY
} }
} }
/** /**
@@ -348,5 +345,4 @@ class SellBuilder(val amount: Int, val items: MutableList<Pair<String, Int>>) {
* Overloads function invokation on Strings to map `"ambiguous_npc_name"(id)` to a [Pair]. * Overloads function invokation on Strings to map `"ambiguous_npc_name"(id)` to a [Pair].
*/ */
operator fun String.invoke(id: Int): Pair<String, Int> = Pair(this, id) operator fun String.invoke(id: Int): Pair<String, Int> = Pair(this, id)
} }
-4
View File
@@ -40,7 +40,6 @@ object Interfaces {
* The id of the text widget that displays a shop's name. * The id of the text widget that displays a shop's name.
*/ */
const val SHOP_NAME = 3901 const val SHOP_NAME = 3901
} }
/** /**
@@ -69,7 +68,6 @@ data class Currency(val id: Int, val plural: Boolean = false) {
else -> name else -> name
} }
} }
} }
/** /**
@@ -124,7 +122,6 @@ class Shop(
else -> throw IllegalArgumentException("Option must be 1-4") else -> throw IllegalArgumentException("Option must be 1-4")
} }
} }
} }
/** /**
@@ -331,5 +328,4 @@ class Shop(
* @param id The id of the [Item] to sell. * @param id The id of the [Item] to sell.
*/ */
private fun sells(id: Int): Boolean = sells.containsKey(id) private fun sells(id: Int): Boolean = sells.containsKey(id)
} }
@@ -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."}" } val catchMessage by lazy { "You catch ${catchSuffix ?: "a $catchName."}" }
private val catchName by lazy { Definitions.item(id).name.toLowerCase().removePrefix("raw ") } private val catchName by lazy { Definitions.item(id).name.toLowerCase().removePrefix("raw ") }
} }
@@ -1,10 +1,10 @@
package org.apollo.game.plugin.skills.fishing package org.apollo.game.plugin.skills.fishing
import java.util.Objects
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.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.plugin.api.fishing import org.apollo.game.plugin.api.fishing
import java.util.Objects
class FishingAction( class FishingAction(
player: Player, player: Player,
@@ -82,7 +82,5 @@ class FishingAction(
internal fun hasTool(player: Player, tool: FishingTool): Boolean { internal fun hasTool(player: Player, tool: FishingTool): Boolean {
return tool.id in player.equipment || tool.id in player.inventory 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) else -> Pair(tool, secondary, primary)
} }
} }
} }
} }
companion object { 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] fun lookup(id: Int): FishingSpot? = FISHING_SPOTS[id]
} }
} }
@@ -35,5 +35,4 @@ data class FishingTarget(val position: Position, val option: FishingSpot.Option)
return false return false
} }
} }
@@ -29,5 +29,4 @@ enum class FishingTool(
* The name of this tool, formatted so it can be inserted into a message. * The name of this tool, formatted so it can be inserted into a message.
*/ */
val formattedName by lazy { Definitions.item(id).name.toLowerCase() } val formattedName by lazy { Definitions.item(id).name.toLowerCase() }
} }
@@ -89,5 +89,4 @@ class FishingActionTests {
private val spots = FishingSpot.values() private val spots = FishingSpot.values()
.map { NpcDefinition(it.npc).apply { name = "<fishing_spot>" } } .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.ActionBlock
import org.apollo.game.action.AsyncAction import org.apollo.game.action.AsyncAction
import org.apollo.game.model.Animation import org.apollo.game.model.Animation
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import java.util.Objects
class CrushIngredientAction( class CrushIngredientAction(
player: Player, player: Player,
@@ -1,10 +1,10 @@
import java.util.Objects
import org.apollo.game.action.ActionBlock import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncAction import org.apollo.game.action.AsyncAction
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.plugin.api.herblore import org.apollo.game.plugin.api.herblore
import org.apollo.util.LanguageUtil import org.apollo.util.LanguageUtil
import java.util.Objects
class IdentifyHerbAction( class IdentifyHerbAction(
player: Player, player: Player,
@@ -1,10 +1,10 @@
import java.util.*
import org.apollo.game.action.ActionBlock import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncAction import org.apollo.game.action.AsyncAction
import org.apollo.game.model.Animation import org.apollo.game.model.Animation
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.api.herblore import org.apollo.game.plugin.api.herblore
import java.util.*
abstract class MakePotionAction( abstract class MakePotionAction(
player: Player, 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,14 +1,12 @@
import java.util.*
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.message.impl.ObjectActionMessage 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.model.entity.Player
import org.apollo.game.plugin.api.* import org.apollo.game.plugin.api.*
import org.apollo.game.plugin.skills.mining.Ore import org.apollo.game.plugin.skills.mining.Ore
import org.apollo.game.plugin.skills.mining.Pickaxe import org.apollo.game.plugin.skills.mining.Pickaxe
import org.apollo.net.message.Message import org.apollo.net.message.Message
import java.util.*
class MiningAction( class MiningAction(
player: Player, player: Player,
@@ -82,57 +80,4 @@ class MiningAction(
} }
override fun hashCode(): Int = Objects.hash(mob, target) 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 fromRock(id: Int): Ore? = ORE_ROCKS[id]
fun fromExpiredRock(id: Int): Ore? = EXPIRED_ORE[id] fun fromExpiredRock(id: Int): Ore? = EXPIRED_ORE[id]
} }
} }
@@ -1,13 +1,12 @@
import java.util.Objects
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.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.plugin.api.Definitions import org.apollo.game.plugin.api.Definitions
import org.apollo.game.plugin.skills.mining.Ore import org.apollo.game.plugin.skills.mining.Ore
import org.apollo.net.message.Message import org.apollo.net.message.Message
import java.util.Objects
class ProspectingAction( class ProspectingAction(
player: Player, player: Player,
@@ -51,42 +50,4 @@ class ProspectingAction(
} }
override fun hashCode(): Int = Objects.hash(mob, position, 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)
} }
@@ -87,5 +87,4 @@ class MiningActionTests {
@ItemDefinitions @ItemDefinitions
fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id)) fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id))
} }
} }
@@ -24,7 +24,6 @@ class PickaxeTests {
assertEquals(null, Pickaxe.bestFor(player)) assertEquals(null, Pickaxe.bestFor(player))
} }
@ParameterizedTest @ParameterizedTest
@EnumSource(Pickaxe::class) @EnumSource(Pickaxe::class)
fun `The highest level pickaxe is chosen when available`(pickaxe: Pickaxe) { fun `The highest level pickaxe is chosen when available`(pickaxe: Pickaxe) {
@@ -43,7 +42,6 @@ class PickaxeTests {
assertEquals(Pickaxe.BRONZE, Pickaxe.bestFor(player)) assertEquals(Pickaxe.BRONZE, Pickaxe.bestFor(player))
} }
@ParameterizedTest @ParameterizedTest
@EnumSource(value = Pickaxe::class) @EnumSource(value = Pickaxe::class)
fun `Pickaxes can be chosen from equipment as well as inventory`(pickaxe: Pickaxe) { fun `Pickaxes can be chosen from equipment as well as inventory`(pickaxe: Pickaxe) {
@@ -53,7 +51,6 @@ class PickaxeTests {
assertEquals(pickaxe, Pickaxe.bestFor(player)) assertEquals(pickaxe, Pickaxe.bestFor(player))
} }
@ParameterizedTest @ParameterizedTest
@EnumSource(value = Pickaxe::class) @EnumSource(value = Pickaxe::class)
fun `Pickaxes with a level requirement higher than the player's are ignored`(pickaxe: Pickaxe) { 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 } ItemDefinition(it.id).apply { isStackable = false }
} }
} }
} }
@@ -45,5 +45,4 @@ class ProspectingTests {
ItemDefinition(it.id).also { it.name = "<ore_type>" } ItemDefinition(it.id).also { it.name = "<ore_type>" }
} }
} }
} }
+1 -1
View File
@@ -1,8 +1,8 @@
import java.util.stream.Stream
import org.apollo.game.plugin.skills.mining.Ore import org.apollo.game.plugin.skills.mining.Ore
import org.junit.jupiter.api.extension.ExtensionContext import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsProvider
import java.util.stream.Stream
data class MiningTestData(val rockId: Int, val expiredRockId: Int, val ore: Ore) data class MiningTestData(val rockId: Int, val expiredRockId: Int, val ore: Ore)
@@ -28,5 +28,4 @@ class BuryBoneAction(
public val BURY_BONE_ANIMATION = Animation(827) public val BURY_BONE_ANIMATION = Animation(827)
internal const val BURY_OPTION = 1 internal const val BURY_OPTION = 1
} }
} }
@@ -70,5 +70,4 @@ class BuryBoneTests {
return Bone.values().map { ItemDefinition(it.id) } return Bone.values().map { ItemDefinition(it.id) }
} }
} }
} }
+1 -2
View File
@@ -2,7 +2,6 @@ package org.apollo.game.plugin.skill.runecrafting
import org.apollo.game.plugin.skill.runecrafting.Altar.* import org.apollo.game.plugin.skill.runecrafting.Altar.*
interface Rune { interface Rune {
/** /**
* The item id of the rune. * The item id of the rune.
@@ -29,7 +28,7 @@ interface Rune {
* *
* [playerLevel] - The players current runecrafting level. * [playerLevel] - The players current runecrafting level.
*/ */
fun getBonusMultiplier(playerLevel: Int) : Double fun getBonusMultiplier(playerLevel: Int): Double
} }
enum class DefaultRune( enum class DefaultRune(
@@ -8,11 +8,10 @@ private val changeAltarObjectConfigId = 491
internal val RUNES = mutableListOf<Rune>() 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 } return find { rune -> rune.id == id }
} }
start { start {
RUNES.addAll(DefaultRune.values()) RUNES.addAll(DefaultRune.values())
} }
@@ -25,7 +25,7 @@ class RunecraftingAction(val player: Player, val rune: Rune, altar: Altar) : Asy
wait(1) wait(1)
val name = Definitions.item(rune.id).name; val name = Definitions.item(rune.id).name
val nameArticle = LanguageUtil.getIndefiniteArticle(name) val nameArticle = LanguageUtil.getIndefiniteArticle(name)
val essenceAmount = player.inventory.removeAll(runeEssenceId) val essenceAmount = player.inventory.removeAll(runeEssenceId)
val runeAmount = essenceAmount * rune.getBonusMultiplier(player.runecraft.current) val runeAmount = essenceAmount * rune.getBonusMultiplier(player.runecraft.current)
@@ -27,7 +27,6 @@ class RunecraftingActionTests {
fun setupPlayer() { fun setupPlayer() {
player.position = TEST_ALTAR.center player.position = TEST_ALTAR.center
player.inventory.add(runeEssenceId, 25) player.inventory.add(runeEssenceId, 25)
} }
@Test @Test
@@ -1,4 +1,5 @@
import java.util.concurrent.TimeUnit
import org.apollo.game.GameConstants import org.apollo.game.GameConstants
import org.apollo.game.action.ActionBlock import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncDistancedAction 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.api.*
import org.apollo.game.plugin.skills.woodcutting.Axe import org.apollo.game.plugin.skills.woodcutting.Axe
import org.apollo.game.plugin.skills.woodcutting.Tree 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 // 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. * Returns whether or not the tree was cut down.
*/ */
fun isCutDown(): Boolean = rand(100) <= tree.chance * 100 fun isCutDown(): Boolean = rand(100) <= tree.chance * 100
} }
class WoodcuttingAction( class WoodcuttingAction(
@@ -102,5 +101,4 @@ class WoodcuttingAction(
} }
} }
} }
} }
@@ -70,5 +70,4 @@ class AxeTests {
ItemDefinition(it.id).apply { isStackable = false } 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.apollo.game.plugin.skills.woodcutting.Tree
import org.junit.jupiter.api.extension.ExtensionContext import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsProvider
import java.util.stream.Stream
data class WoodcuttingTestData(val treeId: Int, val stumpId: Int, val tree: Tree) data class WoodcuttingTestData(val treeId: Int, val stumpId: Int, val tree: Tree)
@@ -2,6 +2,7 @@
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import java.util.Random
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill 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.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ArgumentsSource import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.Random
@ExtendWith(ApolloTestingExtension::class) @ExtendWith(ApolloTestingExtension::class)
class WoodcuttingTests { class WoodcuttingTests {
@@ -1,6 +1,5 @@
package org.apollo.game.action package org.apollo.game.action
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
import java.util.concurrent.CancellationException import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
@@ -11,6 +10,7 @@ import kotlin.coroutines.experimental.RestrictsSuspension
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
import kotlin.coroutines.experimental.intrinsics.createCoroutineUnchecked import kotlin.coroutines.experimental.intrinsics.createCoroutineUnchecked
import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
typealias ActionPredicate = () -> Boolean typealias ActionPredicate = () -> Boolean
typealias ActionBlock = suspend ActionCoroutine.() -> Unit typealias ActionBlock = suspend ActionCoroutine.() -> Unit
@@ -25,5 +25,5 @@ interface AsyncActionTrait {
/** /**
* Create a new `ActionBlock` to execute. * Create a new `ActionBlock` to execute.
*/ */
fun action() : ActionBlock fun action(): ActionBlock
} }
@@ -19,4 +19,3 @@ abstract class AsyncDistancedAction<T : Mob> : DistancedAction<T>, AsyncActionTr
} }
} }
} }
@@ -1,5 +1,8 @@
package org.apollo.game.plugin.kotlin package org.apollo.game.plugin.kotlin
import kotlin.reflect.KClass
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.annotations.KotlinScriptFileExtension
import org.apollo.game.command.Command import org.apollo.game.command.Command
import org.apollo.game.command.CommandListener import org.apollo.game.command.CommandListener
import org.apollo.game.message.handler.MessageHandler import org.apollo.game.message.handler.MessageHandler
@@ -12,9 +15,6 @@ import org.apollo.game.model.event.EventListener
import org.apollo.game.model.event.PlayerEvent import org.apollo.game.model.event.PlayerEvent
import org.apollo.game.plugin.PluginContext import org.apollo.game.plugin.PluginContext
import org.apollo.net.message.Message import org.apollo.net.message.Message
import kotlin.reflect.KClass
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.annotations.KotlinScriptFileExtension
@KotlinScript("Apollo Plugin Script") @KotlinScript("Apollo Plugin Script")
@KotlinScriptFileExtension("plugin.kts") @KotlinScriptFileExtension("plugin.kts")
@@ -63,7 +63,6 @@ abstract class KotlinPluginScript(private var world: World, val context: PluginC
fun doStop(world: World) { fun doStop(world: World) {
this.stopListener.invoke(world) this.stopListener.invoke(world)
} }
} }
/** /**
@@ -86,13 +85,11 @@ interface KotlinPlayerHandlerProxyTrait<S : Any> {
this.register() this.register()
} }
fun handleProxy(player: Player, subject: S) { fun handleProxy(player: Player, subject: S) {
if (subject.predicate()) { if (subject.predicate()) {
subject.callback(player) subject.callback(player)
} }
} }
} }
/** /**
@@ -106,7 +103,6 @@ class KotlinPlayerEventHandler<T : PlayerEvent>(val world: World, val type: KCla
override fun handle(event: T) = handleProxy(event.player, event) override fun handle(event: T) = handleProxy(event.player, event)
override fun register() = world.listenFor(type.java, this) override fun register() = world.listenFor(type.java, this)
} }
/** /**
@@ -134,7 +130,6 @@ class KotlinEventHandler<S : Event>(val world: World, val type: KClass<S>) : Eve
} }
fun register() = world.listenFor(type.java, this) fun register() = world.listenFor(type.java, this)
} }
/** /**
@@ -148,7 +143,6 @@ class KotlinMessageHandler<T : Message>(val world: World, val context: PluginCon
override fun handle(player: Player, message: T) = handleProxy(player, message) override fun handle(player: Player, message: T) = handleProxy(player, message)
override fun register() = context.addMessageHandler(type.java, this) override fun register() = context.addMessageHandler(type.java, this)
} }
/** /**
@@ -162,5 +156,4 @@ class KotlinCommandHandler(val world: World, val command: String, privileges: Pr
override fun execute(player: Player, command: Command) = handleProxy(player, command) override fun execute(player: Player, command: Command) = handleProxy(player, command)
override fun register() = world.commandDispatcher.register(command, this) override fun register() = world.commandDispatcher.register(command, this)
} }
+5 -4
View File
@@ -257,7 +257,7 @@ formatting:
active: true active: true
autoCorrect: true autoCorrect: true
NoWildcardImports: NoWildcardImports:
active: true active: false
autoCorrect: true autoCorrect: true
ParameterListWrapping: ParameterListWrapping:
active: true active: true
@@ -304,10 +304,11 @@ naming:
minimumFunctionNameLength: 3 minimumFunctionNameLength: 3
FunctionNaming: FunctionNaming:
active: true active: true
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)|(on_[a-zA-Z_$0-9]*)$'
excludeClassPattern: '$^' excludeClassPattern: '$^'
MatchingDeclarationName: MatchingDeclarationName:
active: true active: true
autoCorrect: true
MemberNameEqualsClassName: MemberNameEqualsClassName:
active: false active: false
ignoreOverriddenFunction: true ignoreOverriddenFunction: true
@@ -317,7 +318,7 @@ naming:
constantPattern: '[A-Za-z][_A-Za-z0-9]*' constantPattern: '[A-Za-z][_A-Za-z0-9]*'
PackageNaming: PackageNaming:
active: true active: true
packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' packagePattern: '^[a-z]+(\.[a-z][a-zA-Z0-9]*)*$'
TopLevelPropertyNaming: TopLevelPropertyNaming:
active: false active: false
constantPattern: '[A-Z][_A-Z0-9]*' constantPattern: '[A-Z][_A-Z0-9]*'
@@ -470,5 +471,5 @@ style:
VarCouldBeVal: VarCouldBeVal:
active: false active: false
WildcardImport: WildcardImport:
active: true active: false
excludeImports: 'java.util.*,kotlinx.android.synthetic.*' excludeImports: 'java.util.*,kotlinx.android.synthetic.*'