mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-19 21:10:17 -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
|
|
@ -115,3 +115,4 @@
|
||||||
- Spinolyps only drain prayer if they hit, and always target ranged defence (plus null reference fix) - 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
|
- 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
|
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.game.node.item.Item
|
||||||
import core.tools.RandomFunction
|
|
||||||
import org.rs09.consts.Items
|
|
||||||
|
|
||||||
class NPCDropTable : WeightBasedTable() {
|
class NPCDropTable : WeightBasedTable() {
|
||||||
val charmDrops = WeightBasedTable()
|
private val charmDrops = WeightBasedTable()
|
||||||
|
|
||||||
fun addToCharms(element: WeightedItem): Boolean {
|
fun addToCharms(element: WeightedItem): Boolean {
|
||||||
return charmDrops.add(element)
|
return charmDrops.add(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun roll(player: Player?): ArrayList<Item> {
|
override fun roll(): ArrayList<Item> {
|
||||||
val items= ArrayList<Item>(3)
|
val items = ArrayList<Item>()
|
||||||
items.addAll(guaranteedItems.map { it.getItem() }.toList())
|
|
||||||
|
|
||||||
// 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(null))
|
items.addAll(charmDrops.roll())
|
||||||
|
items.addAll(super.roll())
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,52 +10,59 @@ import core.tools.RandomFunction
|
||||||
import org.rs09.consts.Items
|
import org.rs09.consts.Items
|
||||||
|
|
||||||
open class WeightBasedTable : ArrayList<WeightedItem>() {
|
open class WeightBasedTable : ArrayList<WeightedItem>() {
|
||||||
var totalWeight = 0.0
|
private var totalWeight = 0.0
|
||||||
val guaranteedItems = ArrayList<WeightedItem>(5)
|
private val guaranteedItems = ArrayList<WeightedItem>()
|
||||||
|
|
||||||
override fun add(element: WeightedItem): Boolean {
|
override fun add(element: WeightedItem): Boolean {
|
||||||
|
return if (element.guaranteed) {
|
||||||
|
guaranteedItems.add(element)
|
||||||
|
} else {
|
||||||
totalWeight += element.weight
|
totalWeight += element.weight
|
||||||
return if(element.guaranteed) guaranteedItems.add(element)
|
super.add(element)
|
||||||
else super.add(element)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun roll(): ArrayList<Item>{
|
open fun roll(): ArrayList<Item>{
|
||||||
return roll(null)
|
val items = ArrayList<WeightedItem>()
|
||||||
|
items.addAll(guaranteedItems)
|
||||||
|
|
||||||
|
if (size == 1) {
|
||||||
|
items.add(get(0))
|
||||||
}
|
}
|
||||||
|
else if (isNotEmpty()) {
|
||||||
open fun roll(player: Player?): ArrayList<Item>{
|
var rngWeight = RandomFunction.randomDouble(totalWeight)
|
||||||
val items= ArrayList<Item>(3)
|
|
||||||
items.addAll(guaranteedItems.map { it.getItem() }.toList())
|
|
||||||
|
|
||||||
if(player?.inventory?.isFull == true){
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isNotEmpty()) {
|
|
||||||
var tempWeight = RandomFunction.randomDouble(totalWeight)
|
|
||||||
for (item in shuffled()) {
|
for (item in shuffled()) {
|
||||||
tempWeight -= item.weight
|
rngWeight -= item.weight
|
||||||
if (tempWeight <= 0) {
|
if (rngWeight <= 0) {
|
||||||
when(item.id){
|
items.add(item)
|
||||||
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
|
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{
|
open fun canRoll(player: Player): Boolean{
|
||||||
val guaranteed = guaranteedItems.map { it.getItem() }.toTypedArray()
|
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{
|
fun insertEasyClue(weight: Double): WeightBasedTable{
|
||||||
this.add(WeightedItem(SLOT_CLUE_EASY,1,1,weight,false))
|
this.add(WeightedItem(SLOT_CLUE_EASY,1,1,weight,false))
|
||||||
return this
|
return this
|
||||||
|
|
@ -76,7 +83,6 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(vararg items: WeightedItem): WeightBasedTable{
|
fun create(vararg items: WeightedItem): WeightBasedTable{
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class ThievingListeners : InteractionListener() {
|
||||||
node.asNpc().face(null)
|
node.asNpc().face(null)
|
||||||
} else {
|
} else {
|
||||||
player.lock(2)
|
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)
|
player.skills.addExperience(Skills.THIEVING,pickpocketData.experience)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue