Advertisement
neutale

Random Treasure

May 20th, 2019
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.63 KB | None | 0 0
  1. #===============================================================================
  2. # 2018/08/03 @kido0617
  3. # http://kido0617.github.io/
  4. # Public Domain
  5. # Credit not required.
  6. # Blog: http://kido0617.github.io/rpgmaker/2018-08-03-random-treasure-vxace
  7. # Ver.1.0
  8. #-------------------------------------------------------------------------------
  9.  
  10.  
  11. module RANDOMTREASURE
  12.   NAME_VAR = -1   #Variable number to store acquired item name
  13.   ICON_VAR = -1   #Variable number for storing icon number of the acquired item
  14. end
  15.  
  16. class Game_System
  17.   attr_accessor :random_treasures
  18.  
  19.   alias my_init initialize
  20.   def initialize
  21.     my_init
  22.     @random_treasures = nil
  23.   end
  24. end
  25.  
  26. class Random_Treasure
  27.  
  28.   @@shop_interrupt = false
  29.  
  30.   def self.reset
  31.     @@shop_interrupt = true
  32.   end
  33.  
  34.   def self.is_reset?
  35.     @@shop_interrupt
  36.   end
  37.  
  38.   def self.shop_called
  39.     @@shop_interrupt = false
  40.   end
  41.  
  42.   def self.get
  43.     if !$game_system.random_treasures || $game_system.random_treasures.length == 0
  44.       return
  45.     end
  46.     rate_max = 0
  47.     $game_system.random_treasures.each do |treasure|
  48.       rate_max += treasure['rate']
  49.     end
  50.     rand = rand(rate_max)
  51.     sum = 0
  52.     for i in 0..$game_system.random_treasures.length do
  53.       sum += $game_system.random_treasures[i]['rate']
  54.       if rand < sum
  55.         id = $game_system.random_treasures[i]['id']
  56.         type = $game_system.random_treasures[i]['type']
  57.         item = self.get_item(type, id)
  58.         break
  59.       end
  60.     end
  61.     $game_party.gain_item(item, 1)
  62.     if RANDOMTREASURE::NAME_VAR != -1
  63.        $game_variables[RANDOMTREASURE::NAME_VAR] = item.name
  64.     end
  65.     if RANDOMTREASURE::ICON_VAR != -1
  66.        $game_variables[RANDOMTREASURE::ICON_VAR] = item.icon_index
  67.     end
  68.   end
  69.  
  70.   def self.get_item(type, id)
  71.     case type
  72.     when 0;
  73.       item = $data_items[id]
  74.     when 1;
  75.       item = $data_weapons[id]
  76.     when 2;
  77.       item = $data_armors[id]
  78.     end
  79.     return item
  80.   end
  81.  
  82. end
  83.  
  84.  
  85. class Game_Interpreter
  86.  
  87.   alias my_command_302 command_302
  88.   def command_302
  89.     if Random_Treasure.is_reset?
  90.       Random_Treasure.shop_called
  91.       goodsList = [@params]
  92.       while next_event_code == 605
  93.         @index += 1
  94.         goodsList.push(@list[@index].parameters)
  95.       end
  96.       data = [];
  97.       goodsList.each do |goods|
  98.         item = Random_Treasure.get_item(goods[0], goods[1])
  99.         data.push({
  100.           'type' => goods[0],
  101.           'id' => goods[1],
  102.           'rate' => goods[2] === 0 ? item.price : goods[3]
  103.         });
  104.       end
  105.       $game_system.random_treasures = data
  106.       Fiber.yield
  107.     else
  108.       my_command_302
  109.     end
  110.   end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement