From 475c7ac74136fc884ac746d2cbf35994972dafb9 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Tue, 4 Sep 2018 04:43:34 +0100 Subject: [PATCH] Fix kotlin code style issues --- .../testing/assertions/actionAsserts.kt | 1 - .../plugin/testing/junit/ApolloTestState.kt | 2 +- ...Extension.kt => ApolloTestingExtension.kt} | 33 +-- .../plugin/testing/junit/api/ActionCapture.kt | 5 +- .../junit/api/annotations/testAnnotations.kt | 6 - .../testing/junit/api/interactions/world.kt | 1 - .../junit/params/DefinitionProviders.kt | 13 +- .../testing/junit/stubs/GameObjectStubInfo.kt | 1 - .../plugin/testing/junit/stubs/NpcStubInfo.kt | 1 - .../testing/junit/stubs/PlayerStubInfo.kt | 2 - .../org/apollo/game/plugin/api/Definitions.kt | 3 +- .../src/org/apollo/game/plugin/api/Player.kt | 1 - .../src/org/apollo/game/plugin/api/World.kt | 1 - .../game/plugin/api/DefinitionsTests.kt | 2 - .../org/apollo/game/plugin/api/PlayerTests.kt | 1 - .../apollo/game/plugin/api/PositionTests.kt | 1 - game/plugin/areas/src/Area.kt | 2 - game/plugin/areas/src/AreaActionBuilder.kt | 1 - game/plugin/areas/test/AreaActionTests.kt | 1 - game/plugin/bank/src/bank.plugin.kts | 3 - game/plugin/bank/test/OpenBankTest.kt | 1 - game/plugin/cmd/src/teleport-cmd.plugin.kts | 275 +++++++++--------- game/plugin/cmd/test/AnimateCommandTests.kt | 1 - game/plugin/cmd/test/LookupCommandTests.kt | 1 - game/plugin/cmd/test/SpawnCommandTests.kt | 2 +- .../cmd/test/TeleportToPlayerCommandTests.kt | 1 - game/plugin/consumables/src/consumables.kt | 14 +- .../consumables/src/consumables.plugin.kts | 1 - game/plugin/consumables/src/drinks.plugin.kts | 6 +- game/plugin/consumables/src/foods.plugin.kts | 26 +- .../consumables/test/FoodOrDrinkTests.kt | 8 +- game/plugin/dummy/src/dummy.plugin.kts | 6 - game/plugin/dummy/test/TrainingDummyTest.kt | 3 +- .../emote-tab/src/{emote.kt => Emote.kt} | 0 ...ote-tab.plugin.kts => EmoteTab.plugin.kts} | 0 .../entity/actions/src/PlayerActionEvent.kt | 6 + .../src/{PlayerAction.kt => playerAction.kt} | 5 +- .../entity/actions/test/PlayerActionTests.kt | 1 - .../{Following.kt => FollowAction.kt} | 1 - .../entity/following/Following.plugin.kts | 1 - .../game/plugin/entity/spawn/SpawnTests.kt | 1 - .../locations/edgeville/src/npcs.plugin.kts | 1 - .../locations/varrock/src/npcs.plugin.kts | 2 - game/plugin/logout/src/logout.plugin.kts | 4 +- game/plugin/logout/test/LogoutTests.kt | 16 +- game/plugin/navigation/door/src/door.kt | 7 +- game/plugin/run/src/run.plugin.kts | 8 +- game/plugin/shops/src/action.kt | 2 - game/plugin/shops/src/dsl.kt | 16 +- game/plugin/shops/src/shop.kt | 4 - .../apollo/game/plugin/skills/fishing/Fish.kt | 1 - .../plugin/skills/fishing/FishingAction.kt | 4 +- .../game/plugin/skills/fishing/FishingSpot.kt | 3 - .../plugin/skills/fishing/FishingTarget.kt | 1 - .../game/plugin/skills/fishing/FishingTool.kt | 1 - .../skills/fishing/FishingActionTests.kt | 1 - .../herblore/src/CrushIngredientAction.kt | 2 +- .../skills/herblore/src/IdentifyHerbAction.kt | 2 +- .../skills/herblore/src/MakePotionAction.kt | 2 +- .../mining/src/ExpiredProspectingAction.kt | 41 +++ .../skills/mining/src/{gem.kt => Gem.kt} | 0 .../{mining.plugin.kts => Mining.plugin.kts} | 0 .../mining/src/{mining.kt => MiningAction.kt} | 57 +--- game/plugin/skills/mining/src/MiningTarget.kt | 58 ++++ .../skills/mining/src/{ore.kt => Ore.kt} | 1 - .../mining/src/{pickaxe.kt => Pickaxe.kt} | 0 .../{prospecting.kt => ProspectingAction.kt} | 41 +-- .../skills/mining/test/MiningActionTests.kt | 1 - .../plugin/skills/mining/test/PickaxeTests.kt | 4 - .../skills/mining/test/ProspectingTests.kt | 1 - game/plugin/skills/mining/test/TestData.kt | 2 +- .../{BoneBuryAction.kt => BuryBoneAction.kt} | 1 - .../{prayer.plugin.kts => Prayer.plugin.kts} | 0 .../skills/prayer/test/BuryBoneTests.kt | 1 - game/plugin/skills/runecrafting/src/Rune.kt | 3 +- .../runecrafting/src/Runecrafting.plugin.kts | 3 +- .../runecrafting/src/RunecraftingAction.kt | 2 +- .../test/RunecraftingActionTests.kt | 1 - .../skills/woodcutting/src/{axe.kt => Axe.kt} | 0 .../woodcutting/src/{wood.kt => Tree.kt} | 0 ...ting.plugin.kts => Woodcutting.plugin.kts} | 4 +- .../skills/woodcutting/test/AxeTests.kt | 3 +- .../skills/woodcutting/test/TestData.kt | 2 +- .../woodcutting/test/WoodcuttingTests.kt | 2 +- .../org/apollo/game/action/ActionCoroutine.kt | 2 +- .../apollo/game/action/AsyncActionTrait.kt | 2 +- .../game/action/AsyncDistancedAction.kt | 1 - .../game/plugin/kotlin/KotlinPluginScript.kt | 13 +- gradle/config/detekt.yml | 9 +- 89 files changed, 338 insertions(+), 435 deletions(-) rename game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/{ApolloTestExtension.kt => ApolloTestingExtension.kt} (96%) delete mode 100644 game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/annotations/testAnnotations.kt rename game/plugin/emote-tab/src/{emote.kt => Emote.kt} (100%) rename game/plugin/emote-tab/src/{emote-tab.plugin.kts => EmoteTab.plugin.kts} (100%) create mode 100644 game/plugin/entity/actions/src/PlayerActionEvent.kt rename game/plugin/entity/actions/src/{PlayerAction.kt => playerAction.kt} (84%) rename game/plugin/entity/following/src/org/apollo/plugin/entity/following/{Following.kt => FollowAction.kt} (99%) create mode 100644 game/plugin/skills/mining/src/ExpiredProspectingAction.kt rename game/plugin/skills/mining/src/{gem.kt => Gem.kt} (100%) rename game/plugin/skills/mining/src/{mining.plugin.kts => Mining.plugin.kts} (100%) rename game/plugin/skills/mining/src/{mining.kt => MiningAction.kt} (59%) create mode 100644 game/plugin/skills/mining/src/MiningTarget.kt rename game/plugin/skills/mining/src/{ore.kt => Ore.kt} (99%) rename game/plugin/skills/mining/src/{pickaxe.kt => Pickaxe.kt} (100%) rename game/plugin/skills/mining/src/{prospecting.kt => ProspectingAction.kt} (59%) rename game/plugin/skills/prayer/src/{BoneBuryAction.kt => BuryBoneAction.kt} (99%) rename game/plugin/skills/prayer/src/{prayer.plugin.kts => Prayer.plugin.kts} (100%) rename game/plugin/skills/woodcutting/src/{axe.kt => Axe.kt} (100%) rename game/plugin/skills/woodcutting/src/{wood.kt => Tree.kt} (100%) rename game/plugin/skills/woodcutting/src/{woodcutting.plugin.kts => Woodcutting.plugin.kts} (99%) diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/assertions/actionAsserts.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/assertions/actionAsserts.kt index 7433a033..f514a0d5 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/assertions/actionAsserts.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/assertions/actionAsserts.kt @@ -4,7 +4,6 @@ import io.mockk.MockKVerificationScope import io.mockk.verify import org.apollo.game.plugin.testing.junit.api.ActionCaptureCallbackRegistration - /** * Verify some expectations on a [mock] after a delayed event (specified by [DelayMode]). */ diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt index a9e8c4f1..cae99293 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt @@ -3,6 +3,7 @@ package org.apollo.game.plugin.testing.junit import io.mockk.every import io.mockk.slot import io.mockk.spyk +import kotlin.reflect.KClass import org.apollo.game.action.Action import org.apollo.game.message.handler.MessageHandlerChainSet 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.net.message.Message import org.apollo.util.security.PlayerCredentials -import kotlin.reflect.KClass data class ApolloTestState(val handlers: MessageHandlerChainSet, val world: World) { val players = mutableListOf() diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestExtension.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestingExtension.kt similarity index 96% rename from game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestExtension.kt rename to game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestingExtension.kt index d9fbfc51..1a6f5af2 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestExtension.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestingExtension.kt @@ -4,6 +4,14 @@ import io.mockk.every import io.mockk.slot import io.mockk.spyk 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.NpcDefinition 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.mocking.StubPrototype 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 : AfterTestExecutionCallback, @@ -168,6 +160,13 @@ class ApolloTestingExtension : } companion object { + internal val supportedTestDoubleTypes = setOf( + Player::class.createType(), + Npc::class.createType(), + GameObject::class.createType(), + World::class.createType(), + ActionCapture::class.createType() + ) inline fun findTestDefinitions( callables: Collection>, @@ -185,7 +184,5 @@ class ApolloTestingExtension : method.call(companionObjectInstance) } } - } - } \ No newline at end of file diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/ActionCapture.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/ActionCapture.kt index 9d0a1478..8ebf8fa3 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/ActionCapture.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/ActionCapture.kt @@ -1,10 +1,10 @@ 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.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue -import kotlin.reflect.KClass -import kotlin.reflect.full.isSuperclassOf class ActionCapture(val type: KClass>) { private var action: Action<*>? = null @@ -62,7 +62,6 @@ class ActionCapture(val type: KClass>) { }) } - /** * Create a callback registration that triggers after exactly [count] ticks. */ diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/annotations/testAnnotations.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/annotations/testAnnotations.kt deleted file mode 100644 index 03aa36a1..00000000 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/annotations/testAnnotations.kt +++ /dev/null @@ -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> = Action::class) \ No newline at end of file diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/world.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/world.kt index c94c6e10..8dfd2cbc 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/world.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/world.kt @@ -18,7 +18,6 @@ fun World.spawnObject(id: Int, position: Position): GameObject { return obj } - /** * Spawns a new NPC with the minimum set of dependencies required to function correctly in the world. */ diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/params/DefinitionProviders.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/params/DefinitionProviders.kt index 5edfd5eb..1daced5d 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/params/DefinitionProviders.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/params/DefinitionProviders.kt @@ -1,5 +1,10 @@ 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.NpcDefinition 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.ArgumentsProvider 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`. @@ -64,7 +64,6 @@ object ItemDefinitionsProvider : DefinitionsProvider( override fun accept(source: ItemDefinitionSource) { sourceNames = source.sourceNames.toHashSet() } - } /** @@ -80,7 +79,6 @@ object NpcDefinitionsProvider : DefinitionsProvider( override fun accept(source: NpcDefinitionSource) { sourceNames = source.sourceNames.toHashSet() } - } /** @@ -96,5 +94,4 @@ object ObjectDefinitionsProvider : DefinitionsProvider( override fun accept(source: ObjectDefinitionSource) { sourceNames = source.sourceNames.toHashSet() } - } diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/GameObjectStubInfo.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/GameObjectStubInfo.kt index c5306f1f..48c842f8 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/GameObjectStubInfo.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/GameObjectStubInfo.kt @@ -1,2 +1 @@ package org.apollo.game.plugin.testing.junit.stubs - diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/NpcStubInfo.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/NpcStubInfo.kt index c5306f1f..48c842f8 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/NpcStubInfo.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/NpcStubInfo.kt @@ -1,2 +1 @@ package org.apollo.game.plugin.testing.junit.stubs - diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/PlayerStubInfo.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/PlayerStubInfo.kt index 3aae860c..cd192c06 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/PlayerStubInfo.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/stubs/PlayerStubInfo.kt @@ -18,10 +18,8 @@ class PlayerStubInfo { return info } - } var position = Position(3222, 3222) var name = "test" } - diff --git a/game/plugin/api/src/org/apollo/game/plugin/api/Definitions.kt b/game/plugin/api/src/org/apollo/game/plugin/api/Definitions.kt index d083dc9c..f0873b99 100644 --- a/game/plugin/api/src/org/apollo/game/plugin/api/Definitions.kt +++ b/game/plugin/api/src/org/apollo/game/plugin/api/Definitions.kt @@ -1,9 +1,9 @@ package org.apollo.game.plugin.api +import java.lang.IllegalArgumentException import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.ObjectDefinition -import java.lang.IllegalArgumentException /** * Provides plugins with access to item, npc, and object definitions @@ -101,5 +101,4 @@ object Definitions { val normalizedName = name.replace('_', ' ') return definitions.firstOrNull { it.nameSupplier().equals(normalizedName, ignoreCase = true) } } - } \ No newline at end of file diff --git a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt index 9205bc0b..a98a5448 100644 --- a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt +++ b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt @@ -86,5 +86,4 @@ class SkillProxy(private val skills: SkillSet, private val skill: Int) { val new = Math.min(current + amount, maximum) skills.setCurrentLevel(skill, new) } - } \ No newline at end of file diff --git a/game/plugin/api/src/org/apollo/game/plugin/api/World.kt b/game/plugin/api/src/org/apollo/game/plugin/api/World.kt index a44163c1..6f981e48 100644 --- a/game/plugin/api/src/org/apollo/game/plugin/api/World.kt +++ b/game/plugin/api/src/org/apollo/game/plugin/api/World.kt @@ -100,5 +100,4 @@ private class ExpireObjectTask( stop() } } - } \ No newline at end of file diff --git a/game/plugin/api/test/org/apollo/game/plugin/api/DefinitionsTests.kt b/game/plugin/api/test/org/apollo/game/plugin/api/DefinitionsTests.kt index 43af9485..89c662ae 100644 --- a/game/plugin/api/test/org/apollo/game/plugin/api/DefinitionsTests.kt +++ b/game/plugin/api/test/org/apollo/game/plugin/api/DefinitionsTests.kt @@ -88,7 +88,5 @@ class DefinitionsTests { @ObjectDefinitions val objs = listOf("obj zero", "obj one", "obj two", "obj duplicate name", "obj duplicate name") .mapIndexed { id, name -> ObjectDefinition(id).also { it.name = name } } - } - } \ No newline at end of file diff --git a/game/plugin/api/test/org/apollo/game/plugin/api/PlayerTests.kt b/game/plugin/api/test/org/apollo/game/plugin/api/PlayerTests.kt index a1b1f3b7..753f1663 100644 --- a/game/plugin/api/test/org/apollo/game/plugin/api/PlayerTests.kt +++ b/game/plugin/api/test/org/apollo/game/plugin/api/PlayerTests.kt @@ -119,5 +119,4 @@ class PlayerTests { assertEquals(10, hitpoints.maximum) } } - } \ No newline at end of file diff --git a/game/plugin/api/test/org/apollo/game/plugin/api/PositionTests.kt b/game/plugin/api/test/org/apollo/game/plugin/api/PositionTests.kt index 452d2f00..7d9644bf 100644 --- a/game/plugin/api/test/org/apollo/game/plugin/api/PositionTests.kt +++ b/game/plugin/api/test/org/apollo/game/plugin/api/PositionTests.kt @@ -22,5 +22,4 @@ class PositionTests { assertEquals(y, y2) { "y coordinate mismatch in Position destructuring." } assertEquals(z, z2) { "z coordinate mismatch in Position destructuring." } } - } \ No newline at end of file diff --git a/game/plugin/areas/src/Area.kt b/game/plugin/areas/src/Area.kt index 376ce33a..e594a170 100644 --- a/game/plugin/areas/src/Area.kt +++ b/game/plugin/areas/src/Area.kt @@ -14,7 +14,6 @@ interface Area { * Returns whether or not the specified [Position] is inside this [Area]. */ operator fun contains(position: Position): Boolean - } 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 return x in this.x && y in this.y && z == height } - } diff --git a/game/plugin/areas/src/AreaActionBuilder.kt b/game/plugin/areas/src/AreaActionBuilder.kt index 00ba8eb6..7da8aead 100644 --- a/game/plugin/areas/src/AreaActionBuilder.kt +++ b/game/plugin/areas/src/AreaActionBuilder.kt @@ -38,5 +38,4 @@ class AreaActionBuilder internal constructor(val name: String, val area: Area) { fun exit(listener: AreaListener) { this.exit = listener } - } \ No newline at end of file diff --git a/game/plugin/areas/test/AreaActionTests.kt b/game/plugin/areas/test/AreaActionTests.kt index 0fbd5e1b..7c577efd 100644 --- a/game/plugin/areas/test/AreaActionTests.kt +++ b/game/plugin/areas/test/AreaActionTests.kt @@ -55,5 +55,4 @@ class AreaActionTests { assertTrue(triggered) { "exit_test_action was not triggered." } } - } \ No newline at end of file diff --git a/game/plugin/bank/src/bank.plugin.kts b/game/plugin/bank/src/bank.plugin.kts index 10d424e3..0aef5ac1 100644 --- a/game/plugin/bank/src/bank.plugin.kts +++ b/game/plugin/bank/src/bank.plugin.kts @@ -9,7 +9,6 @@ import org.apollo.net.message.Message val BANK_BOOTH_ID = 2213 - /** * 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(0 player.startAction(BankAction(player, position)) message.terminate() } - } override fun executeAction() { @@ -72,5 +70,4 @@ class BankAction(player: Player, position: Position) : DistancedAction(0 override fun hashCode(): Int { return position.hashCode() } - } diff --git a/game/plugin/bank/test/OpenBankTest.kt b/game/plugin/bank/test/OpenBankTest.kt index 58b7b5e4..578325e0 100644 --- a/game/plugin/bank/test/OpenBankTest.kt +++ b/game/plugin/bank/test/OpenBankTest.kt @@ -49,5 +49,4 @@ class OpenBankTest { verifyAfter(action.complete()) { player.openBank() } } - } \ No newline at end of file diff --git a/game/plugin/cmd/src/teleport-cmd.plugin.kts b/game/plugin/cmd/src/teleport-cmd.plugin.kts index 4cc6c8ad..1aedd5b9 100644 --- a/game/plugin/cmd/src/teleport-cmd.plugin.kts +++ b/game/plugin/cmd/src/teleport-cmd.plugin.kts @@ -1,139 +1,138 @@ - -import com.google.common.primitives.Ints -import org.apollo.game.model.Position -import org.apollo.game.model.entity.setting.PrivilegeLevel -import org.apollo.game.plugin.api.Position.component1 -import org.apollo.game.plugin.api.Position.component2 -import org.apollo.game.plugin.api.Position.component3 - -/** - * Sends the player's position. - */ -on_command("pos", PrivilegeLevel.MODERATOR) - .then { player -> - val (x, y, z) = player.position - val region = player.position.regionCoordinates - - player.sendMessage("You are at: ($x, $y, $z) in region (${region.x}, ${region.y}).") - } - -/** - * Teleports the player to the specified position. - */ -on_command("tele", PrivilegeLevel.ADMINISTRATOR) - .then { player -> - val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z] or ::tele [place name]" - - if (arguments.size == 1) { - val query = arguments[0] - val results = TELEPORT_DESTINATIONS.filter { (name) -> name.startsWith(query) } - - if (results.isEmpty()) { - player.sendMessage("No destinations matching '$query'.") - player.sendMessage(invalidSyntax) - return@then - } else if (results.size > 1) { - player.sendMessage("Ambiguous query '$query' (could be $results). Please disambiguate.") - return@then - } - - val (name, dest) = results[0] - player.sendMessage("Teleporting to $name.") - player.teleport(dest) - - return@then - } - - if (arguments.size !in 2..3) { - player.sendMessage(invalidSyntax) - return@then - } - - val x = Ints.tryParse(arguments[0]) - if (x == null) { - player.sendMessage(invalidSyntax) - return@then - } - - val y = Ints.tryParse(arguments[1]) - if (y == null) { - player.sendMessage(invalidSyntax) - return@then - } - - var z = player.position.height - if (arguments.size == 3) { - val plane = Ints.tryParse(arguments[2]) - if (plane == null) { - player.sendMessage(invalidSyntax) - return@then - } - z = plane - } - - if (z in 0..4) { - player.teleport(Position(x, y, z)) - } - } - -/** - * Teleports the player to another player. - */ -on_command("teleto", PrivilegeLevel.ADMINISTRATOR) - .then { player -> - val invalidSyntax = "Invalid syntax - ::teleto [player name]" - - if (arguments.size == 1) { - val playerName = arguments[0] - try { - val foundPlayer = player.world.getPlayer(playerName) - - if (foundPlayer == null) { - player.sendMessage("Player $playerName is currently offline or does not exist.") - return@then - } - - player.teleport(foundPlayer.position) - player.sendMessage("You have teleported to player $playerName.") - } catch (_: Exception) { - // Invalid player name syntax - player.sendMessage(invalidSyntax) - } - } else { - player.sendMessage(invalidSyntax) - } - } - - -internal val TELEPORT_DESTINATIONS = listOf( - "alkharid" to Position(3292, 3171), - "ardougne" to Position(2662, 3304), - "barrows" to Position(3565, 3314), - "brimhaven" to Position(2802, 3179), - "burthorpe" to Position(2898, 3545), - "camelot" to Position(2757, 3478), - "canifis" to Position(3493, 3489), - "cw" to Position(2442, 3090), - "draynor" to Position(3082, 3249), - "duelarena" to Position(3370, 3267), - "edgeville" to Position(3087, 3504), - "entrana" to Position(2827, 3343), - "falador" to Position(2965, 3379), - "ge" to Position(3164, 3476), - "kbd" to Position(2273, 4680), - "keldagrim" to Position(2845, 10210), - "kq" to Position(3507, 9494), - "lumbridge" to Position(3222, 3219), - "lunar" to Position(2113, 3915), - "misc" to Position(2515, 3866), - "neit" to Position(2332, 3804), - "pc" to Position(2658, 2660), - "rellekka" to Position(2660, 3657), - "shilo" to Position(2852, 2955), - "taverley" to Position(2895, 3443), - "tutorial" to Position(3094, 3107), - "tzhaar" to Position(2480, 5175), - "varrock" to Position(3212, 3423), - "yanille" to Position(2605, 3096), - "zanaris" to Position(2452, 4473) + +import com.google.common.primitives.Ints +import org.apollo.game.model.Position +import org.apollo.game.model.entity.setting.PrivilegeLevel +import org.apollo.game.plugin.api.Position.component1 +import org.apollo.game.plugin.api.Position.component2 +import org.apollo.game.plugin.api.Position.component3 + +/** + * Sends the player's position. + */ +on_command("pos", PrivilegeLevel.MODERATOR) + .then { player -> + val (x, y, z) = player.position + val region = player.position.regionCoordinates + + player.sendMessage("You are at: ($x, $y, $z) in region (${region.x}, ${region.y}).") + } + +/** + * Teleports the player to the specified position. + */ +on_command("tele", PrivilegeLevel.ADMINISTRATOR) + .then { player -> + val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z] or ::tele [place name]" + + if (arguments.size == 1) { + val query = arguments[0] + val results = TELEPORT_DESTINATIONS.filter { (name) -> name.startsWith(query) } + + if (results.isEmpty()) { + player.sendMessage("No destinations matching '$query'.") + player.sendMessage(invalidSyntax) + return@then + } else if (results.size > 1) { + player.sendMessage("Ambiguous query '$query' (could be $results). Please disambiguate.") + return@then + } + + val (name, dest) = results[0] + player.sendMessage("Teleporting to $name.") + player.teleport(dest) + + return@then + } + + if (arguments.size !in 2..3) { + player.sendMessage(invalidSyntax) + return@then + } + + val x = Ints.tryParse(arguments[0]) + if (x == null) { + player.sendMessage(invalidSyntax) + return@then + } + + val y = Ints.tryParse(arguments[1]) + if (y == null) { + player.sendMessage(invalidSyntax) + return@then + } + + var z = player.position.height + if (arguments.size == 3) { + val plane = Ints.tryParse(arguments[2]) + if (plane == null) { + player.sendMessage(invalidSyntax) + return@then + } + z = plane + } + + if (z in 0..4) { + player.teleport(Position(x, y, z)) + } + } + +/** + * Teleports the player to another player. + */ +on_command("teleto", PrivilegeLevel.ADMINISTRATOR) + .then { player -> + val invalidSyntax = "Invalid syntax - ::teleto [player name]" + + if (arguments.size == 1) { + val playerName = arguments[0] + try { + val foundPlayer = player.world.getPlayer(playerName) + + if (foundPlayer == null) { + player.sendMessage("Player $playerName is currently offline or does not exist.") + return@then + } + + player.teleport(foundPlayer.position) + player.sendMessage("You have teleported to player $playerName.") + } catch (_: Exception) { + // Invalid player name syntax + player.sendMessage(invalidSyntax) + } + } else { + player.sendMessage(invalidSyntax) + } + } + +internal val TELEPORT_DESTINATIONS = listOf( + "alkharid" to Position(3292, 3171), + "ardougne" to Position(2662, 3304), + "barrows" to Position(3565, 3314), + "brimhaven" to Position(2802, 3179), + "burthorpe" to Position(2898, 3545), + "camelot" to Position(2757, 3478), + "canifis" to Position(3493, 3489), + "cw" to Position(2442, 3090), + "draynor" to Position(3082, 3249), + "duelarena" to Position(3370, 3267), + "edgeville" to Position(3087, 3504), + "entrana" to Position(2827, 3343), + "falador" to Position(2965, 3379), + "ge" to Position(3164, 3476), + "kbd" to Position(2273, 4680), + "keldagrim" to Position(2845, 10210), + "kq" to Position(3507, 9494), + "lumbridge" to Position(3222, 3219), + "lunar" to Position(2113, 3915), + "misc" to Position(2515, 3866), + "neit" to Position(2332, 3804), + "pc" to Position(2658, 2660), + "rellekka" to Position(2660, 3657), + "shilo" to Position(2852, 2955), + "taverley" to Position(2895, 3443), + "tutorial" to Position(3094, 3107), + "tzhaar" to Position(2480, 5175), + "varrock" to Position(3212, 3423), + "yanille" to Position(2605, 3096), + "zanaris" to Position(2452, 4473) ) \ No newline at end of file diff --git a/game/plugin/cmd/test/AnimateCommandTests.kt b/game/plugin/cmd/test/AnimateCommandTests.kt index c52e72ba..5a49dd6e 100644 --- a/game/plugin/cmd/test/AnimateCommandTests.kt +++ b/game/plugin/cmd/test/AnimateCommandTests.kt @@ -36,5 +36,4 @@ class AnimateCommandTests { player.sendMessage(contains("Invalid syntax")) } } - } \ No newline at end of file diff --git a/game/plugin/cmd/test/LookupCommandTests.kt b/game/plugin/cmd/test/LookupCommandTests.kt index 73208f8d..ada7ebee 100644 --- a/game/plugin/cmd/test/LookupCommandTests.kt +++ b/game/plugin/cmd/test/LookupCommandTests.kt @@ -93,5 +93,4 @@ class LookupCommandTests { length = 1 }) } - } \ No newline at end of file diff --git a/game/plugin/cmd/test/SpawnCommandTests.kt b/game/plugin/cmd/test/SpawnCommandTests.kt index ef9a3d60..8dfde978 100644 --- a/game/plugin/cmd/test/SpawnCommandTests.kt +++ b/game/plugin/cmd/test/SpawnCommandTests.kt @@ -37,7 +37,7 @@ class SpawnCommandTests { verify { world.register(match { - it.id == 1 && it.position == Position(3, 3,0) + it.id == 1 && it.position == Position(3, 3, 0) }) } } diff --git a/game/plugin/cmd/test/TeleportToPlayerCommandTests.kt b/game/plugin/cmd/test/TeleportToPlayerCommandTests.kt index 6b4e2864..d70c8e4d 100644 --- a/game/plugin/cmd/test/TeleportToPlayerCommandTests.kt +++ b/game/plugin/cmd/test/TeleportToPlayerCommandTests.kt @@ -49,5 +49,4 @@ class TeleportToPlayerCommandTests { player.sendMessage(contains("Invalid syntax")) } } - } \ No newline at end of file diff --git a/game/plugin/consumables/src/consumables.kt b/game/plugin/consumables/src/consumables.kt index 3fec3eaf..f8bc5ef0 100644 --- a/game/plugin/consumables/src/consumables.kt +++ b/game/plugin/consumables/src/consumables.kt @@ -18,7 +18,6 @@ abstract class Consumable(val name: String, val id: Int, val sound: Int, val del player.inventory.add(replacement) } } - } private val consumables = mutableMapOf() @@ -41,12 +40,12 @@ class FoodOrDrink : Consumable { val type: FoodOrDrinkType constructor( - name: String, - id: Int, - delay: Int, - type: FoodOrDrinkType, - restoration: Int, - replacement: Int? = null + name: String, + id: Int, + delay: Int, + type: FoodOrDrinkType, + restoration: Int, + replacement: Int? = null ) : super(name, id, EAT_FOOD_SOUND, delay, replacement) { this.type = type this.restoration = restoration @@ -64,7 +63,6 @@ class FoodOrDrink : Consumable { player.skillSet.setCurrentLevel(Skill.HITPOINTS, newHitpointsLevel) } - } /** diff --git a/game/plugin/consumables/src/consumables.plugin.kts b/game/plugin/consumables/src/consumables.plugin.kts index c633e900..1711d43e 100644 --- a/game/plugin/consumables/src/consumables.plugin.kts +++ b/game/plugin/consumables/src/consumables.plugin.kts @@ -34,5 +34,4 @@ class ConsumeAction(val consumable: Consumable, player: Player, val slot: Int) : wait(consumable.delay) stop() } - } diff --git a/game/plugin/consumables/src/drinks.plugin.kts b/game/plugin/consumables/src/drinks.plugin.kts index f3c8075a..a96a8a3f 100644 --- a/game/plugin/consumables/src/drinks.plugin.kts +++ b/game/plugin/consumables/src/drinks.plugin.kts @@ -1,13 +1,13 @@ import org.apollo.plugin.consumables.drink -//# Wine +// # Wine 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 = 4240, restoration = 3) -//# Gnome Cocktails +// # Gnome Cocktails drink(name = "fruit_blast", id = 2034, restoration = 9) drink(name = "fruit_blast", id = 2084, restoration = 9) drink(name = "pineapple_punch", id = 2036, restoration = 9) diff --git a/game/plugin/consumables/src/foods.plugin.kts b/game/plugin/consumables/src/foods.plugin.kts index 7762969b..02981890 100644 --- a/game/plugin/consumables/src/foods.plugin.kts +++ b/game/plugin/consumables/src/foods.plugin.kts @@ -32,12 +32,12 @@ food(name = "shark", id = 385, restoration = 20) food(name = "sea_turtle", id = 397, restoration = 21) food(name = "manta_ray", id = 391, restoration = 22) -//# Breads/Wraps +// # Breads/Wraps food(name = "bread", id = 2309, restoration = 5) food(name = "oomlie_wrap", id = 2343, restoration = 14) food(name = "ugthanki_kebab", id = 1883, restoration = 19) -//# Fruits +// # Fruits food(name = "banana", id = 1963, restoration = 2) food(name = "sliced_banana", id = 3162, 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_slices", id = 2112, restoration = 2) -//# Pies -//# TODO: pie special effects (e.g. fish pie raises fishing level) +// # Pies +// # 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 = 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 = 7220, restoration = 11, delay = 1) -//# Stews +// # Stews food(name = "stew", id = 2003, restoration = 11) food(name = "banana_stew", id = 4016, restoration = 11) food(name = "curry", id = 2011, restoration = 19) -//# Pizzas +// # Pizzas food(name = "plain_pizza", id = 2289, restoration = 7, replacement = 2291) 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 = 2303, restoration = 11) -//# Cakes +// # Cakes food(name = "fishcake", id = 7530, restoration = 11) 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 = 1901, restoration = 5) -//# Vegetables +// # Vegetables food(name = "potato", id = 1942, restoration = 1) food(name = "spinach_roll", id = 1969, restoration = 2) 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 = "tuna_potato", id = 7060, restoration = 22) -//# Dairy +// # Dairy food(name = "cheese", id = 1985, restoration = 2) food(name = "pot_of_cream", id = 2130, restoration = 1) -//# Gnome Food +// # Gnome Food 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 = 2233, 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 = 2229, restoration = 15) -//# Gnome Crunchies +// # Gnome Crunchies food(name = "toad_crunchies", id = 2217, restoration = 7) food(name = "toad_crunchies", id = 2243, 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 = 2239, restoration = 7) -//# Gnome Battas +// # Gnome Battas food(name = "fruit_batta", id = 2225, restoration = 11) food(name = "fruit_batta", id = 2277, restoration = 11) food(name = "toad_batta", id = 2221, restoration = 11) diff --git a/game/plugin/consumables/test/FoodOrDrinkTests.kt b/game/plugin/consumables/test/FoodOrDrinkTests.kt index 851f3290..59aad8da 100644 --- a/game/plugin/consumables/test/FoodOrDrinkTests.kt +++ b/game/plugin/consumables/test/FoodOrDrinkTests.kt @@ -3,8 +3,8 @@ package org.apollo.plugin.consumables import io.mockk.verify import org.apollo.game.model.entity.Player 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.contains import org.apollo.game.plugin.testing.assertions.verifyAfter import org.apollo.game.plugin.testing.junit.ApolloTestingExtension 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`() { 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 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) - verifyAfter(action.complete()) { player.sendMessage("You eat the ${TEST_FOOD_NAME}.") } + verifyAfter(action.complete()) { player.sendMessage("You eat the $TEST_FOOD_NAME.") } } - } \ No newline at end of file diff --git a/game/plugin/dummy/src/dummy.plugin.kts b/game/plugin/dummy/src/dummy.plugin.kts index f02507b1..a4501f95 100644 --- a/game/plugin/dummy/src/dummy.plugin.kts +++ b/game/plugin/dummy/src/dummy.plugin.kts @@ -1,9 +1,6 @@ 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.AsyncDistancedAction -import org.apollo.game.action.DistancedAction import org.apollo.game.message.impl.ObjectActionMessage import org.apollo.game.model.Animation import org.apollo.game.model.Position @@ -50,10 +47,8 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction player.startAction(DummyAction(player, position)) message.terminate() } - } - override fun action(): ActionBlock = { mob.sendMessage("You hit the dummy.") mob.turnTo(position) @@ -68,5 +63,4 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction skills.addExperience(Skill.ATTACK, EXP_PER_HIT) } } - } diff --git a/game/plugin/dummy/test/TrainingDummyTest.kt b/game/plugin/dummy/test/TrainingDummyTest.kt index 4a4284b5..ccc22be2 100644 --- a/game/plugin/dummy/test/TrainingDummyTest.kt +++ b/game/plugin/dummy/test/TrainingDummyTest.kt @@ -5,12 +5,12 @@ import org.apollo.game.model.World import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Skill 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.api.ActionCapture 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.spawnObject -import org.apollo.game.plugin.testing.assertions.contains import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test @@ -60,5 +60,4 @@ class TrainingDummyTest { assertEquals(beforeExp, skills.getExperience(Skill.ATTACK)) } } - } diff --git a/game/plugin/emote-tab/src/emote.kt b/game/plugin/emote-tab/src/Emote.kt similarity index 100% rename from game/plugin/emote-tab/src/emote.kt rename to game/plugin/emote-tab/src/Emote.kt diff --git a/game/plugin/emote-tab/src/emote-tab.plugin.kts b/game/plugin/emote-tab/src/EmoteTab.plugin.kts similarity index 100% rename from game/plugin/emote-tab/src/emote-tab.plugin.kts rename to game/plugin/emote-tab/src/EmoteTab.plugin.kts diff --git a/game/plugin/entity/actions/src/PlayerActionEvent.kt b/game/plugin/entity/actions/src/PlayerActionEvent.kt new file mode 100644 index 00000000..3cca682a --- /dev/null +++ b/game/plugin/entity/actions/src/PlayerActionEvent.kt @@ -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) \ No newline at end of file diff --git a/game/plugin/entity/actions/src/PlayerAction.kt b/game/plugin/entity/actions/src/playerAction.kt similarity index 84% rename from game/plugin/entity/actions/src/PlayerAction.kt rename to game/plugin/entity/actions/src/playerAction.kt index ff8fd6d2..d08b7797 100644 --- a/game/plugin/entity/actions/src/PlayerAction.kt +++ b/game/plugin/entity/actions/src/playerAction.kt @@ -1,11 +1,8 @@ package org.apollo.game.plugin.entity.actions +import java.util.* import org.apollo.game.message.impl.SetPlayerActionMessage 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) { send(SetPlayerActionMessage(action.displayName, action.slot, action.primary)) diff --git a/game/plugin/entity/actions/test/PlayerActionTests.kt b/game/plugin/entity/actions/test/PlayerActionTests.kt index 2a654693..153345d0 100644 --- a/game/plugin/entity/actions/test/PlayerActionTests.kt +++ b/game/plugin/entity/actions/test/PlayerActionTests.kt @@ -30,5 +30,4 @@ class PlayerActionTests { verify { player.send(eq(SetPlayerActionMessage("null", type.slot, type.primary))) } assertFalse(player.actionEnabled(type)) { "Action $type should not have been enabled, but was." } } - } \ No newline at end of file diff --git a/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.kt b/game/plugin/entity/following/src/org/apollo/plugin/entity/following/FollowAction.kt similarity index 99% rename from game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.kt rename to game/plugin/entity/following/src/org/apollo/plugin/entity/following/FollowAction.kt index 2c678c28..517c0af9 100644 --- a/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.kt +++ b/game/plugin/entity/following/src/org/apollo/plugin/entity/following/FollowAction.kt @@ -46,5 +46,4 @@ class FollowAction(player: Player, private val target: Player) : Action( lastPosition = target.position } } - } \ No newline at end of file diff --git a/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.plugin.kts b/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.plugin.kts index 10d483ce..98916343 100644 --- a/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.plugin.kts +++ b/game/plugin/entity/following/src/org/apollo/plugin/entity/following/Following.plugin.kts @@ -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.PlayerActionType -import org.apollo.plugin.entity.following.FollowAction on_player_event { PlayerActionEvent::class } .where { action == PlayerActionType.FOLLOW } diff --git a/game/plugin/entity/spawn/test/org/apollo/game/plugin/entity/spawn/SpawnTests.kt b/game/plugin/entity/spawn/test/org/apollo/game/plugin/entity/spawn/SpawnTests.kt index 9e434b29..7290a789 100644 --- a/game/plugin/entity/spawn/test/org/apollo/game/plugin/entity/spawn/SpawnTests.kt +++ b/game/plugin/entity/spawn/test/org/apollo/game/plugin/entity/spawn/SpawnTests.kt @@ -139,5 +139,4 @@ class SpawnTests { } } } - } diff --git a/game/plugin/locations/edgeville/src/npcs.plugin.kts b/game/plugin/locations/edgeville/src/npcs.plugin.kts index 7419b2b2..d89e8492 100644 --- a/game/plugin/locations/edgeville/src/npcs.plugin.kts +++ b/game/plugin/locations/edgeville/src/npcs.plugin.kts @@ -45,7 +45,6 @@ spawnNpc("oziach", x = 3067, y = 3518, facing = Direction.EAST) spawnNpc("shop_keeper", id = 528, x = 3079, y = 3509) spawnNpc("shop_assistant", id = 529, x = 3082, y = 3513) - spawnNpc("banker", x = 3096, y = 3489, facing = Direction.WEST) spawnNpc("banker", x = 3096, y = 3491, facing = Direction.WEST) spawnNpc("banker", x = 3096, y = 3492) diff --git a/game/plugin/locations/varrock/src/npcs.plugin.kts b/game/plugin/locations/varrock/src/npcs.plugin.kts index 1e5c9f0c..83d5fb9e 100644 --- a/game/plugin/locations/varrock/src/npcs.plugin.kts +++ b/game/plugin/locations/varrock/src/npcs.plugin.kts @@ -56,7 +56,6 @@ spawnNpc("woman", x = 3221, y = 3396) spawnNpc("woman", id = 5, x = 3279, y = 3497) spawnNpc("woman", id = 25, x = 3278, y = 3492) - spawnNpc("thief", x = 3285, y = 3500) spawnNpc("thief", x = 3234, y = 3389) 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 = 3260, y = 3356) - spawnNpc("ram", id = 3673, x = 3238, y = 3346) spawnNpc("ram", id = 3673, x = 3248, y = 3352) spawnNpc("ram", id = 3673, x = 3260, y = 3348) diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index e3bf59ef..0243b091 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,5 +1,5 @@ val LOGOUT_BUTTON_ID = 2458 on_button(LOGOUT_BUTTON_ID) - .where { widgetId == LOGOUT_BUTTON_ID } - .then { it.logout() } \ No newline at end of file + .where { widgetId == LOGOUT_BUTTON_ID } + .then { it.logout() } \ No newline at end of file diff --git a/game/plugin/logout/test/LogoutTests.kt b/game/plugin/logout/test/LogoutTests.kt index c536976f..9a8cb9c6 100644 --- a/game/plugin/logout/test/LogoutTests.kt +++ b/game/plugin/logout/test/LogoutTests.kt @@ -1,4 +1,3 @@ - import io.mockk.verify import org.apollo.game.message.impl.ButtonMessage import org.apollo.game.model.entity.Player @@ -8,20 +7,19 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @ExtendWith(ApolloTestingExtension::class) -class LogoutTests { +class LogoutTests { - companion object { - const val LOGOUT_BUTTON_ID = 2458 - } + companion object { + const val LOGOUT_BUTTON_ID = 2458 + } @TestMock lateinit var player: Player - @Test + @Test fun `The player should be logged out when they click the logout button`() { - player.send(ButtonMessage(LOGOUT_BUTTON_ID)) + player.send(ButtonMessage(LOGOUT_BUTTON_ID)) verify { player.logout() } - } - + } } \ No newline at end of file diff --git a/game/plugin/navigation/door/src/door.kt b/game/plugin/navigation/door/src/door.kt index d7255cb7..59ee1325 100644 --- a/game/plugin/navigation/door/src/door.kt +++ b/game/plugin/navigation/door/src/door.kt @@ -1,5 +1,6 @@ package org.apollo.plugin.navigation.door +import java.util.* import org.apollo.game.action.DistancedAction import org.apollo.game.model.Direction 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.plugin.api.findObject import org.apollo.net.message.Message -import java.util.* enum class DoorType { LEFT, RIGHT, NOT_SUPPORTED @@ -59,7 +59,6 @@ class Door(private val gameObject: GameObject) { return type() !== DoorType.NOT_SUPPORTED } - /** * Computes the given door type by which id exists in * the supported left and right hinged doors @@ -97,7 +96,6 @@ class Door(private val gameObject: GameObject) { toggledDoors.remove(gameObject) regionRepository.fromPosition(originalDoor.position).addEntity(originalDoor) } - } /** @@ -120,7 +118,6 @@ class Door(private val gameObject: GameObject) { DoorType.NOT_SUPPORTED -> null } } - } class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction( @@ -140,7 +137,6 @@ class OpenDoorAction(private val player: Player, private val door: Door, positio player.startAction(OpenDoorAction(player, door, position)) message.terminate() } - } 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) - } class OpenDoorEvent(player: Player) : PlayerEvent(player) diff --git a/game/plugin/run/src/run.plugin.kts b/game/plugin/run/src/run.plugin.kts index 00c6a470..fa65f049 100644 --- a/game/plugin/run/src/run.plugin.kts +++ b/game/plugin/run/src/run.plugin.kts @@ -4,7 +4,7 @@ val WALK_BUTTON_ID = 152 val RUN_BUTTON_ID = 153 on { ButtonMessage::class } - .where { widgetId == WALK_BUTTON_ID || widgetId == RUN_BUTTON_ID } - .then { - it.toggleRunning() - } \ No newline at end of file + .where { widgetId == WALK_BUTTON_ID || widgetId == RUN_BUTTON_ID } + .then { + it.toggleRunning() + } \ No newline at end of file diff --git a/game/plugin/shops/src/action.kt b/game/plugin/shops/src/action.kt index 0449253c..8f31158f 100644 --- a/game/plugin/shops/src/action.kt +++ b/game/plugin/shops/src/action.kt @@ -50,7 +50,6 @@ class OpenShopAction( shop.removeListener(shopListener) } } - } /** @@ -64,5 +63,4 @@ class PlayerInventorySupplier : InventorySupplier { else -> null } } - } \ No newline at end of file diff --git a/game/plugin/shops/src/dsl.kt b/game/plugin/shops/src/dsl.kt index b5f5da39..7974ff6d 100644 --- a/game/plugin/shops/src/dsl.kt +++ b/game/plugin/shops/src/dsl.kt @@ -45,8 +45,12 @@ class ShopBuilder(val name: String) { * @param depluralise Whether or not the category name should have the "s". * @param builder The builder used to add items to the category. */ - fun category(name: String, affix: Affix = Affix.Suffix, depluralise: Boolean = true, - builder: CategoryWrapper.() -> Unit) { + fun category( + name: String, + affix: Affix = Affix.Suffix, + depluralise: Boolean = true, + builder: CategoryWrapper.() -> Unit + ) { val items = mutableListOf>() builder.invoke(CategoryWrapper(items)) @@ -118,7 +122,6 @@ class ShopBuilder(val name: String) { * Gets the [List] of shop operator ids. */ internal fun operators(): MutableList = operated.operators - } @ShopDslMarker @@ -148,14 +151,12 @@ class CategoryWrapper(private val items: MutableList>) { * Joins the item and category name in the expected manner. */ fun join(item: String, category: String): String = joiner(item, category) - } /** * Creates a [SellBuilder] with the specified [amount]. */ 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. */ operator fun plus(pair: Pair): OperatorBuilder = by(pair) - } /** @@ -270,7 +270,6 @@ class ActionBuilder { */ 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.") - } /** @@ -288,7 +287,6 @@ class CurrencyBuilder { builder.currency = this return true } - } /** @@ -312,7 +310,6 @@ class PurchasesBuilder { infix fun any(@Suppress("UNUSED_PARAMETER") items: Unit) { policy = Shop.PurchasePolicy.ANY } - } /** @@ -348,5 +345,4 @@ class SellBuilder(val amount: Int, val items: MutableList>) { * Overloads function invokation on Strings to map `"ambiguous_npc_name"(id)` to a [Pair]. */ operator fun String.invoke(id: Int): Pair = Pair(this, id) - } diff --git a/game/plugin/shops/src/shop.kt b/game/plugin/shops/src/shop.kt index 20863225..f5490906 100644 --- a/game/plugin/shops/src/shop.kt +++ b/game/plugin/shops/src/shop.kt @@ -40,7 +40,6 @@ object Interfaces { * The id of the text widget that displays a shop's name. */ const val SHOP_NAME = 3901 - } /** @@ -69,7 +68,6 @@ data class Currency(val id: Int, val plural: Boolean = false) { else -> name } } - } /** @@ -124,7 +122,6 @@ class Shop( else -> throw IllegalArgumentException("Option must be 1-4") } } - } /** @@ -331,5 +328,4 @@ class Shop( * @param id The id of the [Item] to sell. */ private fun sells(id: Int): Boolean = sells.containsKey(id) - } \ No newline at end of file diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fish.kt b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fish.kt index 1a281943..45f76b82 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fish.kt +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fish.kt @@ -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 ") } - } diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingAction.kt b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingAction.kt index a02412e7..9eacf024 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingAction.kt +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingAction.kt @@ -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 } - } - } \ No newline at end of file diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingSpot.kt b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingSpot.kt index 54a54298..380dd1a0 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingSpot.kt +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingSpot.kt @@ -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] } - } \ No newline at end of file diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTarget.kt b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTarget.kt index 7275ee63..bdcb5713 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTarget.kt +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTarget.kt @@ -35,5 +35,4 @@ data class FishingTarget(val position: Position, val option: FishingSpot.Option) return false } - } \ No newline at end of file diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTool.kt b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTool.kt index 41f639d0..e4912214 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTool.kt +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/FishingTool.kt @@ -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() } - } \ No newline at end of file diff --git a/game/plugin/skills/fishing/test/org/apollo/game/plugin/skills/fishing/FishingActionTests.kt b/game/plugin/skills/fishing/test/org/apollo/game/plugin/skills/fishing/FishingActionTests.kt index 10f90abb..42fd6cbb 100644 --- a/game/plugin/skills/fishing/test/org/apollo/game/plugin/skills/fishing/FishingActionTests.kt +++ b/game/plugin/skills/fishing/test/org/apollo/game/plugin/skills/fishing/FishingActionTests.kt @@ -89,5 +89,4 @@ class FishingActionTests { private val spots = FishingSpot.values() .map { NpcDefinition(it.npc).apply { name = "" } } } - } \ No newline at end of file diff --git a/game/plugin/skills/herblore/src/CrushIngredientAction.kt b/game/plugin/skills/herblore/src/CrushIngredientAction.kt index bf9cb283..6c519431 100644 --- a/game/plugin/skills/herblore/src/CrushIngredientAction.kt +++ b/game/plugin/skills/herblore/src/CrushIngredientAction.kt @@ -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, diff --git a/game/plugin/skills/herblore/src/IdentifyHerbAction.kt b/game/plugin/skills/herblore/src/IdentifyHerbAction.kt index a3b11ac9..bd9bd4b7 100644 --- a/game/plugin/skills/herblore/src/IdentifyHerbAction.kt +++ b/game/plugin/skills/herblore/src/IdentifyHerbAction.kt @@ -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, diff --git a/game/plugin/skills/herblore/src/MakePotionAction.kt b/game/plugin/skills/herblore/src/MakePotionAction.kt index 46759d79..19f5ef94 100644 --- a/game/plugin/skills/herblore/src/MakePotionAction.kt +++ b/game/plugin/skills/herblore/src/MakePotionAction.kt @@ -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, diff --git a/game/plugin/skills/mining/src/ExpiredProspectingAction.kt b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt new file mode 100644 index 00000000..41f3229e --- /dev/null +++ b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt @@ -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(DELAY, true, mob, position, ORE_SIZE) { + + companion object { + private const val DELAY = 0 + private const val ORE_SIZE = 1 + + /** + * Starts a [ExpiredProspectingAction] for the specified [Player], terminating the [Message] that triggered it. + */ + fun start(message: ObjectActionMessage, player: Player) { + val action = ExpiredProspectingAction(player, message.position) + player.startAction(action) + + message.terminate() + } + } + + override fun executeAction() { + mob.sendMessage("There is currently no ore available in this rock.") + stop() + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ExpiredProspectingAction + return mob == other.mob && position == other.position + } + + override fun hashCode(): Int = Objects.hash(mob, position) +} \ No newline at end of file diff --git a/game/plugin/skills/mining/src/gem.kt b/game/plugin/skills/mining/src/Gem.kt similarity index 100% rename from game/plugin/skills/mining/src/gem.kt rename to game/plugin/skills/mining/src/Gem.kt diff --git a/game/plugin/skills/mining/src/mining.plugin.kts b/game/plugin/skills/mining/src/Mining.plugin.kts similarity index 100% rename from game/plugin/skills/mining/src/mining.plugin.kts rename to game/plugin/skills/mining/src/Mining.plugin.kts diff --git a/game/plugin/skills/mining/src/mining.kt b/game/plugin/skills/mining/src/MiningAction.kt similarity index 59% rename from game/plugin/skills/mining/src/mining.kt rename to game/plugin/skills/mining/src/MiningAction.kt index c3b773f2..0f159b38 100644 --- a/game/plugin/skills/mining/src/mining.kt +++ b/game/plugin/skills/mining/src/MiningAction.kt @@ -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 - -} - diff --git a/game/plugin/skills/mining/src/MiningTarget.kt b/game/plugin/skills/mining/src/MiningTarget.kt new file mode 100644 index 00000000..5bbe1b4a --- /dev/null +++ b/game/plugin/skills/mining/src/MiningTarget.kt @@ -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 +} \ No newline at end of file diff --git a/game/plugin/skills/mining/src/ore.kt b/game/plugin/skills/mining/src/Ore.kt similarity index 99% rename from game/plugin/skills/mining/src/ore.kt rename to game/plugin/skills/mining/src/Ore.kt index 7e76cf81..1f4a94ff 100644 --- a/game/plugin/skills/mining/src/ore.kt +++ b/game/plugin/skills/mining/src/Ore.kt @@ -36,7 +36,6 @@ enum class Ore( fun fromRock(id: Int): Ore? = ORE_ROCKS[id] fun fromExpiredRock(id: Int): Ore? = EXPIRED_ORE[id] - } } diff --git a/game/plugin/skills/mining/src/pickaxe.kt b/game/plugin/skills/mining/src/Pickaxe.kt similarity index 100% rename from game/plugin/skills/mining/src/pickaxe.kt rename to game/plugin/skills/mining/src/Pickaxe.kt diff --git a/game/plugin/skills/mining/src/prospecting.kt b/game/plugin/skills/mining/src/ProspectingAction.kt similarity index 59% rename from game/plugin/skills/mining/src/prospecting.kt rename to game/plugin/skills/mining/src/ProspectingAction.kt index 9b0f3d1c..10bf83a1 100644 --- a/game/plugin/skills/mining/src/prospecting.kt +++ b/game/plugin/skills/mining/src/ProspectingAction.kt @@ -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(DELAY, true, mob, position, ORE_SIZE) { - - companion object { - private const val DELAY = 0 - private const val ORE_SIZE = 1 - - /** - * Starts a [ExpiredProspectingAction] for the specified [Player], terminating the [Message] that triggered it. - */ - fun start(message: ObjectActionMessage, player: Player) { - val action = ExpiredProspectingAction(player, message.position) - player.startAction(action) - - message.terminate() - } - } - - override fun executeAction() { - mob.sendMessage("There is currently no ore available in this rock.") - stop() - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as ExpiredProspectingAction - return mob == other.mob && position == other.position - } - - override fun hashCode(): Int = Objects.hash(mob, position) - -} \ No newline at end of file diff --git a/game/plugin/skills/mining/test/MiningActionTests.kt b/game/plugin/skills/mining/test/MiningActionTests.kt index 2bd964f5..59e9a6be 100644 --- a/game/plugin/skills/mining/test/MiningActionTests.kt +++ b/game/plugin/skills/mining/test/MiningActionTests.kt @@ -87,5 +87,4 @@ class MiningActionTests { @ItemDefinitions fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id)) } - } \ No newline at end of file diff --git a/game/plugin/skills/mining/test/PickaxeTests.kt b/game/plugin/skills/mining/test/PickaxeTests.kt index 69e37539..70112ec1 100644 --- a/game/plugin/skills/mining/test/PickaxeTests.kt +++ b/game/plugin/skills/mining/test/PickaxeTests.kt @@ -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 } } } - } \ No newline at end of file diff --git a/game/plugin/skills/mining/test/ProspectingTests.kt b/game/plugin/skills/mining/test/ProspectingTests.kt index 2bbc0766..27d11c71 100644 --- a/game/plugin/skills/mining/test/ProspectingTests.kt +++ b/game/plugin/skills/mining/test/ProspectingTests.kt @@ -45,5 +45,4 @@ class ProspectingTests { ItemDefinition(it.id).also { it.name = "" } } } - } \ No newline at end of file diff --git a/game/plugin/skills/mining/test/TestData.kt b/game/plugin/skills/mining/test/TestData.kt index e6583035..aa798d24 100644 --- a/game/plugin/skills/mining/test/TestData.kt +++ b/game/plugin/skills/mining/test/TestData.kt @@ -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) diff --git a/game/plugin/skills/prayer/src/BoneBuryAction.kt b/game/plugin/skills/prayer/src/BuryBoneAction.kt similarity index 99% rename from game/plugin/skills/prayer/src/BoneBuryAction.kt rename to game/plugin/skills/prayer/src/BuryBoneAction.kt index c5fe0089..3b6720ca 100644 --- a/game/plugin/skills/prayer/src/BoneBuryAction.kt +++ b/game/plugin/skills/prayer/src/BuryBoneAction.kt @@ -28,5 +28,4 @@ class BuryBoneAction( public val BURY_BONE_ANIMATION = Animation(827) internal const val BURY_OPTION = 1 } - } \ No newline at end of file diff --git a/game/plugin/skills/prayer/src/prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts similarity index 100% rename from game/plugin/skills/prayer/src/prayer.plugin.kts rename to game/plugin/skills/prayer/src/Prayer.plugin.kts diff --git a/game/plugin/skills/prayer/test/BuryBoneTests.kt b/game/plugin/skills/prayer/test/BuryBoneTests.kt index 6d485334..23d57f68 100644 --- a/game/plugin/skills/prayer/test/BuryBoneTests.kt +++ b/game/plugin/skills/prayer/test/BuryBoneTests.kt @@ -70,5 +70,4 @@ class BuryBoneTests { return Bone.values().map { ItemDefinition(it.id) } } } - } \ No newline at end of file diff --git a/game/plugin/skills/runecrafting/src/Rune.kt b/game/plugin/skills/runecrafting/src/Rune.kt index 9d2c3991..5717442b 100644 --- a/game/plugin/skills/runecrafting/src/Rune.kt +++ b/game/plugin/skills/runecrafting/src/Rune.kt @@ -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( diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index b31dbc5b..88f983f7 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -8,11 +8,10 @@ private val changeAltarObjectConfigId = 491 internal val RUNES = mutableListOf() -fun List.findById(id: Int) : Rune? { +fun List.findById(id: Int): Rune? { return find { rune -> rune.id == id } } - start { RUNES.addAll(DefaultRune.values()) } diff --git a/game/plugin/skills/runecrafting/src/RunecraftingAction.kt b/game/plugin/skills/runecrafting/src/RunecraftingAction.kt index 371a3554..ec8c0438 100644 --- a/game/plugin/skills/runecrafting/src/RunecraftingAction.kt +++ b/game/plugin/skills/runecrafting/src/RunecraftingAction.kt @@ -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) diff --git a/game/plugin/skills/runecrafting/test/RunecraftingActionTests.kt b/game/plugin/skills/runecrafting/test/RunecraftingActionTests.kt index 4e01a44b..9751696b 100644 --- a/game/plugin/skills/runecrafting/test/RunecraftingActionTests.kt +++ b/game/plugin/skills/runecrafting/test/RunecraftingActionTests.kt @@ -27,7 +27,6 @@ class RunecraftingActionTests { fun setupPlayer() { player.position = TEST_ALTAR.center player.inventory.add(runeEssenceId, 25) - } @Test diff --git a/game/plugin/skills/woodcutting/src/axe.kt b/game/plugin/skills/woodcutting/src/Axe.kt similarity index 100% rename from game/plugin/skills/woodcutting/src/axe.kt rename to game/plugin/skills/woodcutting/src/Axe.kt diff --git a/game/plugin/skills/woodcutting/src/wood.kt b/game/plugin/skills/woodcutting/src/Tree.kt similarity index 100% rename from game/plugin/skills/woodcutting/src/wood.kt rename to game/plugin/skills/woodcutting/src/Tree.kt diff --git a/game/plugin/skills/woodcutting/src/woodcutting.plugin.kts b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts similarity index 99% rename from game/plugin/skills/woodcutting/src/woodcutting.plugin.kts rename to game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts index 2966914e..f0d96239 100644 --- a/game/plugin/skills/woodcutting/src/woodcutting.plugin.kts +++ b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts @@ -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( } } } - } \ No newline at end of file diff --git a/game/plugin/skills/woodcutting/test/AxeTests.kt b/game/plugin/skills/woodcutting/test/AxeTests.kt index cbbedb55..4f271f48 100644 --- a/game/plugin/skills/woodcutting/test/AxeTests.kt +++ b/game/plugin/skills/woodcutting/test/AxeTests.kt @@ -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 } } } - } \ No newline at end of file diff --git a/game/plugin/skills/woodcutting/test/TestData.kt b/game/plugin/skills/woodcutting/test/TestData.kt index 073b81ef..80c82e76 100644 --- a/game/plugin/skills/woodcutting/test/TestData.kt +++ b/game/plugin/skills/woodcutting/test/TestData.kt @@ -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) diff --git a/game/plugin/skills/woodcutting/test/WoodcuttingTests.kt b/game/plugin/skills/woodcutting/test/WoodcuttingTests.kt index c1a6e1ad..f98ab24f 100644 --- a/game/plugin/skills/woodcutting/test/WoodcuttingTests.kt +++ b/game/plugin/skills/woodcutting/test/WoodcuttingTests.kt @@ -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 { diff --git a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt index 5c49c794..28ca3338 100644 --- a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt +++ b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt @@ -1,6 +1,5 @@ package org.apollo.game.action -import kotlinx.coroutines.experimental.suspendCancellableCoroutine import java.util.concurrent.CancellationException import java.util.concurrent.atomic.AtomicInteger 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.createCoroutineUnchecked import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn +import kotlinx.coroutines.experimental.suspendCancellableCoroutine typealias ActionPredicate = () -> Boolean typealias ActionBlock = suspend ActionCoroutine.() -> Unit diff --git a/game/src/main/kotlin/org/apollo/game/action/AsyncActionTrait.kt b/game/src/main/kotlin/org/apollo/game/action/AsyncActionTrait.kt index 55a02aef..2f0e20d0 100644 --- a/game/src/main/kotlin/org/apollo/game/action/AsyncActionTrait.kt +++ b/game/src/main/kotlin/org/apollo/game/action/AsyncActionTrait.kt @@ -25,5 +25,5 @@ interface AsyncActionTrait { /** * Create a new `ActionBlock` to execute. */ - fun action() : ActionBlock + fun action(): ActionBlock } \ No newline at end of file diff --git a/game/src/main/kotlin/org/apollo/game/action/AsyncDistancedAction.kt b/game/src/main/kotlin/org/apollo/game/action/AsyncDistancedAction.kt index 761714d0..ce550eb3 100644 --- a/game/src/main/kotlin/org/apollo/game/action/AsyncDistancedAction.kt +++ b/game/src/main/kotlin/org/apollo/game/action/AsyncDistancedAction.kt @@ -19,4 +19,3 @@ abstract class AsyncDistancedAction : DistancedAction, AsyncActionTr } } } - diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt index fca5698d..a1a0ba4f 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt @@ -1,5 +1,8 @@ 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.CommandListener 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.plugin.PluginContext 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") @KotlinScriptFileExtension("plugin.kts") @@ -63,7 +63,6 @@ abstract class KotlinPluginScript(private var world: World, val context: PluginC fun doStop(world: World) { this.stopListener.invoke(world) } - } /** @@ -86,13 +85,11 @@ interface KotlinPlayerHandlerProxyTrait { this.register() } - fun handleProxy(player: Player, subject: S) { if (subject.predicate()) { subject.callback(player) } } - } /** @@ -106,7 +103,6 @@ class KotlinPlayerEventHandler(val world: World, val type: KCla override fun handle(event: T) = handleProxy(event.player, event) override fun register() = world.listenFor(type.java, this) - } /** @@ -134,7 +130,6 @@ class KotlinEventHandler(val world: World, val type: KClass) : Eve } fun register() = world.listenFor(type.java, this) - } /** @@ -148,7 +143,6 @@ class KotlinMessageHandler(val world: World, val context: PluginCon override fun handle(player: Player, message: T) = handleProxy(player, message) 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 register() = world.commandDispatcher.register(command, this) - } diff --git a/gradle/config/detekt.yml b/gradle/config/detekt.yml index 774cafc7..493cd78b 100644 --- a/gradle/config/detekt.yml +++ b/gradle/config/detekt.yml @@ -257,7 +257,7 @@ formatting: active: true autoCorrect: true NoWildcardImports: - active: true + active: false autoCorrect: true ParameterListWrapping: active: true @@ -304,10 +304,11 @@ naming: minimumFunctionNameLength: 3 FunctionNaming: 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: '$^' MatchingDeclarationName: active: true + autoCorrect: true MemberNameEqualsClassName: active: false ignoreOverriddenFunction: true @@ -317,7 +318,7 @@ naming: constantPattern: '[A-Za-z][_A-Za-z0-9]*' PackageNaming: active: true - packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' + packagePattern: '^[a-z]+(\.[a-z][a-zA-Z0-9]*)*$' TopLevelPropertyNaming: active: false constantPattern: '[A-Z][_A-Z0-9]*' @@ -470,5 +471,5 @@ style: VarCouldBeVal: active: false WildcardImport: - active: true + active: false excludeImports: 'java.util.*,kotlinx.android.synthetic.*'