diff --git a/build.gradle b/build.gradle index bdaa13e1..a9cb46d6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,15 @@ allprojects { group = 'apollo' version = '0.0.1' - apply plugin: 'java' +} + +ext { + kotlinVersion = '1.1.2-4' } subprojects { + apply plugin: 'java' + sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -41,8 +46,9 @@ subprojects { } } -task(run, dependsOn: classes, type: JavaExec) { - def gameSubproject = project(':game') +def gameSubproject = project(':game') + +task(run, dependsOn: gameSubproject.tasks['classes'], type: JavaExec) { def gameClasspath = gameSubproject.sourceSets.main.runtimeClasspath main = 'org.apollo.Server' diff --git a/game/build.gradle b/game/build.gradle index 15e9fbb8..c380c06a 100644 --- a/game/build.gradle +++ b/game/build.gradle @@ -1,8 +1,6 @@ description = 'Apollo Game' buildscript { - ext.kotlinVersion = '1.1.2-4' - repositories { mavenCentral() } @@ -14,19 +12,22 @@ buildscript { apply plugin: 'kotlin' +sourceSets { + main.kotlin.srcDirs += 'src/kotlin' + + plugins { + kotlin.srcDirs += 'data/plugins' + } +} + dependencies { compile project(':cache') compile project(':net') compile project(':util') - compile group: 'org.jetbrains.kotlin', name: 'kotlin-compiler', version: $kotlinVersion - compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: $kotlinVersion -} + pluginsCompile(configurations.compile) + pluginsCompile(sourceSets.main.output) -sourceSets { - main.kotlin.srcDirs += 'src/kotlin' -} - -repositories { - mavenCentral() + compile group: 'org.jetbrains.kotlin', name: 'kotlin-compiler', version: "$kotlinVersion" + compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: "$kotlinVersion" } diff --git a/game/data/plugins/bank/bank.plugin.kts b/game/data/plugins/bank/bank.plugin.kts new file mode 100644 index 00000000..929ffacd --- /dev/null +++ b/game/data/plugins/bank/bank.plugin.kts @@ -0,0 +1,75 @@ +import org.apollo.game.action.DistancedAction +import org.apollo.game.message.impl.NpcActionMessage +import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.model.Position +import org.apollo.game.model.entity.Npc +import org.apollo.game.model.entity.Player +import org.apollo.game.model.inter.bank.BankUtils +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. + */ +on { ObjectActionMessage::class } + .where { option == 2 && id == BANK_BOOTH_ID } + .then { BankAction.start(this, it, position) } + +/** + * Hook into the [NpcActionMessage] and listen for when a banker's second action ("Open Bank") is selected. + */ +on { NpcActionMessage::class } + .where { option == 2 } + .then { + val npc: Npc = Any() as Npc // TODO world.npcRepository.get(index) + + if (npc.id in BANKER_NPCS) { + BankAction.start(this, it, npc.position) + } + } + +/** + * The ids of all banker [Npcs][Npc]. + */ +val BANKER_NPCS = setOf(166, 494, 495, 496, 497, 498, 499, 1036, 1360, 1702, 2163, 2164, 2354, 2355, 2568, 2569, 2570) + +/** + * A [DistancedAction] that opens a [Player]'s bank when they get close enough to a booth or banker. + * + * @property position The [Position] of the booth/[Npc]. + */ +class BankAction(player: Player, position: Position) : DistancedAction(0, true, player, position, DISTANCE) { + + companion object { + + /** + * The distance threshold that must be reached before the bank interface is opened. + */ + const val DISTANCE = 1 + + /** + * Starts a [BankAction] for the specified [Player], terminating the [Message] that triggered. + */ + fun start(message: Message, player: Player, position: Position) { + player.startAction(BankAction(player, position)) + message.terminate() + } + + } + + override fun executeAction() { + mob.turnTo(position) + BankUtils.openBank(mob) + stop() + } + + override fun equals(other: Any?): Boolean { + return other is BankAction && position == other.position + } + + override fun hashCode(): Int { + return position.hashCode() + } + +} diff --git a/game/data/plugins/bank/plugin.xml b/game/data/plugins/bank/plugin.xml new file mode 100644 index 00000000..4402e5f0 --- /dev/null +++ b/game/data/plugins/bank/plugin.xml @@ -0,0 +1,14 @@ + + + bank + 1 + Bank + Opens the bank interface when players select 'use-quickly' on a bank booth. + + Major + + + + + + diff --git a/game/data/plugins/dialogue/dialogue.plugin.kts b/game/data/plugins/dialogue/dialogue.plugin.kts new file mode 100644 index 00000000..e69de29b diff --git a/game/data/plugins/dialogue/plugin.xml b/game/data/plugins/dialogue/plugin.xml new file mode 100644 index 00000000..e69de29b diff --git a/game/data/plugins/stub.kt b/game/data/plugins/stub.kt new file mode 100644 index 00000000..4e6fe63f --- /dev/null +++ b/game/data/plugins/stub.kt @@ -0,0 +1,20 @@ +/** + * NOTE: This file is a stub, intended only for use within an IDE. It should be updated + * each time [org.apollo.game.plugin.kotlin.KotlinPluginScript] has a new method added to it. + * + * Until IntelliJ IDEA starts to support ScriptTemplateDefinitions this is + * required to resolve references within plugin code. + */ + +import org.apollo.game.model.World +import org.apollo.game.plugin.PluginContext +import org.apollo.game.plugin.kotlin.KotlinMessageHandler +import org.apollo.net.message.Message +import kotlin.reflect.KClass + +val world: World = null!! +var context: PluginContext = null!! + +fun on(type: () -> KClass): KotlinMessageHandler { + null!! +} \ No newline at end of file diff --git a/game/src/main/org/apollo/game/plugin/PluginManager.java b/game/src/main/org/apollo/game/plugin/PluginManager.java index 2e498785..d816a733 100644 --- a/game/src/main/org/apollo/game/plugin/PluginManager.java +++ b/game/src/main/org/apollo/game/plugin/PluginManager.java @@ -72,7 +72,7 @@ public final class PluginManager { * @throws SAXException If a SAX error occurs. */ private Collection findPlugins() throws IOException, SAXException { - return findPlugins(new File("./data/plugins")); + return findPlugins(new File("./game/data/plugins")); } /**