From c59f66f7c58ee8576c07c4ad8ebdba6c7c00d6a6 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Fri, 19 Mar 2021 23:32:12 -0500 Subject: [PATCH] NPC drop tables -> NPCDropTable.kt Corrections to HAM members --- .../node/entity/npc/drop/NPCDropTables.java | 43 +++++--------- .../rs09/game/content/global/NPCDropTable.kt | 16 ++++- .../game/content/global/WeightBasedTable.kt | 59 ++++++++++++++++++- .../shootingstar/ShootingStarEvent.kt | 1 - .../node/entity/skill/thieving/Pickpockets.kt | 20 +++---- .../skill/thieving/ThievingListeners.kt | 2 + .../game/system/config/DropTableParser.kt | 26 ++++---- 7 files changed, 107 insertions(+), 60 deletions(-) diff --git a/Server/src/main/java/core/game/node/entity/npc/drop/NPCDropTables.java b/Server/src/main/java/core/game/node/entity/npc/drop/NPCDropTables.java index 2d93498c0..e50428254 100644 --- a/Server/src/main/java/core/game/node/entity/npc/drop/NPCDropTables.java +++ b/Server/src/main/java/core/game/node/entity/npc/drop/NPCDropTables.java @@ -1,22 +1,26 @@ package core.game.node.entity.npc.drop; import core.cache.def.impl.NPCDefinition; -import core.game.node.item.*; -import rs09.game.system.config.ItemConfigParser; -import rs09.game.ai.AIPlayer; -import rs09.game.ai.AIRepository; -import rs09.game.ai.general.GeneralBotCreator; -import core.game.ge.GrandExchangeDatabase; import core.game.content.global.Bones; -import core.game.node.entity.skill.Skills; +import core.game.ge.GrandExchangeDatabase; import core.game.node.entity.Entity; import core.game.node.entity.npc.NPC; import core.game.node.entity.player.Player; +import core.game.node.entity.skill.Skills; +import core.game.node.item.GroundItem; +import core.game.node.item.GroundItemManager; +import core.game.node.item.Item; +import core.game.node.item.WeightedChanceItem; import core.game.world.map.Location; import core.game.world.map.RegionManager; -import rs09.game.world.repository.Repository; import core.tools.RandomFunction; import core.tools.StringUtils; +import rs09.game.ai.AIPlayer; +import rs09.game.ai.AIRepository; +import rs09.game.ai.general.GeneralBotCreator; +import rs09.game.content.global.NPCDropTable; +import rs09.game.system.config.ItemConfigParser; +import rs09.game.world.repository.Repository; import java.util.ArrayList; import java.util.List; @@ -52,6 +56,8 @@ public final class NPCDropTables { */ private final List mainTable = new ArrayList<>(20); + public final NPCDropTable table = new NPCDropTable(); + /** * The NPC definitions. */ @@ -82,26 +88,7 @@ public final class NPCDropTables { */ public void drop(NPC npc, Entity looter) { Player p = looter instanceof Player ? (Player) looter : null; - if (!charmTable.isEmpty()) { - boolean rollCharms = RandomFunction.random(5) == 3; - if(rollCharms) { - createDrop(RandomFunction.rollWeightedChanceTable(charmTable),p,npc,npc.getDropLocation()); - } - } - defaultTable.forEach(drop -> { - createDrop(drop.getItem(),p,npc,npc.getDropLocation()); - }); - Item item = RandomFunction.rollWeightedChanceTable(mainTable); - //boolean hasWealthRing = p != null && p.getEquipment().getNew(EquipmentContainer.SLOT_RING).getId() == 2572; - if(item != null) { - boolean isRDTSlot = item.getId() == RareDropTable.SLOT_ITEM_ID; - if (isRDTSlot) { - item = RareDropTable.retrieve(); - } - if (item != null && p != null && npc != null) { - createDrop(item, p, npc, npc.getDropLocation()); - } - } + table.roll().forEach(item -> createDrop(item,p,npc,npc.getDropLocation())); } /** diff --git a/Server/src/main/kotlin/rs09/game/content/global/NPCDropTable.kt b/Server/src/main/kotlin/rs09/game/content/global/NPCDropTable.kt index cce744d0a..984b2465e 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/NPCDropTable.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/NPCDropTable.kt @@ -1,5 +1,8 @@ package rs09.game.content.global +import core.game.content.ttrail.ClueLevel +import core.game.content.ttrail.ClueScrollPlugin +import core.game.node.entity.npc.drop.RareDropTable import core.game.node.entity.player.Player import core.game.node.item.Item import core.tools.RandomFunction @@ -14,13 +17,14 @@ class NPCDropTable : WeightBasedTable() { else super.add(element) } - override fun roll(player: Player): ArrayList { + override fun roll(player: Player?): ArrayList { + if(size == 0) return ArrayList() val items= ArrayList(3) var tempWeight = RandomFunction.randomDouble(totalWeight) items.addAll(guaranteedItems.map { it.getItem() }.toList()) if(RandomFunction.random(1,15) == 5){ - items.addAll(charmDrops.roll(player)) + items.addAll(charmDrops.roll(null)) } if(size == 1){ items.add(get(0).getItem()) @@ -30,7 +34,13 @@ class NPCDropTable : WeightBasedTable() { for (item in shuffled()) { tempWeight -= item.weight if (tempWeight <= 0) { - items.add(item.getItem()) + when(item.id){ + SLOT_CLUE_EASY -> items.add(ClueScrollPlugin.getClue(ClueLevel.EASY)) + SLOT_CLUE_MEDIUM -> items.add(ClueScrollPlugin.getClue(ClueLevel.MEDIUM)) + SLOT_CLUE_HARD -> items.add(ClueScrollPlugin.getClue(ClueLevel.HARD)) + SLOT_RDT -> items.add(RareDropTable.retrieve()) + else -> items.add(item.getItem()) + } break } } diff --git a/Server/src/main/kotlin/rs09/game/content/global/WeightBasedTable.kt b/Server/src/main/kotlin/rs09/game/content/global/WeightBasedTable.kt index c1499796d..0abe908bf 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/WeightBasedTable.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/WeightBasedTable.kt @@ -1,8 +1,13 @@ package rs09.game.content.global +import core.cache.def.impl.ItemDefinition +import core.game.content.ttrail.ClueLevel +import core.game.content.ttrail.ClueScrollPlugin +import core.game.node.entity.npc.drop.RareDropTable import core.game.node.entity.player.Player import core.game.node.item.Item import core.tools.RandomFunction +import org.rs09.consts.Items open class WeightBasedTable : ArrayList() { var totalWeight = 0.0 @@ -14,12 +19,17 @@ open class WeightBasedTable : ArrayList() { else super.add(element) } - open fun roll(player: Player): ArrayList{ + fun roll(): ArrayList{ + return roll(null) + } + + open fun roll(player: Player?): ArrayList{ + if(size == 0) return ArrayList() val items= ArrayList(3) var tempWeight = RandomFunction.randomDouble(totalWeight) items.addAll(guaranteedItems.map { it.getItem() }.toList()) - if(player.inventory.isFull){ + if(player?.inventory?.isFull == true){ return items } @@ -27,7 +37,13 @@ open class WeightBasedTable : ArrayList() { for (item in shuffled()) { tempWeight -= item.weight if (tempWeight <= 0) { - items.add(item.getItem()) + when(item.id){ + SLOT_CLUE_EASY -> items.add(ClueScrollPlugin.getClue(ClueLevel.EASY)) + SLOT_CLUE_MEDIUM -> items.add(ClueScrollPlugin.getClue(ClueLevel.MEDIUM)) + SLOT_CLUE_HARD -> items.add(ClueScrollPlugin.getClue(ClueLevel.HARD)) + SLOT_RDT -> items.add(RareDropTable.retrieve()) + else -> items.add(item.getItem()) + } break } } @@ -40,6 +56,28 @@ open class WeightBasedTable : ArrayList() { return (player.inventory.hasSpaceFor(*guaranteed) && guaranteed.isNotEmpty()) || !player.inventory.isFull } + + fun insertEasyClue(weight: Double): WeightBasedTable{ + this.add(WeightedItem(SLOT_CLUE_EASY,1,1,weight,false)) + return this + } + + fun insertMediumClue(weight: Double): WeightBasedTable{ + this.add(WeightedItem(SLOT_CLUE_MEDIUM,1,1,weight,false)) + return this + } + + fun insertHardClue(weight: Double): WeightBasedTable{ + this.add(WeightedItem(SLOT_CLUE_HARD,1,1,weight,false)) + return this + } + + fun insertRDTRoll(weight: Double): WeightBasedTable{ + this.add(WeightedItem(SLOT_RDT,1,1,weight,false)) + return this + } + + companion object { @JvmStatic fun create(vararg items: WeightedItem): WeightBasedTable{ @@ -49,5 +87,20 @@ open class WeightBasedTable : ArrayList() { } return table } + + @JvmField + val SLOT_RDT = Items.TINDERBOX_31 + val SLOT_CLUE_EASY = Items.TOOLKIT_1 + val SLOT_CLUE_MEDIUM = Items.ROTTEN_POTATO_5733 + val SLOT_CLUE_HARD = Items.GRANITE_LOBSTER_POUCH_12070 + } + + override fun toString(): String { + val builder = StringBuilder() + for(item in this){ + builder.append("${ItemDefinition.forId(item.id).name} || Weight: ${item.weight} || MinAmt: ${item.minAmt} || maxAmt: ${item.maxAmt}") + builder.appendLine() + } + return builder.toString() } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt index bf74ee482..ff11e467c 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt @@ -23,7 +23,6 @@ class ShootingStarEvent : WorldEvent("shooting-stars") { override fun initialize() { plugins = PluginSet( ScoreboardHandler(), - ShootingStarOptionHandler(), ShootingStarScoreboard(), StarChartPlugin(), ShootingStarCommands(), diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/Pickpockets.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/Pickpockets.kt index 825312e45..885a4a36c 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/Pickpockets.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/Pickpockets.kt @@ -25,10 +25,10 @@ enum class Pickpockets(val ids: IntArray, val requiredLevel: Int, val low: Doubl WeightedItem(Items.UNCUT_OPAL_1625,1,1,2.5), WeightedItem(Items.RAW_ANCHOVIES_321,1,1,7.0), WeightedItem(Items.RAW_CHICKEN_2138,1,1,3.5), - WeightedItem(Items.HAM_CLOAK_4304,1,1,1.0), - WeightedItem(Items.HAM_HOOD_4302,1,1,1.0), - WeightedItem(Items.HAM_LOGO_4306,1,1,1.0), - WeightedItem(Items.HAM_ROBE_4300,1,1,1.0), + WeightedItem(Items.HAM_CLOAK_4304,1,1,0.25), + WeightedItem(Items.HAM_HOOD_4302,1,1,0.25), + WeightedItem(Items.HAM_LOGO_4306,1,1,0.25), + WeightedItem(Items.HAM_ROBE_4300,1,1,0.25), WeightedItem(Items.BOOTS_4310,1,1,1.0), WeightedItem(Items.GLOVES_4308,1,1,1.0), WeightedItem(Items.BRONZE_PICKAXE_1265,1,1,5.0), @@ -42,7 +42,7 @@ enum class Pickpockets(val ids: IntArray, val requiredLevel: Int, val low: Doubl WeightedItem(Items.BROKEN_ARMOUR_698,1,1,3.5), WeightedItem(Items.BROKEN_STAFF_689,1,1,3.2), WeightedItem(Items.BROKEN_ARROW_687,1,1,3.1) - )), + ).insertEasyClue(1.0)), FEMALE_HAM_MEMBER(intArrayOf(1715), 15, 135.0, 240.0, 18.5, 1,3,4, WeightBasedTable.create( WeightedItem(Items.COINS_995,1,21,5.5), WeightedItem(Items.TINDERBOX_590,1,1,5.0), @@ -51,10 +51,10 @@ enum class Pickpockets(val ids: IntArray, val requiredLevel: Int, val low: Doubl WeightedItem(Items.UNCUT_OPAL_1625,1,1,2.5), WeightedItem(Items.RAW_ANCHOVIES_321,1,1,7.0), WeightedItem(Items.RAW_CHICKEN_2138,1,1,3.5), - WeightedItem(Items.HAM_CLOAK_4304,1,1,1.0), - WeightedItem(Items.HAM_HOOD_4302,1,1,1.0), - WeightedItem(Items.HAM_LOGO_4306,1,1,1.0), - WeightedItem(Items.HAM_ROBE_4300,1,1,1.0), + WeightedItem(Items.HAM_CLOAK_4304,1,1,0.25), + WeightedItem(Items.HAM_HOOD_4302,1,1,0.25), + WeightedItem(Items.HAM_LOGO_4306,1,1,0.25), + WeightedItem(Items.HAM_ROBE_4300,1,1,0.25), WeightedItem(Items.BOOTS_4310,1,1,1.0), WeightedItem(Items.GLOVES_4308,1,1,1.0), WeightedItem(Items.BRONZE_PICKAXE_1265,1,1,5.0), @@ -68,7 +68,7 @@ enum class Pickpockets(val ids: IntArray, val requiredLevel: Int, val low: Doubl WeightedItem(Items.BROKEN_ARMOUR_698,1,1,3.5), WeightedItem(Items.BROKEN_STAFF_689,1,1,3.2), WeightedItem(Items.BROKEN_ARROW_687,1,1,3.1) - )), + ).insertEasyClue(1.0)), WARRIOR(intArrayOf(15, 18), 25, 84.0, 240.0, 26.0, 2, 2, 5, WeightBasedTable.create( WeightedItem(Items.COINS_995,18,18,1.0,true) )), diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/ThievingListeners.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/ThievingListeners.kt index 935cc15dd..7550f392f 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/ThievingListeners.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/thieving/ThievingListeners.kt @@ -10,6 +10,7 @@ import core.game.world.update.flag.context.Animation import core.tools.RandomFunction import org.rs09.consts.Items import rs09.game.interaction.InteractionListener +import rs09.game.system.SystemLogger import rs09.tools.secondsToTicks class ThievingListeners : InteractionListener() { @@ -24,6 +25,7 @@ class ThievingListeners : InteractionListener() { on(NPC,"pickpocket","pick-pocket"){player, node -> val pickpocketData = Pickpockets.forID(node.id) ?: return@on false var successMod = 0 + SystemLogger.logInfo(pickpocketData.table.toString()) if(player.inCombat()){ player.sendMessage("You can't pickpocket while in combat.") diff --git a/Server/src/main/kotlin/rs09/game/system/config/DropTableParser.kt b/Server/src/main/kotlin/rs09/game/system/config/DropTableParser.kt index 788f5c8ec..9c72326bb 100644 --- a/Server/src/main/kotlin/rs09/game/system/config/DropTableParser.kt +++ b/Server/src/main/kotlin/rs09/game/system/config/DropTableParser.kt @@ -1,14 +1,14 @@ package rs09.game.system.config -import rs09.ServerConstants import core.cache.def.impl.NPCDefinition -import core.game.node.item.WeightedChanceItem -import rs09.game.system.SystemLogger import org.json.simple.JSONArray import org.json.simple.JSONObject import org.json.simple.parser.JSONParser +import rs09.ServerConstants +import rs09.game.content.global.WeightBasedTable +import rs09.game.content.global.WeightedItem +import rs09.game.system.SystemLogger import java.io.FileReader -import java.util.* class DropTableParser { val parser = JSONParser() @@ -23,28 +23,24 @@ class DropTableParser { for(n in ids){ val def = NPCDefinition.forId(n.toInt()).dropTables def ?: continue - val mainTable: List = parseTable(tab["main"] as JSONArray) - val charmTable: List = parseTable(tab["charm"] as JSONArray) - val defaultTable: List = parseTable(tab["default"] as JSONArray) - def.mainTable.addAll(mainTable) - def.charmTable.addAll(charmTable) - def.defaultTable.addAll(defaultTable) + parseTable(tab["main"] as JSONArray, def.table, false) + parseTable(tab["charm"] as JSONArray, def.table, false) + parseTable(tab["default"] as JSONArray,def.table,true) + count++ } } SystemLogger.logInfo("Parsed $count drop tables.") } - private fun parseTable(data: JSONArray): List { - val table: MutableList = ArrayList() + private fun parseTable(data: JSONArray, destTable: WeightBasedTable, isAlways: Boolean) { for(it in data){ val item = it as JSONObject val id = item["id"].toString().toInt() val minAmount = item["minAmount"].toString().toInt() val maxAmount = item["maxAmount"].toString().toInt() val weight = item["weight"].toString().toInt() - val newItem = WeightedChanceItem(id,minAmount,maxAmount,weight) - table.add(newItem) + val newItem = WeightedItem(id,minAmount,maxAmount,weight.toDouble(),isAlways) + destTable.add(newItem) } - return table } } \ No newline at end of file