Skip to content

Commit

Permalink
Dragon Priority sorting logic fix (#142)
Browse files Browse the repository at this point in the history
* Fixed Dragon Priority sorting logic

* nice job bonsai

* Prevented unnecessary sorting

* Renamed function parameters

* use toMutableList instead of casting to MutableList

---------

Co-authored-by: odtheking <[email protected]>
  • Loading branch information
SubAt0m1c and odtheking authored Dec 19, 2024
1 parent cbe422e commit 57b4833
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/me/odinmain/commands/impl/DevCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val devCommand = commodore("oddev") {

literal("drags") {
runs { text: GreedyString ->
WitherDragonsEnum.entries.forEach {
val drags = WitherDragonsEnum.entries.mapNotNull {
if (text.string.lowercase().contains(it.name.lowercase())) {
when (it.name) {
"Red" -> sendChatMessage("/particle flame 27 18 60 1 1 1 1 100 force")
Expand All @@ -41,8 +41,10 @@ val devCommand = commodore("oddev") {
"Blue" -> sendChatMessage("/particle flame 84 18 95 1 1 1 1 100 force")
"Purple" -> sendChatMessage("/particle flame 57 18 125 1 1 1 1 100 force")
}
}
}
it
} else null
}.toMutableList()
modMessage("Expected priority for dragons [${drags.joinToString(", ")}], with class ${DungeonUtils.currentDungeonPlayer.clazz}, with result of ${findPriority(drags)}")
}

literal("reset").runs { soft: Boolean? ->
Expand Down
28 changes: 15 additions & 13 deletions src/main/kotlin/me/odinmain/features/impl/floor7/DragonPriority.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import me.odinmain.features.impl.floor7.WitherDragons.soloDebuffOnAll
import me.odinmain.utils.equalsOneOf
import me.odinmain.utils.skyblock.PlayerUtils
import me.odinmain.utils.skyblock.devMessage
import me.odinmain.utils.skyblock.dungeon.*
import me.odinmain.utils.skyblock.dungeon.Blessing
import me.odinmain.utils.skyblock.dungeon.DungeonClass
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.modMessage

object DragonPriority {

fun findPriority(spawningDragon: MutableList<WitherDragonsEnum>): WitherDragonsEnum {
val priorityList = listOf(WitherDragonsEnum.Red, WitherDragonsEnum.Orange, WitherDragonsEnum.Blue, WitherDragonsEnum.Purple, WitherDragonsEnum.Green)
fun findPriority(spawningDragons: MutableList<WitherDragonsEnum>): WitherDragonsEnum {
return if (!dragonPriorityToggle) {
spawningDragon.sortBy { priorityList.indexOf(it) }
spawningDragon[0]
spawningDragons.sortBy { listOf(WitherDragonsEnum.Red, WitherDragonsEnum.Orange, WitherDragonsEnum.Blue, WitherDragonsEnum.Purple, WitherDragonsEnum.Green).indexOf(it) }
spawningDragons[0]
} else
sortPriority(spawningDragon)
sortPriority(spawningDragons)
}

fun displaySpawningDragon(dragon: WitherDragonsEnum) {
Expand All @@ -30,23 +31,24 @@ object DragonPriority {
if (dragonPriorityToggle && WitherDragons.enabled) modMessage("§${dragon.colorCode}${dragon.name} §7is your priority dragon!")
}

private fun sortPriority(spawningDragon: MutableList<WitherDragonsEnum>): WitherDragonsEnum {
private fun sortPriority(spawningDragons: MutableList<WitherDragonsEnum>): WitherDragonsEnum {
val totalPower = Blessing.POWER.current * (if (paulBuff) 1.25 else 1.0) + (if (Blessing.TIME.current > 0) 2.5 else 0.0)
val playerClass = DungeonUtils.currentDungeonPlayer.clazz.apply { if (this == DungeonClass.Unknown) modMessage("§cFailed to get dungeon class.") }

val dragonList = listOf(WitherDragonsEnum.Orange, WitherDragonsEnum.Green, WitherDragonsEnum.Red, WitherDragonsEnum.Blue, WitherDragonsEnum.Purple)
val priorityList =
if (totalPower >= normalPower || (spawningDragon.any { it == WitherDragonsEnum.Purple } && totalPower >= easyPower))
if (totalPower >= normalPower || (spawningDragons.any { it == WitherDragonsEnum.Purple } && totalPower >= easyPower))
if (playerClass.equalsOneOf(DungeonClass.Berserk, DungeonClass.Mage)) dragonList else dragonList.reversed()
else listOf(WitherDragonsEnum.Red, WitherDragonsEnum.Orange, WitherDragonsEnum.Blue, WitherDragonsEnum.Purple, WitherDragonsEnum.Green)

spawningDragon.sortBy { priorityList.indexOf(it) }
spawningDragons.sortBy { priorityList.indexOf(it) }

if (totalPower >= easyPower) {
if (soloDebuff == 1 && playerClass == DungeonClass.Tank && (spawningDragon.any { it == WitherDragonsEnum.Purple } || soloDebuffOnAll)) spawningDragon.sortByDescending { priorityList.indexOf(it) }
else if (playerClass == DungeonClass.Healer && spawningDragon.any { it == WitherDragonsEnum.Purple } || soloDebuffOnAll) spawningDragon.sortByDescending { priorityList.indexOf(it) }
if (soloDebuff == 1 && playerClass == DungeonClass.Tank && (spawningDragons.any { it == WitherDragonsEnum.Purple } || soloDebuffOnAll)) spawningDragons.sortByDescending { priorityList.indexOf(it) }
else if (playerClass == DungeonClass.Healer && (spawningDragons.any { it == WitherDragonsEnum.Purple } || soloDebuffOnAll)) spawningDragons.sortByDescending { priorityList.indexOf(it) }
}
devMessage("§7Priority: §6$totalPower §7Class: §${playerClass.colorCode}${playerClass.name} §7Dragons: §a${spawningDragon.joinToString(", ") { it.name }} §7-> §c${priorityList.joinToString(", ") { it.name.first().toString() }}")
return spawningDragon[0]

devMessage("§7Priority: §6$totalPower §7Class: §${playerClass.colorCode}${playerClass.name} §7Dragons: §a${spawningDragons.joinToString(", ") { it.name }} §7-> §c${priorityList.joinToString(", ") { it.name.first().toString() }}")
return spawningDragons[0]
}
}

0 comments on commit 57b4833

Please sign in to comment.