mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Fixed bug causing herb and uncommon seed drop tables to only roll once when they should have rolled multiple times
This commit is contained in:
parent
74cbec067c
commit
676397f3fd
1 changed files with 30 additions and 9 deletions
|
|
@ -42,27 +42,48 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
|
||||||
return roll(receiver, 1)
|
return roll(receiver, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun roll(receiver: Entity? = null, times: Int = 1): ArrayList<Item>{
|
open fun roll(receiver: Entity?, times: Int = 1): ArrayList<Item> {
|
||||||
val items = ArrayList<WeightedItem>((guaranteedItems.size + 1) * times)
|
val weightedItemsToDrop = ArrayList<WeightedItem>()
|
||||||
|
|
||||||
for (i in 0 until times) {
|
repeat(times) {
|
||||||
items.addAll(guaranteedItems)
|
// Guaranteed items
|
||||||
|
for (item in guaranteedItems) {
|
||||||
|
if (isSpecialSlot(item.id)) {
|
||||||
|
val rolls = RandomFunction.random(item.minAmt, item.maxAmt)
|
||||||
|
repeat(rolls) {
|
||||||
|
weightedItemsToDrop.add(item)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add just one instance with amount set by getItem()
|
||||||
|
weightedItemsToDrop.add(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (size == 1) {
|
// Weighted roll (one per table roll)
|
||||||
items.add(get(0))
|
if (isNotEmpty()) {
|
||||||
} else if (isNotEmpty()) {
|
|
||||||
var rngWeight = RandomFunction.randomDouble(totalWeight)
|
var rngWeight = RandomFunction.randomDouble(totalWeight)
|
||||||
for (item in this) {
|
for (item in this) {
|
||||||
rngWeight -= item.weight
|
rngWeight -= item.weight
|
||||||
if (rngWeight <= 0) {
|
if (rngWeight <= 0) {
|
||||||
items.add(item)
|
if (isSpecialSlot(item.id)) {
|
||||||
|
val rolls = RandomFunction.random(item.minAmt, item.maxAmt)
|
||||||
|
repeat(rolls) {
|
||||||
|
weightedItemsToDrop.add(item)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
weightedItemsToDrop.add(item)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertWeightedItems(items, receiver)
|
return convertWeightedItems(weightedItemsToDrop, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isSpecialSlot(id: Int): Boolean {
|
||||||
|
return id == SLOT_HDT || id == SLOT_USDT // extend this if a drop table is not dropping multiple times
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertWeightedItems(weightedItems: ArrayList<WeightedItem>, receiver: Entity?): ArrayList<Item> {
|
fun convertWeightedItems(weightedItems: ArrayList<WeightedItem>, receiver: Entity?): ArrayList<Item> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue