From cc989d5844bf5ba0a124e12eec9f8f9abc450584 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Wed, 4 Oct 2023 23:17:01 +0000 Subject: [PATCH] Added support for tertiary drop tables --- Server/src/main/core/api/utils/NPCDropTable.kt | 6 ++++++ .../src/main/core/game/system/config/DropTableParser.kt | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Server/src/main/core/api/utils/NPCDropTable.kt b/Server/src/main/core/api/utils/NPCDropTable.kt index 80b19f9b4..defe06ea6 100644 --- a/Server/src/main/core/api/utils/NPCDropTable.kt +++ b/Server/src/main/core/api/utils/NPCDropTable.kt @@ -5,16 +5,22 @@ import core.game.node.item.Item class NPCDropTable : WeightBasedTable() { private val charmDrops = WeightBasedTable() + private val tertiaryDrops = WeightBasedTable() fun addToCharms(element: WeightedItem): Boolean { return charmDrops.add(element) } + fun addToTertiary(element: WeightedItem) : Boolean { + return tertiaryDrops.add(element) + } + override fun roll(receiver: Entity?, times: Int): ArrayList { val items = ArrayList() // 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. items.addAll(charmDrops.roll(receiver, times)) + items.addAll(tertiaryDrops.roll(receiver, times)) items.addAll(super.roll(receiver, times)) return items } diff --git a/Server/src/main/core/game/system/config/DropTableParser.kt b/Server/src/main/core/game/system/config/DropTableParser.kt index 30c1b6e2f..465a1c6ee 100644 --- a/Server/src/main/core/game/system/config/DropTableParser.kt +++ b/Server/src/main/core/game/system/config/DropTableParser.kt @@ -25,8 +25,9 @@ class DropTableParser { try { val table = NPCDropTable() - parseTable(tab["main"] as JSONArray, table, false) - parseTable(tab["charm"] as JSONArray, table, false, true) + parseTable(tab["main"] as JSONArray, table, isAlways = false) + 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) for(n in ids){ @@ -42,7 +43,7 @@ class DropTableParser { 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){ val item = it as JSONObject val id = item["id"].toString().toInt() @@ -56,6 +57,7 @@ class DropTableParser { val weight = item["weight"].toString().toDouble() val newItem = WeightedItem(id,minAmount,maxAmount,weight.toDouble(),isAlways) if(isCharms) destTable.addToCharms(newItem) + else if (isTertiary) destTable.addToTertiary(newItem) else destTable.add(newItem) } }