Remove potentially problematic while loops
This commit is contained in:
@@ -44,10 +44,10 @@ class CerterEventInterface : InterfaceListener() {
|
|||||||
|
|
||||||
player.packetDispatch.sendString(items[correct],CERTER_INTERFACE,optionFromIndex(correctIndex))
|
player.packetDispatch.sendString(items[correct],CERTER_INTERFACE,optionFromIndex(correctIndex))
|
||||||
|
|
||||||
val tempOptions = falseOptions
|
val tempOptions = falseOptions.toMutableList()
|
||||||
val false1 = tempOptions.random()
|
val false1 = tempOptions.random()
|
||||||
|
tempOptions.remove(false1)
|
||||||
var false2 = tempOptions.random()
|
var false2 = tempOptions.random()
|
||||||
while(false1 == false2) false2 = tempOptions.random()
|
|
||||||
|
|
||||||
player.packetDispatch.sendString(false1,CERTER_INTERFACE,optionFromIndex(indexes[0]))
|
player.packetDispatch.sendString(false1,CERTER_INTERFACE,optionFromIndex(indexes[0]))
|
||||||
player.packetDispatch.sendString(false2,CERTER_INTERFACE,optionFromIndex(indexes[1]))
|
player.packetDispatch.sendString(false2,CERTER_INTERFACE,optionFromIndex(indexes[1]))
|
||||||
|
|||||||
@@ -75,10 +75,7 @@ class WorkForInteractionListener : InteractionListener() {
|
|||||||
|
|
||||||
val type = typeMap[node.id] ?: return@on false
|
val type = typeMap[node.id] ?: return@on false
|
||||||
jobId = if(type == 0) {
|
jobId = if(type == 0) {
|
||||||
var job = gatheringMap[node.id]?.random()
|
var job = gatheringMap[node.id]?.filter { checkRequirement(player, it) }?.random()
|
||||||
while(!checkRequirement(player,job)){
|
|
||||||
job = gatheringMap[node.id]?.random()
|
|
||||||
}
|
|
||||||
amount = job?.getAmount() ?: 0
|
amount = job?.getAmount() ?: 0
|
||||||
job?.ordinal ?: 0
|
job?.ordinal ?: 0
|
||||||
} else {
|
} else {
|
||||||
@@ -111,8 +108,7 @@ class WorkForInteractionListener : InteractionListener() {
|
|||||||
|
|
||||||
fun checkRequirement(player: Player, jobs: GatheringJobs?): Boolean{
|
fun checkRequirement(player: Player, jobs: GatheringJobs?): Boolean{
|
||||||
jobs ?: return true
|
jobs ?: return true
|
||||||
val requirement: Pair<Int,Int> = Pair(jobs.lvlReq,jobs.skill)
|
if(player.skills.getLevel(jobs.skill) < jobs.lvlReq){
|
||||||
if(player.skills.getLevel(requirement.second) < requirement.first){
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
+3
-2
@@ -53,8 +53,9 @@ fun getNewTTL(): Int{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getNewLoc(): Location {
|
fun getNewLoc(): Location {
|
||||||
var loc = locations.random()
|
val possibleLoc = locations.toTypedArray().toMutableList()
|
||||||
while(usedLocations.contains(loc)) loc = locations.random()
|
possibleLoc.removeAll(usedLocations)
|
||||||
|
val loc = possibleLoc.random()
|
||||||
usedLocations.add(loc)
|
usedLocations.add(loc)
|
||||||
return loc
|
return loc
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user