Repackage player actions plugin

This commit is contained in:
Major-
2018-08-28 18:50:54 +01:00
parent c89179825c
commit 1a4724dcce
7 changed files with 7 additions and 9 deletions
@@ -0,0 +1,31 @@
package org.apollo.game.plugin.entity.actions
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))
actions += action
}
fun Player.disableAction(action: PlayerActionType) {
send(SetPlayerActionMessage("null", action.slot, action.primary))
actions -= action
}
fun Player.actionEnabled(action: PlayerActionType): Boolean {
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.actions
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)
}
@@ -0,0 +1,20 @@
package org.apollo.game.plugin.entity.actions
import org.apollo.game.message.impl.PlayerActionMessage
import org.apollo.game.model.event.impl.LoginEvent
on { PlayerActionMessage::class }
.then {
val action = it.actionAt(option)
if (action != null) {
it.world.submit(PlayerActionEvent(it, it.world.playerRepository[index], action))
}
terminate()
}
on_player_event { LoginEvent::class }
.then {
it.enableAction(PlayerActionType.FOLLOW)
it.enableAction(PlayerActionType.TRADE)
}