Add packages to plugins

This commit is contained in:
Major
2017-09-24 22:35:07 +01:00
parent b4e8a7136b
commit 046f373c9e
32 changed files with 398 additions and 366 deletions
@@ -1,4 +1,4 @@
package org.apollo.game.plugins.api
package org.apollo.game.plugin.api
import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition
@@ -1,4 +1,6 @@
import java.util.*
package org.apollo.game.plugin.api
import java.util.Random
val RAND = Random()
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.api
import org.apollo.game.model.Position
import org.apollo.game.model.World
import org.apollo.game.model.area.Region
@@ -7,21 +9,17 @@ import org.apollo.game.model.entity.EntityType.DYNAMIC_OBJECT
import org.apollo.game.model.entity.EntityType.STATIC_OBJECT
import org.apollo.game.model.entity.obj.DynamicGameObject
import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.model.entity.obj.StaticGameObject
import org.apollo.game.scheduling.ScheduledTask
import java.lang.IllegalArgumentException
import java.util.*
import java.util.Optional
import java.util.stream.Stream
fun <T : Entity> Region.find(position: Position, pred: (T) -> Boolean, vararg types: EntityType): Stream<T> {
val result = this.getEntities<T>(position, *types)
return result.stream()
.filter(pred::invoke)
fun <T : Entity> Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Stream<T> {
val result = getEntities<T>(position, *types)
return result.stream().filter(predicate::invoke)
}
fun Region.findObjects(position: Position, id: Int): Stream<GameObject> {
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
return find(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
}
fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
@@ -30,16 +28,16 @@ fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
}
class ExpireObjectTask(
val world: World,
val obj: GameObject,
val replacement: GameObject,
val respawnDelay: Int
private val world: World,
private val existing: GameObject,
private val replacement: GameObject,
private val respawnDelay: Int
) : ScheduledTask(0, true) {
private var respawning: Boolean = false
override fun execute() {
val region = world.regionRepository.fromPosition(obj.position)
val region = world.regionRepository.fromPosition(existing.position)
if (!respawning) {
world.spawn(replacement)
@@ -47,7 +45,7 @@ class ExpireObjectTask(
setDelay(respawnDelay)
} else {
region.removeEntity(replacement)
world.spawn(obj)
world.spawn(existing)
stop()
}
}
@@ -55,7 +53,6 @@ class ExpireObjectTask(
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation)
val respawnedObj = DynamicGameObject.createPublic(this, obj.id, obj.position, obj.type, obj.orientation)
schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
}
+2 -1
View File
@@ -1,11 +1,12 @@
import com.google.common.primitives.Ints
import org.apollo.game.model.Animation
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("animate", PrivilegeLevel.MODERATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
if(valid_arg_length(arguments, 1, player, invalidSyntax)) {
if (valid_arg_length(arguments, 1, player, invalidSyntax)) {
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
+1
View File
@@ -1,6 +1,7 @@
import com.google.common.primitives.Ints
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("item", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
+1
View File
@@ -3,6 +3,7 @@ import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
@@ -1,4 +1,3 @@
import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.setting.PrivilegeLevel
-1
View File
@@ -1,4 +1,3 @@
import com.google.common.primitives.Doubles
import com.google.common.primitives.Ints
import org.apollo.game.model.entity.Skill
@@ -1,6 +1,7 @@
import com.google.common.primitives.Ints
import org.apollo.game.model.Position
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
/**
* Sends the player's position.
@@ -1,9 +1,7 @@
import com.google.common.primitives.Ints
import org.apollo.game.message.impl.PlayerActionMessage
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.entity.player_action.PlayerActionType
import org.apollo.plugin.entity.following.FollowAction
on_player_event { PlayerActionEvent::class }
on_player_event { org.apollo.game.plugin.entity.player_action.PlayerActionEvent::class }
.where { action == PlayerActionType.FOLLOW }
.then {
FollowAction.start(it, target)
@@ -1,7 +1,9 @@
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.*
import java.util.EnumSet
enum class PlayerActionType(val displayName: String, val slot: Int, val primary: Boolean = true) {
ATTACK("Attack", 2),
@@ -1,5 +1,9 @@
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 {
+7 -3
View File
@@ -1,8 +1,12 @@
import org.apollo.game.model.*
package org.apollo.game.plugin.entity.spawn
import org.apollo.game.model.Animation
import org.apollo.game.model.Direction
import org.apollo.game.model.Graphic
import org.apollo.game.model.Position
data class Spawn(val id: Int?, val name: String, val position: Position, val facing: Direction,
val spawnAnimation: Animation? = null,
val spawnGraphic: Graphic? = null)
val spawnAnimation: Animation? = null, val spawnGraphic: Graphic? = null)
object Spawns {
val list = mutableListOf<Spawn>()
+5 -10
View File
@@ -1,23 +1,18 @@
import org.apollo.cache.def.NpcDefinition
import org.apollo.game.model.entity.Npc
import org.apollo.game.plugin.entity.spawn.Spawns
import org.apollo.game.plugin.util.lookup.lookup_npc
start { world ->
Spawns.list.forEach {
val definition = if (it.id != null) NpcDefinition.lookup(it.id!!) else lookup_npc(it.name)
if (definition == null) {
val definition = it.id?.let { NpcDefinition.lookup(it) } ?: lookup_npc(it.name) ?:
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)
}
it.spawnAnimation?.let(npc::playAnimation)
it.spawnGraphic?.let(npc::playGraphic)
world.register(npc)
}
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs
@@ -1,3 +1,4 @@
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs
@@ -1,3 +1,5 @@
import org.apollo.game.plugin.entity.spawn.npc_spawn
npc_spawn("woman", id = 4, x = 3232, y = 3207)
npc_spawn("man", id = 1, x = 3231, y = 3237)
npc_spawn("man", id = 2, x = 3224, y = 3240)
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Functional npcs
@@ -1,3 +1,5 @@
import org.apollo.game.plugin.shops.shop
shop("Aubury's Rune Shop.") {
operated by "Aubury"
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
npc_spawn("barbarian_woman", x = 3222, y = 3399)
+6 -4
View File
@@ -8,9 +8,9 @@ import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.obj.DynamicGameObject
import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.model.event.PlayerEvent
import org.apollo.game.plugin.api.findObject
import org.apollo.net.message.Message
import java.util.Objects
import findObject
enum class DoorType {
LEFT, RIGHT, NOT_SUPPORTED
@@ -94,7 +94,8 @@ class Door(private val gameObject: GameObject) {
val position = movePosition()
val orientation: Int = translateDirection()?.toOrientationInteger() ?: gameObject.orientation
val toggledDoor = DynamicGameObject.createPublic(world, gameObject.id, position, gameObject.type, orientation)
val toggledDoor = DynamicGameObject.createPublic(world, gameObject.id, position, gameObject.type,
orientation)
regionRepository.fromPosition(position).addEntity(toggledDoor)
toggledDoors.put(toggledDoor, gameObject)
@@ -118,7 +119,7 @@ class Door(private val gameObject: GameObject) {
*/
private fun translateDirection(): Direction? {
val direction = Direction.WNES[gameObject.orientation]
return when(type()) {
return when (type()) {
DoorType.LEFT -> LEFT_HINGE_ORIENTATION[direction]
DoorType.RIGHT -> RIGHT_HINGE_ORIENTATION[direction]
DoorType.NOT_SUPPORTED -> null
@@ -127,7 +128,8 @@ class Door(private val gameObject: GameObject) {
}
class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction<Player>(0, true, player, position, DISTANCE) {
class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction<Player>(
0, true, player, position, DISTANCE) {
companion object {
+2
View File
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.shops
import org.apollo.game.action.DistancedAction
import org.apollo.game.message.handler.ItemVerificationHandler.InventorySupplier
import org.apollo.game.message.impl.SetWidgetTextMessage
+5 -1
View File
@@ -1,5 +1,9 @@
import CategoryWrapper.Affix
package org.apollo.game.plugin.shops
import org.apollo.cache.def.NpcDefinition
import org.apollo.game.plugin.shops.CategoryWrapper.Affix
import org.apollo.game.plugin.util.lookup.lookup_item
import org.apollo.game.plugin.util.lookup.lookup_npc
import org.jetbrains.kotlin.utils.keysToMap
/**
+7 -5
View File
@@ -1,13 +1,15 @@
import Shop.Companion.ExchangeType.BUYING
import Shop.Companion.ExchangeType.SELLING
import Shop.PurchasePolicy.ANY
import Shop.PurchasePolicy.NOTHING
import Shop.PurchasePolicy.OWNED
package org.apollo.game.plugin.shops
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.Item
import org.apollo.game.model.entity.Player
import org.apollo.game.model.inv.Inventory
import org.apollo.game.model.inv.Inventory.StackMode.STACK_ALWAYS
import org.apollo.game.plugin.shops.Shop.Companion.ExchangeType.BUYING
import org.apollo.game.plugin.shops.Shop.Companion.ExchangeType.SELLING
import org.apollo.game.plugin.shops.Shop.PurchasePolicy.ANY
import org.apollo.game.plugin.shops.Shop.PurchasePolicy.NOTHING
import org.apollo.game.plugin.shops.Shop.PurchasePolicy.OWNED
/**
* Contains shop-related interface ids.
+5 -1
View File
@@ -1,8 +1,12 @@
import org.apollo.game.message.handler.ItemVerificationHandler
import org.apollo.game.message.impl.ItemActionMessage
import org.apollo.game.message.impl.NpcActionMessage
import org.apollo.game.model.entity.Mob
import org.apollo.game.plugin.shops.Interfaces
import org.apollo.game.plugin.shops.OpenShopAction
import org.apollo.game.plugin.shops.PlayerInventorySupplier
import org.apollo.game.plugin.shops.SHOPS
import org.apollo.game.plugin.shops.Shop
import org.apollo.game.scheduling.ScheduledTask
fun Mob.shop(): Shop? = SHOPS[definition.id]
+2 -1
View File
@@ -1,6 +1,7 @@
import org.apollo.game.model.Direction
import org.apollo.game.model.Position
import org.apollo.game.plugin.entity.spawn.Spawn
import org.apollo.game.plugin.entity.spawn.Spawns
import org.apollo.game.plugin.skills.fishing.FishingSpot
import org.apollo.game.plugin.skills.fishing.FishingSpot.CAGE_HARPOON
import org.apollo.game.plugin.skills.fishing.FishingSpot.NET_HARPOON
+2
View File
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.util.command
import org.apollo.game.model.entity.Player
/**
+2
View File
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.util.lookup
import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition