document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #===========RGSS+ (v.1.13)==============
  2. #-------------------------------------------------------------------------------
  3. #Различные добавки к RGSS.
  4. #Версия набора: 1.13 от 13.05.2015
  5. # Array:
  6. #   ~random - возвращает случайный элемент из массива
  7. #   ~size= - строго устанавливает количество элементов
  8. # Integer:
  9. #       ~sign - возвращает знак для числа (положительное/отрицательное/ноль)
  10. #   ~factorial - возвращает факториал числа
  11. #   ~combine - пересчитывает количество комбинаций от K до текущего
  12. # Font:
  13. #       ~shadowed? - включены ли наборы теней
  14. #       ~shadowed= - включает/выключает наборы теней
  15. #       ~shadows - возвращает список теней
  16. #       ~shadows= - позволяет задать набор теней в виде хэша в формате:
  17. #               {индекс=> [смещение_по_х, смещение_по_у, цвет]}
  18. #               (индекс определяет порядок отрисовки)
  19. # Sprite:
  20. #   ~dispose - добавляет удаление битмапа перед удалением спрайта
  21. #   ~text_color - для добавления в спрайт текста с параметрами
  22. #           цвета как в window_base, то есть:
  23. #     ~~normal_color
  24. #     ~~disabled_color
  25. #     ~~system_color
  26. #     ~~crisis_color
  27. #     ~~knockout_color
  28. #   ~break_into_lines - разрезает строку текста на несколько
  29. #   ~symbolize - превращает строку в символ правильно
  30. # String:
  31. #   ~to_ary - возвращает массив, где каждый элемент - это один символ из строки
  32. #   ~symbolize - правильно конвертирует в символ
  33. #       Дополнено для работы с кириллицей:
  34. #   ~updace - делает буквы ПРОПИСНЫМИ, меняет исходную строку
  35. #   ~downcase - делает буквы строчными, меняет исходную строку
  36. # RPG:
  37. #   ~confirm - вызывает окно для подтверждения действия
  38. #   ~warn - вызывает окно для показа ошибки/уведомления
  39. # Bitmap:
  40. #       ~darken - затемняет картинку
  41. #       ~lighten - осветляет картинку
  42. #       Переписано для работы с наборами теней (см. Font):
  43. #       ~draw_text - отображение текста на картинке с набором теней (если включены)
  44. # Bitmask - полностью скопировано со скрипта от MoonPearl
  45. # Symbol:
  46. #   ~display - правильно конвертирует в строку
  47. # Dir:
  48. #   ~files - возвращает массив файлов в папке
  49. #   ~subdirectories - возвращает массив подкаталогов в папке
  50. #   ~has_subdirectories? - проверяет наличие хотя бы одного подкаталога
  51. # File:
  52. #   ~directory? - проверяет, является ли файл папкой
  53. # Kernel (неявно):
  54. #   ~with - добавляет аналог метода из VisualBasic и Delphi
  55. #   ~dtime - получает разницу во времени в миллисекундах
  56. #-------------------------------------------------------------------------------
  57. ($imported ||= {})[:de79_rgss_plus] = 1.13
  58. #-------------------------------------------------------------------------------
  59. #                               ARRAY
  60. #-------------------------------------------------------------------------------
  61. class Array
  62.   def random
  63.     if self.size!=nil
  64.       ret=rand(self.size)
  65.       return self[ret-1]
  66.     end
  67.     return nil
  68.   end
  69.  
  70.   def size=(value)
  71.         return if value==self.size
  72.         new_arr=[]
  73.         if value<self.size
  74.             for index in 0...value
  75.                 new_arr<<self[index]
  76.             end
  77.             self.clear
  78.             for index in 0...new_arr.size
  79.                 self.push new_arr[index]
  80.             end
  81.         elsif value>self.size
  82.             for index in self.size...value
  83.                 self.push nil
  84.             end
  85.         end
  86.     end
  87. end
  88. #-------------------------------------------------------------------------------
  89. #                               INTEGER
  90. #-------------------------------------------------------------------------------
  91. class Integer
  92.     def sign
  93.         if self>0 then
  94.             return 1
  95.         elsif self<0
  96.             return -1
  97.         else
  98.             return 0
  99.         end
  100.     end
  101.  
  102.     # Возвращает значение факториала от переменной self
  103.   def factorial
  104.     f = 1
  105.     for i in 1..self
  106.       f *= i
  107.     end
  108.     return f
  109.   end
  110.  
  111.   # Пересчитывает количество комбинаций от K до текущего
  112.     #  - k: любое положительное число, которое меньеше и равно текущему
  113.   def combin(k)
  114.     return self.factorial / (k.factorial * (n - k).factorial)
  115.   end
  116. end
  117. #-------------------------------------------------------------------------------
  118. #                                   FONT
  119. #-------------------------------------------------------------------------------
  120. class Font
  121.   alias original_initialize initialize
  122.   def initialize
  123.     original_initialize
  124.     @shadowed=false
  125.     @shadows={}
  126.   end
  127.  
  128.   def shadowed?
  129.     return @shadowed
  130.   end
  131.  
  132.   def shadowed=(value)
  133.     @shadowed=value if value.class==TrueClass||FalseClass
  134.   end
  135.  
  136.   def black_color
  137.     Color.new(0,0,0,128)
  138.   end
  139.  
  140.   def white_color
  141.     Color.new(255,255,255,128)
  142.   end
  143.  
  144.   def shadows
  145.     return @shadows
  146.   end
  147.  
  148.   def shadows=(value)
  149.     @shadows=value if value.class==Hash
  150.   end
  151.  
  152.   def set_simple_shadow
  153.     shadowed=true
  154.     @shadows={
  155.       0=>[1,1,black_color]
  156.     }
  157.   end
  158.  
  159.   def set_simple_stamping
  160.     shadowed=true
  161.     @shadows={
  162.       0=>[1,1,black_color],
  163.       1=>[-1,-1,white_color]
  164.     }
  165.   end
  166. end
  167. #-------------------------------------------------------------------------------
  168. #                               SPRITE
  169. #-------------------------------------------------------------------------------
  170. class Sprite
  171.   alias old_dispose dispose
  172.   def dispose
  173.     if self.bitmap!=nil
  174.       self.bitmap.dispose
  175.     end
  176.     old_dispose
  177.   end
  178.     def text_color(n)
  179.     case n
  180.     when 0
  181.       return Color.new(255, 255, 255, 255)
  182.     when 1
  183.       return Color.new(128, 128, 255, 255)
  184.     when 2
  185.       return Color.new(255, 128, 128, 255)
  186.     when 3
  187.       return Color.new(128, 255, 128, 255)
  188.     when 4
  189.       return Color.new(128, 255, 255, 255)
  190.     when 5
  191.       return Color.new(255, 128, 255, 255)
  192.     when 6
  193.       return Color.new(255, 255, 128, 255)
  194.     when 7
  195.       return Color.new(192, 192, 192, 255)
  196.     else
  197.       normal_color
  198.     end
  199.   end
  200.     def normal_color
  201.     return Color.new(255, 255, 255, 255)
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Get Disabled Text Color
  205.   #--------------------------------------------------------------------------
  206.   def disabled_color
  207.     return Color.new(255, 255, 255, 128)
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Get System Text Color
  211.   #--------------------------------------------------------------------------
  212.   def system_color
  213.     return Color.new(192, 224, 255, 255)
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Get Crisis Text Color
  217.   #--------------------------------------------------------------------------
  218.   def crisis_color
  219.     return Color.new(255, 255, 64, 255)
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Get Knockout Text Color
  223.   #--------------------------------------------------------------------------
  224.   def knockout_color
  225.     return Color.new(255, 64, 0)
  226.   end
  227. end
  228. #-------------------------------------------------------------------------------
  229. #                               STRING
  230. #-------------------------------------------------------------------------------
  231. class String
  232.     # Разрезает строку текста на несколько
  233.     #  - amount: максимальное количество символов в одной строке
  234.   def break_into_lines(amount)
  235.     if self.size <= amount
  236.       yield self
  237.     else
  238.       i = 0
  239.       until i >= self.size
  240.         n = self[i, amount].reverse.index(" ")
  241.         n = amount - (n.nil? ? 0 : n)
  242.         yield self[i, n]
  243.         i += n
  244.       end
  245.     end
  246.   end
  247.  
  248.     # Превращает строку в символ правильно
  249.   def symbolize
  250.     return :empty if self.empty?
  251.     return self.downcase.gsub(" ", "_").to_sym
  252.   end
  253.  
  254.   # Заменяет все строчные буквы прописными
  255.   alias old_upcase upcase
  256.     def upcase
  257.     newstring=self.old_upcase.clone
  258.     newcase=[]
  259.     if RUBY_VERSION.to_i<1.9
  260.       (\'А\'..\'П\').each{ |item|
  261.         newcase+= [ item ]
  262.       }
  263.       (\'О\'..\'Я\').each{ |item|
  264.         newcase+= [ item ]
  265.       }
  266.       index=0
  267.       (\'а\'..\'п\').each{ |item|
  268.         newstring.gsub!(item) {newcase[ index ]}
  269.         index+=1
  270.       }
  271.       (\'о\'..\'я\').each{ |item|
  272.         newstring.gsub!(item) {newcase[ index ]}
  273.         index+=1
  274.       }
  275.     else
  276.       (\'А\'..\'Я\').each{ |item|
  277.         newcase+= [ item ]
  278.       }
  279.       index=0
  280.       (\'а\'..\'я\').each{ |item|
  281.         newstring.gsub!(item) {newcase[ index ]}
  282.         index+=1
  283.       }
  284.     end
  285.     newstring.gsub!(\'ё\') { \'Ё\' }
  286.     return newstring
  287.     end
  288.  
  289.     alias old_upcase! upcase!
  290.     def upcase!
  291.     self.old_upcase!
  292.     newcase=[]
  293.     if RUBY_VERSION.to_i<1.9
  294.       (\'А\'..\'П\').each{ |item|
  295.         newcase+= [ item ]
  296.       }
  297.       (\'О\'..\'Я\').each{ |item|
  298.         newcase+= [ item ]
  299.       }
  300.       index=0
  301.       (\'а\'..\'п\').each{ |item|
  302.         self.gsub!(item) {newcase[ index ]}
  303.         index+=1
  304.       }
  305.       (\'о\'..\'я\').each{ |item|
  306.         self.gsub!(item) {newcase[ index ]}
  307.         index+=1
  308.       }
  309.     else
  310.       (\'А\'..\'Я\').each{ |item|
  311.         newcase+= [ item ]
  312.       }
  313.       index=0
  314.       (\'а\'..\'я\').each{ |item|
  315.         self.gsub!(item) {newcase[ index ]}
  316.         index+=1
  317.       }
  318.     end
  319.     self.gsub!(\'ё\') { \'Ё\' }
  320.     return self
  321.     end
  322.    
  323.     # Заменяет прописные буквы строчными
  324.     alias old_downcase downcase
  325.     def downcase
  326.       newstring=self.old_downcase.clone
  327.             newcase=[]
  328.             if RUBY_VERSION.to_i<1.9
  329.         (\'а\'..\'п\').each{ |item|
  330.           newcase+= [ item ]
  331.         }
  332.         (\'о\'..\'я\').each{ |item|
  333.           newcase+= [ item ]
  334.         }
  335.         index=0
  336.         (\'А\'..\'П\').each{ |item|
  337.           newstring.gsub!(item) {newcase[ index ]}
  338.           index+=1
  339.         }
  340.         (\'О\'..\'Я\').each{ |item|
  341.           newstring.gsub!(item) {newcase[ index ]}
  342.           index+=1
  343.         }
  344.       else
  345.         (\'а\'..\'я\').each{ |item|
  346.           newcase+= [ item ]
  347.         }
  348.         index=0
  349.         (\'А\'..\'Я\').each{ |item|
  350.           newstring.gsub!(item) {newcase[ index ]}
  351.           index+=1
  352.         }
  353.       end
  354.             newstring.gsub!(\'Ё\') { \'ё\' }
  355.             return newstring
  356.         #end
  357.     end
  358.  
  359.     alias old_downcase! downcase!
  360.     def downcase!
  361.         self.old_downcase!
  362.     if RUBY_VERSION.to_i<1.9
  363.       (\'а\'..\'п\').each{ |item|
  364.         newcase+= [ item ]
  365.       }
  366.       (\'о\'..\'я\').each{ |item|
  367.         newcase+= [ item ]
  368.       }
  369.       index=0
  370.       (\'А\'..\'П\').each{ |item|
  371.         self.gsub!(item) {newcase[ index ]}
  372.         index+=1
  373.       }
  374.       (\'О\'..\'Я\').each{ |item|
  375.         self.gsub!(item) {newcase[ index ]}
  376.         index+=1
  377.       }
  378.     else
  379.       (\'а\'..\'я\').each{ |item|
  380.         newcase+= [ item ]
  381.       }
  382.       index=0
  383.       (\'А\'..\'Я\').each{ |item|
  384.         self.gsub!(item) {newcase[ index ]}
  385.         index+=1
  386.       }
  387.     end
  388.     self.gsub!(\'Ё\') { \'ё\' }
  389.     return self
  390.     end
  391.  
  392.   def to_ary
  393.     ary=[]
  394.     while ((c = self.slice(/./m)) != nil)
  395.       ary+=[c]
  396.     end
  397.     return ary
  398.   end
  399. end
  400.  
  401. #-------------------------------------------------------------------------------
  402. #                             MODULE RPG
  403. #-------------------------------------------------------------------------------
  404. module RPG
  405.     def self.warn(message)
  406.     $game_system.se_play($data_system.decision_se)
  407.     Graphics.freeze
  408.     window = Window_Base.new(32, 192, 576, 96)
  409.     window.contents = Bitmap.new(window.width - 32, window.height - 32)
  410.     window.contents.draw_text(0, 0, window.width - 32, 32, message, 1)
  411.     window.contents.draw_text(0, 32, 544, 32, "OK", 1)
  412.     window.cursor_rect.set(208, 32, 128, 32)
  413.     window.active = true
  414.     window.z = 5000
  415.     Graphics.transition
  416.     loop do
  417.       Input.update
  418.       Graphics.update
  419.       window.update
  420.       if Input.trigger?(Input::C) or Input.trigger?(Input::B)
  421.         $game_system.se_play($data_system.cancel_se)
  422.         break
  423.       end
  424.     end
  425.     Graphics.freeze
  426.     window.dispose
  427.     Graphics.transition
  428.     return
  429.   end
  430.  
  431.   def self.confirm(message)
  432.     $game_system.se_play($data_system.buzzer_se)
  433.     Graphics.freeze
  434.     window = Window_Base.new(32, 192, 576, 96)
  435.     window.contents = Bitmap.new(window.width - 32, window.height - 32)
  436.     window.contents.draw_text(0, 0, window.width - 32, 32, message, 1)
  437.     window.contents.draw_text(0, 32, 272, 32, "OK", 1)
  438.     window.contents.draw_text(272, 32, 272, 32, "Cancel", 1)
  439.     window.cursor_rect.set(72, 32, 128, 32)
  440.     window.active = true
  441.     window.z = 5000
  442.     Graphics.transition
  443.     index = 0
  444.     result = nil
  445.     while result.nil?
  446.       Input.update
  447.       Graphics.update
  448.       window.update
  449.       if Input.repeat?(Input::LEFT) or Input.repeat?(Input::RIGHT)
  450.         $game_system.se_play($data_system.cursor_se)
  451.         index += 1
  452.         index %= 2
  453.         window.cursor_rect.set(72 + 272 * index, 32, 128, 32)
  454.       end
  455.       if Input.trigger?(Input::C)
  456.         $game_system.se_play($data_system.decision_se)
  457.         result = index == 0
  458.       end
  459.       if Input.trigger?(Input::B)
  460.         $game_system.se_play($data_system.cancel_se)
  461.         result = false
  462.       end
  463.     end
  464.     Graphics.freeze
  465.     window.dispose
  466.     Graphics.transition
  467.     return result
  468.   end
  469. end
  470. #-------------------------------------------------------------------------------
  471. #                               BITMAP
  472. #-------------------------------------------------------------------------------
  473. class Bitmap
  474.   attr_reader :filename
  475.     alias old_initialize initialize
  476.     def initialize(arg1=32,arg2=32)
  477.         old_initialize(arg1,arg2) if arg1.is_a?(Integer)
  478.         if arg1.is_a? String
  479.             @filename=arg1
  480.             old_initialize @filename
  481.         end
  482.     end
  483.  
  484.   def darken(factor)
  485.     factor = 1 - factor
  486.     for y in 0...self.height
  487.       for x in 0...self.width
  488.         color = self.get_pixel(x, y)
  489.         next if color.alpha == 0
  490.         self.set_pixel(x, y, Color.new(color.red * factor, color.green * factor,
  491.           color.blue * factor, color.alpha) )
  492.       end
  493.     end
  494.     GC.start
  495.   end
  496.  
  497.   def lighten(factor)
  498.     p = 255 * factor
  499.     factor = 1 - factor
  500.     for y in 0...self.height
  501.       for x in 0...self.width
  502.         color = self.get_pixel(x, y)
  503.         next if color.alpha == 0
  504.         self.set_pixel(x, y, Color.new(color.red * factor + p, color.green * factor + p,
  505.           color.blue * factor + p, color.alpha) )
  506.       end
  507.     end
  508.     GC.start
  509.   end
  510.  
  511.   alias old_draw_text draw_text
  512.   def draw_text(*args)
  513.     old_color=self.font.color.clone
  514.     if args.size<=3
  515.       draw_shadows_rect(args[0],args[1], (args[2].is_a? NilClass) ? 0 : args[2]) if self.font.shadowed?
  516.       self.font.color=old_color
  517.       old_draw_text(args[0],args[1],(args[2].is_a? NilClass) ? 0 : args[2])
  518.     elsif args.size<=6
  519.       draw_shadows_normal(args[0],args[1],args[2],args[3],args[4],(args[5].is_a? NilClass) ? 0 : args[5]) if self.font.shadowed?
  520.       self.font.color=old_color
  521.       old_draw_text(args[0],args[1],args[2],args[3],args[4],(args[5].is_a? NilClass) ? 0 : args[5])
  522.     end
  523.   end
  524.  
  525.   def draw_shadows_rect(rect,str,align=0)
  526.     arr=self.font.shadows.keys
  527.     arr.sort!
  528.     index=arr.first
  529.     loop do
  530.       if self.font.shadows.has_key? index
  531.         self.font.color=self.font.shadows[index][2]
  532.         old_draw_text(rect.x+self.font.shadows[index][0],rect.y+self.font.shadows[index][1],
  533.         rect.width,rect.height,str,align)
  534.       end
  535.       index+=1
  536.       break if index>=arr.last
  537.     end
  538.   end
  539.  
  540.   def draw_shadows_normal(x,y,w,h,str,align=0)
  541.     arr=self.font.shadows.keys
  542.     arr.sort!
  543.     index=arr.first
  544.     loop do
  545.       if self.font.shadows.has_key? index
  546.         self.font.color=self.font.shadows[index][2]
  547.         old_draw_text(x+self.font.shadows[index][0],y+self.font.shadows[index][1],
  548.         w,h,str,align)
  549.       end
  550.       index+=1
  551.       break if index>=arr.last
  552.     end
  553.   end
  554. end
  555. #-------------------------------------------------------------------------------
  556. #                               BITMASK
  557. #-------------------------------------------------------------------------------
  558. class Bitmask
  559.   def initialize(size = 1)
  560.     @data = [0]
  561.     resize(size)
  562.   end
  563.  
  564.   def [](i)
  565.     if i >= @size
  566.       raise RangeError, "Bit ##{i} not defined (max = #{@size - 1}) in Bitmask#[]"
  567.     end
  568.     return @data[i >> 5][i & 31] == 1
  569.   end
  570.  
  571.   def []=(i, b)
  572.     case b
  573.     when TrueClass, FalseClass
  574.       if self[i] == b
  575.         return nil
  576.       else
  577.         @data[i >> 5] ^= 2 ** i
  578.         return b
  579.       end
  580.     else
  581.       raise TypeError, "TrueClass or FalseClass expected as parameters in Bitmask#[]="
  582.     end
  583.   end
  584.  
  585.   def resize(size)
  586.     while (size >> 5) >= @data.size
  587.       @data << 0
  588.     end
  589.     @size = size
  590.   end
  591.  
  592.   def to_s
  593.     str = String.new
  594.     for i in 0...@size
  595.       if i & 7 == 0
  596.         str << " "
  597.       end
  598.       str << @data[i >> 5][i & 31].to_s
  599.     end
  600.     return str
  601.   end
  602. end
  603. #-------------------------------------------------------------------------------
  604. #                                SYMBOL
  605. #-------------------------------------------------------------------------------
  606. class Symbol
  607.     # Правильно превращает символ в строку текста
  608.   def display
  609.     str = ""
  610.     name = self.to_s
  611.     name.split("_").each { |s| str += s.capitalize + " " }
  612.     str = str.rstrip
  613.     return str
  614.   end
  615. end
  616. #-------------------------------------------------------------------------------
  617. #                                   DIR
  618. #-------------------------------------------------------------------------------
  619. class Dir
  620.   # Возвращает все файлы, в названии которых имеются заданные значения,
  621.   # в заданном каталоге как массив
  622.   #  - каталог: путь к папке, в которой будет произведен поиск
  623.   # (примеры: "C:\\Temp" или "Graphics\\Titles")
  624.   #  - фильтр(-ы): значения, по которым нужно искать
  625.   # (примеры: "_blue", "icon", ".png", [".txt",".html"] )
  626.   def self.files(directory = self.pwd, *filters)
  627.     ary = []
  628.     for filename in self.entries(directory)
  629.       next if File.directory?(filename) or filename == "." or filename == ".."
  630.       if filters.empty? or filters.include?(File.extname(filename))
  631.         ary << filename
  632.       end
  633.     end
  634.     return ary
  635.   end
  636.  
  637.   # Возвращает все каталоги, находящиеся в заданном, как массив
  638.   def self.subdirectories(directory = self.pwd)
  639.     ary = []
  640.     for filename in self.entries(directory)
  641.       if File.directory?(filename)
  642.         ary << filename
  643.       end
  644.     end
  645.     return ary
  646.   end
  647.  
  648.     def self.has_subdirectories?(directory = self.pwd)
  649.         ary = []
  650.         for filename in self.entries(directory)
  651.             if File.directory?(filename)
  652.                 ary << filename
  653.             end
  654.         end
  655.         return true if ary.size>0
  656.         return false
  657.     end
  658. end
  659. #-------------------------------------------------------------------------------
  660. #                                   FILE
  661. #-------------------------------------------------------------------------------
  662. class File
  663.     def self.directory?(filename)
  664.         return false if filename == "."
  665.         return true if self.extname(filename) == ""
  666.         return false
  667.     end
  668. end
  669. #-------------------------------------------------------------------------------
  670. #                                   CACHE
  671. #-------------------------------------------------------------------------------
  672. module RPG
  673.   module Cache
  674.     def self.face(filename, hue)
  675.       self.load_bitmap("Graphics/Faces/", filename, hue)
  676.     end
  677.        
  678.         def self.state(filename)
  679.       self.load_bitmap("Graphics/States/", filename)
  680.     end
  681.    
  682.     def self.logo(filename)
  683.       self.load_bitmap("Graphics/Logos/", filename)
  684.     end
  685.   end
  686. end
  687. #-------------------------------------------------------------------------------
  688. #                                   KERNEL
  689. #-------------------------------------------------------------------------------
  690. def with(instance, &block)
  691.   instance.instance_eval(&block)
  692.   instance
  693. end
  694.  
  695. # use with t1=Time.now before check and t2=Time.now after
  696. def dtime(start, finish)
  697.    (finish - start) * 1000.0
  698. end
');