Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class Light_Item
  2.  
  3. def initialize(items_hash)
  4. @items_hash = items_hash
  5. @inverted_items = items_hash.invert
  6. @percentages = items_hash.values.sort
  7. sum = @percentages.inject(0) {|sum, i| sum + i}
  8. if sum < 100
  9. @items_hash[nil] = @items_hash[nil] || 0 + 100 - sum
  10. end
  11. end
  12.  
  13. def get_random_item
  14. result = rand(100)
  15. i = 0
  16. @percentages.each { |current|
  17. old_sum = i
  18. i += current
  19. return current if old_sum <= result && result < i
  20. }
  21. end
  22.  
  23. def give_item
  24. return false if !Shadow_Utilities.prompt_for_unhide if $Trainer.hidden?
  25. random_item = @inverted_items[self.get_random_item]
  26. Kernel.pbMessage(_INTL(
  27. "You light up this zone using the powers of light and..."
  28. ))
  29. if random_item.nil?
  30. Kernel.pbMessage(_INTL("You find nothing."))
  31. else
  32. Kernel.pbItemBall(random_item)
  33. end
  34. return true
  35. end
  36.  
  37. def sun_crest
  38. if Kernel.pbConfirmMessage(_INTL("Want to light up this zone?"))
  39. return self.give_item
  40. end
  41. end
  42.  
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement