Implemented a loot message for the reward from Fishing trawler
Optimised junk item removal from Fishing trawler loot
This commit is contained in:
@@ -172,14 +172,9 @@ class NetLootDialogue(player: Player? = null): core.game.dialogue.DialoguePlugin
|
|||||||
override fun handle(interfaceId: Int, buttonId: Int): Boolean {
|
override fun handle(interfaceId: Int, buttonId: Int): Boolean {
|
||||||
val level = player.skills.getLevel(Skills.FISHING)
|
val level = player.skills.getLevel(Skills.FISHING)
|
||||||
when(buttonId){
|
when(buttonId){
|
||||||
1 -> TrawlerLoot.getLoot(level, rolls, true).forEach {
|
1 -> TrawlerLoot.addLootAndMessage(player, level, rolls, true)
|
||||||
if(!player.bank.add(it)) GroundItemManager.create(it,player)
|
2 -> TrawlerLoot.addLootAndMessage(player, level, rolls, false)
|
||||||
}
|
}
|
||||||
2 -> TrawlerLoot.getLoot(level, rolls, false).forEach {
|
|
||||||
if(!player.bank.add(it)) GroundItemManager.create(it,player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.sendMessage(colorize("%RYour reward has been sent to your bank."))
|
|
||||||
player.skills.addExperience(Skills.FISHING,(((0.015 * player.skills.getLevel(Skills.FISHING))) * player.skills.getLevel(Skills.FISHING)) * rolls)
|
player.skills.addExperience(Skills.FISHING,(((0.015 * player.skills.getLevel(Skills.FISHING))) * player.skills.getLevel(Skills.FISHING)) * rolls)
|
||||||
player.removeAttribute("ft-session")
|
player.removeAttribute("ft-session")
|
||||||
end()
|
end()
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
package content.minigame.fishingtrawler
|
package content.minigame.fishingtrawler
|
||||||
|
|
||||||
import content.global.skill.fishing.Fish
|
import content.global.skill.fishing.Fish
|
||||||
|
import core.api.splitLines
|
||||||
|
import core.game.node.entity.player.Player
|
||||||
|
import core.game.node.item.GroundItemManager
|
||||||
import core.game.node.item.Item
|
import core.game.node.item.Item
|
||||||
import core.game.node.item.WeightedChanceItem
|
import core.game.node.item.WeightedChanceItem
|
||||||
import core.tools.RandomFunction
|
import core.tools.RandomFunction
|
||||||
|
import core.tools.colorize
|
||||||
import org.rs09.consts.Items
|
import org.rs09.consts.Items
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rolls/stores the loot table for fishing trawler
|
* Rolls/stores the loot table for fishing trawler
|
||||||
* @author Ceikry
|
* @author Ceikry, RiL
|
||||||
*/
|
*/
|
||||||
object TrawlerLoot {
|
object TrawlerLoot {
|
||||||
val junkItems = arrayOf(Items.BROKEN_ARMOUR_698, Items.BROKEN_ARROW_687, Items.OLD_BOOT_685, Items.BROKEN_GLASS_1469, Items.BROKEN_STAFF_689, Items.BUTTONS_688,Items.DAMAGED_ARMOUR_697, Items.RUSTY_SWORD_686, Items.EMPTY_POT_1931, Items.OYSTER_407)
|
private val junkItems = arrayOf(Items.BROKEN_ARMOUR_698, Items.BROKEN_ARROW_687, Items.OLD_BOOT_685, Items.BROKEN_GLASS_1469, Items.BROKEN_STAFF_689, Items.BUTTONS_688,Items.DAMAGED_ARMOUR_697, Items.RUSTY_SWORD_686, Items.EMPTY_POT_1931, Items.OYSTER_407)
|
||||||
val trawlerFish = arrayOf(Fish.MANTA_RAY, Fish.SEA_TURTLE, Fish.SHARK, Fish.SWORDFISH, Fish.LOBSTER, Fish.TUNA, Fish.ANCHOVIE, Fish.SARDINE, Fish.SHRIMP)
|
private val trawlerFish = arrayOf(Fish.MANTA_RAY, Fish.SEA_TURTLE, Fish.SHARK, Fish.SWORDFISH, Fish.LOBSTER, Fish.TUNA, Fish.ANCHOVIE, Fish.SARDINE, Fish.SHRIMP)
|
||||||
|
private val trawlerFishIds = arrayOf(Items.RAW_MANTA_RAY_389, Items.RAW_SEA_TURTLE_395, Items.RAW_SHARK_383, Items.RAW_SWORDFISH_371, Items.RAW_LOBSTER_377, Items.RAW_TUNA_359, Items.RAW_ANCHOVIES_321, Items.RAW_SARDINE_327, Items.RAW_SHRIMPS_317)
|
||||||
|
private val trawlerMisc = arrayOf(Items.LOOP_HALF_OF_A_KEY_987, Items.TOOTH_HALF_OF_A_KEY_985, Items.CASKET_405, Items.PIRATES_HAT_2651, Items.LUCKY_CUTLASS_7140)
|
||||||
|
|
||||||
fun rollTrawlerFish(fishLevel: Int): Item {
|
private fun rollTrawlerFish(fishLevel: Int): Item {
|
||||||
while(true) {
|
while(true) {
|
||||||
for(f in trawlerFish) {
|
for(f in trawlerFish) {
|
||||||
if(f.level > fishLevel) {
|
if(f.level > fishLevel) {
|
||||||
@@ -37,23 +43,41 @@ object TrawlerLoot {
|
|||||||
for(i in 0 until rolls){
|
for(i in 0 until rolls){
|
||||||
val item = RandomFunction.rollWeightedChanceTable(listOf(*lootTable))
|
val item = RandomFunction.rollWeightedChanceTable(listOf(*lootTable))
|
||||||
if(item.id == 0) {
|
if(item.id == 0) {
|
||||||
val item = rollTrawlerFish(fishLevel)
|
loot.add(rollTrawlerFish(fishLevel))
|
||||||
loot.add(item)
|
} else if (!skipJunk || item.id !in junkItems) {
|
||||||
} else {
|
|
||||||
loot.add(item)
|
loot.add(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(skipJunk){
|
|
||||||
val removeList = ArrayList<Item>()
|
|
||||||
for(item in loot){
|
|
||||||
if(junkItems.contains(item.id)) removeList.add(item)
|
|
||||||
}
|
|
||||||
loot.removeAll(removeList)
|
|
||||||
}
|
|
||||||
return loot
|
return loot
|
||||||
}
|
}
|
||||||
|
|
||||||
val lootTable = arrayOf(
|
/**
|
||||||
|
* Add Fishing trawler loot to [player] bank. Send message with summary of the loot
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun addLootAndMessage(player: Player, fishLevel: Int, rolls: Int, skipJunk: Boolean) {
|
||||||
|
val frequencyList = listOf<MutableMap<String, Int>>(HashMap(), HashMap(), HashMap())
|
||||||
|
getLoot(fishLevel, rolls, skipJunk).forEach {
|
||||||
|
if (!player.bank.add(it)) GroundItemManager.create(it, player)
|
||||||
|
when (it.id) {
|
||||||
|
in trawlerFishIds -> frequencyList[0].merge(it.name, 1, Int::plus)
|
||||||
|
in trawlerMisc -> frequencyList[1].merge(it.name, 1, Int::plus)
|
||||||
|
in junkItems -> frequencyList[2].merge(it.name, 1, Int::plus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendMessage(colorize("%RYour reward has been sent to your bank:"))
|
||||||
|
// Extract and join each frequency maps entries as string. Split based on length, then send each line as message.
|
||||||
|
frequencyList.forEachIndexed { idx, fMap ->
|
||||||
|
if (fMap.isNotEmpty()) {
|
||||||
|
splitLines(
|
||||||
|
fMap.entries.joinToString(prefix = if (idx == 0) "Fish: " else if (idx == 1) "Misc: " else "Junk: ", postfix = ".") { "${it.key}: ${it.value}" },
|
||||||
|
85
|
||||||
|
).forEach { player.sendMessage(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val lootTable = arrayOf(
|
||||||
WeightedChanceItem(0,1,1430),
|
WeightedChanceItem(0,1,1430),
|
||||||
WeightedChanceItem(Items.BROKEN_ARROW_687,1,70),
|
WeightedChanceItem(Items.BROKEN_ARROW_687,1,70),
|
||||||
WeightedChanceItem(Items.BROKEN_GLASS_1469,1,70),
|
WeightedChanceItem(Items.BROKEN_GLASS_1469,1,70),
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ class MiscCommandSet : CommandSet(Privilege.ADMIN){
|
|||||||
} else {
|
} else {
|
||||||
args[1].toString().toInt()
|
args[1].toString().toInt()
|
||||||
}
|
}
|
||||||
player.bank.add(*TrawlerLoot.getLoot(player.skills.getLevel(Skills.FISHING), rolls, false).toTypedArray())
|
TrawlerLoot.addLootAndMessage(player, player.skills.getLevel(Skills.FISHING), rolls, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
define("fillbank", Privilege.ADMIN, "", "Right as it says on the tin."){player,_ ->
|
define("fillbank", Privilege.ADMIN, "", "Right as it says on the tin."){player,_ ->
|
||||||
|
|||||||
Reference in New Issue
Block a user