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.ItemDefinition
import org.apollo.cache.def.NpcDefinition 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() val RAND = Random()
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.api
import org.apollo.game.model.Position import org.apollo.game.model.Position
import org.apollo.game.model.World import org.apollo.game.model.World
import org.apollo.game.model.area.Region 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.EntityType.STATIC_OBJECT
import org.apollo.game.model.entity.obj.DynamicGameObject import org.apollo.game.model.entity.obj.DynamicGameObject
import org.apollo.game.model.entity.obj.GameObject import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.model.entity.obj.StaticGameObject
import org.apollo.game.scheduling.ScheduledTask import org.apollo.game.scheduling.ScheduledTask
import java.lang.IllegalArgumentException import java.util.Optional
import java.util.*
import java.util.stream.Stream import java.util.stream.Stream
fun <T : Entity> Region.find(position: Position, pred: (T) -> Boolean, vararg types: EntityType): Stream<T> { fun <T : Entity> Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Stream<T> {
val result = this.getEntities<T>(position, *types) val result = getEntities<T>(position, *types)
return result.stream().filter(predicate::invoke)
return result.stream()
.filter(pred::invoke)
} }
fun Region.findObjects(position: Position, id: Int): Stream<GameObject> { 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> { fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT) return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
.findFirst() .findFirst()
} }
class ExpireObjectTask( class ExpireObjectTask(
val world: World, private val world: World,
val obj: GameObject, private val existing: GameObject,
val replacement: GameObject, private val replacement: GameObject,
val respawnDelay: Int private val respawnDelay: Int
) : ScheduledTask(0, true) { ) : ScheduledTask(0, true) {
private var respawning: Boolean = false private var respawning: Boolean = false
override fun execute() { override fun execute() {
val region = world.regionRepository.fromPosition(obj.position) val region = world.regionRepository.fromPosition(existing.position)
if (!respawning) { if (!respawning) {
world.spawn(replacement) world.spawn(replacement)
@@ -47,7 +45,7 @@ class ExpireObjectTask(
setDelay(respawnDelay) setDelay(respawnDelay)
} else { } else {
region.removeEntity(replacement) region.removeEntity(replacement)
world.spawn(obj) world.spawn(existing)
stop() stop()
} }
} }
@@ -55,7 +53,6 @@ class ExpireObjectTask(
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) { fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation) 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)) schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
} }
+11 -10
View File
@@ -1,17 +1,18 @@
import com.google.common.primitives.Ints import com.google.common.primitives.Ints
import org.apollo.game.model.Animation import org.apollo.game.model.Animation
import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("animate", PrivilegeLevel.MODERATOR) on_command("animate", PrivilegeLevel.MODERATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::animate [animation-id]" 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]) val id = Ints.tryParse(arguments[0])
if (id == null) { if (id == null) {
player.sendMessage(invalidSyntax) player.sendMessage(invalidSyntax)
return@then return@then
}
player.playAnimation(Animation(id))
} }
player.playAnimation(Animation(id))
} }
}
+1 -1
View File
@@ -2,4 +2,4 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
// Opens the player's bank if they are an administrator. // Opens the player's bank if they are an administrator.
on_command("bank", PrivilegeLevel.ADMINISTRATOR) on_command("bank", PrivilegeLevel.ADMINISTRATOR)
.then { player -> player.openBank() } .then { player -> player.openBank() }
+30 -29
View File
@@ -1,39 +1,40 @@
import com.google.common.primitives.Ints import com.google.common.primitives.Ints
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("item", PrivilegeLevel.ADMINISTRATOR) on_command("item", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::item [id] [amount]" val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) { if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
return@then return@then
} }
val id = Ints.tryParse(arguments[0]) val id = Ints.tryParse(arguments[0])
if (id == null) { 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) player.sendMessage(invalidSyntax)
return@then 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 (amount < 0) {
player.sendMessage("The amount you specified is out of bounds!")
return@then
}
player.inventory.add(id, amount)
} }
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
}
player.inventory.add(id, amount)
}
+53 -52
View File
@@ -3,64 +3,65 @@ import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition import org.apollo.cache.def.ObjectDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR) on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]" val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) { if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then 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}\".")
} }
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) on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]" val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) { if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then 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}\".")
} }
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) on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]" val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) { if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then 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 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}.")
}
+6 -6
View File
@@ -1,11 +1,11 @@
import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.entity.setting.PrivilegeLevel
on_command("broadcast", PrivilegeLevel.ADMINISTRATOR) on_command("broadcast", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val message = arguments.joinToString(" ") val message = arguments.joinToString(" ")
val broadcast = "[Broadcast] ${player.username.capitalize()}: $message" val broadcast = "[Broadcast] ${player.username.capitalize()}: $message"
player.world.playerRepository.forEach { other -> player.world.playerRepository.forEach { other ->
other.sendMessage(broadcast) other.sendMessage(broadcast)
}
} }
}
+22 -23
View File
@@ -1,4 +1,3 @@
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.setting.PrivilegeLevel 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. * Adds a command to mute a player. Admins cannot be muted.
*/ */
on_command("mute", PrivilegeLevel.MODERATOR) on_command("mute", PrivilegeLevel.MODERATOR)
.then { player -> .then { player ->
val name = arguments.joinToString(" ") val name = arguments.joinToString(" ")
val targetPlayer = player.world.getPlayer(name) val targetPlayer = player.world.getPlayer(name)
if (validate(player, targetPlayer)) { if (validate(player, targetPlayer)) {
targetPlayer.isMuted = true targetPlayer.isMuted = true
player.sendMessage("You have just unmuted ${targetPlayer.username}.") player.sendMessage("You have just unmuted ${targetPlayer.username}.")
}
} }
}
/** /**
* Adds a command to unmute a player. * Adds a command to unmute a player.
*/ */
on_command("unmute", PrivilegeLevel.MODERATOR) on_command("unmute", PrivilegeLevel.MODERATOR)
.then { player -> .then { player ->
val name = arguments.joinToString(" ") val name = arguments.joinToString(" ")
val targetPlayer = player.world.getPlayer(name) val targetPlayer = player.world.getPlayer(name)
if (validate(player, targetPlayer)) { if (validate(player, targetPlayer)) {
targetPlayer.isMuted = false targetPlayer.isMuted = false
player.sendMessage("You have just unmuted ${targetPlayer.username}.") player.sendMessage("You have just unmuted ${targetPlayer.username}.")
}
} }
}
/** /**
* Adds a command to ban a player. Admins cannot be banned. * Adds a command to ban a player. Admins cannot be banned.
*/ */
on_command("ban", PrivilegeLevel.ADMINISTRATOR) on_command("ban", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val name = arguments.joinToString(" ") val name = arguments.joinToString(" ")
val targetPlayer = player.world.getPlayer(name) val targetPlayer = player.world.getPlayer(name)
if (validate(player, targetPlayer)) { if (validate(player, targetPlayer)) {
targetPlayer.ban() targetPlayer.ban()
targetPlayer.logout() // TODO force logout targetPlayer.logout() // TODO force logout
player.sendMessage("You have just banned ${targetPlayer.username}.") player.sendMessage("You have just banned ${targetPlayer.username}.")
}
} }
}
/** /**
* Ensures the player isn't null, and that they aren't an Administrator. * Ensures the player isn't null, and that they aren't an Administrator.
+61 -62
View File
@@ -1,4 +1,3 @@
import com.google.common.primitives.Doubles import com.google.common.primitives.Doubles
import com.google.common.primitives.Ints import com.google.common.primitives.Ints
import org.apollo.game.model.entity.Skill 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. * Maximises the player's skill set.
*/ */
on_command("max", PrivilegeLevel.ADMINISTRATOR) on_command("max", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val skills = player.skillSet val skills = player.skillSet
for (skill in 0 until skills.size()) { for (skill in 0 until skills.size()) {
skills.addExperience(skill, SkillSet.MAXIMUM_EXP) skills.addExperience(skill, SkillSet.MAXIMUM_EXP)
}
} }
}
/** /**
* Levels the specified skill to the specified level, optionally updating the current level as well. * Levels the specified skill to the specified level, optionally updating the current level as well.
*/ */
on_command("level", PrivilegeLevel.ADMINISTRATOR) on_command("level", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::level [skill-id] [level] <old>" val invalidSyntax = "Invalid syntax - ::level [skill-id] [level] <old>"
if (arguments.size !in 2..3) { if (arguments.size !in 2..3) {
player.sendMessage(invalidSyntax) player.sendMessage(invalidSyntax)
return@then 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))
} }
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. * Adds the specified amount of experience to the specified skill.
*/ */
on_command("xp", PrivilegeLevel.ADMINISTRATOR) on_command("xp", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::xp [skill-id] [experience]" val invalidSyntax = "Invalid syntax - ::xp [skill-id] [experience]"
if (arguments.size != 2) { if (arguments.size != 2) {
player.sendMessage(invalidSyntax) player.sendMessage(invalidSyntax)
return@then 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
}
player.skillSet.addExperience(skillId, experience)
} }
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
}
player.skillSet.addExperience(skillId, experience)
}
+83 -83
View File
@@ -13,98 +13,98 @@ val blacklist: IntArray = intArrayOf()
* 'y' are not supplied. * 'y' are not supplied.
*/ */
on_command("spawn", PrivilegeLevel.ADMINISTRATOR) on_command("spawn", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]" val invalidSyntax = "Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]"
if (arguments.size !in intArrayOf(1, 3, 4)) { if (arguments.size !in intArrayOf(1, 3, 4)) {
player.sendMessage(invalidSyntax) player.sendMessage(invalidSyntax)
return@then 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))
} }
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. * Mass spawns npcs around the player.
*/ */
on_command("mass", PrivilegeLevel.ADMINISTRATOR) on_command("mass", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::mass [npc id] [range (1-5)]" val invalidSyntax = "Invalid syntax - ::mass [npc id] [range (1-5)]"
if (arguments.size != 2) { if (arguments.size != 2) {
player.sendMessage(invalidSyntax) player.sendMessage(invalidSyntax)
return@then 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.")
} }
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. * Unregisters all npcs from the world npc repository.
*/ */
on_command("clearnpcs", PrivilegeLevel.ADMINISTRATOR) on_command("clearnpcs", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
player.world.npcRepository.forEach { npc -> player.world.unregister(npc) } player.world.npcRepository.forEach { npc -> player.world.unregister(npc) }
player.sendMessage("Unregistered all npcs from the world.") player.sendMessage("Unregistered all npcs from the world.")
} }
+35 -34
View File
@@ -1,48 +1,49 @@
import com.google.common.primitives.Ints import com.google.common.primitives.Ints
import org.apollo.game.model.Position import org.apollo.game.model.Position
import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
/** /**
* Sends the player's position. * Sends the player's position.
*/ */
on_command("pos", PrivilegeLevel.MODERATOR) on_command("pos", PrivilegeLevel.MODERATOR)
.then { player -> .then { player ->
player.sendMessage("You are at: ${player.position}.") player.sendMessage("You are at: ${player.position}.")
} }
/** /**
* Teleports the player to the specified position. * Teleports the player to the specified position.
*/ */
on_command("tele", PrivilegeLevel.ADMINISTRATOR) on_command("tele", PrivilegeLevel.ADMINISTRATOR)
.then { player -> .then { player ->
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]" val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]"
if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) { if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) {
return@then return@then
}
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
}
if (z in 0..4) {
player.teleport(Position(x, y, z))
}
} }
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
}
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.plugin.entity.player_action.PlayerActionType
import org.apollo.game.message.impl.PlayerActionMessage
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.plugin.entity.following.FollowAction 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 } .where { action == PlayerActionType.FOLLOW }
.then { .then {
FollowAction.start(it, target) FollowAction.start(it, target)
terminate() terminate()
} }
@@ -1,7 +1,9 @@
package org.apollo.game.plugin.entity.player_action
import org.apollo.game.message.impl.SetPlayerActionMessage import org.apollo.game.message.impl.SetPlayerActionMessage
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.event.PlayerEvent 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) { enum class PlayerActionType(val displayName: String, val slot: Int, val primary: Boolean = true) {
ATTACK("Attack", 2), ATTACK("Attack", 2),
@@ -1,18 +1,22 @@
import org.apollo.game.message.impl.PlayerActionMessage import org.apollo.game.message.impl.PlayerActionMessage
import org.apollo.game.model.event.impl.LoginEvent 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 } on { PlayerActionMessage::class }
.then { .then {
val action = it.actionAt(option) val action = it.actionAt(option)
if (action != null) { if (action != null) {
it.world.submit(PlayerActionEvent(it, it.world.playerRepository[index], action)) it.world.submit(PlayerActionEvent(it, it.world.playerRepository[index], action))
}
terminate()
} }
terminate()
}
on_player_event { LoginEvent::class } on_player_event { LoginEvent::class }
.then { .then {
it.enableAction(PlayerActionType.FOLLOW) it.enableAction(PlayerActionType.FOLLOW)
it.enableAction(PlayerActionType.TRADE) it.enableAction(PlayerActionType.TRADE)
} }
+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, data class Spawn(val id: Int?, val name: String, val position: Position, val facing: Direction,
val spawnAnimation: Animation? = null, val spawnAnimation: Animation? = null, val spawnGraphic: Graphic? = null)
val spawnGraphic: Graphic? = null)
object Spawns { object Spawns {
val list = mutableListOf<Spawn>() val list = mutableListOf<Spawn>()
+5 -10
View File
@@ -1,23 +1,18 @@
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.game.model.entity.Npc 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 -> start { world ->
Spawns.list.forEach { Spawns.list.forEach {
val definition = if (it.id != null) NpcDefinition.lookup(it.id!!) else lookup_npc(it.name) val definition = it.id?.let { NpcDefinition.lookup(it) } ?: lookup_npc(it.name) ?:
if (definition == null) {
throw IllegalArgumentException("Invalid NPC name or ID ${it.name}, ${it.id}") throw IllegalArgumentException("Invalid NPC name or ID ${it.name}, ${it.id}")
}
val npc = Npc(world, definition.id, it.position) val npc = Npc(world, definition.id, it.position)
npc.turnTo(it.position.step(1, it.facing)) npc.turnTo(it.position.step(1, it.facing))
if (it.spawnAnimation != null) { it.spawnAnimation?.let(npc::playAnimation)
npc.playAnimation(it.spawnAnimation) it.spawnGraphic?.let(npc::playGraphic)
}
if (it.spawnGraphic != null) {
npc.playGraphic(it.spawnGraphic)
}
world.register(npc) world.register(npc)
} }
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs // Generic npcs
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs // Generic npcs
@@ -1,3 +1,4 @@
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Generic npcs // 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("woman", id = 4, x = 3232, y = 3207)
npc_spawn("man", id = 1, x = 3231, y = 3237) npc_spawn("man", id = 1, x = 3231, y = 3237)
npc_spawn("man", id = 2, x = 3224, y = 3240) npc_spawn("man", id = 2, x = 3224, y = 3240)
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
// Functional npcs // Functional npcs
@@ -1,3 +1,5 @@
import org.apollo.game.plugin.shops.shop
shop("Aubury's Rune Shop.") { shop("Aubury's Rune Shop.") {
operated by "Aubury" operated by "Aubury"
@@ -1,4 +1,5 @@
import org.apollo.game.model.Direction import org.apollo.game.model.Direction
import org.apollo.game.plugin.entity.spawn.npc_spawn
npc_spawn("barbarian_woman", x = 3222, y = 3399) npc_spawn("barbarian_woman", x = 3222, y = 3399)
+14 -12
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.DynamicGameObject
import org.apollo.game.model.entity.obj.GameObject import org.apollo.game.model.entity.obj.GameObject
import org.apollo.game.model.event.PlayerEvent import org.apollo.game.model.event.PlayerEvent
import org.apollo.game.plugin.api.findObject
import org.apollo.net.message.Message import org.apollo.net.message.Message
import java.util.Objects import java.util.Objects
import findObject
enum class DoorType { enum class DoorType {
LEFT, RIGHT, NOT_SUPPORTED LEFT, RIGHT, NOT_SUPPORTED
@@ -21,17 +21,17 @@ class Door(private val gameObject: GameObject) {
companion object { companion object {
val LEFT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf( val LEFT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf(
Direction.NORTH to Direction.WEST, Direction.NORTH to Direction.WEST,
Direction.SOUTH to Direction.EAST, Direction.SOUTH to Direction.EAST,
Direction.WEST to Direction.SOUTH, Direction.WEST to Direction.SOUTH,
Direction.EAST to Direction.NORTH Direction.EAST to Direction.NORTH
) )
val RIGHT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf( val RIGHT_HINGE_ORIENTATION: HashMap<Direction, Direction> = hashMapOf(
Direction.NORTH to Direction.EAST, Direction.NORTH to Direction.EAST,
Direction.SOUTH to Direction.WEST, Direction.SOUTH to Direction.WEST,
Direction.WEST to Direction.NORTH, Direction.WEST to Direction.NORTH,
Direction.EAST to Direction.SOUTH Direction.EAST to Direction.SOUTH
) )
val toggledDoors: HashMap<GameObject, GameObject> = hashMapOf() val toggledDoors: HashMap<GameObject, GameObject> = hashMapOf()
@@ -94,7 +94,8 @@ class Door(private val gameObject: GameObject) {
val position = movePosition() val position = movePosition()
val orientation: Int = translateDirection()?.toOrientationInteger() ?: gameObject.orientation 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) regionRepository.fromPosition(position).addEntity(toggledDoor)
toggledDoors.put(toggledDoor, gameObject) toggledDoors.put(toggledDoor, gameObject)
@@ -118,7 +119,7 @@ class Door(private val gameObject: GameObject) {
*/ */
private fun translateDirection(): Direction? { private fun translateDirection(): Direction? {
val direction = Direction.WNES[gameObject.orientation] val direction = Direction.WNES[gameObject.orientation]
return when(type()) { return when (type()) {
DoorType.LEFT -> LEFT_HINGE_ORIENTATION[direction] DoorType.LEFT -> LEFT_HINGE_ORIENTATION[direction]
DoorType.RIGHT -> RIGHT_HINGE_ORIENTATION[direction] DoorType.RIGHT -> RIGHT_HINGE_ORIENTATION[direction]
DoorType.NOT_SUPPORTED -> null 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 { 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.action.DistancedAction
import org.apollo.game.message.handler.ItemVerificationHandler.InventorySupplier import org.apollo.game.message.handler.ItemVerificationHandler.InventorySupplier
import org.apollo.game.message.impl.SetWidgetTextMessage 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.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 import org.jetbrains.kotlin.utils.keysToMap
/** /**
+7 -5
View File
@@ -1,13 +1,15 @@
import Shop.Companion.ExchangeType.BUYING package org.apollo.game.plugin.shops
import Shop.Companion.ExchangeType.SELLING
import Shop.PurchasePolicy.ANY
import Shop.PurchasePolicy.NOTHING
import Shop.PurchasePolicy.OWNED
import org.apollo.cache.def.ItemDefinition import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.Item import org.apollo.game.model.Item
import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.Player
import org.apollo.game.model.inv.Inventory import org.apollo.game.model.inv.Inventory
import org.apollo.game.model.inv.Inventory.StackMode.STACK_ALWAYS 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. * 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.handler.ItemVerificationHandler
import org.apollo.game.message.impl.ItemActionMessage import org.apollo.game.message.impl.ItemActionMessage
import org.apollo.game.message.impl.NpcActionMessage import org.apollo.game.message.impl.NpcActionMessage
import org.apollo.game.model.entity.Mob 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 import org.apollo.game.scheduling.ScheduledTask
fun Mob.shop(): Shop? = SHOPS[definition.id] 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.Direction
import org.apollo.game.model.Position 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
import org.apollo.game.plugin.skills.fishing.FishingSpot.CAGE_HARPOON import org.apollo.game.plugin.skills.fishing.FishingSpot.CAGE_HARPOON
import org.apollo.game.plugin.skills.fishing.FishingSpot.NET_HARPOON import org.apollo.game.plugin.skills.fishing.FishingSpot.NET_HARPOON
+3 -1
View File
@@ -1,3 +1,5 @@
package org.apollo.game.plugin.util.command
import org.apollo.game.model.entity.Player 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. * message if not.
*/ */
fun valid_arg_length(args: Array<String>, length: Int, player: Player, message: String) 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)
+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.ItemDefinition
import org.apollo.cache.def.NpcDefinition import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition import org.apollo.cache.def.ObjectDefinition