Advertisement
Guest User

Master Farmer Pickpocketing

a guest
Apr 5th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.13 KB | None | 0 0
  1. package org.nr.plugins.npc.thieving
  2.  
  3. import com.fasterxml.jackson.databind.ObjectMapper
  4. import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
  5. import com.fasterxml.jackson.module.kotlin.KotlinModule
  6. import com.fasterxml.jackson.module.kotlin.readValue
  7. import org.nr.plugins.items.pojos.category.ChanceCategory
  8. import org.nr.plugins.items.pojos.group.ChanceNamedItemEntryRangedAmountGroup
  9. import org.nr.plugins.items.pojos.getRandomWeightedElement
  10. import org.nr.plugins.items.pojos.individual.asItem
  11. import org.nr.server.model.entity.npc.Npc
  12. import org.nr.server.model.*
  13. import java.nio.file.Path
  14. import java.nio.file.Paths
  15. import java.util.concurrent.ThreadLocalRandom
  16.  
  17. val masterFarmerNpcId = 2234
  18. val pickpocketOption = 2
  19.  
  20. val mapper: ObjectMapper = ObjectMapper(YAMLFactory()).registerModule(KotlinModule())
  21. val path: Path = Paths.get("data", "def", "yaml", "items", "masterfarmer.yml")
  22. val categories: List<ChanceCategory<ChanceNamedItemEntryRangedAmountGroup>> = mapper.readValue(path.toFile())
  23.  
  24. on_npc_option(masterFarmerNpcId, pickpocketOption) { farmer ->
  25.     player.attemptPickpocketOn(farmer) {
  26.         val groups = categories.getRandomWeightedElement().groups
  27.         val group = groups.getRandomWeightedElement()
  28.         val item = group.items.random().asItem()
  29.         // ^ this is the item the player will get from the data file
  30.     }
  31. }
  32.  
  33. fun Player.attemptPickpocketOn(npc: Npc, successAction: () -> Unit) {
  34.     val thievingLevel = skillManager.getCurrentLevel(Skill.THIEVING)
  35.     if (thievingLevel < 38) {
  36.         message("You need at least 38 Thieving to pickpocket this NPC.")
  37.         return
  38.     }
  39.     val successChance = (90 + 1.53061224 * (thievingLevel - 1)) / 255
  40.     val roll = ThreadLocalRandom.current().nextDouble()
  41.     if (roll <= successChance) {
  42.         performAnimation(Animation(881))
  43.         successAction()
  44.     } else {
  45.         npc.forceChat("Cor blimey mate, what are ye doing in me pockets?")
  46.         npc.positionToFace = position
  47.         performGraphic(Graphic(80, Graphic.GraphicHeight.HIGH))
  48.         performAnimation(Animation(404))
  49.         stun(ThreadLocalRandom.current().nextInt(7, 11))
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement