mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 00:38:11 +00:00
Remove plugins.gradle and factor into common extension
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
apolloPlugin {
|
||||
name = "following"
|
||||
packageName = "org.apollo.game.plugin.entity"
|
||||
authors = [
|
||||
"Gary Tierney",
|
||||
]
|
||||
dependencies = [
|
||||
"walkto",
|
||||
"command_utilities",
|
||||
"player_action",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name = "following"
|
||||
package = "org.apollo.game.plugin.entity"
|
||||
authors = [ "Gary Tierney" ]
|
||||
dependencies = [ "walkto", "command_utilities", "player_action"]
|
||||
|
||||
[config]
|
||||
srcDir = "src/"
|
||||
testDir = "test/"
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.apollo.plugin.entity.following
|
||||
|
||||
import org.apollo.game.action.Action
|
||||
import org.apollo.game.model.Direction
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.entity.Mob
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.net.message.Message
|
||||
import org.apollo.plugin.entity.walkto.walkBehind
|
||||
import org.apollo.plugin.entity.walkto.walkTo
|
||||
|
||||
class FollowAction(player: Player, val target: Player) : Action<Player>(0, true, player) {
|
||||
var lastPosition: Position? = null
|
||||
|
||||
companion object {
|
||||
fun start(player: Player, target: Player, message: Message? = null) {
|
||||
player.startAction(FollowAction(player, target))
|
||||
message?.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
if (!target.isActive) {
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
mob.interactingMob = target
|
||||
|
||||
if (target.position == lastPosition) {
|
||||
return
|
||||
}
|
||||
|
||||
val distance = mob.position.getDistance(target.position)
|
||||
if (distance >= 15) {
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
if (mob.position == target.position) {
|
||||
val directions = Direction.NESW
|
||||
val directionOffset = (Math.random() * directions.size).toInt()
|
||||
|
||||
mob.walkTo(target.position.step(1, directions[directionOffset]))
|
||||
return
|
||||
}
|
||||
|
||||
mob.walkBehind(target)
|
||||
lastPosition = target.position
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import com.google.common.primitives.Ints
|
||||
import org.apollo.game.message.impl.PlayerActionMessage
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
import org.apollo.plugin.entity.following.FollowAction
|
||||
|
||||
on_player_event { PlayerActionEvent::class }
|
||||
.where { action == PlayerActionType.FOLLOW }
|
||||
.then {
|
||||
FollowAction.start(it, target)
|
||||
terminate()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
apolloPlugin {
|
||||
name = "player_action"
|
||||
packageName = "org.apollo.game.plugin.entity"
|
||||
authors = [
|
||||
"Gary Tierney",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name = "player_action"
|
||||
package = "org.apollo.game.plugin.entity"
|
||||
authors = [ "Gary Tierney" ]
|
||||
dependencies = []
|
||||
|
||||
[config]
|
||||
srcDir = "src/"
|
||||
testDir = "test/"
|
||||
@@ -0,0 +1,35 @@
|
||||
import org.apollo.game.message.impl.SetPlayerActionMessage
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.event.PlayerEvent
|
||||
import java.util.*
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
fun Player.disableAction(action: PlayerActionType) {
|
||||
send(SetPlayerActionMessage("null", action.slot, action.primary))
|
||||
actions.remove(action)
|
||||
}
|
||||
|
||||
fun Player.actionEnabled(action: PlayerActionType): Boolean {
|
||||
return actions.contains(action)
|
||||
}
|
||||
|
||||
fun Player.actionAt(slot: Int): PlayerActionType? {
|
||||
return actions.find { it.slot == slot }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
apolloPlugin {
|
||||
name = "spawning"
|
||||
packageName = "org.apollo.game.plugin.entity"
|
||||
authors = [
|
||||
"Gary Tierney",
|
||||
]
|
||||
dependencies = [
|
||||
"entity_lookup",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name = "spawning"
|
||||
package = "org.apollo.game.plugin.entity"
|
||||
authors = [ "Gary Tierney" ]
|
||||
dependencies = [ "entity_lookup" ]
|
||||
|
||||
[config]
|
||||
srcDir = "src/"
|
||||
testDir = "test/"
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.apollo.game.model.*
|
||||
|
||||
data class Spawn(val id: Int?, val name: String, val position: Position, val facing: Direction,
|
||||
val spawnAnimation: Animation? = null,
|
||||
val spawnGraphic: Graphic? = null)
|
||||
|
||||
object Spawns {
|
||||
val list = mutableListOf<Spawn>()
|
||||
}
|
||||
|
||||
fun npc_spawn(name: String, x: Int, y: Int, z: Int = 0, id: Int? = null, facing: Direction = Direction.NORTH) {
|
||||
Spawns.list.add(Spawn(id, name, Position(x, y, z), facing))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.game.model.entity.Npc
|
||||
|
||||
start { world ->
|
||||
Spawns.list.forEach {
|
||||
val definition = if (it.id != null) NpcDefinition.lookup(it.id!!) else lookup_npc(it.name)
|
||||
if (definition == null) {
|
||||
throw IllegalArgumentException("Invalid NPC name or ID ${it.name}, ${it.id}")
|
||||
}
|
||||
|
||||
val npc = Npc(world, definition.id, it.position)
|
||||
npc.turnTo(it.position.step(1, it.facing))
|
||||
|
||||
if (it.spawnAnimation != null) {
|
||||
npc.playAnimation(it.spawnAnimation)
|
||||
}
|
||||
|
||||
if (it.spawnGraphic != null) {
|
||||
npc.playGraphic(it.spawnGraphic)
|
||||
}
|
||||
|
||||
world.register(npc)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
apolloPlugin {
|
||||
name = "walkto"
|
||||
packageName = "org.apollo.plugin.entity.walkto"
|
||||
authors = [
|
||||
"Gary Tierney",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "walkto"
|
||||
package = "org.apollo.plugin.entity.walkto"
|
||||
authors = ["Gary Tierney"]
|
||||
dependencies = []
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.apollo.plugin.entity.walkto
|
||||
|
||||
import org.apollo.game.model.Direction
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.entity.*
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm
|
||||
|
||||
private fun bounds(target: Entity): Pair<Int, Int> = when (target) {
|
||||
is GameObject -> {
|
||||
val orientation = Direction.WNES[target.orientation]
|
||||
val rotated = (orientation == Direction.WEST || orientation == Direction.EAST)
|
||||
|
||||
val width = if (rotated) target.definition.length else target.definition.width
|
||||
val height = if (rotated) target.definition.width else target.definition.length
|
||||
|
||||
Pair(width, height)
|
||||
}
|
||||
is Npc -> Pair(target.definition.size, target.definition.size)
|
||||
is Player -> Pair(1, 1)
|
||||
else -> error("Invalid entity type")
|
||||
}
|
||||
|
||||
fun Mob.walkTo(target: Entity, positioningDirection: Direction? = null) {
|
||||
val (sourceWidth, sourceHeight) = bounds(target)
|
||||
val (targetWidth, targetHeight) = bounds(target)
|
||||
|
||||
val direction = positioningDirection ?: Direction.between(position, target.position)
|
||||
val dx = direction.deltaX()
|
||||
val dy = direction.deltaY()
|
||||
|
||||
val targetX = if (dx <= 0) target.position.x else target.position.x + targetWidth - 1
|
||||
val targetY = if (dy <= 0) target.position.y else target.position.y + targetHeight - 1
|
||||
val offsetX = if (dx < 0) -sourceWidth else if (dx > 0) 1 else 0
|
||||
val offsetY = if (dy < 0) -sourceHeight else if (dy > 0) 1 else 0
|
||||
|
||||
walkTo(Position(targetX + offsetX, targetY + offsetY, position.height))
|
||||
}
|
||||
|
||||
fun Mob.walkBehind(target: Mob) {
|
||||
walkTo(target, target.lastDirection.opposite())
|
||||
}
|
||||
|
||||
fun Mob.walkTo(target: Position, positionPredicate: (Position) -> Boolean = { true }) {
|
||||
if (position == target) {
|
||||
return
|
||||
}
|
||||
|
||||
val pathfinder = SimplePathfindingAlgorithm(world.collisionManager)
|
||||
val path = pathfinder.find(position, target)
|
||||
|
||||
for (step in path) {
|
||||
if (!positionPredicate.invoke(step)) {
|
||||
return
|
||||
}
|
||||
|
||||
walkingQueue.addStep(step)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user