mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
Added support for tertiary drop tables
This commit is contained in:
parent
3a72aadbab
commit
cc989d5844
2 changed files with 11 additions and 3 deletions
|
|
@ -5,16 +5,22 @@ import core.game.node.item.Item
|
||||||
|
|
||||||
class NPCDropTable : WeightBasedTable() {
|
class NPCDropTable : WeightBasedTable() {
|
||||||
private val charmDrops = WeightBasedTable()
|
private val charmDrops = WeightBasedTable()
|
||||||
|
private val tertiaryDrops = WeightBasedTable()
|
||||||
|
|
||||||
fun addToCharms(element: WeightedItem): Boolean {
|
fun addToCharms(element: WeightedItem): Boolean {
|
||||||
return charmDrops.add(element)
|
return charmDrops.add(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addToTertiary(element: WeightedItem) : Boolean {
|
||||||
|
return tertiaryDrops.add(element)
|
||||||
|
}
|
||||||
|
|
||||||
override fun roll(receiver: Entity?, times: Int): ArrayList<Item> {
|
override fun roll(receiver: Entity?, times: Int): ArrayList<Item> {
|
||||||
val items = ArrayList<Item>()
|
val items = ArrayList<Item>()
|
||||||
// Charms table is always rolled, and should contain explicit "Nothing"
|
// Charms table is always rolled, and should contain explicit "Nothing"
|
||||||
// entries at the data level to account for the chance to not drop a charm.
|
// entries at the data level to account for the chance to not drop a charm.
|
||||||
items.addAll(charmDrops.roll(receiver, times))
|
items.addAll(charmDrops.roll(receiver, times))
|
||||||
|
items.addAll(tertiaryDrops.roll(receiver, times))
|
||||||
items.addAll(super.roll(receiver, times))
|
items.addAll(super.roll(receiver, times))
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ class DropTableParser {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val table = NPCDropTable()
|
val table = NPCDropTable()
|
||||||
parseTable(tab["main"] as JSONArray, table, false)
|
parseTable(tab["main"] as JSONArray, table, isAlways = false)
|
||||||
parseTable(tab["charm"] as JSONArray, table, false, true)
|
parseTable(tab["charm"] as JSONArray, table, isAlways = false, isCharms = true)
|
||||||
|
(tab["tertiary"] as? JSONArray)?.let { parseTable(it, table, isAlways = false, isTertiary = true) }
|
||||||
parseTable(tab["default"] as JSONArray, table, true)
|
parseTable(tab["default"] as JSONArray, table, true)
|
||||||
|
|
||||||
for(n in ids){
|
for(n in ids){
|
||||||
|
|
@ -42,7 +43,7 @@ class DropTableParser {
|
||||||
log(this::class.java, Log.FINE, "Parsed $count drop tables.")
|
log(this::class.java, Log.FINE, "Parsed $count drop tables.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseTable(data: JSONArray, destTable: NPCDropTable, isAlways: Boolean, isCharms: Boolean = false) {
|
private fun parseTable(data: JSONArray, destTable: NPCDropTable, isAlways: Boolean, isTertiary: Boolean = false, isCharms: Boolean = false) {
|
||||||
for(it in data){
|
for(it in data){
|
||||||
val item = it as JSONObject
|
val item = it as JSONObject
|
||||||
val id = item["id"].toString().toInt()
|
val id = item["id"].toString().toInt()
|
||||||
|
|
@ -56,6 +57,7 @@ class DropTableParser {
|
||||||
val weight = item["weight"].toString().toDouble()
|
val weight = item["weight"].toString().toDouble()
|
||||||
val newItem = WeightedItem(id,minAmount,maxAmount,weight.toDouble(),isAlways)
|
val newItem = WeightedItem(id,minAmount,maxAmount,weight.toDouble(),isAlways)
|
||||||
if(isCharms) destTable.addToCharms(newItem)
|
if(isCharms) destTable.addToCharms(newItem)
|
||||||
|
else if (isTertiary) destTable.addToTertiary(newItem)
|
||||||
else destTable.add(newItem)
|
else destTable.add(newItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue