From 3c5c702e7e9f1825ab361b3f96e1754378e65c66 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 8 Aug 2021 23:40:14 -0500 Subject: [PATCH] Remove potentially problematic while loops --- .../content/ame/events/certer/CerterEventInterface.kt | 4 ++-- .../rs09/game/content/jobs/WorkForInteractionListener.kt | 8 ++------ .../skill/gather/fishing/barbfishing/SpotManager.kt | 5 +++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/content/ame/events/certer/CerterEventInterface.kt b/Server/src/main/kotlin/rs09/game/content/ame/events/certer/CerterEventInterface.kt index 1e21f8cc8..3dbadca5b 100644 --- a/Server/src/main/kotlin/rs09/game/content/ame/events/certer/CerterEventInterface.kt +++ b/Server/src/main/kotlin/rs09/game/content/ame/events/certer/CerterEventInterface.kt @@ -44,10 +44,10 @@ class CerterEventInterface : InterfaceListener() { player.packetDispatch.sendString(items[correct],CERTER_INTERFACE,optionFromIndex(correctIndex)) - val tempOptions = falseOptions + val tempOptions = falseOptions.toMutableList() val false1 = tempOptions.random() + tempOptions.remove(false1) var false2 = tempOptions.random() - while(false1 == false2) false2 = tempOptions.random() player.packetDispatch.sendString(false1,CERTER_INTERFACE,optionFromIndex(indexes[0])) player.packetDispatch.sendString(false2,CERTER_INTERFACE,optionFromIndex(indexes[1])) 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 bfacf46eb..22e638436 100644 --- a/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt +++ b/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt @@ -75,10 +75,7 @@ class WorkForInteractionListener : InteractionListener() { val type = typeMap[node.id] ?: return@on false jobId = if(type == 0) { - var job = gatheringMap[node.id]?.random() - while(!checkRequirement(player,job)){ - job = gatheringMap[node.id]?.random() - } + var job = gatheringMap[node.id]?.filter { checkRequirement(player, it) }?.random() amount = job?.getAmount() ?: 0 job?.ordinal ?: 0 } else { @@ -111,8 +108,7 @@ class WorkForInteractionListener : InteractionListener() { fun checkRequirement(player: Player, jobs: GatheringJobs?): Boolean{ jobs ?: return true - val requirement: Pair = Pair(jobs.lvlReq,jobs.skill) - if(player.skills.getLevel(requirement.second) < requirement.first){ + if(player.skills.getLevel(jobs.skill) < jobs.lvlReq){ return false } return true diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/gather/fishing/barbfishing/SpotManager.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/gather/fishing/barbfishing/SpotManager.kt index b81234d45..695c02450 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/gather/fishing/barbfishing/SpotManager.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/gather/fishing/barbfishing/SpotManager.kt @@ -53,8 +53,9 @@ fun getNewTTL(): Int{ } fun getNewLoc(): Location { - var loc = locations.random() - while(usedLocations.contains(loc)) loc = locations.random() + val possibleLoc = locations.toTypedArray().toMutableList() + possibleLoc.removeAll(usedLocations) + val loc = possibleLoc.random() usedLocations.add(loc) return loc }