mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-11 09:00:23 -07:00
Merge branch 'weighteditem' into 'master'
refactor NPCDropTable, WeightBasedTable to fix bugs See merge request 2009scape/2009scape!390
This commit is contained in:
commit
869773bf60
4 changed files with 46 additions and 67 deletions
|
|
@ -114,4 +114,5 @@
|
|||
- Waterbirth Dungeon is now cannonable - aweinstock
|
||||
- Spinolyps only drain prayer if they hit, and always target ranged defence (plus null reference fix) - aweinstock
|
||||
- Increase drop rate of Sinister Key to 1/12 - aweinstock
|
||||
- Strike spells now always max on Salarin, convert Yanille Agility Dungeon to kotlin + listener - aweinstock
|
||||
- Strike spells now always max on Salarin, convert Yanille Agility Dungeon to kotlin + listener - aweinstock
|
||||
- Refactor NPCDropTable, WeightBasedTable and fixed bug where special items weren't processed in some cases - ryannathans
|
||||
|
|
|
|||
|
|
@ -1,48 +1,20 @@
|
|||
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
|
||||
import org.rs09.consts.Items
|
||||
|
||||
class NPCDropTable : WeightBasedTable() {
|
||||
val charmDrops = WeightBasedTable()
|
||||
private val charmDrops = WeightBasedTable()
|
||||
|
||||
fun addToCharms(element: WeightedItem): Boolean {
|
||||
return charmDrops.add(element)
|
||||
}
|
||||
|
||||
override fun roll(player: Player?): ArrayList<Item> {
|
||||
val items= ArrayList<Item>(3)
|
||||
items.addAll(guaranteedItems.map { it.getItem() }.toList())
|
||||
|
||||
override fun roll(): ArrayList<Item> {
|
||||
val items = ArrayList<Item>()
|
||||
// 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(null))
|
||||
|
||||
if(size == 1){
|
||||
items.add(get(0).getItem())
|
||||
return items
|
||||
}
|
||||
if(isNotEmpty()) {
|
||||
var tempWeight = RandomFunction.randomDouble(totalWeight)
|
||||
for (item in shuffled()) {
|
||||
tempWeight -= item.weight
|
||||
if (tempWeight <= 0) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
items.addAll(charmDrops.roll())
|
||||
items.addAll(super.roll())
|
||||
return items
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,52 +10,59 @@ import core.tools.RandomFunction
|
|||
import org.rs09.consts.Items
|
||||
|
||||
open class WeightBasedTable : ArrayList<WeightedItem>() {
|
||||
var totalWeight = 0.0
|
||||
val guaranteedItems = ArrayList<WeightedItem>(5)
|
||||
private var totalWeight = 0.0
|
||||
private val guaranteedItems = ArrayList<WeightedItem>()
|
||||
|
||||
override fun add(element: WeightedItem): Boolean {
|
||||
totalWeight += element.weight
|
||||
return if(element.guaranteed) guaranteedItems.add(element)
|
||||
else super.add(element)
|
||||
}
|
||||
|
||||
fun roll(): ArrayList<Item>{
|
||||
return roll(null)
|
||||
}
|
||||
|
||||
open fun roll(player: Player?): ArrayList<Item>{
|
||||
val items= ArrayList<Item>(3)
|
||||
items.addAll(guaranteedItems.map { it.getItem() }.toList())
|
||||
|
||||
if(player?.inventory?.isFull == true){
|
||||
return items
|
||||
return if (element.guaranteed) {
|
||||
guaranteedItems.add(element)
|
||||
} else {
|
||||
totalWeight += element.weight
|
||||
super.add(element)
|
||||
}
|
||||
}
|
||||
|
||||
if(isNotEmpty()) {
|
||||
var tempWeight = RandomFunction.randomDouble(totalWeight)
|
||||
open fun roll(): ArrayList<Item>{
|
||||
val items = ArrayList<WeightedItem>()
|
||||
items.addAll(guaranteedItems)
|
||||
|
||||
if (size == 1) {
|
||||
items.add(get(0))
|
||||
}
|
||||
else if (isNotEmpty()) {
|
||||
var rngWeight = RandomFunction.randomDouble(totalWeight)
|
||||
for (item in shuffled()) {
|
||||
tempWeight -= item.weight
|
||||
if (tempWeight <= 0) {
|
||||
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())
|
||||
}
|
||||
rngWeight -= item.weight
|
||||
if (rngWeight <= 0) {
|
||||
items.add(item)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return items
|
||||
|
||||
return convertWeightedItems(items)
|
||||
}
|
||||
|
||||
private fun convertWeightedItems(weightedItems: ArrayList<WeightedItem>): ArrayList<Item> {
|
||||
val safeItems = ArrayList<Item>(weightedItems.size)
|
||||
weightedItems.forEach { e ->
|
||||
val safeItem = when (e.id) {
|
||||
SLOT_CLUE_EASY -> ClueScrollPlugin.getClue(ClueLevel.EASY)
|
||||
SLOT_CLUE_MEDIUM -> ClueScrollPlugin.getClue(ClueLevel.MEDIUM)
|
||||
SLOT_CLUE_HARD -> ClueScrollPlugin.getClue(ClueLevel.HARD)
|
||||
SLOT_RDT -> RareDropTable.retrieve()
|
||||
else -> e.getItem()
|
||||
}
|
||||
safeItems.add(safeItem)
|
||||
}
|
||||
return safeItems
|
||||
}
|
||||
|
||||
open fun canRoll(player: Player): Boolean{
|
||||
val guaranteed = guaranteedItems.map { it.getItem() }.toTypedArray()
|
||||
return (player.inventory.hasSpaceFor(*guaranteed) && guaranteed.isNotEmpty()) || !player.inventory.isFull
|
||||
return (guaranteed.isNotEmpty() && player.inventory.hasSpaceFor(*guaranteed)) || !player.inventory.isFull
|
||||
}
|
||||
|
||||
|
||||
fun insertEasyClue(weight: Double): WeightBasedTable{
|
||||
this.add(WeightedItem(SLOT_CLUE_EASY,1,1,weight,false))
|
||||
return this
|
||||
|
|
@ -76,7 +83,6 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
|
|||
return this
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun create(vararg items: WeightedItem): WeightBasedTable{
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class ThievingListeners : InteractionListener() {
|
|||
node.asNpc().face(null)
|
||||
} else {
|
||||
player.lock(2)
|
||||
pickpocketData.table.roll(player).forEach { player.inventory.add(it) }
|
||||
pickpocketData.table.roll().forEach { player.inventory.add(it) }
|
||||
player.skills.addExperience(Skills.THIEVING,pickpocketData.experience)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue