diff --git a/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationListener.kt b/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationListener.kt new file mode 100644 index 000000000..401d09d54 --- /dev/null +++ b/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationListener.kt @@ -0,0 +1,27 @@ +package content.region.asgarnia.goblinvillage.handlers + +import core.game.interaction.IntType +import core.game.interaction.InteractionListener +import core.game.node.entity.combat.DeathTask +import core.game.world.map.RegionManager.getLocalNpcs +import org.rs09.consts.Scenery + +class GoblinVillagePopulationListener : InteractionListener{ + override fun defineListeners() { + on(Scenery.SIGNPOST_31301, IntType.SCENERY, "read") { player, node -> + var population = 3 // This covers General Wartface, General Bentnoze and Grubfoot + val npcs = getLocalNpcs(player, 50) // This radius covers more than the goblin village. + // There should be 18 Goblins walking around. + // 10 are within the village walls where the generals are. + // 8 of them are fighting each other on the west of the path to the village. + // Total should be 21. They respawn really fast. + for (n in npcs) { + if (n.name == "Goblin" && !DeathTask.isDead(n)) { + population++ + } + player.dialogueInterpreter.sendPlainMessage(false, "Welcome to Goblin Village.", "Current population: $population") + } + return@on true + } + } +} \ No newline at end of file diff --git a/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationPlugin.java b/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationPlugin.java deleted file mode 100644 index 2a1debd1d..000000000 --- a/Server/src/main/content/region/asgarnia/goblinvillage/handlers/GoblinVillagePopulationPlugin.java +++ /dev/null @@ -1,36 +0,0 @@ -package content.region.asgarnia.goblinvillage.handlers; - -import java.util.List; - -import core.cache.def.impl.SceneryDefinition; -import core.game.interaction.OptionHandler; -import core.game.node.Node; -import core.game.node.entity.npc.NPC; -import core.game.node.entity.player.Player; -import core.game.world.map.RegionManager; -import core.plugin.Initializable; -import core.plugin.Plugin; - -@Initializable -public class GoblinVillagePopulationPlugin extends OptionHandler { - - @Override - public Plugin newInstance(Object arg) throws Throwable { - SceneryDefinition.forId(31301).getHandlers().put("option:read", this); - return this; - } - - @Override - public boolean handle(Player player, Node node, String option) { - int population = 2; - final List npcs = RegionManager.getLocalNpcs(player); - for (NPC n : npcs) { - if (n.getName().equals("Goblin")) { - population++; - player.getDialogueInterpreter().sendPlainMessage(false, "Welcome to Goblin Village.", "Current population: " + population); - } - } - return true; - } - -}