Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.nr.plugins.npc.thieving
- import com.fasterxml.jackson.databind.ObjectMapper
- import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
- import com.fasterxml.jackson.module.kotlin.KotlinModule
- import com.fasterxml.jackson.module.kotlin.readValue
- import org.nr.plugins.items.pojos.category.ChanceCategory
- import org.nr.plugins.items.pojos.group.ChanceNamedItemEntryRangedAmountGroup
- import org.nr.plugins.items.pojos.getRandomWeightedElement
- import org.nr.plugins.items.pojos.individual.asItem
- import org.nr.server.model.entity.npc.Npc
- import org.nr.server.model.*
- import java.nio.file.Path
- import java.nio.file.Paths
- import java.util.concurrent.ThreadLocalRandom
- val masterFarmerNpcId = 2234
- val pickpocketOption = 2
- val mapper: ObjectMapper = ObjectMapper(YAMLFactory()).registerModule(KotlinModule())
- val path: Path = Paths.get("data", "def", "yaml", "items", "masterfarmer.yml")
- val categories: List<ChanceCategory<ChanceNamedItemEntryRangedAmountGroup>> = mapper.readValue(path.toFile())
- on_npc_option(masterFarmerNpcId, pickpocketOption) { farmer ->
- player.attemptPickpocketOn(farmer) {
- val groups = categories.getRandomWeightedElement().groups
- val group = groups.getRandomWeightedElement()
- val item = group.items.random().asItem()
- // ^ this is the item the player will get from the data file
- }
- }
- fun Player.attemptPickpocketOn(npc: Npc, successAction: () -> Unit) {
- val thievingLevel = skillManager.getCurrentLevel(Skill.THIEVING)
- if (thievingLevel < 38) {
- message("You need at least 38 Thieving to pickpocket this NPC.")
- return
- }
- val successChance = (90 + 1.53061224 * (thievingLevel - 1)) / 255
- val roll = ThreadLocalRandom.current().nextDouble()
- if (roll <= successChance) {
- performAnimation(Animation(881))
- successAction()
- } else {
- npc.forceChat("Cor blimey mate, what are ye doing in me pockets?")
- npc.positionToFace = position
- performGraphic(Graphic(80, Graphic.GraphicHeight.HIGH))
- performAnimation(Animation(404))
- stun(ThreadLocalRandom.current().nextInt(7, 11))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement