Add tests for player actions

This commit is contained in:
Major-
2018-08-20 22:01:09 +01:00
parent d4de32c82c
commit 2080e1e700
6 changed files with 76 additions and 23 deletions
@@ -3,35 +3,29 @@ package org.apollo.game.plugin.entity.player_action
import org.apollo.game.message.impl.SetPlayerActionMessage
import org.apollo.game.model.entity.Player
import org.apollo.game.model.event.PlayerEvent
import java.util.EnumSet
enum class PlayerActionType(val displayName: String, val slot: Int, val primary: Boolean = true) {
ATTACK("Attack", 2),
CHALLENGE("Challenge", 2),
FOLLOW("Follow", 4),
TRADE("Trade with", 5)
}
import java.util.*
class PlayerActionEvent(player: Player, val target: Player, val action: PlayerActionType) : PlayerEvent(player)
private val playerActionsMap = mutableMapOf<Player, EnumSet<PlayerActionType>>()
private val Player.actions: EnumSet<PlayerActionType>
get() = playerActionsMap.computeIfAbsent(this, { EnumSet.noneOf(PlayerActionType::class.java) })
fun Player.enableAction(action: PlayerActionType) {
send(SetPlayerActionMessage(action.displayName, action.slot, action.primary))
actions.add(action)
actions += action
}
fun Player.disableAction(action: PlayerActionType) {
send(SetPlayerActionMessage("null", action.slot, action.primary))
actions.remove(action)
actions -= action
}
fun Player.actionEnabled(action: PlayerActionType): Boolean {
return actions.contains(action)
return action in actions
}
fun Player.actionAt(slot: Int): PlayerActionType? {
return actions.find { it.slot == slot }
}
}
private val playerActionsMap = mutableMapOf<Player, EnumSet<PlayerActionType>>()
private val Player.actions: EnumSet<PlayerActionType>
get() = playerActionsMap.computeIfAbsent(this) { EnumSet.noneOf(PlayerActionType::class.java) }
@@ -0,0 +1,8 @@
package org.apollo.game.plugin.entity.player_action
enum class PlayerActionType(val displayName: String, val slot: Int, val primary: Boolean = true) {
ATTACK("Attack", 2),
CHALLENGE("Challenge", 2),
FOLLOW("Follow", 4),
TRADE("Trade with", 5)
}
@@ -1,9 +1,7 @@
package org.apollo.game.plugin.entity.player_action
import org.apollo.game.message.impl.PlayerActionMessage
import org.apollo.game.model.event.impl.LoginEvent
import org.apollo.game.plugin.entity.player_action.PlayerActionEvent
import org.apollo.game.plugin.entity.player_action.PlayerActionType
import org.apollo.game.plugin.entity.player_action.actionAt
import org.apollo.game.plugin.entity.player_action.enableAction
on { PlayerActionMessage::class }
.then {