diff --git a/game/plugin/api/src/org/apollo/game/plugins/api/definitions.kt b/game/plugin/api/src/definitions.kt similarity index 92% rename from game/plugin/api/src/org/apollo/game/plugins/api/definitions.kt rename to game/plugin/api/src/definitions.kt index 3de58a11..69966d43 100644 --- a/game/plugin/api/src/org/apollo/game/plugins/api/definitions.kt +++ b/game/plugin/api/src/definitions.kt @@ -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 diff --git a/game/plugin/api/src/org/apollo/game/plugins/api/util.kt b/game/plugin/api/src/util.kt similarity index 58% rename from game/plugin/api/src/org/apollo/game/plugins/api/util.kt rename to game/plugin/api/src/util.kt index 377af6c8..01264cbf 100644 --- a/game/plugin/api/src/org/apollo/game/plugins/api/util.kt +++ b/game/plugin/api/src/util.kt @@ -1,4 +1,6 @@ -import java.util.* +package org.apollo.game.plugin.api + +import java.util.Random val RAND = Random() diff --git a/game/plugin/api/src/org/apollo/game/plugins/api/world.kt b/game/plugin/api/src/world.kt similarity index 63% rename from game/plugin/api/src/org/apollo/game/plugins/api/world.kt rename to game/plugin/api/src/world.kt index 8d77ce1c..6dd75879 100644 --- a/game/plugin/api/src/org/apollo/game/plugins/api/world.kt +++ b/game/plugin/api/src/world.kt @@ -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 Region.find(position: Position, pred: (T) -> Boolean, vararg types: EntityType): Stream { - val result = this.getEntities(position, *types) - - return result.stream() - .filter(pred::invoke) +fun Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Stream { + val result = getEntities(position, *types) + return result.stream().filter(predicate::invoke) } fun Region.findObjects(position: Position, id: Int): Stream { - return find(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 { return find(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)) } diff --git a/game/plugin/cmd/src/animate-cmd.plugin.kts b/game/plugin/cmd/src/animate-cmd.plugin.kts index cab21041..42786020 100644 --- a/game/plugin/cmd/src/animate-cmd.plugin.kts +++ b/game/plugin/cmd/src/animate-cmd.plugin.kts @@ -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 } - } \ No newline at end of file + + player.playAnimation(Animation(id)) + } + } \ No newline at end of file diff --git a/game/plugin/cmd/src/bank-cmd.plugin.kts b/game/plugin/cmd/src/bank-cmd.plugin.kts index 181a1194..6ded33eb 100644 --- a/game/plugin/cmd/src/bank-cmd.plugin.kts +++ b/game/plugin/cmd/src/bank-cmd.plugin.kts @@ -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() } \ No newline at end of file + .then { player -> player.openBank() } \ No newline at end of file diff --git a/game/plugin/cmd/src/item-cmd.plugin.kts b/game/plugin/cmd/src/item-cmd.plugin.kts index 52eafb18..97f3b8ac 100644 --- a/game/plugin/cmd/src/item-cmd.plugin.kts +++ b/game/plugin/cmd/src/item-cmd.plugin.kts @@ -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) - } \ No newline at end of file + player.inventory.add(id, amount) + } \ No newline at end of file diff --git a/game/plugin/cmd/src/lookup.plugin.kts b/game/plugin/cmd/src/lookup.plugin.kts index a599c0f4..8f844ecc 100644 --- a/game/plugin/cmd/src/lookup.plugin.kts +++ b/game/plugin/cmd/src/lookup.plugin.kts @@ -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}.") - } \ No newline at end of file + 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}.") + } \ No newline at end of file diff --git a/game/plugin/cmd/src/messaging-cmd.plugin.kts b/game/plugin/cmd/src/messaging-cmd.plugin.kts index 883d7a51..304c1468 100644 --- a/game/plugin/cmd/src/messaging-cmd.plugin.kts +++ b/game/plugin/cmd/src/messaging-cmd.plugin.kts @@ -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) } + } diff --git a/game/plugin/cmd/src/punish-cmd.plugin.kts b/game/plugin/cmd/src/punish-cmd.plugin.kts index 619d4674..3df799c4 100644 --- a/game/plugin/cmd/src/punish-cmd.plugin.kts +++ b/game/plugin/cmd/src/punish-cmd.plugin.kts @@ -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. diff --git a/game/plugin/cmd/src/skill-cmd.plugin.kts b/game/plugin/cmd/src/skill-cmd.plugin.kts index ade6e6c0..b95ed018 100644 --- a/game/plugin/cmd/src/skill-cmd.plugin.kts +++ b/game/plugin/cmd/src/skill-cmd.plugin.kts @@ -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] " - 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] " + 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) - } \ No newline at end of file + player.skillSet.addExperience(skillId, experience) + } \ No newline at end of file diff --git a/game/plugin/cmd/src/spawn-cmd.plugin.kts b/game/plugin/cmd/src/spawn-cmd.plugin.kts index 7f124d89..70b80a2d 100644 --- a/game/plugin/cmd/src/spawn-cmd.plugin.kts +++ b/game/plugin/cmd/src/spawn-cmd.plugin.kts @@ -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.") - } \ No newline at end of file + .then { player -> + player.world.npcRepository.forEach { npc -> player.world.unregister(npc) } + player.sendMessage("Unregistered all npcs from the world.") + } \ No newline at end of file diff --git a/game/plugin/cmd/src/teleport-cmd.plugin.kts b/game/plugin/cmd/src/teleport-cmd.plugin.kts index 75490b9f..65ae83a7 100644 --- a/game/plugin/cmd/src/teleport-cmd.plugin.kts +++ b/game/plugin/cmd/src/teleport-cmd.plugin.kts @@ -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)) - } - } \ No newline at end of file + if (z in 0..4) { + player.teleport(Position(x, y, z)) + } + } \ No newline at end of file diff --git a/game/plugin/entity/following/src/following.plugin.kts b/game/plugin/entity/following/src/following.plugin.kts index 6037e24d..3fc65c1f 100644 --- a/game/plugin/entity/following/src/following.plugin.kts +++ b/game/plugin/entity/following/src/following.plugin.kts @@ -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() - } \ No newline at end of file +on_player_event { org.apollo.game.plugin.entity.player_action.PlayerActionEvent::class } + .where { action == PlayerActionType.FOLLOW } + .then { + FollowAction.start(it, target) + terminate() + } \ No newline at end of file diff --git a/game/plugin/entity/player-action/src/player_action.kt b/game/plugin/entity/player-action/src/player_action.kt index bfec0e6d..2b5c230d 100644 --- a/game/plugin/entity/player-action/src/player_action.kt +++ b/game/plugin/entity/player-action/src/player_action.kt @@ -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), diff --git a/game/plugin/entity/player-action/src/player_action.plugin.kts b/game/plugin/entity/player-action/src/player_action.plugin.kts index c165f30a..b3859a79 100644 --- a/game/plugin/entity/player-action/src/player_action.plugin.kts +++ b/game/plugin/entity/player-action/src/player_action.plugin.kts @@ -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) - } \ No newline at end of file + .then { + it.enableAction(PlayerActionType.FOLLOW) + it.enableAction(PlayerActionType.TRADE) + } \ No newline at end of file diff --git a/game/plugin/entity/spawn/src/spawn.kt b/game/plugin/entity/spawn/src/spawn.kt index cb49a6af..f21f7d20 100644 --- a/game/plugin/entity/spawn/src/spawn.kt +++ b/game/plugin/entity/spawn/src/spawn.kt @@ -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() diff --git a/game/plugin/entity/spawn/src/spawn.plugin.kts b/game/plugin/entity/spawn/src/spawn.plugin.kts index 37625df2..0f172491 100644 --- a/game/plugin/entity/spawn/src/spawn.plugin.kts +++ b/game/plugin/entity/spawn/src/spawn.plugin.kts @@ -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) } diff --git a/game/plugin/locations/al-kharid/src/al-kharid-npcs.plugin.kts b/game/plugin/locations/al-kharid/src/al-kharid-npcs.plugin.kts index ba5acf90..278ffea0 100644 --- a/game/plugin/locations/al-kharid/src/al-kharid-npcs.plugin.kts +++ b/game/plugin/locations/al-kharid/src/al-kharid-npcs.plugin.kts @@ -1,4 +1,5 @@ import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.npc_spawn // Generic npcs diff --git a/game/plugin/locations/edgeville/src/edgeville-npcs.plugin.kts b/game/plugin/locations/edgeville/src/edgeville-npcs.plugin.kts index 71919510..be3ba855 100644 --- a/game/plugin/locations/edgeville/src/edgeville-npcs.plugin.kts +++ b/game/plugin/locations/edgeville/src/edgeville-npcs.plugin.kts @@ -1,4 +1,5 @@ import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.npc_spawn // Generic npcs diff --git a/game/plugin/locations/falador/src/falador-npcs.plugin.kts b/game/plugin/locations/falador/src/falador-npcs.plugin.kts index 1663b60c..f03926a0 100644 --- a/game/plugin/locations/falador/src/falador-npcs.plugin.kts +++ b/game/plugin/locations/falador/src/falador-npcs.plugin.kts @@ -1,3 +1,4 @@ +import org.apollo.game.plugin.entity.spawn.npc_spawn // Generic npcs diff --git a/game/plugin/locations/lumbridge/src/lumbridge-npcs.plugin.kts b/game/plugin/locations/lumbridge/src/lumbridge-npcs.plugin.kts index fe547d0d..9af0f50d 100644 --- a/game/plugin/locations/lumbridge/src/lumbridge-npcs.plugin.kts +++ b/game/plugin/locations/lumbridge/src/lumbridge-npcs.plugin.kts @@ -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) diff --git a/game/plugin/locations/tutorial-island/src/tutorial-island-npcs.plugin.kts b/game/plugin/locations/tutorial-island/src/tutorial-island-npcs.plugin.kts index d6c6501f..ed80dacb 100644 --- a/game/plugin/locations/tutorial-island/src/tutorial-island-npcs.plugin.kts +++ b/game/plugin/locations/tutorial-island/src/tutorial-island-npcs.plugin.kts @@ -1,4 +1,5 @@ import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.npc_spawn // Functional npcs diff --git a/game/plugin/locations/varrock/src/shops.plugin.kts b/game/plugin/locations/varrock/src/shops.plugin.kts index d48e15e6..9406e91f 100644 --- a/game/plugin/locations/varrock/src/shops.plugin.kts +++ b/game/plugin/locations/varrock/src/shops.plugin.kts @@ -1,3 +1,5 @@ +import org.apollo.game.plugin.shops.shop + shop("Aubury's Rune Shop.") { operated by "Aubury" diff --git a/game/plugin/locations/varrock/src/varrock-npcs.plugin.kts b/game/plugin/locations/varrock/src/varrock-npcs.plugin.kts index b8d40abb..11c64a58 100644 --- a/game/plugin/locations/varrock/src/varrock-npcs.plugin.kts +++ b/game/plugin/locations/varrock/src/varrock-npcs.plugin.kts @@ -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) diff --git a/game/plugin/navigation/door/src/door.kt b/game/plugin/navigation/door/src/door.kt index b3369cad..afc8f14d 100644 --- a/game/plugin/navigation/door/src/door.kt +++ b/game/plugin/navigation/door/src/door.kt @@ -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 = 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 = 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 = 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(0, true, player, position, DISTANCE) { +class OpenDoorAction(private val player: Player, private val door: Door, position: Position) : DistancedAction( + 0, true, player, position, DISTANCE) { companion object { diff --git a/game/plugin/shops/src/action.kt b/game/plugin/shops/src/action.kt index db9561e4..0449253c 100644 --- a/game/plugin/shops/src/action.kt +++ b/game/plugin/shops/src/action.kt @@ -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 diff --git a/game/plugin/shops/src/dsl.kt b/game/plugin/shops/src/dsl.kt index 19100bbd..71365f66 100644 --- a/game/plugin/shops/src/dsl.kt +++ b/game/plugin/shops/src/dsl.kt @@ -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 /** diff --git a/game/plugin/shops/src/shop.kt b/game/plugin/shops/src/shop.kt index 90e81086..20863225 100644 --- a/game/plugin/shops/src/shop.kt +++ b/game/plugin/shops/src/shop.kt @@ -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. diff --git a/game/plugin/shops/src/shop.plugin.kts b/game/plugin/shops/src/shop.plugin.kts index 8dd974a8..644e96c3 100644 --- a/game/plugin/shops/src/shop.plugin.kts +++ b/game/plugin/shops/src/shop.plugin.kts @@ -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] diff --git a/game/plugin/skills/fishing/src/spots.kts b/game/plugin/skills/fishing/src/spots.kts index 83080e29..46001275 100644 --- a/game/plugin/skills/fishing/src/spots.kts +++ b/game/plugin/skills/fishing/src/spots.kts @@ -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 diff --git a/game/plugin/util/command/src/command.kt b/game/plugin/util/command/src/command.kt index 7746d948..dd17c26c 100644 --- a/game/plugin/util/command/src/command.kt +++ b/game/plugin/util/command/src/command.kt @@ -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, length: IntRange, player: Player, mess * message if not. */ fun valid_arg_length(args: Array, length: Int, player: Player, message: String) - = valid_arg_length(args, IntRange(length, length), player, message) \ No newline at end of file + = valid_arg_length(args, IntRange(length, length), player, message) \ No newline at end of file diff --git a/game/plugin/util/lookup/src/lookup.kt b/game/plugin/util/lookup/src/lookup.kt index a789b17d..895d63c3 100644 --- a/game/plugin/util/lookup/src/lookup.kt +++ b/game/plugin/util/lookup/src/lookup.kt @@ -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