mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Repackage api plugin
This commit is contained in:
+10
-8
@@ -3,6 +3,7 @@ package org.apollo.game.plugin.api
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.cache.def.ObjectDefinition
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
object Definitions {
|
||||
fun item(id: Int): ItemDefinition? {
|
||||
@@ -22,11 +23,7 @@ object Definitions {
|
||||
}
|
||||
|
||||
fun npc(id: Int): NpcDefinition? {
|
||||
try {
|
||||
return NpcDefinition.lookup(id)
|
||||
} catch (e: NullPointerException) {
|
||||
throw RuntimeException("Failed to find npc $id: count=${NpcDefinition.count()}")
|
||||
}
|
||||
return NpcDefinition.lookup(id)
|
||||
}
|
||||
|
||||
fun npc(name: String): NpcDefinition? {
|
||||
@@ -43,11 +40,16 @@ object Definitions {
|
||||
nameSupplier: T.() -> String,
|
||||
name: String
|
||||
): T? {
|
||||
val definitions = definitionsProvider.invoke()
|
||||
val definitions = definitionsProvider()
|
||||
|
||||
if (ID_REGEX matches name) {
|
||||
val id = name.substring(name.lastIndexOf('_') + 1, name.length).toInt()
|
||||
return definitions.getOrNull(id)
|
||||
val id = name.substring(name.lastIndexOf('_') + 1, name.length).toIntOrNull()
|
||||
|
||||
if (id == null || id >= definitions.size) {
|
||||
throw IllegalArgumentException("Error while searching for definition: invalid id suffix in $name.")
|
||||
}
|
||||
|
||||
return definitions[id]
|
||||
}
|
||||
|
||||
val normalizedName = name.replace('_', ' ')
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.apollo.game.plugins.api
|
||||
package org.apollo.game.plugin.api
|
||||
|
||||
import org.apollo.game.model.Position
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.apollo.game.plugin.api
|
||||
|
||||
import java.util.*
|
||||
|
||||
public val RAND = Random()
|
||||
val RAND = Random()
|
||||
|
||||
fun rand(bounds: Int): Int {
|
||||
return RAND.nextInt(bounds)
|
||||
+21
-16
@@ -10,23 +10,34 @@ 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.scheduling.ScheduledTask
|
||||
import java.util.Optional
|
||||
import java.util.stream.Stream
|
||||
|
||||
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 <T : Entity> Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Sequence<T> {
|
||||
return getEntities<T>(position, *types).asSequence().filter(predicate)
|
||||
}
|
||||
|
||||
fun Region.findObjects(position: Position, id: Int): Stream<GameObject> {
|
||||
fun Region.findObjects(position: Position, id: Int): Sequence<GameObject> {
|
||||
return find(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
}
|
||||
|
||||
fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
|
||||
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
.findFirst()
|
||||
fun Region.findObject(position: Position, id: Int): GameObject? {
|
||||
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT).firstOrNull()
|
||||
}
|
||||
|
||||
fun World.findObject(position: Position, objectId: Int): GameObject? {
|
||||
return regionRepository.fromPosition(position).findObject(position, objectId)
|
||||
}
|
||||
|
||||
fun World.findObjects(position: Position, id: Int): Sequence<GameObject> {
|
||||
return regionRepository.fromPosition(position).findObjects(position, id)
|
||||
}
|
||||
|
||||
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
|
||||
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation)
|
||||
|
||||
schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
|
||||
}
|
||||
|
||||
|
||||
class ExpireObjectTask(
|
||||
private val world: World,
|
||||
private val existing: GameObject,
|
||||
@@ -49,10 +60,4 @@ class ExpireObjectTask(
|
||||
stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
|
||||
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation)
|
||||
|
||||
schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.apollo.game.plugins.area
|
||||
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.plugins.api.Position.component1
|
||||
import org.apollo.game.plugins.api.Position.component2
|
||||
import org.apollo.game.plugins.api.Position.component3
|
||||
import org.apollo.game.plugin.api.Position.component1
|
||||
import org.apollo.game.plugin.api.Position.component2
|
||||
import org.apollo.game.plugin.api.Position.component3
|
||||
|
||||
/**
|
||||
* An area in the game world.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import com.google.common.primitives.Ints
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
import org.apollo.game.plugins.api.Position.component1
|
||||
import org.apollo.game.plugins.api.Position.component2
|
||||
import org.apollo.game.plugins.api.Position.component3
|
||||
import org.apollo.game.plugin.api.Position.component1
|
||||
import org.apollo.game.plugin.api.Position.component2
|
||||
import org.apollo.game.plugin.api.Position.component3
|
||||
|
||||
/**
|
||||
* Sends the player's position.
|
||||
@@ -75,35 +75,35 @@ on_command("tele", PrivilegeLevel.ADMINISTRATOR)
|
||||
}
|
||||
}
|
||||
|
||||
private val TELEPORT_DESTINATIONS = listOf(
|
||||
"alkharid" to Position(3292, 3171, 0),
|
||||
"ardougne" to Position(2662, 3304, 0),
|
||||
"barrows" to Position(3565, 3314, 0),
|
||||
"brimhaven" to Position(2802, 3179, 0),
|
||||
"burthorpe" to Position(2898, 3545, 0),
|
||||
"camelot" to Position(2757, 3478, 0),
|
||||
"canifis" to Position(3493, 3489, 0),
|
||||
"cw" to Position(2442, 3090, 0),
|
||||
"draynor" to Position(3082, 3249, 0),
|
||||
"duelarena" to Position(3370, 3267, 0),
|
||||
"edgeville" to Position(3087, 3504, 0),
|
||||
"entrana" to Position(2827, 3343, 0),
|
||||
"falador" to Position(2965, 3379, 0),
|
||||
"ge" to Position(3164, 3476, 0),
|
||||
"kbd" to Position(2273, 4680, 0),
|
||||
"keldagrim" to Position(2845, 10210, 0),
|
||||
"kq" to Position(3507, 9494, 0),
|
||||
"lumbridge" to Position(3222, 3219, 0),
|
||||
"lunar" to Position(2113, 3915, 0),
|
||||
"misc" to Position(2515, 3866, 0),
|
||||
"neit" to Position(2332, 3804, 0),
|
||||
"pc" to Position(2658, 2660, 0),
|
||||
"rellekka" to Position(2660, 3657, 0),
|
||||
"shilo" to Position(2852, 2955, 0),
|
||||
"taverley" to Position(2895, 3443, 0),
|
||||
"tutorial" to Position(3094, 3107, 0),
|
||||
"tzhaar" to Position(2480, 5175, 0),
|
||||
"varrock" to Position(3212, 3423, 0),
|
||||
"yanille" to Position(2605, 3096, 0),
|
||||
"zanaris" to Position(2452, 4473, 0)
|
||||
internal val TELEPORT_DESTINATIONS = listOf(
|
||||
"alkharid" to Position(3292, 3171),
|
||||
"ardougne" to Position(2662, 3304),
|
||||
"barrows" to Position(3565, 3314),
|
||||
"brimhaven" to Position(2802, 3179),
|
||||
"burthorpe" to Position(2898, 3545),
|
||||
"camelot" to Position(2757, 3478),
|
||||
"canifis" to Position(3493, 3489),
|
||||
"cw" to Position(2442, 3090),
|
||||
"draynor" to Position(3082, 3249),
|
||||
"duelarena" to Position(3370, 3267),
|
||||
"edgeville" to Position(3087, 3504),
|
||||
"entrana" to Position(2827, 3343),
|
||||
"falador" to Position(2965, 3379),
|
||||
"ge" to Position(3164, 3476),
|
||||
"kbd" to Position(2273, 4680),
|
||||
"keldagrim" to Position(2845, 10210),
|
||||
"kq" to Position(3507, 9494),
|
||||
"lumbridge" to Position(3222, 3219),
|
||||
"lunar" to Position(2113, 3915),
|
||||
"misc" to Position(2515, 3866),
|
||||
"neit" to Position(2332, 3804),
|
||||
"pc" to Position(2658, 2660),
|
||||
"rellekka" to Position(2660, 3657),
|
||||
"shilo" to Position(2852, 2955),
|
||||
"taverley" to Position(2895, 3443),
|
||||
"tutorial" to Position(3094, 3107),
|
||||
"tzhaar" to Position(2480, 5175),
|
||||
"varrock" to Position(3212, 3423),
|
||||
"yanille" to Position(2605, 3096),
|
||||
"zanaris" to Position(2452, 4473)
|
||||
)
|
||||
@@ -10,7 +10,7 @@ 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 java.util.*
|
||||
|
||||
enum class DoorType {
|
||||
LEFT, RIGHT, NOT_SUPPORTED
|
||||
@@ -34,7 +34,7 @@ class Door(private val gameObject: GameObject) {
|
||||
Direction.EAST to Direction.SOUTH
|
||||
)
|
||||
|
||||
val toggledDoors: HashMap<GameObject, GameObject> = hashMapOf()
|
||||
val toggledDoors = hashMapOf<GameObject, GameObject>()
|
||||
|
||||
val LEFT_HINGED = setOf(1516, 1536, 1533)
|
||||
|
||||
@@ -47,13 +47,7 @@ class Door(private val gameObject: GameObject) {
|
||||
* @param objectId The [GameObject] id of the door
|
||||
*/
|
||||
fun find(world: World, position: Position, objectId: Int): Door? {
|
||||
val region = world.regionRepository.fromPosition(position)
|
||||
val gameObject = region.findObject(position, objectId).orElseGet(null)
|
||||
return if (gameObject == null) {
|
||||
null
|
||||
} else {
|
||||
Door(gameObject)
|
||||
}
|
||||
return world.findObject(position, objectId)?.let(::Door)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +82,7 @@ class Door(private val gameObject: GameObject) {
|
||||
|
||||
regionRepository.fromPosition(gameObject.position).removeEntity(gameObject)
|
||||
|
||||
val originalDoor: GameObject? = toggledDoors[gameObject]
|
||||
val originalDoor = toggledDoors[gameObject]
|
||||
|
||||
if (originalDoor == null) {
|
||||
val position = movePosition()
|
||||
@@ -98,7 +92,7 @@ class Door(private val gameObject: GameObject) {
|
||||
orientation)
|
||||
|
||||
regionRepository.fromPosition(position).addEntity(toggledDoor)
|
||||
toggledDoors.put(toggledDoor, gameObject)
|
||||
toggledDoors[toggledDoor] = gameObject
|
||||
} else {
|
||||
toggledDoors.remove(gameObject)
|
||||
regionRepository.fromPosition(originalDoor.position).addEntity(originalDoor)
|
||||
@@ -119,6 +113,7 @@ class Door(private val gameObject: GameObject) {
|
||||
*/
|
||||
private fun translateDirection(): Direction? {
|
||||
val direction = Direction.WNES[gameObject.orientation]
|
||||
|
||||
return when (type()) {
|
||||
DoorType.LEFT -> LEFT_HINGE_ORIENTATION[direction]
|
||||
DoorType.RIGHT -> RIGHT_HINGE_ORIENTATION[direction]
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.apollo.game.message.impl.ObjectActionMessage
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.plugin.api.*
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
@@ -88,22 +87,14 @@ class MiningAction(
|
||||
|
||||
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||
|
||||
/**
|
||||
* Get the [GameObject] represented by this target.
|
||||
*
|
||||
* @todo: api: shouldn't be as verbose
|
||||
*/
|
||||
private fun getObject(world: World): GameObject? {
|
||||
val region = world.regionRepository.fromPosition(position)
|
||||
return region.findObject(position, objectId).orElse(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deplete this mining resource from the [World], and schedule it to be respawned
|
||||
* in a number of ticks specified by the [Ore].
|
||||
*/
|
||||
fun deplete(world: World) {
|
||||
world.expireObject(getObject(world)!!, ore.objects[objectId]!!, ore.respawn)
|
||||
val obj = world.findObject(position, objectId)!!
|
||||
|
||||
world.expireObject(obj, ore.objects[objectId]!!, ore.respawn)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +108,7 @@ data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore)
|
||||
/**
|
||||
* Check if this target is still valid in the [World] (i.e. has not been [deplete]d).
|
||||
*/
|
||||
fun isValid(world: World) = getObject(world) != null
|
||||
fun isValid(world: World) = world.findObject(position, objectId) != null
|
||||
|
||||
/**
|
||||
* Get the normalized name of the [Ore] represented by this target.
|
||||
@@ -142,5 +133,6 @@ data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore)
|
||||
* this [MiningTarget].
|
||||
*/
|
||||
fun skillRequirementsMet(mob: Player) = mob.mining.current < ore.level
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,7 @@ import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.plugin.api.Definitions
|
||||
import org.apollo.game.plugin.api.expireObject
|
||||
import org.apollo.game.plugin.api.findObject
|
||||
import org.apollo.game.plugin.api.rand
|
||||
import org.apollo.game.plugin.api.woodcutting
|
||||
import org.apollo.game.plugin.api.*
|
||||
import org.apollo.game.plugin.skills.woodcutting.Axe
|
||||
import org.apollo.game.plugin.skills.woodcutting.Tree
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -30,8 +26,7 @@ class WoodcuttingTarget(private val objectId: Int, val position: Position, val t
|
||||
* Get the tree object in the world
|
||||
*/
|
||||
fun getObject(world: World): GameObject? {
|
||||
val region = world.regionRepository.fromPosition(position)
|
||||
return region.findObject(position, objectId).orElse(null)
|
||||
return world.findObject(position, objectId)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user