Add an inverse percent column.

This commit is contained in:
Avi Weinstock 2022-01-25 21:07:59 -05:00
parent 20d6e42366
commit a96020f3eb

View file

@ -201,6 +201,7 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
mainModel.addColumn("Max Amt")
mainModel.addColumn("Weight")
mainModel.addColumn("(%)")
mainModel.addColumn("(1/%)")
defaultModel.addColumn("ID")
defaultModel.addColumn("Name")
@ -312,6 +313,7 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
fun getPercentage(weight: Double, table: WeightBasedTable): String{
return "${round((weight / table.totalWeight) * 100.0,4)}%"
}
fun round(value: Double, places: Int): Double {
require(places >= 0)
var bd: BigDecimal = BigDecimal.valueOf(value)
@ -328,7 +330,7 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
charmModel.addRow(arrayOf(item.id,TableData.getItemName(item.id),item.minAmt,item.maxAmt,item.weight,getPercentage(item.weight,table.charmTable)))
}
for(item in table){
mainModel.addRow(arrayOf(item.id,TableData.getItemName(item.id),item.minAmt,item.maxAmt,item.weight,getPercentage(item.weight,table)))
mainModel.addRow(arrayOf(item.id,TableData.getItemName(item.id),item.minAmt,item.maxAmt,item.weight,getPercentage(item.weight,table),getInversePercentage(item.weight, table)))
}
isVisible = true
}
@ -337,6 +339,10 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
return "${round((weight / table.totalWeight) * 100.0,2)}%"
}
fun getInversePercentage(weight: Double, table: WeightBasedTable): String {
return "${1.0/(weight / table.totalWeight)}"
}
fun updateCharmPercentages(){
for(i in 0 until charmModel.rowCount){
charmModel.setValueAt(getPercentage(table.charmTable[i].weight,table.charmTable),i,5)
@ -346,6 +352,7 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
fun updateMainPercentages(){
for(i in 0 until mainModel.rowCount){
mainModel.setValueAt(getPercentage(table[i].weight,table),i,5)
mainModel.setValueAt(getInversePercentage(table[i].weight,table),i,6)
}
}
@ -355,4 +362,4 @@ class DropTableEditor(val table: NPCDropTable) : JFrame("Editing ${if(table.ids.
bd = bd.setScale(places, RoundingMode.HALF_UP)
return bd.toDouble()
}
}
}