Skip to content

rift.world

inline fun <reified T : Entity> WorldSpatialIndex.entitiesWithin(
center: Tile3,
radius: Int,
shard: Int = WorldSpatialIndex.GLOBAL,
noinline predicate: (T) -> Boolean = { true }
): List<T>
fun WorldSpatialIndex.entitiesWithin(
center: Tile3,
radius: Int,
vararg types: KClass<out Entity>,
shard: Int = WorldSpatialIndex.GLOBAL,
predicate: (Entity) -> Boolean = { true }
): List<Entity>
Example
on_input<DeveloperCommandInput> { player ->
if (name != "near") return@on_input
val here = player.tile4
val near = World.spatial.entitiesWithin<Entity>(here.tile, radius = 5, shard = here.shard)
player.message("${near.size} things within 5 tiles.")
}
fun WorldSpatialIndex.npcsWithin(
center: Tile3,
radius: Int,
shard: Int = WorldSpatialIndex.GLOBAL,
predicate: (Npc) -> Boolean = { true }
): List<Npc>
Example
on_npc_option(Assets.Npc.hans.id, "Shout") { player ->
val here = target.tile4
val goblins = World.spatial.npcsWithin(here.tile, radius = 8, shard = here.shard)
goblins.forEach { it.speak("Coming!") }
}
fun placeRecoveredKey(): String
Example
on_event<PlaceRecovered>(placeRecoveredKey()) { subject ->
Logger.info("${subject.uuid} was moved off its saved tile")
}
fun WorldSpatialIndex.playersWithin(
center: Tile3,
radius: Int,
shard: Int = WorldSpatialIndex.GLOBAL,
predicate: (Actor) -> Boolean = { true }
): List<Actor>
Example
on_object_option(Assets.WorldObject.poordoor, "Ring-bell") { player ->
val here = target.tile4
World.spatial.playersWithin(here.tile, radius = 10, shard = here.shard).forEach { it.message("Someone is at the door.") }
}
fun WorldSpatialIndex.projectionsWithin(
center: Tile3,
radius: Int,
shard: Int = WorldSpatialIndex.GLOBAL,
predicate: (WorldProjection) -> Boolean = { true }
): List<WorldProjection>
Example
on_input<DeveloperCommandInput> { player ->
if (name != "boats") return@on_input
val here = player.tile4
val boats = World.spatial.projectionsWithin(here.tile, radius = 30, shard = here.shard)
player.message("${boats.size} world projections within 30 tiles.")
}
val worldNumber: Int
Example
on_login { player ->
player.message("Welcome to realm $worldNumber.")
}
val RiftPackage.worldRecords: WorldRecords
Example
import rift.ecs.Persist
import rift.ecs.Persistent
@Persistent class Signature(@Persist val text: String = "")
on_object_option(Assets.WorldObject.poordoor, "Sign") { player ->
val book = Game.worldRecords.collection<Signature>()
book.put(player.uuid.toString(), Signature("Was here."))
player.message("You sign the guestbook (${book.keys().size} signatures).")
}