From 931409ba97bcdd6fe7c4ff370d9fe7c0772ea764 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Sat, 2 Jul 2022 07:54:27 +0000 Subject: [PATCH] Fixed exception occurring when an NPC has no jobs that can be assigned to the player Fixed an issue that caused killing jobs not to work without relogging first --- .../java/core/game/node/entity/Entity.java | 8 +------- .../content/jobs/WorkForInteractionListener.kt | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Server/src/main/java/core/game/node/entity/Entity.java b/Server/src/main/java/core/game/node/entity/Entity.java index 24caeb50d..8899676f6 100644 --- a/Server/src/main/java/core/game/node/entity/Entity.java +++ b/Server/src/main/java/core/game/node/entity/Entity.java @@ -178,13 +178,7 @@ public abstract class Entity extends Node { */ public void unhook(EventHook hook) { - GameWorld.getPulser().submit(new Pulse() { - @Override - public boolean pulse() { - for(ArrayList s : hooks.values()) s.remove(hook); - return true; - } - }); + for(ArrayList s : hooks.values()) s.remove(hook); } /** diff --git a/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt b/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt index 062dcffe7..6c85cabcb 100644 --- a/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt +++ b/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt @@ -5,6 +5,7 @@ import SlayingJob import api.* import api.events.EventHook import api.events.NPCKillEvent +import core.game.content.dialogue.FacialExpression import core.game.node.entity.Entity import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player @@ -85,9 +86,20 @@ class WorkForInteractionListener : InteractionListener, LoginListener { val type = typeMap[node.id] ?: return@on false jobId = if(type == 0) { - var job = gatheringMap[node.id]?.filter { checkRequirement(player, it) }?.random() - amount = job?.getAmount() ?: 0 - job?.ordinal ?: 0 + val job = gatheringMap[node.id]?.filter { checkRequirement(player, it) }?.randomOrNull() + + if (job == null) { + sendNPCDialogue( + player, + node.id, + "I'm sorry, I don't currently have any jobs that you're qualified for.", + FacialExpression.HALF_THINKING + ) + return@on true + } + + amount = job.getAmount() + job.ordinal } else { SlayingJob.values().random().ordinal.also { amount = SlayingJob.values()[it].getAmount() } }