Remove potentially problematic while loops

This commit is contained in:
ceikry 2021-08-08 23:40:14 -05:00
parent be194f6e5e
commit 3c5c702e7e
3 changed files with 7 additions and 10 deletions

View file

@ -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]))

View file

@ -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<Int,Int> = 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

View file

@ -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
}