Remove plugins.gradle and factor into common extension

This commit is contained in:
Gary Tierney
2017-09-16 18:49:06 +01:00
parent d323bcd69c
commit 36282cf81e
104 changed files with 608 additions and 408 deletions
+7
View File
@@ -0,0 +1,7 @@
apolloPlugin {
name = "training-dummy"
packageName = "org.apollo.game.plugin.entity"
authors = [
"Gary Tierney",
]
}
+7
View File
@@ -0,0 +1,7 @@
name = "training-dummy"
package = "org.apollo.game.plugin.entity"
authors = [ "Gary Tierney" ]
[config]
srcDir = "src/"
testDir = "test/"
+71
View File
@@ -0,0 +1,71 @@
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.selects.select
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
import org.apollo.game.model.entity.*
import org.apollo.net.message.Message
/**
* A list of [ObjectDefinition] identifiers which are training dummies.
*/
val DUMMY_IDS = setOf<Int>(823)
on { ObjectActionMessage::class }
.where { option == 2 && id in DUMMY_IDS }
.then { DummyAction.start(this, it, position) }
class DummyAction(val player: Player, position: Position) : AsyncDistancedAction<Player>(0, true, player, position, DISTANCE) {
companion object {
/**
* The maximum level a player can be before the dummy stops giving XP.
*/
const val LEVEL_THRESHOLD = 8
/**
* The number of experience points per hit.
*/
const val EXP_PER_HIT = 5.0
/**
* The minimum distance a player can be from the dummy.
*/
const val DISTANCE = 1
/**
* The [Animation] played when a player hits a dummy.
*/
val PUNCH_ANIMATION = Animation(422)
/**
* Starts a [DummyAction] for the specified [Player], terminating the [Message] that triggered it.
*/
fun start(message: Message, player: Player, position: Position) {
player.startAction(DummyAction(player, position))
message.terminate()
}
}
override suspend fun executeActionAsync() {
mob.sendMessage("You hit the dummy.")
mob.turnTo(this.position)
mob.playAnimation(PUNCH_ANIMATION)
wait()
val skills = player.skillSet
if (skills.getSkill(Skill.ATTACK).maximumLevel >= LEVEL_THRESHOLD) {
player.sendMessage("There is nothing more you can learn from hitting a dummy.")
} else {
skills.addExperience(Skill.ATTACK, EXP_PER_HIT)
}
}
}
@@ -0,0 +1,43 @@
import org.apollo.game.model.Position
import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.testing.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.mockito.Mockito.contains
import org.mockito.Mockito.verify
class TrainingDummyTest : KotlinPluginTest() {
companion object {
const val DUMMY_ID = 823
val DUMMY_POSITION = Position(3200, 3230, 0)
}
@Test fun `Hitting the training dummy should give the player attack experience`() {
val dummy = world.spawnObject(DUMMY_ID, DUMMY_POSITION)
val skills = player.skillSet
val beforeExp = skills.getExperience(Skill.ATTACK)
player.interactWith(dummy, option = 2)
player.waitForActionCompletion()
val afterExp = skills.getExperience(Skill.ATTACK)
assertThat(afterExp).isGreaterThan(beforeExp)
}
@Test fun `The player should stop getting attack experience from the training dummy at level 8`() {
val dummy = world.spawnObject(DUMMY_ID, DUMMY_POSITION)
val skills = player.skillSet
skills.setMaximumLevel(Skill.ATTACK, 8)
val beforeExp = skills.getExperience(Skill.ATTACK)
player.interactWith(dummy, option = 2)
player.waitForActionCompletion()
val afterExp = skills.getExperience(Skill.ATTACK)
verify(player).sendMessage(contains("nothing more you can learn"))
assertThat(afterExp).isEqualTo(beforeExp)
}
}