mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add packages to plugins
This commit is contained in:
+1
-1
@@ -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
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
import java.util.*
|
||||
package org.apollo.game.plugin.api
|
||||
|
||||
import java.util.Random
|
||||
|
||||
val RAND = Random()
|
||||
|
||||
+14
-17
@@ -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,39 +9,35 @@ 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> {
|
||||
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
.findFirst()
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
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)) {
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
player.playAnimation(Animation(id))
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
|
||||
if (valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
}
|
||||
|
||||
player.playAnimation(Animation(id))
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,4 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
|
||||
// Opens the player's bank if they are an administrator.
|
||||
on_command("bank", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player -> player.openBank() }
|
||||
.then { player -> player.openBank() }
|
||||
@@ -1,39 +1,40 @@
|
||||
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 ->
|
||||
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
|
||||
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
|
||||
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
var amount = 1
|
||||
if (arguments.size == 2) {
|
||||
val amt = Ints.tryParse(arguments[1])
|
||||
if (amt == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
amount = amt
|
||||
}
|
||||
|
||||
var amount = 1
|
||||
if (arguments.size == 2) {
|
||||
val amt = Ints.tryParse(arguments[1])
|
||||
if (amt == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
amount = amt
|
||||
}
|
||||
if (id < 0 || id >= ItemDefinition.count()) {
|
||||
player.sendMessage("The item id you specified is out of bounds!")
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id < 0 || id >= ItemDefinition.count()) {
|
||||
player.sendMessage("The item id you specified is out of bounds!")
|
||||
return@then
|
||||
}
|
||||
if (amount < 0) {
|
||||
player.sendMessage("The amount you specified is out of bounds!")
|
||||
return@then
|
||||
}
|
||||
|
||||
if (amount < 0) {
|
||||
player.sendMessage("The amount you specified is out of bounds!")
|
||||
return@then
|
||||
}
|
||||
|
||||
player.inventory.add(id, amount)
|
||||
}
|
||||
player.inventory.add(id, amount)
|
||||
}
|
||||
@@ -3,64 +3,65 @@ 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 ->
|
||||
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val definition = ItemDefinition.lookup(id)
|
||||
val members = if (definition.isMembersOnly) "members" else "not members"
|
||||
|
||||
player.sendMessage("Item $id is called ${definition.name}, is $members only, and has a " +
|
||||
"team of ${definition.team}.")
|
||||
player.sendMessage("Its description is \"${definition.description}\".")
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val definition = ItemDefinition.lookup(id)
|
||||
val members = if (definition.isMembersOnly) "members" else "not members"
|
||||
|
||||
player.sendMessage("Item $id is called ${definition.name}, is $members only, and has a " +
|
||||
"team of ${definition.team}.")
|
||||
player.sendMessage("Its description is \"${definition.description}\".")
|
||||
}
|
||||
|
||||
on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val definition = NpcDefinition.lookup(id)
|
||||
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
|
||||
"does not have a combat level"
|
||||
|
||||
player.sendMessage("Npc $id is called ${definition.name} and $isCombative.")
|
||||
player.sendMessage("Its description is \"${definition.description}\".")
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val definition = NpcDefinition.lookup(id)
|
||||
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
|
||||
"does not have a combat level"
|
||||
|
||||
player.sendMessage("Npc $id is called ${definition.name} and $isCombative.")
|
||||
player.sendMessage("Its description is \"${definition.description}\".")
|
||||
}
|
||||
|
||||
on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
|
||||
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val definition = ObjectDefinition.lookup(id)
|
||||
player.sendMessage("Object $id is called ${definition.name} and its description is " +
|
||||
"\"${definition.description}\".")
|
||||
player.sendMessage("Its width is ${definition.width} and its length is ${definition.length}.")
|
||||
}
|
||||
val definition = ObjectDefinition.lookup(id)
|
||||
player.sendMessage("Object $id is called ${definition.name} and its description is " +
|
||||
"\"${definition.description}\".")
|
||||
player.sendMessage("Its width is ${definition.width} and its length is ${definition.length}.")
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
|
||||
on_command("broadcast", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val message = arguments.joinToString(" ")
|
||||
val broadcast = "[Broadcast] ${player.username.capitalize()}: $message"
|
||||
.then { player ->
|
||||
val message = arguments.joinToString(" ")
|
||||
val broadcast = "[Broadcast] ${player.username.capitalize()}: $message"
|
||||
|
||||
player.world.playerRepository.forEach { other ->
|
||||
other.sendMessage(broadcast)
|
||||
}
|
||||
player.world.playerRepository.forEach { other ->
|
||||
other.sendMessage(broadcast)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
|
||||
@@ -6,44 +5,44 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
* Adds a command to mute a player. Admins cannot be muted.
|
||||
*/
|
||||
on_command("mute", PrivilegeLevel.MODERATOR)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.isMuted = true
|
||||
player.sendMessage("You have just unmuted ${targetPlayer.username}.")
|
||||
}
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.isMuted = true
|
||||
player.sendMessage("You have just unmuted ${targetPlayer.username}.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a command to unmute a player.
|
||||
*/
|
||||
on_command("unmute", PrivilegeLevel.MODERATOR)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.isMuted = false
|
||||
player.sendMessage("You have just unmuted ${targetPlayer.username}.")
|
||||
}
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.isMuted = false
|
||||
player.sendMessage("You have just unmuted ${targetPlayer.username}.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a command to ban a player. Admins cannot be banned.
|
||||
*/
|
||||
on_command("ban", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
.then { player ->
|
||||
val name = arguments.joinToString(" ")
|
||||
val targetPlayer = player.world.getPlayer(name)
|
||||
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.ban()
|
||||
targetPlayer.logout() // TODO force logout
|
||||
player.sendMessage("You have just banned ${targetPlayer.username}.")
|
||||
}
|
||||
if (validate(player, targetPlayer)) {
|
||||
targetPlayer.ban()
|
||||
targetPlayer.logout() // TODO force logout
|
||||
player.sendMessage("You have just banned ${targetPlayer.username}.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the player isn't null, and that they aren't an Administrator.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import com.google.common.primitives.Doubles
|
||||
import com.google.common.primitives.Ints
|
||||
import org.apollo.game.model.entity.Skill
|
||||
@@ -9,78 +8,78 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
* Maximises the player's skill set.
|
||||
*/
|
||||
on_command("max", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val skills = player.skillSet
|
||||
.then { player ->
|
||||
val skills = player.skillSet
|
||||
|
||||
for (skill in 0 until skills.size()) {
|
||||
skills.addExperience(skill, SkillSet.MAXIMUM_EXP)
|
||||
}
|
||||
for (skill in 0 until skills.size()) {
|
||||
skills.addExperience(skill, SkillSet.MAXIMUM_EXP)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Levels the specified skill to the specified level, optionally updating the current level as well.
|
||||
*/
|
||||
on_command("level", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::level [skill-id] [level] <old>"
|
||||
if (arguments.size !in 2..3) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val skillId = Ints.tryParse(arguments[0])
|
||||
if (skillId == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val level = Ints.tryParse(arguments[1])
|
||||
if (level == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (skillId !in 0..20 || level !in 1..99) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val experience = SkillSet.getExperienceForLevel(level).toDouble()
|
||||
var current = level
|
||||
|
||||
if (arguments.size == 3 && arguments[2] == "old") {
|
||||
val skill = player.skillSet.getSkill(skillId)
|
||||
current = skill.currentLevel
|
||||
}
|
||||
|
||||
player.skillSet.setSkill(skillId, Skill(experience, current, level))
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::level [skill-id] [level] <old>"
|
||||
if (arguments.size !in 2..3) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val skillId = Ints.tryParse(arguments[0])
|
||||
if (skillId == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val level = Ints.tryParse(arguments[1])
|
||||
if (level == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (skillId !in 0..20 || level !in 1..99) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val experience = SkillSet.getExperienceForLevel(level).toDouble()
|
||||
var current = level
|
||||
|
||||
if (arguments.size == 3 && arguments[2] == "old") {
|
||||
val skill = player.skillSet.getSkill(skillId)
|
||||
current = skill.currentLevel
|
||||
}
|
||||
|
||||
player.skillSet.setSkill(skillId, Skill(experience, current, level))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount of experience to the specified skill.
|
||||
*/
|
||||
on_command("xp", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::xp [skill-id] [experience]"
|
||||
if (arguments.size != 2) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::xp [skill-id] [experience]"
|
||||
if (arguments.size != 2) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val skillId = Ints.tryParse(arguments[0])
|
||||
if (skillId == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val experience = Doubles.tryParse(arguments[1])
|
||||
if (experience == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val skillId = Ints.tryParse(arguments[0])
|
||||
if (skillId == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
val experience = Doubles.tryParse(arguments[1])
|
||||
if (experience == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (skillId !in 0..20 || experience <= 0) {
|
||||
player.sendMessage("Invalid syntax - ::xp [skill-id] [experience]")
|
||||
return@then
|
||||
}
|
||||
if (skillId !in 0..20 || experience <= 0) {
|
||||
player.sendMessage("Invalid syntax - ::xp [skill-id] [experience]")
|
||||
return@then
|
||||
}
|
||||
|
||||
player.skillSet.addExperience(skillId, experience)
|
||||
}
|
||||
player.skillSet.addExperience(skillId, experience)
|
||||
}
|
||||
@@ -13,98 +13,98 @@ val blacklist: IntArray = intArrayOf()
|
||||
* 'y' are not supplied.
|
||||
*/
|
||||
on_command("spawn", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]"
|
||||
if (arguments.size !in intArrayOf(1, 3, 4)) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id in blacklist) {
|
||||
player.sendMessage("Sorry, npc $id is blacklisted!")
|
||||
return@then
|
||||
}
|
||||
|
||||
val position: Position?
|
||||
if (arguments.size == 1) {
|
||||
position = player.position
|
||||
} else {
|
||||
var height = player.position.height
|
||||
if (arguments.size == 4) {
|
||||
val h = Ints.tryParse(arguments[3])
|
||||
if (h == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
height = h
|
||||
}
|
||||
position = Position(arguments[1].toInt(), arguments[2].toInt(), height)
|
||||
}
|
||||
|
||||
player.world.register(Npc(player.world, id, position))
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]"
|
||||
if (arguments.size !in intArrayOf(1, 3, 4)) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id in blacklist) {
|
||||
player.sendMessage("Sorry, npc $id is blacklisted!")
|
||||
return@then
|
||||
}
|
||||
|
||||
val position: Position?
|
||||
if (arguments.size == 1) {
|
||||
position = player.position
|
||||
} else {
|
||||
var height = player.position.height
|
||||
if (arguments.size == 4) {
|
||||
val h = Ints.tryParse(arguments[3])
|
||||
if (h == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
height = h
|
||||
}
|
||||
position = Position(arguments[1].toInt(), arguments[2].toInt(), height)
|
||||
}
|
||||
|
||||
player.world.register(Npc(player.world, id, position))
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass spawns npcs around the player.
|
||||
*/
|
||||
on_command("mass", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::mass [npc id] [range (1-5)]"
|
||||
if (arguments.size != 2) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val range = Ints.tryParse(arguments[1])
|
||||
if (range == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id < 0 || range !in 1..5) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id in blacklist) {
|
||||
player.sendMessage("Sorry, npc $id is blacklisted!")
|
||||
return@then
|
||||
}
|
||||
|
||||
val centerPosition = player.position
|
||||
|
||||
val minX = centerPosition.x - range
|
||||
val minY = centerPosition.y - range
|
||||
val maxX = centerPosition.x + range
|
||||
val maxY = centerPosition.y + range
|
||||
val z = centerPosition.height
|
||||
|
||||
for (x in minX..maxX) {
|
||||
for (y in minY..maxY) {
|
||||
player.world.register(Npc(player.world, id, Position(x, y, z)))
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage("Mass spawning npcs with id $id.")
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::mass [npc id] [range (1-5)]"
|
||||
if (arguments.size != 2) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val id = Ints.tryParse(arguments[0])
|
||||
if (id == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val range = Ints.tryParse(arguments[1])
|
||||
if (range == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id < 0 || range !in 1..5) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
if (id in blacklist) {
|
||||
player.sendMessage("Sorry, npc $id is blacklisted!")
|
||||
return@then
|
||||
}
|
||||
|
||||
val centerPosition = player.position
|
||||
|
||||
val minX = centerPosition.x - range
|
||||
val minY = centerPosition.y - range
|
||||
val maxX = centerPosition.x + range
|
||||
val maxY = centerPosition.y + range
|
||||
val z = centerPosition.height
|
||||
|
||||
for (x in minX..maxX) {
|
||||
for (y in minY..maxY) {
|
||||
player.world.register(Npc(player.world, id, Position(x, y, z)))
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage("Mass spawning npcs with id $id.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all npcs from the world npc repository.
|
||||
*/
|
||||
on_command("clearnpcs", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
player.world.npcRepository.forEach { npc -> player.world.unregister(npc) }
|
||||
player.sendMessage("Unregistered all npcs from the world.")
|
||||
}
|
||||
.then { player ->
|
||||
player.world.npcRepository.forEach { npc -> player.world.unregister(npc) }
|
||||
player.sendMessage("Unregistered all npcs from the world.")
|
||||
}
|
||||
@@ -1,48 +1,49 @@
|
||||
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.
|
||||
*/
|
||||
on_command("pos", PrivilegeLevel.MODERATOR)
|
||||
.then { player ->
|
||||
player.sendMessage("You are at: ${player.position}.")
|
||||
}
|
||||
.then { player ->
|
||||
player.sendMessage("You are at: ${player.position}.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the player to the specified position.
|
||||
*/
|
||||
on_command("tele", PrivilegeLevel.ADMINISTRATOR)
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]"
|
||||
if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
.then { player ->
|
||||
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]"
|
||||
if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) {
|
||||
return@then
|
||||
}
|
||||
|
||||
val x = Ints.tryParse(arguments[0])
|
||||
if (x == null) {
|
||||
val x = Ints.tryParse(arguments[0])
|
||||
if (x == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val y = Ints.tryParse(arguments[1])
|
||||
if (y == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
var z = player.position.height
|
||||
if (arguments.size == 3) {
|
||||
val plane = Ints.tryParse(arguments[2])
|
||||
if (plane == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
z = plane
|
||||
}
|
||||
|
||||
val y = Ints.tryParse(arguments[1])
|
||||
if (y == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
var z = player.position.height
|
||||
if (arguments.size == 3) {
|
||||
val plane = Ints.tryParse(arguments[2])
|
||||
if (plane == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
z = plane
|
||||
}
|
||||
|
||||
if (z in 0..4) {
|
||||
player.teleport(Position(x, y, z))
|
||||
}
|
||||
}
|
||||
if (z in 0..4) {
|
||||
player.teleport(Position(x, y, z))
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
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 }
|
||||
.where { action == PlayerActionType.FOLLOW }
|
||||
.then {
|
||||
FollowAction.start(it, target)
|
||||
terminate()
|
||||
}
|
||||
on_player_event { org.apollo.game.plugin.entity.player_action.PlayerActionEvent::class }
|
||||
.where { action == PlayerActionType.FOLLOW }
|
||||
.then {
|
||||
FollowAction.start(it, target)
|
||||
terminate()
|
||||
}
|
||||
@@ -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,18 +1,22 @@
|
||||
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 {
|
||||
val action = it.actionAt(option)
|
||||
if (action != null) {
|
||||
it.world.submit(PlayerActionEvent(it, it.world.playerRepository[index], action))
|
||||
}
|
||||
|
||||
terminate()
|
||||
.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)
|
||||
}
|
||||
.then {
|
||||
it.enableAction(PlayerActionType.FOLLOW)
|
||||
it.enableAction(PlayerActionType.TRADE)
|
||||
}
|
||||
@@ -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>()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -21,17 +21,17 @@ class Door(private val gameObject: GameObject) {
|
||||
companion object {
|
||||
|
||||
val LEFT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf(
|
||||
Direction.NORTH to Direction.WEST,
|
||||
Direction.SOUTH to Direction.EAST,
|
||||
Direction.WEST to Direction.SOUTH,
|
||||
Direction.EAST to Direction.NORTH
|
||||
Direction.NORTH to Direction.WEST,
|
||||
Direction.SOUTH to Direction.EAST,
|
||||
Direction.WEST to Direction.SOUTH,
|
||||
Direction.EAST to Direction.NORTH
|
||||
)
|
||||
|
||||
val RIGHT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf(
|
||||
Direction.NORTH to Direction.EAST,
|
||||
Direction.SOUTH to Direction.WEST,
|
||||
Direction.WEST to Direction.NORTH,
|
||||
Direction.EAST to Direction.SOUTH
|
||||
Direction.NORTH to Direction.EAST,
|
||||
Direction.SOUTH to Direction.WEST,
|
||||
Direction.WEST to Direction.NORTH,
|
||||
Direction.EAST to Direction.SOUTH
|
||||
)
|
||||
|
||||
val toggledDoors: HashMap<GameObject, GameObject> = hashMapOf()
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
package org.apollo.game.plugin.util.command
|
||||
|
||||
import org.apollo.game.model.entity.Player
|
||||
|
||||
/**
|
||||
@@ -17,4 +19,4 @@ fun valid_arg_length(args: Array<String>, length: IntRange, player: Player, mess
|
||||
* message if not.
|
||||
*/
|
||||
fun valid_arg_length(args: Array<String>, length: Int, player: Player, message: String)
|
||||
= valid_arg_length(args, IntRange(length, length), player, message)
|
||||
= valid_arg_length(args, IntRange(length, length), player, message)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user