查看: 4333|回复: 1

[转载发布] 【梅莉渣翻】在RMVA中使用RMXP的地图及多层地图

[复制链接]
梦石
0
星屑
1078
在线时间
127 小时
注册时间
2017-9-27
回帖
32
发表于 2017-12-2 20:42:11 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
https://littledrago.blogspot.jp/2014/08/rgss3-xp-map-loader-ii.html
↑原作者地址(需要科学上网)作者 : LiTTleDRAgo



  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # XP地图读取及多层地图制作
  3. # 版本: 2.05
  4. # 作者 : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_xp_map_loader] = 2.05
  7. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  8. #
  9. # 介绍:
  10. #
  11. #   XP地图读取及多层地图制作的整合脚本第2版。
  12. #
  13. # 特性:
  14. #   
  15. #  读取RMXP制作的地图:
  16. #  - 在Drago的Custom Resolution II这一脚本中,缩放功能不可使用。
  17. #  - 可用于RMVA读取RMXP的地图,不可反向用RMXP读取RMVA的地图。
  18. #  - 只在RMVA可用。
  19. #
  20. #  多层地图:
  21. #  - 层数越多卡得越厉害。
  22. #
  23. #  译者补充,原文来自littledrago.blogspot.jp/2014/08/rgss3-xp-map-loader-ii.html)
  24. #  使用方法:
  25. #  - 需要前置脚本Drago - Core Engine和Custom Resolution(超长,懒得翻译用法)
  26. #
  27. #  - 读取RMXP制作的地图:先在RMXP中做好你的地图,然后把所有地图涉及的文件复制到
  28. # 你的RMVA工程的文件夹下对应位置。
  29. # 包括:原工程\Data文件夹下所有名为MapXXX.rxdata(XXX是地图ID),Tileset.rxdata以及
  30. # 原工程\Graphics文件夹下的Autotiles, Fog, Panorama,Tileset这四个文件夹所有内容。
  31. #  - 请注意把需要对应的RMVA地图的文件名与复制来的XP地图文件名一一对应起来。
  32. #
  33. #  - 多层地图:
  34. #  - 在需要使用多层地图的原地图下面建立一个名叫"[join]"的子地图。
  35. #  - 可以用写标签[join:1][join:2]等指定多层。是否显示的条件可以在下面设定。
  36. #  - 同类脚本可能会冲突
  37. #  - 需要额外注意A5和B图块中一些透明但不通行的图块,如果通行度不正常请首先排查。
  38. #
  39. #  注意:
  40. #  - 此脚本只调用RMXP工程中的地图、远景、雾图形、通行度、灌木柜台等特殊地形标志,
  41. #  其余图像文件及地图涉及到的BGM、BGS仍沿用原本的RMVA工程。
  42. #
  43. #==============================================================================
  44. module LiTTleDRAgo
  45.   
  46.   # Condition for layer to be joined
  47.   MultiLayerCond = proc do |i|
  48.     condition = {
  49.    
  50.       1 => $game_switches[1], # 1号开关开启时本层显示,否则不显示
  51.       2 => $game_variables[1] == 200, #1号变量=200时显示,否则不显示
  52.       
  53.       }
  54.     condition[i]   #请勿删除本行
  55.   end
  56.   
  57.   
  58. end
  59.   
  60. core  = "This script needs Drago - Core Engine ver 1.44 or above"
  61. implemented = "%1$s has already implemented, Please remove the %1$s script"

  62. ($imported[:drg_core_engine] || 0) >= 1.44 || raise(core)
  63. ($imported[:drg_multi_layer])&& raise(sprintf(implemented,"Multi Layer"))
  64. #==============================================================================
  65. # ** Game_Map
  66. #------------------------------------------------------------------------------
  67. #  This class handles maps. It includes scrolling and passage determination
  68. # functions. The instance of this class is referenced by $game_map.
  69. #==============================================================================
  70. class Game_Map
  71.   #--------------------------------------------------------------------------
  72.   # * Public Instance Variables
  73.   #--------------------------------------------------------------------------
  74.   attr_sec_accessor :panorama_name, :fog_name,             'String.new'      
  75.   attr_sec_accessor :panorama_hue, :fog_hue, :fog_zoom,    1        
  76.   attr_sec_accessor :fog_opacity, :fog_blend_type,         0
  77.   attr_sec_accessor :fog_sx, :fog_sy, :fog_ox, :fog_oy,    0
  78.   attr_sec_accessor :fog_tone, :fog_tone_target,           'Tone.new(0,0,0)'
  79.   attr_sec_accessor :multi_layer_condition_true,           'Array.new'
  80.   attr_sec_accessor :multi_layer_condition_false,          'Array.new'
  81.   attr_sec_reader   :xpmap,  'Array.new'            
  82.   attr_sec_reader   :vxamap, 'Array.new'
  83.   #--------------------------------------------------------------------------
  84.   # * Class Variable
  85.   #--------------------------------------------------------------------------
  86.   tileset = "Data/Tilesets.rxdata"
  87.   @@tileset_xp = File.exist?(tileset) ? load_data(tileset) : nil
  88.   @@rpgmakerxp = LiTTleDRAgo::XP
  89.   #--------------------------------------------------------------------------
  90.   # * Define Method
  91.   #--------------------------------------------------------------------------
  92.   unless @@rpgmakerxp
  93.     define_method(:zoom_x) { 1 }
  94.     define_method(:zoom_y) { 1 }
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # * Undefine Method
  98.   #--------------------------------------------------------------------------
  99.   if !@@rpgmakerxp && method_defined?(:zoom)
  100.     undef :zoom, :zoom_in, :zoom_out, :zoom_x=, :zoom_y=, :start_zoom
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Alias Listing
  104.   #--------------------------------------------------------------------------
  105.   alias_sec_method :xpmap_loader_setup,         :setup
  106.   alias_sec_method :xpmap_loader_update,        :update
  107.   alias_sec_method :layered_tiles_flag_vxlayer, :layered_tiles_flag?
  108.   #--------------------------------------------------------------------------
  109.   # * Aliased Method : setup
  110.   #--------------------------------------------------------------------------
  111.   def setup(*args)
  112.     xpmap_loader_setup(*args)
  113.     setup_map_xp
  114.     setup_map_layer
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * New Method : setup_map_xp
  118.   #--------------------------------------------------------------------------
  119.   def setup_map_xp
  120.     reset_map_xp
  121.     map = sprintf("Map%03d",@map_id)
  122.     b   = "The dimension on %1$s.rvdata2 %2$s and %1$s.rxdata %3$s is not same"
  123.    
  124.     return unless @@tileset_xp && File.exist?("Data/"+map+".rxdata")
  125.     return if @@rpgmakerxp
  126.     return if self.xpmap.detect {|xp| xp && xp[:map_id] == @map_id }
  127.    
  128.    
  129.     _xp = load_map_data(@map_id,:rxdata)
  130.     _sz   = [@map,_xp].flatten.map {|m| [m.width,m.height]}.uniq
  131.     fail( sprintf( b, map, *_sz.map {|s| s.inspect})) if _sz.size > 1
  132.    
  133.     self.xpmap[0]                   = {}
  134.     self.xpmap[0][:map_id]          = @map_id
  135.     self.xpmap[0][:map]             = _xp
  136.     self.xpmap[0][:tileset_id]      = _xp.tileset_id
  137.     _xp = @@tileset_xp[_xp.tileset_id]
  138.     self.xpmap[0][:tileset_name]    = _xp.tileset_name
  139.     self.xpmap[0][:autotile_names]  = _xp.autotile_names
  140.     self.xpmap[0][:passages]        = _xp.passages
  141.     self.xpmap[0][:priorities]      = _xp.priorities
  142.     self.xpmap[0][:terrain_tags]    = _xp.terrain_tags
  143.    
  144.     @panorama_name   = _xp.panorama_name
  145.     @panorama_hue    = _xp.panorama_hue
  146.     @fog_name        = _xp.fog_name
  147.     @fog_hue         = _xp.fog_hue
  148.     @fog_opacity     = _xp.fog_opacity
  149.     @fog_blend_type  = _xp.fog_blend_type
  150.     @fog_zoom        = _xp.fog_zoom
  151.     @fog_sx          = _xp.fog_sx
  152.     @fog_sy          = _xp.fog_sy
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Aliased Method : update
  156.   #--------------------------------------------------------------------------
  157.   def update(*args)
  158.     xpmap_loader_update(*args)
  159.     update_fog unless @@rpgmakerxp
  160.     update_layer_condition
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * New Method : reset_map_xp
  164.   #--------------------------------------------------------------------------
  165.   def reset_map_xp
  166.     self.xpmap.clear
  167.     self.vxamap.clear
  168.     self.multi_layer_condition_true.clear
  169.     self.multi_layer_condition_false.clear
  170.     @mapinfo = nil
  171.     self.clear_panorama unless @@rpgmakerxp
  172.     self.clear_fog      unless @@rpgmakerxp
  173.   end  
  174.   #--------------------------------------------------------------------------
  175.   # * New Method : setup_map_layer
  176.   #--------------------------------------------------------------------------
  177.   def setup_map_layer
  178.     layered = false
  179.     self.child_ids.each_with_index do |submap_id,index|
  180.       next if self.vxamap.detect {|vxa| vxa && vxa[:map_id] == submap_id }
  181.       next if self.xpmap.detect {|xp| xp && xp[:map_id] == submap_id }
  182.       next unless (map_info = mapInfo[submap_id]).not.nil?
  183.       next unless (map_info.parent_id == map_id)
  184.       join = map_info.name[/\[\s*join\s*\]/]
  185.       if map_info.name[/\[\s*join:\s*([-]?\d+)\s*\]/]
  186.         id = $1.to_i
  187.         cond = LiTTleDRAgo::MultiLayerCond.call(id)
  188.         if !cond && multi_layer_condition_true.not.include?(id)
  189.           @multi_layer_condition_true << id
  190.         end
  191.         if cond && multi_layer_condition_false.not.include?(id)
  192.           @multi_layer_condition_false << id
  193.         end
  194.         join ||= cond
  195.       end
  196.       next unless join
  197.       map     = sprintf("Map%03d",submap_id)
  198.       org     = sprintf("Map%03d",map_id)
  199.       notsame = "The dimension of Parent map and Child map must be same"
  200.       
  201.       if @@tileset_xp && File.exist?("Data/"+map+".rxdata")
  202.         _xp = load_map_data(submap_id,:rxdata)
  203.         _sz = [@map,_xp].flatten.map {|m| [m.width,m.height]}.uniq
  204.         _sz.size > 1 && fail(notsame)
  205.          
  206.         self.xpmap[index+1]                   = {}
  207.         self.xpmap[index+1][:map_id]          = submap_id
  208.         self.xpmap[index+1][:map]             = _xp
  209.         self.xpmap[index+1][:tileset_id]      = _xp.tileset_id
  210.         _xp = @@tileset_xp[_xp.tileset_id]
  211.         self.xpmap[index+1][:tileset_name]    = _xp.tileset_name
  212.         self.xpmap[index+1][:autotile_names]  = _xp.autotile_names
  213.         self.xpmap[index+1][:passages]        = _xp.passages
  214.         self.xpmap[index+1][:priorities]      = _xp.priorities
  215.         self.xpmap[index+1][:terrain_tags]    = _xp.terrain_tags
  216.       elsif File.exist?("Data/"+map+".rvdata2")
  217.         _vxa = load_map_data(submap_id,:rvdata2)
  218.         _sz  = [@map,_vxa].flatten.map {|m| [m.width,m.height]}.uniq
  219.         _sz.size > 1 && fail(notsame)
  220.    
  221.         self.vxamap[index] = {}
  222.         self.vxamap[index][:map_id]     = submap_id
  223.         self.vxamap[index][:map]        = _vxa
  224.         self.vxamap[index][:tileset_id] = _vxa.tileset_id
  225.         tileset = $data_tilesets[_vxa.tileset_id]
  226.         self.vxamap[index][:tileset]    = tileset
  227.       end
  228.       layered = _xp || _vxa
  229.     end
  230.     spriteset.create_multi_layer if spriteset
  231.   end  
  232.   #--------------------------------------------------------------------------
  233.   # * New Method : update_layer_condition
  234.   #--------------------------------------------------------------------------
  235.   def update_layer_condition
  236.     meth = LiTTleDRAgo::MultiLayerCond
  237.     condition = multi_layer_condition_true.any?  {|id| meth.call(id)    } ||
  238.                 multi_layer_condition_false.any? {|id| meth.not.call(id)}
  239.     condition && [setup_map_xp, setup_map_layer]
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * New Method : reset_fog_variable
  243.   #--------------------------------------------------------------------------
  244.   def reset_fog_variable
  245.     @fog_ox               =
  246.     @fog_oy               =
  247.     @fog_tone             =
  248.     @fog_tone_target      = nil
  249.     @fog_tone_duration    =
  250.     @fog_opacity_duration =
  251.     @fog_opacity_target   = 0
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * New Method : start_fog_tone_change
  255.   #--------------------------------------------------------------------------
  256.   unless method_defined?(:start_fog_tone_change)
  257.     def start_fog_tone_change(tone, duration)
  258.       @fog_tone_target = tone.clone
  259.       @fog_tone_duration = duration
  260.       if @fog_tone_duration == 0
  261.         @fog_tone = @fog_tone_target.clone
  262.       end
  263.     end
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # * New Method : start_fog_opacity_chang
  267.   #--------------------------------------------------------------------------
  268.   unless method_defined?(:start_fog_opacity_change)
  269.     def start_fog_opacity_change(opacity, duration)
  270.       @fog_opacity_target = opacity * 1.0
  271.       @fog_opacity_duration = duration
  272.       if @fog_opacity_duration == 0
  273.         @fog_opacity = @fog_opacity_target
  274.       end
  275.     end
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * New Method : change_panorama
  279.   #--------------------------------------------------------------------------
  280.   def change_panorama(panorama_name = '',panorama_hue = 0)
  281.     @panorama_name = panorama_name
  282.     @panorama_hue  = panorama_hue
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # * New Method : clear_panorama
  286.   #--------------------------------------------------------------------------
  287.   def clear_panorama(*args)
  288.     change_panorama
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # * New Method : change_fog
  292.   #--------------------------------------------------------------------------
  293.   def change_fog(name='',hue=0,opac = 60, blend = 0,zoom = 1.0,sx = 0,sy = 0)
  294.     @fog_name       = name
  295.     @fog_hue        = hue
  296.     @fog_opacity    = opac
  297.     @fog_blend_type = blend
  298.     @fog_zoom       = zoom
  299.     @fog_sx         = sx
  300.     @fog_sy         = sy
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * New Method : clear_fog
  304.   #--------------------------------------------------------------------------
  305.   def clear_fog(*args)
  306.     change_fog
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # * New Method : update_fog
  310.   #--------------------------------------------------------------------------
  311.   unless method_defined?(:update_fog)
  312.     def update_fog
  313.       @fog_ox = fog_ox - fog_sx / 8.0
  314.       @fog_oy = fog_oy - fog_sy / 8.0
  315.       if (@fog_tone_duration ||= 0) >= 1
  316.         d = (@fog_tone_duration ||= 0)
  317.         target = fog_tone_target
  318.         fog_tone.red   = (fog_tone.red * (d - 1) + target.red) / d
  319.         fog_tone.green = (fog_tone.green * (d - 1) + target.green) / d
  320.         fog_tone.blue  = (fog_tone.blue * (d - 1) + target.blue) / d
  321.         fog_tone.gray  = (fog_tone.gray * (d - 1) + target.gray) / d
  322.         @fog_tone_duration -= 1
  323.       end
  324.       if (@fog_opacity_duration ||= 0) >= 1
  325.         d = (@fog_opacity_duration ||= 0)
  326.         @fog_opacity  = (fog_opacity * (d-1) + (@fog_opacity_target||=0)) / d
  327.         @fog_opacity_duration -= 1
  328.       end
  329.     end
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * New Method : tile_id_obj
  333.   #--------------------------------------------------------------------------
  334.   def tile_id_obj(obj, x, y, z)
  335.     if $game_map.respond_to?(:reverse) && $game_map.reverse && LiTTleDRAgo::XP
  336.       obj.reverse_data[x, y, z] || 0
  337.     else
  338.       obj.data[x, y, z] || 0
  339.     end
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # * New Method : collect_flag_tiles_vxa
  343.   #--------------------------------------------------------------------------
  344.   def collect_flag_tiles_vxa(x,y,*flag)
  345.     result = []
  346.     vxamap.compact.each do |map|
  347.       result += [2, 1, 0].collect do |z|
  348.         tile_id = tile_id_obj(map[:map],x, y, z)
  349.         [tile_id] + flag.collect {|s| map[s].flags[tile_id]}
  350.       end
  351.     end
  352.     return result
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # * New Method : collect_flag_tiles_xp
  356.   #--------------------------------------------------------------------------
  357.   def collect_flag_tiles_xp(x,y,*flag)
  358.     result = []
  359.     xpmap.compact.each do |map|
  360.       result += [2, 1, 0].collect do |z|
  361.         tile_id = tile_id_obj(map[:map],x, y, z)
  362.         [tile_id] + flag.collect {|s| map[s][tile_id]}
  363.       end
  364.     end
  365.     return result
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # * New Method : collect_flag_tiles_original
  369.   #--------------------------------------------------------------------------
  370.   def collect_flag_tiles_original(x,y,*flag)
  371.     all_tiles_rep(x, y).collect do |t_id|
  372.       @@rpgmakerxp ? [t_id] + flag.collect {|map| map[t_id]} :
  373.       [t_id, tileset.flags[t_id]]
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # * Aliased Method : layered_tiles_flag?
  378.   #--------------------------------------------------------------------------
  379.   def layered_tiles_flag?(x, y, bit)
  380.     xp       = collect_flag_tiles_xp(x,y,:passages)
  381.     vxa      = collect_flag_tiles_vxa(x,y,:tileset)
  382.     original = collect_flag_tiles_original(x,y,@passages)
  383.     if @@rpgmakerxp
  384.       result = (xp + vxa + original).any? { |id,flag| flag & bit != 0 }
  385.     else
  386.       result   = layered_tiles_flag_vxlayer(x, y, bit)
  387.       result ||= (xp + vxa ).any? { |id,flag| flag & bit != 0 }
  388.     end
  389.     return result
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Overwriten Method : check_passage
  393.   #--------------------------------------------------------------------------
  394.   def check_passage(x, y, bit)
  395.     original = collect_flag_tiles_original(x,y,@passages)
  396.     xp       = collect_flag_tiles_xp(x,y,:passages)
  397.     vxa      = collect_flag_tiles_vxa(x,y,:tileset)
  398.     ( xp + vxa + original ).each do |t_id,flag,prio|
  399.       next if flag & 0x10 != 0            # [☆]: No effect on passage
  400.       #return true  if flag & bit == 0     # [○] : Passable
  401.       return false if flag & bit != 0     # [×] : Impassable
  402.       return false if flag & bit == bit   # [×] : Impassable
  403.       return true  if prio && prio == 0    # [○] : Passable
  404.     end
  405.     return true#false                          # Impassable
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # * Overwriten Method : terrain_tag
  409.   #--------------------------------------------------------------------------
  410.   def terrain_tag(x, y)
  411.     return 0 unless valid?(x, y)
  412.     original = collect_flag_tiles_original(x,y,@terrain_tags)
  413.     xp  = collect_flag_tiles_xp(x,y,:terrain_tags)
  414.     vxa = collect_flag_tiles_vxa(x,y,:tileset).map {|t| t >> 12}
  415.     (xp + vxa).each { |t_id,tag| return tag if tag > 0 }
  416.     (original).each do |t_id,flag|
  417.       tag = @@rpgmakerxp ? flag : flag >> 12
  418.       return tag if tag > 0
  419.     end
  420.     return 0
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # * Overwriten Method : passable?
  424.   #--------------------------------------------------------------------------
  425.   if @@rpgmakerxp
  426.     def passable?(x, y, d, s = nil)
  427.       original = (event_tiles(x, y, s) + layered_tiles(x, y)).map do |t_id|
  428.         [t_id, @passages[t_id], @priorities[t_id]]
  429.       end
  430.       xp    = collect_flag_tiles_xp(x,y,:passages,:priorities)
  431.       vxa   = collect_flag_tiles_vxa(x,y,:tileset)
  432.       bit   = (1 << (d / 2 - 1)) & 0x0f
  433.       (xp + vxa + original ).each do |t_id,flag,prio|
  434.         next if flag & 0x10 != 0             # [☆]: No effect on passage
  435.         return false if flag & bit != 0      # [×] : Impassable
  436.         return false if flag & 0x0f == 0x0f  # [×] : Impassable
  437.         return true  if prio && prio == 0    # [○] : Passable
  438.       end
  439.       return true                            # [○] : Passable
  440.     end
  441.     #--------------------------------------------------------------------------
  442.     # * Overwriten Method : bush?
  443.     #--------------------------------------------------------------------------
  444.     def bush?(x, y)
  445.       valid?(x, y) && layered_tiles_flag?(x, y, 0x40)
  446.     end
  447.     #--------------------------------------------------------------------------
  448.     # * Overwriten Method : counter?
  449.     #--------------------------------------------------------------------------
  450.     def counter?(x, y)
  451.       valid?(x, y) && layered_tiles_flag?(x, y, 0x80)
  452.     end
  453.   end
  454.   #--------------------------------------------------------------------------
  455.   # * New Method : event_tiles
  456.   #--------------------------------------------------------------------------
  457.   def event_tiles(x, y, s = nil)
  458.     e = events_xy(x,y).select {|e| e.tile_id > 0 && e != s && !e.through}
  459.     e.collect {|event| event.tile_id }
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # * Replicated Method : layered_tiles
  463.   #--------------------------------------------------------------------------
  464.   unless method_defined?(:layered_tiles)
  465.     def layered_tiles(x, y)
  466.       [2, 1, 0].collect {|z| tile_id_obj(@map, x, y, z) }
  467.     end
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # * Replicated Method : all_tiles_rep
  471.   #--------------------------------------------------------------------------
  472.   unless method_defined?(:all_tiles_rep)
  473.     def all_tiles_rep(x, y)
  474.       event_tiles(x, y) + layered_tiles(x,y)
  475.     end
  476.   end
  477.   #--------------------------------------------------------------------------
  478.   # * Replicated Method : events_xy
  479.   #--------------------------------------------------------------------------
  480.   unless method_defined?(:events_xy)
  481.     def events_xy(x, y)
  482.       @events.values.select {|event| event.x == x && event.y == y }
  483.     end
  484.   end
  485. end
  486.   
  487. #==============================================================================
  488. # ** RPG
  489. #------------------------------------------------------------------------------
  490. #
  491. #==============================================================================
  492. module RPG
  493.   #============================================================================
  494.   # ** Map
  495.   #----------------------------------------------------------------------------
  496.   #
  497.   #============================================================================
  498.   class Map
  499.     attr_accessor     :tileset_id
  500.     attr_sec_accessor :reverse_data, 'data.reverse(true,false,false)'
  501.   end
  502.   #============================================================================
  503.   # ** Tileset
  504.   #----------------------------------------------------------------------------
  505.   #
  506.   #============================================================================
  507.   class Tileset
  508.     #--------------------------------------------------------------------------
  509.     # * Public Instance Variables
  510.     #--------------------------------------------------------------------------
  511.     attr_sec_accessor :tileset_name,  :panorama_name, :fog_name,
  512.                       :battleback_name,                      'String.new'
  513.     attr_sec_accessor :autotile_names,                       '[String.new]*7'
  514.     attr_sec_accessor :panorama_hue, :fog_hue, :fog_blend_type,
  515.                       :fog_sx, :fog_sy,                      0
  516.     attr_sec_accessor :passages, :priorities, :terrain_tags, 'Table.new(384)'
  517.     attr_sec_accessor :fog_zoom,                             200
  518.     attr_sec_accessor :fog_opacity,                          64
  519.   end
  520. end

  521. #==============================================================================
  522. # ** Spriteset_Map
  523. #------------------------------------------------------------------------------
  524. #  This class brings together map screen sprites, tilemaps, etc. It's used
  525. # within the Scene_Map class.
  526. #==============================================================================
  527. class Spriteset_Map
  528.   #--------------------------------------------------------------------------
  529.   # * Public Instance Variables
  530.   #--------------------------------------------------------------------------
  531.   attr_sec_reader :tilemap_layer, 'Array.new'
  532.   #--------------------------------------------------------------------------
  533.   # * Class Variable
  534.   #--------------------------------------------------------------------------
  535.   @@rpgmakerxp = LiTTleDRAgo::XP
  536.   @@fog_opacity = @@panorama_opacity = 0
  537.   #--------------------------------------------------------------------------
  538.   # * Alias Listing
  539.   #--------------------------------------------------------------------------
  540.   alias_sec_method :update_multi_layer_cr,         :update
  541.   alias_sec_method :dispose_multi_layer_cr,        :dispose
  542.   alias_sec_method :reload_tilemap_multi_layer_cr, :reload_tilemap
  543.   alias_method     :fog_fix_initialize,            :initialize
  544.   #--------------------------------------------------------------------------
  545.   # * Aliased method: initialize
  546.   #--------------------------------------------------------------------------
  547.   def initialize(*args)
  548.     fog_fix_initialize
  549.     @fog.opacity = @@fog_opacity || 0 if @fog
  550.     @panorama.opacity = @@panorama_opacity || 0 if @panorama
  551.   end
  552.   #--------------------------------------------------------------------------
  553.   # * New Method : create_multi_layer
  554.   #--------------------------------------------------------------------------
  555.   def create_multi_layer
  556.     dispose_multi_layer
  557.     @xpmap_size  = $game_map.xpmap.size
  558.     @vxamap_size = $game_map.vxamap.size
  559.     $game_map.vxamap.compact.each do |data|
  560.       next if @@rpgmakerxp
  561.       tilemap_layer[(i  = tilemap_layer.size)] = Tilemap.new(@viewport1)
  562.       create_layer_tilemap(tilemap_layer[i],data)
  563.     end
  564.     $game_map.xpmap.compact.each do |data|
  565.       _data             = data.clone
  566.       _data[:tileset]   = LiTTleDRAgo.cache.tileset(data[:tileset_name])
  567.       _data[:autotiles] = []
  568.       if (tilemap = ([@tilemap]+tilemap_layer).detect {|t| obj_is_ztilemap?(t)})
  569.         data[:autotile_names].each_with_index do |name, i|
  570.           _data[:autotiles][i] = LiTTleDRAgo.cache.autotile_cr_tilemap(name)
  571.         end
  572.         [tilemap.extra_map_data.push(_data), tilemap.refresh] && next
  573.       end
  574.       unless @@rpgmakerxp
  575.         cr = "This script needs Drago - Custom Resolution ver 2.12 or above"
  576.         ($imported[:drg_custom_resolution] || 0) >= 2.12 || raise(cr)
  577.       end
  578.       klass             = @@rpgmakerxp ? @tilemap.class : ZTilemap
  579.       tilemap_layer[(i  = tilemap_layer.size)] = klass.new(@viewport1)
  580.       create_layer_tilemap(tilemap_layer[i], _data)
  581.     end   
  582.     @viewport_screen_width = 0
  583.   end
  584.   #--------------------------------------------------------------------------
  585.   # * New Method : create_layer_tilemap
  586.   #--------------------------------------------------------------------------
  587.   def create_layer_tilemap(tilemap,data)
  588.     if (@@rpgmakerxp && tilemap.is_a?(Tilemap)) || obj_is_ztilemap?(tilemap)
  589.       if obj_is_ztilemap?(tilemap)
  590.         temp = tilemap.sprite_compact
  591.         tilemap.sprite_compact = false
  592.       end
  593.       (0..6).each do |i|
  594.         name = data[:autotile_names][i]
  595.         bitmap = LiTTleDRAgo.cache.autotile(name)
  596.         @force_tilemap_enabled = true if bitmap.height == 192
  597.         tilemap.autotiles[i] = obj_is_ztilemap?(tilemap) ?
  598.         LiTTleDRAgo.cache.autotile_cr_tilemap(name) : bitmap
  599.       end
  600.       tilemap.tileset     = data[:tileset]
  601.       tilemap.priorities  = data[:priorities]
  602.       tilemap.map_data    = data[:map].data
  603.       update_layer_tilemap(tilemap)
  604.       tilemap.update
  605.       tilemap.sprite_compact = temp  if obj_is_ztilemap?(tilemap)
  606.     else
  607.       tilemap.map_data = data[:map].data
  608.       data[:tileset].tileset_names.each_with_index do |name, i|
  609.         tilemap.bitmaps[i] = LiTTleDRAgo.cache.tileset(name)
  610.       end
  611.       tilemap.flags = data[:tileset].flags
  612.       update_layer_tilemap(tilemap)
  613.       tilemap.update
  614.     end
  615.   end
  616.   #--------------------------------------------------------------------------
  617.   # * Aliased Method : update
  618.   #--------------------------------------------------------------------------
  619.   def update
  620.     unless @@rpgmakerxp                  
  621.       update_panorama
  622.       update_fog
  623.       update_panorama_plane
  624.       update_fog_plane
  625.     end         
  626.     update_multi_layer_cr
  627.     if @xpmap_size != $game_map.xpmap.size ||
  628.       @vxamap_size != $game_map.vxamap.size
  629.       create_multi_layer  
  630.     end
  631.     update_multi_layer
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # * New Method : dispose_multi_layer
  635.   #--------------------------------------------------------------------------
  636.   def dispose_multi_layer
  637.     tilemap_layer.dispose
  638.     tilemap_layer.clear
  639.   end
  640.   #--------------------------------------------------------------------------
  641.   # * New Method : update_multi_layer
  642.   #--------------------------------------------------------------------------
  643.   def update_multi_layer
  644.     tilemap_layer.each { |t| update_layer_tilemap(t) }
  645.   end
  646.   #--------------------------------------------------------------------------
  647.   # * New Method : update_layer_tilemap
  648.   #--------------------------------------------------------------------------
  649.   def update_layer_tilemap(tilemap)
  650.     if obj_is_ztilemap?(tilemap)
  651.       if @@rpgmakerxp
  652.         tilemap.ox      = @tilemap.ox
  653.         tilemap.oy      = @tilemap.oy
  654.         tilemap.zoom_x  = $game_map.zoom_x
  655.         tilemap.zoom_y  = $game_map.zoom_y
  656.         tilemap.opacity = $game_map.tilemap_opacity
  657.         tilemap.hue     = $game_map.tilemap_hue
  658.         tilemap.tone    = $game_map.tilemap_tone
  659.       else
  660.         tilemap.ox = $game_map.display_x * tilemap_move_multiplier
  661.         tilemap.oy = $game_map.display_y * tilemap_move_multiplier
  662.       end
  663.     else
  664.       tilemap.ox = @tilemap.ox rescue $game_map.display_x * tilemap_move_multiplier
  665.       tilemap.oy = @tilemap.oy rescue $game_map.display_y * tilemap_move_multiplier
  666.     end
  667.     tilemap.update
  668.   end
  669.   #--------------------------------------------------------------------------
  670.   # * New Method : obj_is_ztilemap?
  671.   #--------------------------------------------------------------------------
  672.   def obj_is_ztilemap?(obj)
  673.     defined?(ZTilemap) && obj.is_a?(ZTilemap)
  674.   end
  675.   #--------------------------------------------------------------------------
  676.   # * Aliased Method : dispose
  677.   #--------------------------------------------------------------------------
  678.   def dispose
  679.     dispose_multi_layer
  680.     dispose_multi_layer_cr
  681.     [dispose_fog, dispose_panorama] rescue nil unless @@rpgmakerxp
  682.   end
  683.   #--------------------------------------------------------------------------
  684.   # * Aliased Method : reload_tilemap
  685.   #--------------------------------------------------------------------------
  686.   def reload_tilemap
  687.     reload_tilemap_multi_layer_cr      
  688.     create_multi_layer
  689.   end
  690.   #--------------------------------------------------------------------------
  691.   # * New Method : tilemap_move_multiplier
  692.   #--------------------------------------------------------------------------
  693.   def tilemap_move_multiplier
  694.     n = 1.00 / 4
  695.     n = 1.00 / 8  if LiTTleDRAgo::VX
  696.     n = 1.00 * 32 if LiTTleDRAgo::VXA
  697.     return n
  698.   end  
  699.   #--------------------------------------------------------------------------
  700.   # * New Method : update_panorama
  701.   #--------------------------------------------------------------------------
  702.   unless method_defined?(:update_panorama)
  703.     def update_panorama
  704.       if @panorama.nil?
  705.         @panorama = Plane.new(@viewport1)
  706.         @panorama.opacity = (@@panorama_opacity ||= 0)
  707.         @panorama.z = -1000
  708.       end
  709.       if @panorama_name != $game_map.panorama_name or
  710.           @panorama_hue != $game_map.panorama_hue
  711.         @panorama_name = $game_map.panorama_name
  712.         @panorama_hue = $game_map.panorama_hue
  713.         if @panorama.bitmap.respond_to?(:dispose) &&
  714.           @panorama.bitmap.not.disposed?
  715.           @panorama.bitmap.dispose
  716.           @panorama.bitmap = nil
  717.         end
  718.         if @panorama_name != ''
  719.           @panorama.bitmap =
  720.                 LiTTleDRAgo.cache.panorama(@panorama_name, @panorama_hue)
  721.         end
  722.         Graphics.frame_reset
  723.       end
  724.     end
  725.   end
  726.   #--------------------------------------------------------------------------
  727.   # * New Method : update_fog
  728.   #--------------------------------------------------------------------------  
  729.   unless method_defined?(:update_fog)
  730.     def update_fog
  731.       if @fog.nil?
  732.         @fog = Plane.new(@viewport1)
  733.         @fog.opacity = (@@fog_opacity ||= 0)
  734.         @fog.z = 3000
  735.       end
  736.       if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
  737.         @fog_name = $game_map.fog_name
  738.         @fog_hue  = $game_map.fog_hue
  739.         if @fog.bitmap.respond_to?(:dispose) && @fog.bitmap.not.disposed?
  740.           @fog.bitmap.dispose
  741.           @fog.bitmap = nil
  742.         end
  743.         if @fog_name != ''
  744.           @fog.bitmap = LiTTleDRAgo.cache.fog(@fog_name, @fog_hue)
  745.         end
  746.         Graphics.frame_reset
  747.       end
  748.     end
  749.   end
  750.   #--------------------------------------------------------------------------
  751.   # * New Method : update_panorama_plane
  752.   #--------------------------------------------------------------------------
  753.   unless method_defined?(:update_panorama_plane)
  754.     def update_panorama_plane
  755.       @panorama.ox = $game_map.display_x / 8
  756.       @panorama.oy = $game_map.display_y / 8
  757.     end
  758.   end
  759.   #--------------------------------------------------------------------------
  760.   # * New Method : update_fog_plane
  761.   #--------------------------------------------------------------------------
  762.   unless method_defined?(:update_fog_plane)
  763.     def update_fog_plane
  764.       @fog.zoom_x = $game_map.fog_zoom / 100.0
  765.       @fog.zoom_y = $game_map.fog_zoom / 100.0
  766.       @fog.opacity = $game_map.fog_opacity
  767.       @fog.blend_type = $game_map.fog_blend_type
  768.       @fog.ox = $game_map.display_x*tilemap_move_multiplier + $game_map.fog_ox
  769.       @fog.oy = $game_map.display_y*tilemap_move_multiplier + $game_map.fog_oy
  770.       @fog.tone = $game_map.fog_tone
  771.     end
  772.   end
  773.   #--------------------------------------------------------------------------
  774.   # * New Method : dispose_fog
  775.   #--------------------------------------------------------------------------
  776.   unless method_defined?(:dispose_fog)
  777.     def dispose_fog
  778.       unless @fog.nil? || @fog.disposed?
  779.         @@fog_opacity = @fog.opacity
  780.         @fog.dispose
  781.       end
  782.     end
  783.   end
  784.   #--------------------------------------------------------------------------
  785.   # * New Method : dispose_panorama
  786.   #--------------------------------------------------------------------------
  787.   unless method_defined?(:dispose_panorama)
  788.     def dispose_panorama
  789.       unless @panorama.nil? || @panorama.disposed?
  790.         @@panorama_opacity = @panorama.opacity
  791.         @panorama.dispose
  792.       end
  793.     end
  794.   end
  795. end
  796. #==============================================================================
  797. # ** RPG::Cache
  798. #==============================================================================
  799. ModCache = LiTTleDRAgo.cache
  800. module ModCache
  801.   #----------------------------------------------------------------------------
  802.   # * Self
  803.   #----------------------------------------------------------------------------
  804.   class << self
  805.     #--------------------------------------------------------------------------
  806.     # * Get Autotile Graphic
  807.     #--------------------------------------------------------------------------
  808.     unless method_defined?(:autotile)
  809.       def autotile(filename)
  810.         load_bitmap("Graphics/Autotiles/", filename)
  811.       end
  812.     end
  813.     #--------------------------------------------------------------------------
  814.     # * Get Panorama Graphic
  815.     #--------------------------------------------------------------------------
  816.     unless method_defined?(:panorama)
  817.       def panorama(filename, hue = 0)
  818.         load_bitmap("Graphics/Panoramas/", filename, hue)
  819.       end
  820.     end
  821.     #--------------------------------------------------------------------------
  822.     # * Get Fog Graphic
  823.     #--------------------------------------------------------------------------
  824.     unless method_defined?(:fog)
  825.       def fog(filename, hue = 0)
  826.         load_bitmap("Graphics/Fogs/", filename, hue)
  827.       end
  828.     end
  829.   end
  830. end
复制代码



附带两个作为前置的脚本(未翻译):



  1. #==============================================================================
  2. # ** Drago - Core Engine
  3. # Version : 1.59
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. ($imported ||= {})[:drg_core_engine] = 1.59
  7. # =============================================================================
  8. # NOTE:
  9. # -----------------------------------------------------------------------------
  10. # This is a devtool for me to make me easier for scripting
  11. # If you want to use this, put above all custom script & below Scene_Debug
  12. #
  13. # =============================================================================
  14. # DOCUMENTATION:
  15. # -----------------------------------------------------------------------------
  16. =begin
  17.   Version History
  18.   
  19.   1.57 -
  20.   ▼ Overhaul script (108 minor modification)
  21.   ▼ Fixed glitch on BitmapDump method
  22.   ▼ Added Bitmap#rotate90
  23.   ▼ Added Bitmap#rotate180
  24.   ▼ Added Bitmap#rotate270
  25.   
  26.   1.50 -
  27.   ▼ Overhaul script (71 minor modification)
  28.   ▼ Longer script call (RMXP script call bug fix)
  29.   
  30.   1.42 -
  31.   ▼ Fixed Graphics.fullscreen?
  32.   
  33.   1.40 -
  34.   ▼ Modified Game_Map#load_event
  35.   
  36.   1.39 -
  37.   ▼ Fixed glitch at Bitmap#draw_icon
  38.   ▼ Added Fiber class
  39.   ▼ Added Game_Map#load_event
  40.   ▼ Added Game_Map#call_event
  41.   
  42.   1.36 -
  43.   ▼ Added Color class library
  44.   
  45.   1.34 -
  46.   ▼ Added Module#define_third_method(sym = nil, _alias = nil,
  47.                     prevent_stack = true, *a, &block)
  48.   ▼ Added Bitmap#blur
  49.   
  50.   1.31 -
  51.   ▼ Added Module#attr_sec_reader(symbol, default=0)
  52.   ▼ Added Module#attr_sec_accessor(symbol, *a, &block)
  53.   ▼ Added Module#alias_sec_method(sym = nil, *a, &block)
  54.   ▼ Added Module#define_sec_method(sym = nil, *a, &block)
  55.   
  56.   1.29 -
  57.   ▼ Added Array#have_all?(array)
  58.   ▼ Added Array#have_any?(array)
  59.   
  60.   1.27 -
  61.   ▼ Added Added Graphics.brightness
  62.   ▼ Added Graphics.wait(frames = 10)
  63.   ▼ Added Graphics.fadein(frames = 10)
  64.   ▼ Added Graphics.fadeout(frames = 10)
  65.   ▼ Added Bitmap#invert
  66.   ▼ Added Bitmap#invert!
  67.   ▼ Added Bitmap#brighten(amount = 10)
  68.   ▼ Added Bitmap#brighten!(amount = 10)
  69.   ▼ Added Bitmap#darken(amount = 10)
  70.   ▼ Added Bitmap#darken!(amount = 10)
  71.   ▼ Added Bitmap#grayscale
  72.   ▼ Added Bitmap#grayscale!
  73.   ▼ Added Bitmap#pixelate(size = 10)
  74.   ▼ Added Bitmap#pixelate!(size = 10)
  75.   ▼ Added Bitmap#frost(noise = 10)
  76.   ▼ Added Bitmap#frost!(noise = 10)
  77.   
  78.   1.24 -
  79.   ▼ Added Viewport#x
  80.   ▼ Added Viewport#y
  81.   ▼ Added Viewport#width
  82.   ▼ Added Viewport#height
  83.   ▼ Added Viewport#disposed?
  84.   
  85.   1.23 -
  86.   ▼ Added Window_Base#draw_text (same as Bitmap#draw_text)
  87.   ▼ Added Window_Base#draw_icon
  88.   ▼ Added Window_Base#draw_battler
  89.   ▼ Added Window_Base#draw_picture
  90.   
  91.   1.22 -
  92.   ▼ Added Game_Map#load_map_data
  93.   ▼ Added Game_Map#load_event
  94.   ▼ Rename Array#product => Array#prod (because of conflict with RGSS3)
  95.   
  96.   1.21 -
  97.   ▼ Fixed Glitch at Bitmap#crop
  98.   
  99.   1.20 -
  100.   ▼ Fixed Script Hanging Error at Bitmap#export
  101.   
  102.   1.19 -
  103.   ▼ Added some of RMXP method - Game_System#play_bgm
  104.   ▼ Added some of RMXP method - Game_System#play_bgs
  105.   ▼ Added some of RMXP method - Game_System#play_me
  106.   ▼ Added some of RMXP method - Game_System#play_se
  107.   
  108.   1.18 -
  109.   ▼ Fixing Backtrace at Array#method_missing
  110.   
  111.   1.17 -
  112.   ▼ Added Bitmap#flip_vertical
  113.   ▼ Added Bitmap#flip_vertical!
  114.   ▼ Added Bitmap#flip_horizontal
  115.   ▼ Added Bitmap#flip_horizontal!
  116.   
  117.   1.16 -
  118.   ▼ Added Bitmap#export (dump bitmap into .png files)
  119.   
  120.   1.15 -
  121.   ▼ Added Game_Characters#character_above?
  122.   ▼ Added Game_Characters#character_below?
  123.   ▼ Added Game_Characters#character_right?
  124.   ▼ Added Game_Characters#character_left?
  125.   
  126.   1.11 -
  127.   ▼ Fixing Bug at changing screen size
  128.   
  129.   1.10 -
  130.   ▼ Added Graphics.scale_screen(width, height)
  131.   
  132.   1.00 -
  133.   ▼ Original Release

  134. # -----------------------------------------------------------------------------
  135. # Below is the available command in this script
  136. # -----------------------------------------------------------------------------
  137. # * Graphics
  138. # -----------------------------------------------------------------------------
  139. # -----------------------------------------------------------------------------
  140.   This command is not recommended to used in RMXP
  141.   
  142.   Graphics.scale_screen(width,height)
  143.   - Resize the screen and stretched it (if not RMXP) into new resolution
  144.   
  145.   Graphics.fill_monitor
  146.   - Maximize the screen and stretched it (if not RMXP) to fill the monitor
  147.   
  148.   Graphics.control_screen_size(enable = true)
  149.   - Enable or disable screen size control by mouse.
  150.     Resized screen will be stretched (if not RMXP)
  151. # -----------------------------------------------------------------------------

  152.   Graphics.width        - Returns screen width
  153.   Graphics.height       - Returns screen height
  154.   Graphics.fullscreen?  - Returns true if Game in fullscreen mode, else false
  155.   Graphics.fullscreen   - Switch to fullscreen mode
  156.   Graphics.window       - Switch to windowed mode
  157.   Graphics.toggle       - Switch between fullscreen mode and windowed mode
  158.   Graphics.wait(frame)    - Wait for frame
  159.   Graphics.wait_for_input - Wait until input is pressed
  160.   Graphics.fadein(frame)  - Fade in the screen
  161.   Graphics.fadeout(frame) - Fade out the screen
  162.   Graphics.snap_to_bitmap - Snap screen to a bitmap object
  163.   
  164.   Graphics.high_priority = true/false - Change process priority to high / normal
  165.   Graphics.disable_alt_enter  - Disable input ALT+Enter (until game is closed)
  166.   
  167. # -----------------------------------------------------------------------------
  168. # * Module
  169. # -----------------------------------------------------------------------------
  170.   Module#attr_sec_reader(symbol, default=0)
  171.   - Create attr_reader with default value
  172.      Example : attr_sec_reader :something, "Sprite.new"
  173.      Equal : def something
  174.                @something ||= Sprite.new
  175.              end
  176.             
  177.   Module#attr_sec_accessor(symbol, *a, &block)
  178.   - Create (sheer of) attr_accessor with default value
  179.      Example : attr_sec_accessor :sprite1, :sprite2, :sprite3, "Sprite.new"
  180.      Equal : attr_writer :sprite1, :sprite2, :sprite3
  181.              attr_sec_reader :sprite1, "Sprite.new"
  182.              attr_sec_reader :sprite2, "Sprite.new"
  183.              attr_sec_reader :sprite3, "Sprite.new"
  184.   
  185.   Module#alias_sec_method(sym = nil, *a, &block)
  186.   - Create alias only if alias name is not defined and target method is exist
  187.      Example : alias_sec_method :alias_method, :target_method
  188.      Equal : if method_defined?(:target) && !method_defined?(:alias)
  189.                alias_method :alias, :target
  190.              end
  191.             
  192.   Module#define_sec_method(sym = nil, *a, &block)
  193.   - Define method only if the method is not defined
  194.      Example : define_sec_method(:some_method) { |*a| block }
  195.      Equal : unless method_defined?(:some_method)
  196.                def some_method(*a)
  197.                  block
  198.                end
  199.              end
  200.   
  201. # -----------------------------------------------------------------------------
  202. # * Array
  203. # -----------------------------------------------------------------------------
  204.   Array Method Distributor
  205.   - Distribute unexisted method in array into each variable
  206.   (will work only if the method isn't exist in Array)
  207.     Example : [Graphics,Input].update
  208.                 # equal => Graphics.update ; Input.update  
  209.               [@string1,@string2,@integer1,@sprite].dispose
  210.                 # equal => @sprite.dispose
  211.                 # (all variable without dispose method is ignored)
  212.               [@string1,@string2,@integer1].dispose
  213.                 # Throws NoMethodError if all method didn't have dispose method
  214.   
  215.   Array#random_each / Array#random_each_with_index
  216.     Example : a = [1,2,3,4,5,6,7]
  217.               a.random_each {|i| puts i} # 4,5,3,2,7,1,6
  218.               
  219.   Array#sum
  220.   Array#prod
  221.   Array#average
  222.     Example : [1,2,3,4].sum         # 10  (1+2+3+4)
  223.               [1,2,3,4].average     # 2.5 (10 / 4)
  224.               [1,2,3,4].prod        # 24  (1*2*3*4)
  225.               
  226.   Array#shuffle / Array#shuffle!  
  227.     Example : [1,2,3,4].shuffle     # [3,2,4,1]  
  228.    
  229.   Array#random / Array#random!
  230.     Example : [1,2,3,4].random      # 3  
  231.   
  232.   Array#switch=(true/false)
  233.   Array#switch_reverse
  234.   - Turn on / off switches all variable in the array
  235.     (will ignored if variable not integer or not an array)
  236.     Example : [1,2,[3,2,'A'],5].switch = true
  237.                 # equal => $game_switches[1] = true
  238.                            $game_switches[2] = true
  239.                            $game_self_switches[[3,2,'A']] = true
  240.                            $game_switches[5] = true
  241.                            
  242.   Array#variable(value = nil, method = "=")   
  243.   - Change all variable value in the array (ignored if variable not integer)
  244.     Example : [1,2,5].variable(10)
  245.                 # equal => $game_variables[1] = 10
  246.                            $game_variables[2] = 10
  247.                            $game_variables[5] = 10
  248.     Example : [1,2,5].variable(10, "+=")
  249.                 # equal => $game_variables[1] += 10
  250.                            $game_variables[2] += 10
  251.                            $game_variables[5] += 10
  252.                            
  253.   Array#have_all?(array)
  254.   - returns true if contains all elements of the array               
  255.   Array#have_any?(array)
  256.   - returns true if contains any elements of the array   
  257. # -----------------------------------------------------------------------------
  258. # * Sprite
  259. # -----------------------------------------------------------------------------
  260.   Sprite#clone
  261.   Sprite#dup
  262.   - Clone sprite without "can't clone sprite error"
  263.     Example : a = Sprite.new
  264.               b = a.clone
  265.               a.dispose
  266.               print a.disposed? # true
  267.               print b.disposed? # false
  268.               
  269. # -----------------------------------------------------------------------------
  270. # * Spriteset_Map
  271. # -----------------------------------------------------------------------------
  272.   Spriteset_Map#sprite_player
  273.   - returns sprite player at @character_sprites in Spriteset_Map
  274.   
  275.   Spriteset_Map#find_character(character)
  276.   - returns character sprite at @character_sprites in Spriteset_Map
  277.   
  278. # -----------------------------------------------------------------------------
  279. # * Game Battler
  280. # -----------------------------------------------------------------------------
  281.   Game_Battler#hp_percent(integer = false, float_points = 2)
  282.   Game_Battler#sp_percent(integer = false, float_points = 2)
  283.   Example : $game_actors[1].hp_percent
  284.                    # returns 0 - 100 based on percentage hp
  285.                   
  286. # -----------------------------------------------------------------------------
  287. # * Bitmap
  288. # -----------------------------------------------------------------------------
  289.   Bitmap#export(filename)
  290.   - exporting bitmap into a file (only support bmp and png)
  291.   Example : bitmap = Bitmap.new(50,20)
  292.             bitmap.export('empty.png')
  293.             
  294.   Bitmap#flip_vertical
  295.   Bitmap#flip_vertical!
  296.   Bitmap#flip_horizontal
  297.   Bitmap#flip_horizontal!
  298.   - flip the bitmap vertically or horizontally (using ! will modify self)
  299.   Example : bitmap = Bitmap.new(50,20)
  300.             bitmap.flip_vertical!
  301.             
  302.   Bitmap#rotate90
  303.   Bitmap#rotate90!
  304.   Bitmap#rotate180
  305.   Bitmap#rotate180!
  306.   Bitmap#rotate270         
  307.   Bitmap#rotate270!            
  308.       
  309.   Additional Bitmap Effects
  310.   Note : calling this method is process consuming, use with caution
  311.     Bitmap#invert
  312.     Bitmap#invert!
  313.     Bitmap#brighten(amount = 10)
  314.     Bitmap#brighten!(amount = 10)
  315.     Bitmap#darken(amount = 10)
  316.     Bitmap#darken!(amount = 10)
  317.     Bitmap#grayscale
  318.     Bitmap#grayscale!
  319.     Bitmap#pixelate(size = 10)
  320.     Bitmap#pixelate!(size = 10)
  321.     Bitmap#frost(noise = 10)
  322.     Bitmap#frost!(noise = 10)
  323. # -----------------------------------------------------------------------------
  324. # * Color
  325. # -----------------------------------------------------------------------------
  326.   Color RGB value shortcut
  327.   List :
  328.     Color.red
  329.     Color.green
  330.     Color.blue
  331.     Color.white
  332.     Color.black
  333.     Color.yellow
  334.     Color.magenta
  335.     Color.cyan
  336.     Color.purple
  337.     Color.gray
  338.     Color.lightgray
  339.     Color.darkgray
  340.     Color.pink
  341.     Color.orange
  342.     Color.brown
  343.     Color.golden
  344.    
  345.     Color.invert
  346.    
  347.   Color Hex
  348.   - You can use hex value as method in color class (not case sensitive)
  349.     (need to include 'x' in front)
  350.   Example : Color.xffffff, Color.x04dacf, etc
  351.   
  352.   
  353. # -----------------------------------------------------------------------------
  354. # * Game_Map
  355. # -----------------------------------------------------------------------------
  356.   
  357.   Game_Map#load_event(mapid, eventid, x, y, page_id)
  358.   Game_Map#load_event(mapid, eventid, x, y)
  359.   Game_Map#load_event(eventid, x, y)   # map_id will be assumed as current map
  360.   - Duplicate an event from another map to current map at position (x, y)
  361.   
  362.   Game_Map#call_event(mapid, eventid, page_id)
  363.   Game_Map#call_event(mapid, eventid)  # page_id will be assumed as -1
  364.   Game_Map#call_event(eventid)         # map_id will be assumed as current map
  365.   - Call an event from another map to current map
  366.       Note that page_id is start from 1, not 0
  367.       If you're using RMVX or RMVXA, setting page_id to -1 will bring you to
  368.       the page with met condition.
  369.       
  370.       
  371. # -----------------------------------------------------------------------------
  372. # * RTP fix
  373. # -----------------------------------------------------------------------------
  374.   
  375.   Longer script call
  376.   - You can stack script call next to each other as many as possible and they
  377.     will be connected.
  378.   - In addition, this also fixes the Interpreter Script call bug when if you
  379.     use $game_system..... = false, game would freeze. This will prevent that.

  380. # -----------------------------------------------------------------------------
  381. # * End Documentation
  382. # -----------------------------------------------------------------------------
  383. =end
  384. # =============================================================================

  385. #==============================================================================
  386. # ** Module     
  387. #------------------------------------------------------------------------------
  388. #  
  389. #==============================================================================

  390. class Module
  391.   #-------------------------------------------------------------------------
  392.   # * New method: attr_sec_reader (Attr Secondary Reader)
  393.   #-------------------------------------------------------------------------
  394.   unless method_defined?(:attr_sec_reader)
  395.     def attr_sec_reader(*sym)
  396.       if (1..2) === sym.size
  397.         module_eval("define_method(:#{sym[0]}) { @#{sym[0]} ||= #{sym[1]||0}}")
  398.       elsif sym.size > 2
  399.         (default = sym.pop) && sym.each {|s| attr_sec_reader(s,default)}
  400.       end
  401.     end
  402.   end
  403.   #-------------------------------------------------------------------------
  404.   # * New method: attr_sec_accessor (Attr Secondary Accessor)
  405.   #-------------------------------------------------------------------------
  406.   def attr_sec_accessor(sym = nil, *args)
  407.     (args.size > 0) | sym.nil? || args.push(0)
  408.     (default = args.pop) && (b = [sym].concat(args).compact)
  409.     (b).each {|a| (attr_writer(a) || 0) && attr_sec_reader(a,default)}
  410.   end
  411.   #-------------------------------------------------------------------------
  412.   # * New method: alias_sec_method (Alias Secondary Method)
  413.   #   Note : This method will create alias only if alias name is not defined
  414.   #          and target alias is exist
  415.   #-------------------------------------------------------------------------
  416.   unless method_defined?(:alias_sec_method)
  417.     private
  418.     def alias_sec_method(sym = nil, *args)
  419.       (args.size > 0) | sym.nil? || args.clear
  420.       (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
  421.         c = (t == :initialize ? true : method_defined?(t))
  422.         method_defined?(a) || (c && alias_method(a, t))
  423.       end
  424.     end
  425.   end
  426.   #-------------------------------------------------------------------------
  427.   # * New method: redirect_method
  428.   #-------------------------------------------------------------------------
  429.   unless method_defined?(:redirect_method)
  430.     private
  431.     def redirect_method(sym = nil, *args, &block)
  432.       (args.size > 0) | sym.nil? || args.clear
  433.       (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
  434.         meth = "def #{a}[*args] #{t}(*args) end"
  435.         meth.gsub!(/(['")}\](\d+)])\(\*args\)/i)  {    $1     }#'
  436.         meth.gsub!(/\[\*args\]/i)                 { '(*args)' }
  437.         method_defined?(a) || module_eval(meth)
  438.       end
  439.     end
  440.   end
  441.   #-------------------------------------------------------------------------
  442.   # * New method: define_sec_method
  443.   #   Note : This method will not defining method if method name already
  444.   #          exist
  445.   #-------------------------------------------------------------------------
  446.   unless method_defined?(:define_sec_method)
  447.     private
  448.     def define_sec_method(sym = nil, *args, &block)
  449.       sym && (method_defined?(s = sym.to_sym) || define_method(s,*args,&block))
  450.     end
  451.   end
  452.   #-------------------------------------------------------------------------
  453.   # * New method: define_third_method
  454.   #   Note : After aliasing, define a method
  455.   #-------------------------------------------------------------------------
  456.   unless method_defined?(:define_third_method)
  457.     private
  458.     def define_third_method(sym = nil, _alias = nil, *args, &block)
  459.       unless sym.nil? || _alias.nil?
  460.         stack = _alias.to_s =~ /stack/i || sym.to_s == 'initialize'
  461.         stack = (!stack && method_defined?(_alias.to_sym))
  462.         stack || alias_method(_alias.to_sym, sym.to_sym)
  463.         define_method(sym.to_sym,*args,&block)
  464.       end
  465.     end
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # ● New method: define_pre_alias
  469.   #--------------------------------------------------------------------------
  470.   unless method_defined?(:define_pre_method)
  471.     private
  472.     def define_pre_alias(sym = nil, *args, &block)
  473.       _time = Time.now
  474.       _alias = :"#{sym}_#{_time.to_i}_#{_time.usec}"
  475.       define_third_method(:"#{sym}",_alias) do  |*args|
  476.         block.bind(self).call
  477.         send(_alias,*args)
  478.       end
  479.     end
  480.     private
  481.     def define_post_alias(sym = nil, *args, &block)
  482.       _time = Time.now
  483.       _alias = :"#{sym}_#{_time.to_i}_#{_time.usec}"
  484.       define_third_method(:"#{sym}",_alias) do  |*args|
  485.         send(_alias,*args)
  486.         block.bind(self).call
  487.       end
  488.     end
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # ● New method: include_auto_update
  492.   #--------------------------------------------------------------------------
  493.   unless method_defined?(:include_auto_update)
  494.     private
  495.     def include_auto_update
  496.       return if method_defined?(:update_auto_update)
  497.       attr_sec_accessor(:auto_update, "[]")
  498.       define_method(:update_auto_update) do
  499.         return if auto_update.empty?
  500.         auto_update.each do |x|
  501.           (x[1].nil? ? send(x[0]) : (x[2].nil? ? x[0].method(x[1]).call :
  502.           (x[0].method(x[1]).call(*x[2]))))
  503.           (x[3].is_a?(Numeric) && (x[3] -= 1))
  504.         end   
  505.         auto_update.reject! {|x| x[3].is_a?(Numeric) && x[3] <= 0 }
  506.       end
  507.       _time = Time.now
  508.       _alias = :"update_#{_time.to_i}_#{_time.usec}"
  509.       define_third_method(:update,_alias) do  |*args|
  510.         send(_alias,*args)
  511.         update_auto_update
  512.       end
  513.     end
  514.   end  
  515. end
  516. #==============================================================================
  517. # ** LiTTleDRAgo     
  518. #------------------------------------------------------------------------------
  519. #  
  520. #==============================================================================

  521. module LiTTleDRAgo
  522.   #-------------------------------------------------------------------------
  523.   # * Constant
  524.   #-------------------------------------------------------------------------
  525.   VX            = defined?(Window_ActorCommand)
  526.   VXA           = defined?(Window_BattleActor)
  527.   XP            = !VX
  528.   RGSS1         = defined?(Hangup)
  529.   RGSS2         = RUBY_VERSION == '1.8.1' && !RGSS1
  530.   RGSS3         = RUBY_VERSION == '1.9.2'  
  531.   APPPATHDRAGO  = "#{ENV['APPDATA']}/Drago/"
  532. end
  533. #==============================================================================
  534. # ** CoreDLL
  535. #------------------------------------------------------------------------------
  536. #  
  537. #==============================================================================
  538. module CoreDLL
  539.   #-------------------------------------------------------------------------
  540.   # * Constant
  541.   #-------------------------------------------------------------------------
  542.   DLL_USED = ['kernel32','msvcrt','user32','gdi32']
  543.   SCENEVXA = "SceneManager.send(:instance_variable_set,:@scene,args.at(0))"
  544.   L        = LiTTleDRAgo
  545.   #-------------------------------------------------------------------------
  546.   # * Public Instance Variables
  547.   #-------------------------------------------------------------------------
  548.   attr_sec_reader :rtlmemory_pi,  "winapi(0,'RtlMoveMemory','pii','i')"
  549.   attr_sec_reader :rtlmemory_ip,  "winapi(0,'RtlMoveMemory','ipi','i')"
  550.   attr_sec_reader :setpriority,   "winapi(0,'SetPriorityClass','pi','i')"
  551.   attr_sec_reader :getprocesstime,"winapi(0,'GetProcessTimes','ipppp','i')"
  552.   attr_sec_reader :getdc,         "winapi(2,'GetDC','i','i')"
  553.   attr_sec_reader :releasedc,     "winapi(2,'ReleaseDC','ii','i')"
  554.   attr_sec_reader :reghotkey,     "winapi(2,'RegisterHotKey', 'liii', 'i')"
  555.   attr_sec_reader :sendinput,     "winapi(2,'SendInput','ipi','i')"
  556.   attr_sec_reader :setwindowlong, "winapi(2,'SetWindowLong','lll','l')"
  557.   attr_sec_reader :getkeysta,     "winapi(2,'GetKeyboardState','p','i')"
  558.   attr_sec_reader :getkeylay,     "winapi(2,'GetKeyboardLayout','l','l')"
  559.   attr_sec_reader :mapvirkey,     "winapi(2,'MapVirtualKeyEx','iil','i')"
  560.   attr_sec_reader :tounicode,     "winapi(2,'ToUnicodeEx','llppill','l')"
  561.   attr_sec_reader :screentoclient,"winapi(2,'ScreenToClient', 'lp', 'i')"
  562.   attr_sec_reader :cursorposition,"winapi(2,'GetCursorPos', 'p', 'i')"
  563.   attr_sec_reader :systemmetrix,  "winapi(2,'GetSystemMetrics', %w(i), 'i')"
  564.   attr_sec_reader :bitblt,        "winapi(3,'BitBlt','iiiiiiiii','i')"
  565.   attr_sec_reader :ccdc,          "winapi(3,'CreateCompatibleDC','i','i')"
  566.   attr_sec_reader :ccbitmap,      "winapi(3,'CreateCompatibleBitmap','iii','i')"
  567.   attr_sec_reader :deleteobject,  "winapi(3,'DeleteObject','i','i')"
  568.   attr_sec_reader :getbitmapbits, "winapi(3,'GetBitmapBits','llp','l')"
  569.   attr_sec_reader :getdibits,     "winapi(3,'GetDIBits','iiiiipi','i')"
  570.   attr_sec_reader :setdibits,     "winapi(3,'SetDIBits','iiiiipi','i')"
  571.   attr_sec_reader :selectobject,  "winapi(3,'SelectObject','ii','i')"
  572.   attr_sec_reader :getpixel,      "winapi(3,'GetPixel','iii','i')"
  573.   attr_sec_reader :setpixel,      "winapi(3,'SetPixel','liil','l')"  
  574.   attr_sec_reader :disabled_key,  "Array.new"
  575.   attr_sec_reader :high_priority, 'false'
  576.   #-------------------------------------------------------------------------
  577.   # * Define Secondary Listing
  578.   #-------------------------------------------------------------------------
  579.   define_sec_method(:disable_alt_enter) { disable_keys(0x0D) }
  580.   define_sec_method(:fullscreen?) { systemmetrix.call(0) == Graphics.width }
  581.   define_sec_method(:fullscreen)  { self.fullscreen? || toggle }
  582.   define_sec_method(:window)      { self.fullscreen? && toggle }
  583.   #-------------------------------------------------------------------------
  584.   # * Redirect Listing
  585.   #-------------------------------------------------------------------------
  586.   redirect_method :cache,      L::VX  ? '(Cache)' : '(RPG::Cache)'
  587.   redirect_method :scene,      L::VXA ? '(SceneManager.scene)':'($scene)'
  588.   redirect_method :scene=,     L::VXA ? SCENEVXA : '($scene = args[0])'
  589.   #-------------------------------------------------------------------------
  590.   # * Enable change window size via mouse (border required)
  591.   #   Screen will not resized if RMXP
  592.   #-------------------------------------------------------------------------
  593.   def control_screen_size(enable = true)
  594.     hid = @hide_border ? 0x14000000 : 0x14CA0000
  595.     set = enable ? (0x10C70000|0x00080000) : hid
  596.     self.setwindowlong.call(self.hwnd,-16, set)
  597.   end
  598.   #-------------------------------------------------------------------------
  599.   # * Hide window border
  600.   #   Screen size can't be controlled via mouse
  601.   #-------------------------------------------------------------------------
  602.   def hide_borders
  603.      control_screen_size((@hide_border = true) && false)
  604.   end
  605.   #-------------------------------------------------------------------------
  606.   # * Show window border
  607.   #   Screen size can't be controlled via mouse
  608.   #-------------------------------------------------------------------------
  609.   def show_borders
  610.     control_screen_size((@hide_border = false))
  611.   end
  612.   #-------------------------------------------------------------------------
  613.   # * Disable Key
  614.   #-------------------------------------------------------------------------
  615.   def disable_keys(*keys)
  616.     keys.each do |key|
  617.       disabled_key.include?(key) || disabled_key.push(key)
  618.       self.reghotkey.call(self.hwnd, 1, 0x0001, key)
  619.     end
  620.   end
  621.   #-------------------------------------------------------------------------
  622.   # * Resize the screen (scaled)
  623.   #   Screen will not resized if RMXP
  624.   #-------------------------------------------------------------------------
  625.   def scale_screen(width, height)
  626.     width  += ((res = self.systemmetrix).call(5) + (res.call(45))) * 2
  627.     height += (res.call(6) + (res.call(46))) * 2 + res.call(4)
  628.     x = [(res.call(0) - width) / 2, 0].max
  629.     y = [(res.call(1) - height) / 2, 0].max
  630.     self.setwindowpos(self.hwnd,0,x,y,width,height,0)
  631.   end
  632.   #-------------------------------------------------------------------------
  633.   # * Scale the game.exe to fill the monitor
  634.   #   Screen will not resized if RMXP
  635.   #-------------------------------------------------------------------------
  636.   def fill_monitor
  637.     setwindowpos(hwnd,0,0,0,(res = systemmetrix).call(0),res.call(1),0)
  638.   end
  639.   #-------------------------------------------------------------------------
  640.   # * setwindowpos
  641.   #-------------------------------------------------------------------------
  642.   def setwindowpos(hwnd = self.hwnd,at = 0,x = 0,y = 0,
  643.       width = 640, height = 480, ni = 0)
  644.     @setwindowpos ||= winapi(2, 'SetWindowPos', 'liiiiip','i')
  645.     @setwindowpos.call(hwnd, at, x, y, width, height, ni)
  646.   end
  647.   #-------------------------------------------------------------------------
  648.   # * Toggle between fullscreen and windowed
  649.   #-------------------------------------------------------------------------
  650.   def toggle
  651.     @keybd ||= winapi(2, 'keybd_event', %w(i i l l), 'v')
  652.     [@keybd.call(0xA4, 0, 0, 0), @keybd.call(13, 0, 0, 0)  ]
  653.     [@keybd.call(13, 0, 2, 0),   @keybd.call(0xA4, 0, 2, 0)]
  654.   end
  655.   #-------------------------------------------------------------------------
  656.   # * Show FPS
  657.   #-------------------------------------------------------------------------
  658.   def show_fps
  659.     @show_fps ||= winapi(2, 'keybd_event', %w(l l l l), '')
  660.     @show_fps.call(0x71,0,0,0)
  661.     sleep(0.1)
  662.     @show_fps.call(0x71,0,2,0)
  663.   end
  664.   #-------------------------------------------------------------------------
  665.   # * Get the Game Window's width and height
  666.   #-------------------------------------------------------------------------
  667.   def client_size   
  668.     @window_c_rect ||= winapi(2, 'GetClientRect', %w(l p), 'i')
  669.     @window_c_rect.call(self.hwnd, (rect = [0, 0, 0, 0].pack('l4')))
  670.     right, bottom = rect.unpack('l4')[2..3]
  671.     return right, bottom
  672.   end  
  673.   #-------------------------------------------------------------------------
  674.   # * Get the game window handle (specific to game)
  675.   #-------------------------------------------------------------------------
  676.   def hwnd
  677.     @game_window ||= winapi(2, 'FindWindowEx', %w(l l p p), 'i').
  678.                             call(0,0,"RGSS Player",0)
  679.   end  
  680.   #-------------------------------------------------------------------------
  681.   # * always_on_top  (cannot be undone)
  682.   #-------------------------------------------------------------------------
  683.   def always_on_top
  684.     res = self.systemmetrix
  685.     width  = Graphics.width  + (res.call(5) + (res.call(45))) * 2
  686.     height = Graphics.height + (res.call(6) + (res.call(46))) * 2 + res.call(4)
  687.     x = [(res.call(0) - width) / 2, 0].max
  688.     y = [(res.call(1) - height) / 2, 0].max
  689.     self.setwindowpos(self.hwnd,-1,x,y,width,height,0x0200)
  690.   end
  691.   #-------------------------------------------------------------------------
  692.   # * Get the value of game.ini
  693.   #-------------------------------------------------------------------------
  694.   def read_ini(field, key, ini = 'Game.ini')
  695.     @gpps ||= winapi(0, 'GetPrivateProfileString', 'pppplp', 'l')
  696.     @gpps.call(field,key,"",result="\0"*256,256,".//#{ini}") rescue return ""
  697.     return result.delete!("\0")
  698.   end
  699.   #-------------------------------------------------------------------------
  700.   # * Data default extension
  701.   #-------------------------------------------------------------------------
  702.   def data_default_extension
  703.     data = read_ini('Game','Scripts')
  704.     data = data.split('.').last || 'rxdata'
  705.     return data
  706.   end
  707.   #-------------------------------------------------------------------------
  708.   # * High Priority (true/false)
  709.   #-------------------------------------------------------------------------
  710.   def high_priority=(value)
  711.     @high_priority = value && true
  712.     setpriority.call(-1, @high_priority ? 0x00000080 : 0x00000020)
  713.   end
  714.   #--------------------------------------------------------------------------
  715.   # * snap_to_bitmap
  716.   #--------------------------------------------------------------------------
  717.   def snap_to_bitmap
  718.     bitmap = Bitmap.new((w = client_size.at(0)),(h = client_size.at(1)))
  719.     info   = [40,w,h,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
  720.     hDC    = ccdc.call((dc = getdc.call(hwnd)))
  721.     deleteobject.call(selectobject.call(hDC, (hBM = ccbitmap.call(dc, w, h))))
  722.     setdibits.call(hDC, hBM, 0, h, (a = bitmap.address), info, 0)
  723.     bitblt.call(hDC, 0, 0, w, h, dc, 0, 0, 0xCC0020)
  724.     getdibits.call(hDC, hBM, 0, h, a, info, 0)
  725.     deleteobject.call(hBM)
  726.     deleteobject.call(hDC)
  727.     return bitmap
  728.   end                           
  729.   #-------------------------------------------------------------------------
  730.   # * Execute Win32API
  731.   #-------------------------------------------------------------------------
  732.   def winapi(*a)
  733.     Win32API.new(*((a[0].is_a?(Integer) ? a[0] = DLL_USED[a[0]] : a) && a))
  734.   end
  735.   #----------------------------------------------------------------------------
  736.   # * unicode_to_utf8
  737.   #  string - string in Unicode format
  738.   #  Converts a string from Unicode format to UTF-8 format as RGSS does not
  739.   #  support Unicode.
  740.   #----------------------------------------------------------------------------
  741.   def unicode_to_utf8(string)
  742.     result = ''
  743.     string.unpack('L*').each do |c|
  744.       if (c1 = c < 0x0080) || (c2 = c < 0x0800) || (c3 = c < 0x10000) ||
  745.         (c4 = c < 0x200000)|| (c5 = c < 0x4000000) || (c6 = c < 0x80000000)
  746.         result += c.chr                           if c1
  747.         result += (0xC0 | (c >> 6)).chr           if c2
  748.         result += (0xE0 | (c >> 12)).chr          if c3
  749.         result += (0xF0 | (c >> 18)).chr          if c4
  750.         result += (0xF8 | (c >> 24)).chr          if c5
  751.         result += (0xFC | (c >> 30)).chr          if c6
  752.         result += (0x80 | ((c >> 24) & 0x3F)).chr if c6
  753.         result += (0x80 | ((c >> 18) & 0x3F)).chr if c5 || c6
  754.         result += (0x80 | ((c >> 12) & 0x3F)).chr if c4 || c5 || c6
  755.         result += (0x80 | ((c >> 6) & 0x3F)).chr  if c3 || c4 || c5 || c6
  756.         result += (0x80 | (c & 0x3F)).chr         if c2 || c3 || c4 || c5 || c6
  757.       end
  758.     end
  759.     return result
  760.   end
  761. end                        
  762. LiTTleDRAgo.extend(CoreDLL)

  763. #==============================================================================
  764. # ** RPG
  765. #------------------------------------------------------------------------------
  766. #  
  767. #==============================================================================
  768. module RPG
  769.   #============================================================================
  770.   # ** System
  771.   #----------------------------------------------------------------------------
  772.   #
  773.   #============================================================================
  774.   class System
  775.     #----------------------------------------------------------------------
  776.     # ● Class Variables
  777.     #----------------------------------------------------------------------
  778.     if (VX = LiTTleDRAgo::VX)
  779.       #------------------------------------------------------------------------
  780.       # ● Public Instance Variables
  781.       #------------------------------------------------------------------------
  782.       attr_accessor :magic_number,      :windowskin_name, :gameover_name
  783.       attr_accessor :battle_transition, :battleback_name, :title_name
  784.       #------------------------------------------------------------------------
  785.       # ● Redefined Methods
  786.       #------------------------------------------------------------------------
  787.       redirect_method :sounds,            "$data_system.sounds"
  788.       redirect_method :cursor_se,         "sounds[0]"
  789.       redirect_method :decision_se,       "sounds[1]"
  790.       redirect_method :cancel_se,         "sounds[2]"
  791.       redirect_method :buzzer_se,         "sounds[3]"
  792.       redirect_method :equip_se,          "sounds[4]"
  793.       redirect_method :save_se,           "sounds[5]"
  794.       redirect_method :load_se,           "sounds[6]"
  795.       redirect_method :battle_start_se,   "sounds[7]"
  796.       redirect_method :escape_se,         "sounds[8]"
  797.       if (VXA = LiTTleDRAgo::VXA)
  798.         redirect_method :shop_se,           "sounds[21]"
  799.         redirect_method :actor_collapse_se, "sounds[15]"
  800.       else
  801.         redirect_method :shop_se,           "sounds[17]"
  802.         redirect_method :actor_collapse_se, "sounds[13]"
  803.       end
  804.       redirect_method :enemy_collapse_se, "sounds[11]"
  805.       redirect_method :words,             "@words ||= RPG::System::Words.new()"
  806.       #------------------------------------------------------------------------
  807.       # ● Aliased Methods
  808.       #------------------------------------------------------------------------
  809.       alias_sec_method :battleback_name, :battleback1_name
  810.       alias_sec_method :title_name,      :title1_name      
  811.     end
  812.     #========================================================================
  813.     # ** Words
  814.     #------------------------------------------------------------------------
  815.     #
  816.     #========================================================================
  817.     class Words      
  818.       #----------------------------------------------------------------------
  819.       # ● New Methods
  820.       #----------------------------------------------------------------------
  821.       attr_sec_accessor :params,    !(VXA = LiTTleDRAgo::VXA) ? !VX ?
  822.                                     '[hp,sp,str,dex,agi,int]' :         # XP
  823.                                     '[hp,sp,atk,pdef,int,agi]' :        # VX
  824.                                     '[hp,sp,atk,pdef,int,mdef,agi,luk]' # VXA
  825.       attr_sec_accessor :weapon1,   VX && !VXA ? 'Vocab.weapon1' : "'Weapon 1'"
  826.       attr_sec_accessor :weapon2,   VX && !VXA ? 'Vocab.weapon2' : "'Weapon 2'"
  827.       attr_sec_accessor :status,    VX ? 'Vocab.status'          : "'Status'  "
  828.       attr_sec_accessor :save,      VX ? 'Vocab.save'            : "'Save'    "
  829.       attr_sec_accessor :game_end,  VX ? 'Vocab.game_end'        : "'Game End'"
  830.       attr_sec_accessor :fight,     VX ? 'Vocab.fight'           : "'Fight'   "
  831.       attr_sec_accessor :escape,    VX ? 'Vocab.escape'          : "'Escape'  "
  832.       attr_sec_accessor :new_game,  VX ? 'Vocab.new_game'        : "'New Game'"
  833.       attr_sec_accessor :continue,  VX ? 'Vocab.continue'        : "'Continue'"
  834.       attr_sec_accessor :shutdown,  VX ? 'Vocab.shutdown'        : "'Shutdown'"
  835.       attr_sec_accessor :to_title,  VX ? 'Vocab.to_title'        : "'To Title'"
  836.       attr_sec_accessor :cancel,    VX ? 'Vocab.cancel'          : "'Cancel'  "
  837.       #----------------------------------------------------------------------
  838.       # ● Redirect Listings
  839.       #----------------------------------------------------------------------
  840.       redirect_method :gold,   (VXA ? 'Vocab.currency_unit' : 'Vocab.gold')
  841.       redirect_method :hp,     'Vocab.hp'
  842.       redirect_method :sp,     'Vocab.mp'
  843.       redirect_method :str,    'String.new()'
  844.       redirect_method :dex,    'String.new()'
  845.       redirect_method :luk,    (VXA ? 'Vocab.param(7)' : 'String.new()')
  846.       redirect_method :agi,    (VXA ? 'Vocab.param(6)' : 'Vocab.agi')
  847.       redirect_method :int,    (VXA ? 'Vocab.param(4)' : 'Vocab.spi')
  848.       redirect_method :atk,    (VXA ? 'Vocab.param(2)' : 'Vocab.atk')
  849.       redirect_method :pdef,   (VXA ? 'Vocab.param(3)' : 'Vocab.def')
  850.       redirect_method :mdef,   (VXA ? 'Vocab.param(5)' : 'String.new()')
  851.       redirect_method :weapon, (VXA ? 'Vocab.etype(0)' : 'Vocab.weapon')
  852.       redirect_method :armor1, (VXA ? 'Vocab.etype(1)' : 'Vocab.armor1')
  853.       redirect_method :armor2, (VXA ? 'Vocab.etype(2)' : 'Vocab.armor2')
  854.       redirect_method :armor3, (VXA ? 'Vocab.etype(3)' : 'Vocab.armor3')
  855.       redirect_method :armor4, (VXA ? 'Vocab.etype(4)' : 'Vocab.armor4')
  856.       redirect_method :attack, 'Vocab.attack'
  857.       redirect_method :skill,  'Vocab.skill'
  858.       redirect_method :guard,  'Vocab.guard'
  859.       redirect_method :item,   'Vocab.item'
  860.       redirect_method :equip,  'Vocab.equip'
  861.     end
  862.   end
  863. end
  864. #==============================================================================
  865. # ** RPG_FileTest
  866. #------------------------------------------------------------------------------
  867. #
  868. #==============================================================================
  869. module RPG_FileTest
  870.   #--------------------------------------------------------------------------
  871.   # ● New method: self.exist?
  872.   #--------------------------------------------------------------------------
  873.   def self.exist?(filename)
  874.     dir,ext = File.dirname(filename) + '/', File.extname(filename)
  875.     base = File.basename(filename, ext)
  876.     if ['.png','.jpg','.bmp'].include?(ext.downcase)
  877.       cache = defined?(Cache) ? Cache : RPG::Cache
  878.       (cache.load_bitmap(dir,base) && true) rescue false
  879.     elsif ['.rxdata','.rvdata','.rvdata2','.rb','.txt'].include?(ext.downcase)
  880.       (load_data(filename) && true) rescue false
  881.     else
  882.       File.exist?(filename)
  883.     end
  884.   end
  885. end

  886. #==============================================================================
  887. # ** Sound
  888. #------------------------------------------------------------------------------
  889. #  This module plays sound effects. It obtains sound effects specified in the
  890. # database from the global variable $data_system, and plays them.
  891. #==============================================================================
  892. module Sound;  end
  893. class << Sound
  894.   #------------------------------------------------------------------------
  895.   # ● New Method :se_play
  896.   #------------------------------------------------------------------------
  897.   unless method_defined?(:se_play)
  898.     def se_play(type)
  899.       system = ($game_system ||= Game_System.new)
  900.       case type
  901.       when :cursor         then system.se_play($data_system.cursor_se)
  902.       when :decision       then system.se_play($data_system.decision_se)
  903.       when :cancel         then system.se_play($data_system.cancel_se)
  904.       when :buzzer         then system.se_play($data_system.buzzer_se)
  905.       when :shop           then system.se_play($data_system.shop_se)
  906.       when :equip          then system.se_play($data_system.equip_se)
  907.       when :save           then system.se_play($data_system.save_se)
  908.       when :load           then system.se_play($data_system.load_se)
  909.       when :battle_start   then system.se_play($data_system.battle_start_se)
  910.       when :escape         then system.se_play($data_system.escape_se)
  911.       when :actor_collapse then system.se_play($data_system.actor_collapse_se)
  912.       when :enemy_collapse then system.se_play($data_system.enemy_collapse_se)
  913.       end
  914.     end
  915.   end
  916.   #--------------------------------------------------------------------------
  917.   # * Redefined Method
  918.   #--------------------------------------------------------------------------
  919.   define_sec_method(:play_cursor)         { se_play(:cursor)         }
  920.   define_sec_method(:play_decision)       { se_play(:decision)       }
  921.   define_sec_method(:play_cancel)         { se_play(:cancel)         }
  922.   define_sec_method(:play_buzzer)         { se_play(:buzzer)         }
  923.   define_sec_method(:play_equip)          { se_play(:equip)          }
  924.   define_sec_method(:play_save)           { se_play(:save)           }
  925.   define_sec_method(:play_load)           { se_play(:load)           }
  926.   define_sec_method(:play_battle_start)   { se_play(:battle_start)   }
  927.   define_sec_method(:play_escape)         { se_play(:escape)         }
  928.   define_sec_method(:play_enemy_collapse) { se_play(:enemy_collapse) }
  929.   define_sec_method(:play_actor_collapse) { se_play(:actor_collapse) }
  930.   define_sec_method(:play_shop)           { se_play(:shop)           }
  931.   #--------------------------------------------------------------------------
  932.   # * Alias Listing
  933.   #--------------------------------------------------------------------------
  934.   alias_sec_method :play_ok, :play_decision
  935. end

  936. #==============================================================================
  937. # ** Game_System
  938. #------------------------------------------------------------------------------
  939. #  This class handles data surrounding the system. Backround music, etc.
  940. #  is managed here as well. Refer to "$game_system" for the instance of
  941. #  this class.
  942. #==============================================================================
  943. class Game_System
  944.   #--------------------------------------------------------------------------
  945.   # * Constant
  946.   #--------------------------------------------------------------------------
  947.   VX = LiTTleDRAgo::VX && !LiTTleDRAgo::VXA
  948.   #--------------------------------------------------------------------------
  949.   # * Public Instance Variable
  950.   #--------------------------------------------------------------------------
  951.   attr_sec_accessor :bgm_volume    , 100
  952.   attr_sec_accessor :bgs_volume    , 100
  953.   attr_sec_accessor :me_volume     , 100
  954.   attr_sec_accessor :se_volume     , 100
  955.   attr_sec_accessor :bgm_pitch     , 100
  956.   attr_sec_accessor :bgs_pitch     , 100
  957.   attr_sec_accessor :me_pitch      , 100
  958.   attr_sec_accessor :se_pitch      , 100
  959.   attr_sec_accessor :volume_control, 'false'
  960.   #--------------------------------------------------------------------------
  961.   # * Redefined method: bgm_memorize, bgm_restore
  962.   #--------------------------------------------------------------------------
  963.   VX && define_sec_method(:bgm_memorize) { @memorized_bgm = @playing_bgm }
  964.   VX && define_sec_method(:bgm_restore)  { bgm_play(@memorized_bgm)     }
  965.   #--------------------------------------------------------------------------
  966.   # * Redirect Listing
  967.   #--------------------------------------------------------------------------
  968.   redirect_method :bgm_stop,     'Audio.bgm_stop'
  969.   redirect_method :bgs_stop,     'Audio.bgs_stop'
  970.   redirect_method :se_stop,      'Audio.se_stop'
  971.   redirect_method :me_stop,      'Audio.me_stop'
  972.   #--------------------------------------------------------------------------
  973.   # * Alias Listing
  974.   #--------------------------------------------------------------------------
  975.   alias_sec_method :bgm_memorize, :save_bgm
  976.   alias_sec_method :bgm_restore,  :replay_bgm
  977.   alias_sec_method :save_bgm,     :bgm_memorize
  978.   alias_sec_method :replay_bgm,   :bgm_restore
  979.   #--------------------------------------------------------------------------
  980.   # * Aliased method: bgm_play, bgs_play, me_play, se_play
  981.   #--------------------------------------------------------------------------
  982.   [:bgm,:bgs,:me,:se].each do |sa|
  983.     next unless method_defined?(:"#{sa}_play")
  984.     alias_sec_method(:"drg_#{sa}_play", :"#{sa}_play")
  985.     define_method(:"#{sa}_play") do |bgm,*a|
  986.       if bgm.is_a?(String) && bgm != ''
  987.         bgm = RPG::AudioFile.new(bgm,send(:"#{sa}_volume"),send(:"#{sa}_pitch"))
  988.       elsif volume_control && bgm.is_a?(RPG::AudioFile) && bgm.name != ""
  989.         bgm = bgm.clone
  990.         bgm.volume = Math.percent(bgm.volume,send(:"#{sa}_volume"))
  991.         bgm.pitch  = Math.percent(bgm.pitch,send(:"#{sa}_pitch"))
  992.       end
  993.       @playing_bgm = bgm if "#{sa}" == 'bgm'
  994.       @playing_bgs = bgm if "#{sa}" == 'bgs'
  995.       if respond_to?(:"drg_#{sa}_play")
  996.         send(:"drg_#{sa}_play", bgm,*a)
  997.       else
  998.         if bgm.is_a?(RPG::AudioFile) && bgm.name != ''
  999.           Audio.send(:"#{sa}_play","Audio/#{sa}/" + bgm.name,
  1000.              bgm.volume.round, bgm.pitch.round,*a)
  1001.         else
  1002.           send(:"#{sa}_stop")
  1003.         end
  1004.         Graphics.frame_reset
  1005.       end
  1006.     end
  1007.   end
  1008. end

  1009. #==============================================================================
  1010. # ** Object
  1011. #------------------------------------------------------------------------------
  1012. #  This class is superclass for all class
  1013. #==============================================================================
  1014. class Object
  1015.   #-------------------------------------------------------------------------
  1016.   # * New method: all_variable_dispose
  1017.   #-------------------------------------------------------------------------
  1018.   def all_variable_dispose
  1019.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  1020.     all.delete_if {|s| s.not.respond_to?(:dispose) }
  1021.     all.delete_if {|s| s.respond_to?(:disposed?) && s.disposed?}
  1022.     all.dispose
  1023.   end
  1024.   #-------------------------------------------------------------------------
  1025.   # * New method: rand_between
  1026.   #-------------------------------------------------------------------------
  1027.   unless method_defined?(:rand_between)
  1028.     def rand_between(min, max)
  1029.       min + rand(max - min + 1) if min.is_a?(Numeric) && max.is_a?(Numeric)
  1030.     end
  1031.   end
  1032.   #-------------------------------------------------------------------------
  1033.   # * New method: get_note
  1034.   #-------------------------------------------------------------------------
  1035.   unless method_defined?(:get_note)
  1036.     def get_note
  1037.       respond_to?(:note) ? note : ""
  1038.     end
  1039.   end
  1040.   #-------------------------------------------------------------------------
  1041.   # * New method: screen_rect
  1042.   #-------------------------------------------------------------------------
  1043.   unless method_defined?(:screen_rect)
  1044.     def screen_rect(as_rect = true)
  1045.       array = [0,0,Graphics.width,Graphics.height]
  1046.       as_rect ? Rect.new(*array) : array
  1047.     end
  1048.   end
  1049.   #-------------------------------------------------------------------------
  1050.   # * New method: forcesave
  1051.   #-------------------------------------------------------------------------
  1052.   unless method_defined?(:forcesave)
  1053.     def forcesave(index)
  1054.       return DataManager.save_game(index) if defined?(DataManager)
  1055.       save = LiTTleDRAgo::VX ? Scene_File.new(0,nil,0) : Scene_Save.new
  1056.       begin
  1057.         file = File.open(save.make_filename(index), "wb")
  1058.         (save.write_save_data(file) && file.close) || true
  1059.       rescue
  1060.         File.delete(save.make_filename(index)) rescue nil
  1061.         (Sound.play_buzzer) && false
  1062.       end
  1063.     end
  1064.   end
  1065.   #--------------------------------------------------------------------------
  1066.   # * sprite_report
  1067.   #--------------------------------------------------------------------------
  1068.   unless method_defined?(:script_report)
  1069.     def script_report(text,font = nil)
  1070.       s = (text.is_a?(String) || (text = text.inspect)) && Sprite.new
  1071.       s.opacity = (s.bitmap = Bitmap.new((g = Graphics).width,g.height)) && 0
  1072.       s.bitmap.font.name = ['Georgia',Font.default_name].flatten
  1073.       s.bitmap.font = (s.z += 9999) && (font || s.bitmap.font)
  1074.       y = (text.split(/\n/).size * s.bitmap.text_size(text).height) / 2
  1075.       s.bitmap.draw_enter_edging_text(0,0-y,g.width,g.height,text,1)
  1076.       (s.opacity += 10) && g.update until s.opacity >= 255
  1077.       g.wait_for_input
  1078.       (s.opacity -= 10) && g.update until s.opacity <= 0
  1079.       s.dispose
  1080.     end
  1081.   end
  1082.   #-------------------------------------------------------------------------
  1083.   # * New method: not
  1084.   #-------------------------------------------------------------------------
  1085.   define_sec_method(:not) { Not.new(self) }
  1086.   #============================================================================
  1087.   # ** Not
  1088.   #----------------------------------------------------------------------------
  1089.   #
  1090.   #============================================================================
  1091.   class Not
  1092.     #-------------------------------------------------------------------------
  1093.     # * Private
  1094.     #-------------------------------------------------------------------------
  1095.     private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ }
  1096.     #-------------------------------------------------------------------------
  1097.     # * Object Initialization
  1098.     #-------------------------------------------------------------------------
  1099.     define_method(:initialize) {|original|  @original = original }
  1100.     #-------------------------------------------------------------------------
  1101.     # * New method: method_missing
  1102.     #-------------------------------------------------------------------------
  1103.     def method_missing(sym, *a, &blk)
  1104.       !@original.send(sym, *a, &blk)
  1105.     end
  1106.   end
  1107. end

  1108. #==============================================================================
  1109. # ** Kernel
  1110. #------------------------------------------------------------------------------
  1111. #  
  1112. #==============================================================================
  1113. module Kernel
  1114.   #-------------------------------------------------------------------------
  1115.   # * Alias Listing
  1116.   #-------------------------------------------------------------------------
  1117.   $@ || alias_method(:carrot, :proc)
  1118.   #-------------------------------------------------------------------------
  1119.   # * Script Check
  1120.   #-------------------------------------------------------------------------
  1121.   if LiTTleDRAgo::XP && LiTTleDRAgo::RGSS3 && !defined?(XPA_CONFIG)
  1122.     $@ || alias_method(:last_before_p,        :p)
  1123.     $@ || alias_method(:last_before_print,    :print)
  1124.     $@ || alias_method(:last_before_msgbox,   :msgbox)
  1125.     $@ || alias_method(:last_before_msgbox_p, :msgbox_p)
  1126.     define_method(:p)       {|*args| last_before_msgbox_p(*args)}
  1127.     define_method(:print)   {|*args| last_before_msgbox(*args)  }
  1128.     define_method(:msgbox)  {|*args| last_before_print(*args)   }
  1129.     define_method(:msgbox_p){|*args| last_before_p(*args)       }
  1130.   end
  1131.   define_method(:draise) {|*args| (dp(*args) && !1) || exit }
  1132.   define_method(:dp)     {|*a| script_report(a.map {|i| i.inspect}.join("\n"))}
  1133.   #-------------------------------------------------------------------------
  1134.   # * New method: dprint
  1135.   #-------------------------------------------------------------------------
  1136.   def dprint(*args)
  1137.     script_report(args.map {|i| i.is_a?(String) ? i : i.inspect}.join)
  1138.   end
  1139.   #-------------------------------------------------------------------------
  1140.   # * New method: press_any_key
  1141.   #-------------------------------------------------------------------------
  1142.   unless method_defined?(:press_any_key)
  1143.     def press_any_key
  1144.       return false if Input.nil?
  1145.       return true if Input.trigger?(Input::A)    ||Input.trigger?(Input::B)
  1146.       return true if Input.trigger?(Input::C)    ||Input.trigger?(Input::X)
  1147.       return true if Input.trigger?(Input::Y)    ||Input.trigger?(Input::Z)
  1148.       return true if Input.trigger?(Input::L)    ||Input.trigger?(Input::R)
  1149.       return true if Input.trigger?(Input::UP)   ||Input.trigger?(Input::DOWN)
  1150.       return true if Input.trigger?(Input::LEFT) ||Input.trigger?(Input::RIGHT)
  1151.       return true if Input.trigger?(Input::SHIFT)||Input.trigger?(Input::CTRL)
  1152.       return true if Input.trigger?(Input::ALT)  ||Input.trigger?(Input::F5)
  1153.       return true if Input.trigger?(Input::F6)   ||Input.trigger?(Input::F7)
  1154.       return true if Input.trigger?(Input::F8)   ||Input.trigger?(Input::F9)
  1155.     end
  1156.   end
  1157.   #-------------------------------------------------------------------------
  1158.   # * New method: inspect_instance_variable
  1159.   #-------------------------------------------------------------------------
  1160.   unless method_defined?(:inspect_instance_variable)
  1161.     def inspect_instance_variable(class_name, variable)
  1162.       Module.const_get(class_name).new.instance_variable_get(:"@#{variable}")
  1163.     end
  1164.   end
  1165. end

  1166. #==============================================================================
  1167. # ** Proc
  1168. #------------------------------------------------------------------------------
  1169. #  
  1170. #==============================================================================
  1171. class Proc
  1172.   #-------------------------------------------------------------------------
  1173.   # * New method: bind
  1174.   #-------------------------------------------------------------------------
  1175.   unless method_defined?(:bind)
  1176.     def bind(object)
  1177.       block, time = self, Time.now
  1178.       class << object
  1179.         self
  1180.       end.class_eval do
  1181.         define_method((name = "__bind_#{time.to_i}_#{time.usec}"), &block)
  1182.         remove_method((method = instance_method(name)) && name)
  1183.         method
  1184.       end.bind(object)
  1185.     end
  1186.   end
  1187. end
  1188. #==============================================================================
  1189. # ** Enumerable
  1190. #------------------------------------------------------------------------------
  1191. #  
  1192. #==============================================================================
  1193. module Enumerable
  1194.   #---------------------------------------------------------------------------
  1195.   # * Redefined method: shuffle
  1196.   #---------------------------------------------------------------------------
  1197.   define_sec_method(:shuffle) {(a = entries) && Array.new(size){ a.random!}}
  1198.   #---------------------------------------------------------------------------
  1199.   # * New method: random_each
  1200.   #---------------------------------------------------------------------------
  1201.   unless method_defined?(:random_each)
  1202.     def random_each() (block_given? ? shuffle.each {|s| yield s } : random) end
  1203.   end
  1204.   #---------------------------------------------------------------------------
  1205.   # * New method: random_each_with_index
  1206.   #---------------------------------------------------------------------------
  1207.   unless method_defined?(:random_each_with_index)
  1208.     def random_each_with_index
  1209.       block_given? ? self.shuffle.each_with_index {|obj, i| yield obj,i } :
  1210.         self.random                                    
  1211.     end
  1212.   end
  1213.   #---------------------------------------------------------------------------
  1214.   # * Redefined method: drop_while
  1215.   #---------------------------------------------------------------------------
  1216.   unless method_defined?(:drop_while)
  1217.     def drop_while(&block)
  1218.       ary, state = [], false
  1219.       self.each do |e|
  1220.         state = true if !state and !block.call(e)
  1221.         ary << e if state
  1222.       end
  1223.       ary
  1224.     end
  1225.   end
  1226.   #---------------------------------------------------------------------------
  1227.   # * Redefined method: take_while
  1228.   #---------------------------------------------------------------------------
  1229.   unless method_defined?(:take_while)
  1230.     def take_while(&block)
  1231.       ary = []
  1232.       self.each do |e|
  1233.         return ary unless block.call(e)
  1234.         ary << e
  1235.       end
  1236.       ary
  1237.     end
  1238.   end
  1239.   #---------------------------------------------------------------------------
  1240.   # * Redefined method: partition
  1241.   #---------------------------------------------------------------------------
  1242.   unless method_defined?(:partition)
  1243.     def partition(&block)
  1244.       ary_T, ary_F = [], []
  1245.       self.each {|val| block.call(val) ? ary_T.push(val) : ary_F.push(val)}
  1246.       return ary_T, ary_F
  1247.     end
  1248.   end
  1249.   #---------------------------------------------------------------------------
  1250.   # * Redefined method: grep
  1251.   #---------------------------------------------------------------------------
  1252.   unless method_defined?(:grep)
  1253.     def grep(pattern, &block)
  1254.       collect {|v| pattern === v && ary.push((block)? block.call(v): v)}
  1255.     end
  1256.   end
  1257.   #---------------------------------------------------------------------------
  1258.   # * Redefined method: each_slice
  1259.   #---------------------------------------------------------------------------
  1260.   unless method_defined?(:each_slice)
  1261.     def each_slice(n, &block)
  1262.       not_integer = "expected Integer for 1st argument"
  1263.       n.is_a?(Integer) || raise(TypeError,not_integer,caller(1))
  1264.       n <= 0 && raise(ArgumentError, "invalid slice size",caller(1))
  1265.       ary = []
  1266.       self.each do |e|
  1267.         ary << e
  1268.         if ary.size == n
  1269.           block.call(ary)
  1270.           ary = []
  1271.         end
  1272.       end
  1273.       block.call(ary) unless ary.empty?
  1274.     end
  1275.   end
  1276.   #---------------------------------------------------------------------------
  1277.   # * Redefined method: minmax
  1278.   #---------------------------------------------------------------------------
  1279.   unless method_defined?(:minmax)
  1280.     def minmax(&block) (a = sort(&block)) && [a.first,a.last]  end
  1281.   end
  1282. end
  1283.   
  1284. #==============================================================================
  1285. # ** Array
  1286. #------------------------------------------------------------------------------
  1287. #  
  1288. #==============================================================================
  1289. class Array
  1290.   #---------------------------------------------------------------------------
  1291.   # * Define Secondary Listing
  1292.   #---------------------------------------------------------------------------
  1293.   define_sec_method(:have_all?)     { |*array| self & array == array        }
  1294.   define_sec_method(:have_any?)     { |*array| self - array != self         }
  1295.   define_sec_method(:relay)         { |type| map {|s| s.send(:"to_#{type}")}}
  1296.   #---------------------------------------------------------------------------
  1297.   # * Redirect method
  1298.   #---------------------------------------------------------------------------
  1299.   redirect_method :switch_on,      'self.switch = (true)'                  
  1300.   redirect_method :switch_off,     'self.switch = (false)'                  
  1301.   redirect_method :random,         'self.at(rand(size))'         
  1302.   redirect_method :random!,        'self.delete_at(rand(size))'
  1303.   redirect_method :sum,            'self.inject(0) {|r, n| r += n}'
  1304.   redirect_method :prod,           'self.inject(1) {|r, n| r *= n}'
  1305.   redirect_method :next_item,      '(item = shift) && push(item) &&  (item)'
  1306.   redirect_method :previous_item,  '(item = pop) && unshift(item) && (item)'
  1307.   redirect_method :nitems,         'count {|x| x.not.nil?}'
  1308.   redirect_method :switch_reverse, 'switch=(:flip)'
  1309.   #---------------------------------------------------------------------------
  1310.   # * New method: method_missing
  1311.   #---------------------------------------------------------------------------
  1312.   def method_missing(val,*a,&b)
  1313.     en = self.entries.find_all {|s|s.respond_to?(val.to_sym)}
  1314.     if self.not.empty? && en.empty?
  1315.       text = "Undefined method #{val} for #{self.inspect}"
  1316.       raise(NoMethodError,text,caller(1))
  1317.     end
  1318.     return en.map {|s| s.send(val.to_s,*a,&b)}
  1319.   end
  1320.   #-------------------------------------------------------------------------
  1321.   # * New method: each_ntuple
  1322.   #-------------------------------------------------------------------------
  1323.   unless method_defined?(:each_ntuple)
  1324.     def each_ntuple(number)
  1325.       0.step(size - size % number - 1, number) {|i| yield(*self[i, number])}
  1326.     end
  1327.   end
  1328.   #-------------------------------------------------------------------------
  1329.   # * New method: each_pair
  1330.   #-------------------------------------------------------------------------
  1331.   unless method_defined?(:each_pair)
  1332.     def each_pair()   each_ntuple(2) {|a,b| yield a, b }       end
  1333.   end
  1334.   #---------------------------------------------------------------------------
  1335.   # * New method: each_triple
  1336.   #---------------------------------------------------------------------------
  1337.   unless method_defined?(:each_triple)
  1338.     def each_triple() each_ntuple(3) {|a,b,c| yield a, b, c }  end
  1339.   end
  1340.   #---------------------------------------------------------------------------
  1341.   # * Redefined method: shuffle! (for RMXP)
  1342.   #---------------------------------------------------------------------------
  1343.   unless method_defined?(:shuffle!)
  1344.     def shuffle!()  self.dup == replace(shuffle) ? nil : self  end
  1345.   end
  1346.   #---------------------------------------------------------------------------
  1347.   # * New method: sort_by!
  1348.   #---------------------------------------------------------------------------
  1349.   unless method_defined?(:sort_by!)
  1350.     def sort_by!(*args,&block)
  1351.       self.dup == replace(sort_by(*args,&block)) ? nil : self
  1352.     end
  1353.   end
  1354.   #---------------------------------------------------------------------------
  1355.   # * New method: recursive_clone
  1356.   #---------------------------------------------------------------------------
  1357.   unless method_defined?(:rclone)
  1358.     def recursive_clone
  1359.       (clon = self.clone).each_index do |i|
  1360.         clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
  1361.       end
  1362.       clon
  1363.     end
  1364.     alias_method(:rclone, :recursive_clone)
  1365.   end
  1366.   #---------------------------------------------------------------------------
  1367.   # * New method: to_hash
  1368.   #---------------------------------------------------------------------------
  1369.   unless method_defined?(:to_hash)
  1370.     def to_hash
  1371.       (hash = Hash.new) && each_index {|i| hash[i] = self[i]} && hash
  1372.     end
  1373.   end  
  1374.   #---------------------------------------------------------------------------
  1375.   # * Redefined method: count
  1376.   #---------------------------------------------------------------------------
  1377.   unless method_defined?(:count)
  1378.     def count(*args, &block)
  1379.       if block_given?
  1380.         find_all {|s| block.call(s)}.size
  1381.       else
  1382.         ary = args.empty? ? self : args.map {|a| find_all{|s| s == a}}
  1383.         ary.compact.size
  1384.       end
  1385.     end
  1386.   end
  1387.   #---------------------------------------------------------------------------
  1388.   # * New method: each_with_next
  1389.   #---------------------------------------------------------------------------
  1390.   unless method_defined?(:each_with_next)
  1391.     def each_with_next(num = 1)
  1392.       (size - num).times {|i| yield(*self[i..(i+num)])}
  1393.     end
  1394.   end
  1395.   #---------------------------------------------------------------------------
  1396.   # * New method: switch=
  1397.   #---------------------------------------------------------------------------
  1398.   unless method_defined?(:switch=)
  1399.     def switch=(value)
  1400.       integer = search_var_key[0]
  1401.       array   = search_var_key[1]
  1402.       if value == :flip
  1403.         integer.each {|i| $game_switches[i] = !$game_switches[i] }
  1404.         array.each {|i| $game_self_switches[i] = !$game_self_switches[i] }
  1405.       else
  1406.         integer.each {|i| $game_switches[i] = value }
  1407.         array.each {|i| $game_self_switches[i] = value }
  1408.       end
  1409.       $game_map.need_refresh = true if $game_map.respond_to?(:need_refresh)
  1410.     end
  1411.   end
  1412.   #---------------------------------------------------------------------------
  1413.   # * New method: variable
  1414.   #---------------------------------------------------------------------------
  1415.   def variable(value = nil,method = "=")
  1416.     integer = search_var_key[0]  
  1417.     integer += search_var_key[1] if $drago_game_variable
  1418.     return integer.map {|i| $game_variables[i]} if value.nil?
  1419.     result = integer.map {|i| eval("$game_variables[i] #{method} #{value}") }
  1420.     $game_map.need_refresh = true if $game_map.respond_to?(:need_refresh)
  1421.     result
  1422.   end
  1423.   #---------------------------------------------------------------------------
  1424.   # * New method: search_var_key
  1425.   #---------------------------------------------------------------------------
  1426.   def search_var_key
  1427.     integer = self.find_all {|s| s.is_a?(Integer)}
  1428.     range   = self.find_all {|s| s.is_a?(Range)  }
  1429.     array   = self.find_all {|s| s.is_a?(Array)  }
  1430.     string  = self.find_all {|s| s.is_a?(String) }
  1431.     integer = integer + range.collect {|s| s.to_a }.flatten
  1432.     $game_switches      ||= Game_Switches.new
  1433.     $game_self_switches ||= Game_SelfSwitches.new
  1434.     $game_variables     ||= Game_Variables.new
  1435.     return [integer.sort.uniq, array.sort.uniq]
  1436.   end
  1437.   #---------------------------------------------------------------------------
  1438.   # * New method: rindexes
  1439.   #---------------------------------------------------------------------------
  1440.   unless method_defined?(:rindexes)
  1441.     def rindexes(*values)
  1442.       array = Array.new
  1443.       each_index {|i| values.include?(self[i]) && array.push(i)}
  1444.       array
  1445.     end
  1446.   end
  1447.   #---------------------------------------------------------------------------
  1448.   # * New method: deep
  1449.   #---------------------------------------------------------------------------
  1450.   unless method_defined?(:deep)
  1451.     def deep(deep = -1)
  1452.       tmp_deep = deep + 1
  1453.       deep = tmp_deep
  1454.       self.each do |i|
  1455.         deep < i.deep(tmp_deep) && deep = i.deep(tmp_deep)  rescue nil
  1456.       end
  1457.       deep
  1458.     end
  1459.   end
  1460.   #---------------------------------------------------------------------------
  1461.   # * New method: recursive_flatten
  1462.   #---------------------------------------------------------------------------
  1463.   unless method_defined?(:rflatten)
  1464.     def recursive_flatten
  1465.       (array = self.recursive_clone).each_index do |i|
  1466.         array[i] = array[i].to_a if array[i].is_a?(Hash)
  1467.         array[i] = array[i].recursive_flatten rescue array[i]
  1468.       end
  1469.       array.flatten!
  1470.       array
  1471.     end
  1472.     alias_method(:rflatten, :recursive_flatten)
  1473.   end
  1474.   #---------------------------------------------------------------------------
  1475.   # * New method: recursive_flatten!
  1476.   #---------------------------------------------------------------------------
  1477.   unless method_defined?(:rflatten!)
  1478.     def recursive_flatten!
  1479.       self.each_index do |i|
  1480.         self[i] = self[i].to_a if self[i].is_a?(Hash)
  1481.         self[i] = self[i].recursive_flatten! rescue self[i]
  1482.       end
  1483.       self.flatten!
  1484.       self
  1485.     end
  1486.     alias_method(:rflatten!, :recursive_flatten!)
  1487.   end
  1488.   #---------------------------------------------------------------------------
  1489.   # * Redefined method: product
  1490.   #---------------------------------------------------------------------------
  1491.   def dproduct(*arrays)
  1492.     (e = "(result = []) && self.each {|i0| ") &&
  1493.     (a = arrays.size).times {|i| e += "arrays[#{i}].each {|i#{i+1}| " }
  1494.     (e += "result.push([i0,") && a.times {|i| e += "i#{i+1}," }
  1495.     (e += "])}" + "}" * a + " && result"  )
  1496.     return eval(e)
  1497.   end
  1498.   alias_sec_method(:product, :dproduct)
  1499.   #---------------------------------------------------------------------------
  1500.   # * New method: geometric_average
  1501.   #---------------------------------------------------------------------------
  1502.   unless method_defined?(:geometric_average)
  1503.     def geometric_average(float = false)
  1504.       average = empty? ? 0 : prod ** (1.0 / size)
  1505.       return (float ? average : average.to_i)
  1506.     end
  1507.   end
  1508.   #---------------------------------------------------------------------------
  1509.   # * New method: average
  1510.   #---------------------------------------------------------------------------
  1511.   unless method_defined?(:average)
  1512.     def average(float = false)
  1513.       sum / [(float ? size.to_f : size.to_i), 1].max
  1514.     end
  1515.   end
  1516.   #---------------------------------------------------------------------------
  1517.   # * Alias method
  1518.   #---------------------------------------------------------------------------
  1519.   alias_sec_method :has_all?, :have_all?
  1520.   alias_sec_method :has_any?, :have_any?
  1521. end
  1522.   
  1523. #==============================================================================
  1524. # ** Hash
  1525. #------------------------------------------------------------------------------
  1526. #  
  1527. #==============================================================================
  1528. class Hash
  1529.   #--------------------------------------------------------------------------
  1530.   # * Define Secondary Listing
  1531.   #--------------------------------------------------------------------------
  1532.   define_sec_method(:reverse!)  { self.dup == replace(reverse) ? nil : self }
  1533.   #--------------------------------------------------------------------------
  1534.   # ● New method: reverse
  1535.   #--------------------------------------------------------------------------
  1536.   unless method_defined?(:reverse)
  1537.     def reverse
  1538.       key, new_hash = self.keys, {}
  1539.       key.reverse.each_with_index {|k,i| new_hash[k] = self[key[i]]}
  1540.       new_hash
  1541.     end
  1542.   end
  1543.   #--------------------------------------------------------------------------
  1544.   # ● New method: recursive_clone
  1545.   #--------------------------------------------------------------------------
  1546.   unless method_defined?(:rclone)
  1547.     def recursive_clone
  1548.       (clon = self.clone).each_key do |i|
  1549.         clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
  1550.       end
  1551.       clon
  1552.     end
  1553.     alias_method(:rclone, :recursive_clone)
  1554.   end
  1555.   #--------------------------------------------------------------------------
  1556.   # ● New method: deep
  1557.   #--------------------------------------------------------------------------
  1558.   unless method_defined?(:deep)
  1559.     def deep(deep = -1)
  1560.       key_deep = value_deep = tmp_deep = deep + 1
  1561.       self.each do |k, v|
  1562.         key_deep = k.deep(tmp_deep)  if key_deep  < k.deep(tmp_deep) rescue nil
  1563.         value_deep = v.deep(tmp_deep)if value_deep< v.deep(tmp_deep) rescue nil
  1564.       end
  1565.       key_deep > value_deep ? key_deep : value_deep
  1566.     end
  1567.   end
  1568.   #--------------------------------------------------------------------------
  1569.   # ● New method: fusion
  1570.   #--------------------------------------------------------------------------
  1571.   unless method_defined?(:fusion)
  1572.     def fusion
  1573.       (array = sort).each_index do |i|
  1574.         array[i] = array[i][0] + array[i][1] rescue array[i]
  1575.       end
  1576.       array
  1577.     end
  1578.   end
  1579. end
  1580. #==============================================================================
  1581. # ** Range     
  1582. #------------------------------------------------------------------------------
  1583. #  
  1584. #==============================================================================
  1585. class Range
  1586.   #--------------------------------------------------------------------------
  1587.   # * Include Comparable
  1588.   #--------------------------------------------------------------------------
  1589.   include(Comparable)
  1590.   #-------------------------------------------------------------------------
  1591.   # ● New method: random
  1592.   #-------------------------------------------------------------------------
  1593.   define_sec_method(:random) { self.to_a.random }
  1594.   define_sec_method(:sum)    { self.to_a.sum }
  1595.   define_sec_method(:prod)   { self.to_a.prod }
  1596.   #-------------------------------------------------------------------------
  1597.   # ● New method: <=>
  1598.   #-------------------------------------------------------------------------
  1599.   unless method_defined?(:"<=>")
  1600.     def <=>(other)
  1601.       temp = first <=> other.first
  1602.       temp = last <=> other.last if temp = 0
  1603.       return temp
  1604.     end
  1605.   end
  1606. end
  1607. #==============================================================================
  1608. # ** NilClass
  1609. #------------------------------------------------------------------------------
  1610. #  
  1611. #==============================================================================
  1612. class NilClass
  1613.   #--------------------------------------------------------------------------
  1614.   # ● Overwriten method: clone, dup
  1615.   #--------------------------------------------------------------------------
  1616.   define_method(:clone) {|*a|}
  1617.   define_method(:dup)   {|*a|}
  1618. end

  1619. #==============================================================================
  1620. # ** Math
  1621. #------------------------------------------------------------------------------
  1622. #  
  1623. #==============================================================================
  1624. module Math
  1625.   #--------------------------------------------------------------------------
  1626.   # ● New method: A (Ackermann function)
  1627.   #--------------------------------------------------------------------------
  1628.   def self.A(m,n)
  1629.     text = 'Ackermann: No negative values allowed.' if m < 0 or n < 0
  1630.     raise(ArgumentError.new(text))                  if m < 0 or n < 0
  1631.     return n + 1 if m == 0
  1632.     return Math.A(m - 1, 1) if n == 0
  1633.     return Math.A(m - 1, Math.A(m, n - 1))
  1634.   end
  1635.   #--------------------------------------------------------------------------
  1636.   # ● New method: percent
  1637.   #--------------------------------------------------------------------------
  1638.   def self.percent(min,max=100)
  1639.     (min / max.to_f) * 100.0
  1640.   end
  1641. end

  1642. #==============================================================================
  1643. # ** Numeric
  1644. #------------------------------------------------------------------------------
  1645. #  
  1646. #==============================================================================
  1647. class Numeric
  1648.   #--------------------------------------------------------------------------
  1649.   # ● Define Secondary Listing: clamp, sign
  1650.   #--------------------------------------------------------------------------
  1651.   define_sec_method(:clamp) {|min,max|  [[self, min].max, max].min}
  1652.   define_sec_method(:sign)  { zero? ? 0 :  (self / self.abs).to_i }
  1653.   #--------------------------------------------------------------------------
  1654.   # ● New method: group
  1655.   #--------------------------------------------------------------------------
  1656.   unless method_defined?(:group)
  1657.     def group
  1658.       self.to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
  1659.     end
  1660.   end
  1661. end

  1662. #==============================================================================
  1663. # ** Integer
  1664. #------------------------------------------------------------------------------
  1665. #  
  1666. #==============================================================================
  1667. class Integer
  1668.   #--------------------------------------------------------------------------
  1669.   # ● Define Secondary Listing: sum_to, factorial
  1670.   #--------------------------------------------------------------------------
  1671.   define_sec_method(:sum_down)  { sum_to(0)}
  1672.   define_sec_method(:factorial) {(sign * (1..(self.abs)).prod)  }
  1673.   #--------------------------------------------------------------------------
  1674.   # * New method: sum_to
  1675.   #--------------------------------------------------------------------------
  1676.   unless method_defined?(:sum_to)
  1677.     def sum_to(v = self) (v > self ? (self..v) : (v..self)).sum   end
  1678.   end
  1679. end

  1680. #==============================================================================
  1681. # ** Float
  1682. #------------------------------------------------------------------------------
  1683. #  
  1684. #==============================================================================
  1685. class Float
  1686.   #--------------------------------------------------------------------------
  1687.   # ● Overwriten method: =~
  1688.   #--------------------------------------------------------------------------
  1689.   # A close float comparison. Because of rounding errors, this comparison will
  1690.   # help compensate for that. Since 0 and 0.0001 are very close to each other,
  1691.   # it's best to use this custom comparison.
  1692.   define_method(:"=~") {|num| (self + 0.0001 >= num && self - 0.0001 <= num) }
  1693.   #--------------------------------------------------------------------------
  1694.   # ● New method: float_points
  1695.   #--------------------------------------------------------------------------
  1696.   unless method_defined?(:float_points)
  1697.     def float_points(points = 2)
  1698.       n = self * 10 ** points
  1699.       n = n.round.to_f / (10.0 ** points)
  1700.       return n
  1701.     end
  1702.   end
  1703. end

  1704. #==============================================================================
  1705. # ** Color
  1706. #------------------------------------------------------------------------------
  1707. #  
  1708. #==============================================================================
  1709. class Color
  1710.   #--------------------------------------------------------------------------
  1711.   # ● Define Secondary Listing
  1712.   #--------------------------------------------------------------------------
  1713.   define_sec_method(:invert)   { set(255-red, 255-green, 255-blue, alpha)}
  1714.   #----------------------------------------------------------------------------
  1715.   # * New method: to_hex
  1716.   #----------------------------------------------------------------------------
  1717.   def to_hex
  1718.     str = [self.blue.to_i, self.green.to_i, self.red.to_i].pack("C*")
  1719.     str.inspect.gsub('\\x','')
  1720.   end  
  1721. end
  1722. class << Color
  1723.   #--------------------------------------------------------------------------
  1724.   # ● Define Secondary Listing: red, green, blue, white, black... etc
  1725.   #--------------------------------------------------------------------------
  1726.   define_sec_method(:red)      {|*a| self.new(255,  0,  0,a.first||255)}
  1727.   define_sec_method(:green)    {|*a| self.new(  0,255,  0,a.first||255)}
  1728.   define_sec_method(:blue)     {|*a| self.new(  0,  0,255,a.first||255)}
  1729.   define_sec_method(:white)    {|*a| self.new(255,255,255,a.first||255)}
  1730.   define_sec_method(:purple)   {|*a| self.new(128,  0,128,a.first||255)}
  1731.   define_sec_method(:gray)     {|*a| self.new(128,128,128,a.first||255)}
  1732.   define_sec_method(:lgray)    {|*a| self.new(211,211,211,a.first||255)}
  1733.   define_sec_method(:dgray)    {|*a| self.new( 64, 64, 64,a.first||255)}
  1734.   define_sec_method(:pink)     {|*a| self.new(255,175,175,a.first||255)}
  1735.   define_sec_method(:orange)   {|*a| self.new(255,165,  0,a.first||255)}
  1736.   define_sec_method(:brown)    {|*a| self.new(128, 64,  0,a.first||255)}
  1737.   define_sec_method(:chocolate){|*a| self.new(210,105, 30,a.first||255)}
  1738.   define_sec_method(:golden)   {|*a| self.new(218,165, 32,a.first||255)}
  1739.   define_sec_method(:silver)   {|*a| self.new(192,192,192,a.first||255)}
  1740.   define_sec_method(:system)   {|*a| self.new(192,224,255,a.first||255)}
  1741.   define_sec_method(:crisis)   {|*a| self.new(255,255, 64,a.first||255)}
  1742.   define_sec_method(:knockout) {|*a| self.new(255, 64,  0,a.first||255)}
  1743.   #--------------------------------------------------------------------------
  1744.   # ● Redirect Listing: cyan, magenta, yellow, black, disabled, erase
  1745.   #--------------------------------------------------------------------------
  1746.   redirect_method :cyan,       '(red(*args).invert  )'
  1747.   redirect_method :magenta,    '(green(*args).invert)'
  1748.   redirect_method :yellow,     '(blue(*args).invert )'
  1749.   redirect_method :black,      '(white(*args).invert)'
  1750.   redirect_method :disabled,   '(black(128).invert  )'
  1751.   redirect_method :erase,      '(white(0).invert    )'
  1752.   #--------------------------------------------------------------------------
  1753.   # ● Alias method: grey, light_grey, dark_grey
  1754.   #--------------------------------------------------------------------------
  1755.   alias_sec_method :normal,    :white
  1756.   alias_sec_method :grey,      :gray
  1757.   alias_sec_method :lightgrey, :lightgray, :light_grey, :light_gray, :lgray
  1758.   alias_sec_method :darkgrey,  :darkgray,  :dark_grey,  :dark_gray,  :dgray
  1759.   #--------------------------------------------------------------------------
  1760.   # ● New method: method_missing
  1761.   #--------------------------------------------------------------------------
  1762.   def method_missing(val,*a)
  1763.     val = "#{val}".gsub(/x/i,'')
  1764.     if "#{val}".size == 6 && "#{val}".gsub(/(\d+|[a-f])/i,'')
  1765.       r = "#{val}"[0..1].hex
  1766.       g = "#{val}"[2..3].hex
  1767.       b = "#{val}"[4..5].hex
  1768.       return self.new(r,g,b,a.first||255)
  1769.     end
  1770.     text = "Undefined method #{val} for #{self.inspect}"
  1771.     raise(NoMethodError, text, caller(1))               
  1772.   end
  1773. end

  1774. #==============================================================================
  1775. # ** Viewport
  1776. #------------------------------------------------------------------------------
  1777. #  
  1778. #==============================================================================
  1779. class Viewport
  1780.   unless method_defined?(:disposed?)
  1781.     #--------------------------------------------------------------------------
  1782.     # ● Alias Listing
  1783.     #--------------------------------------------------------------------------
  1784.     alias_sec_method :d3x40932s2, :dispose
  1785.     #--------------------------------------------------------------------------
  1786.     # ● New method: disposed?
  1787.     #   help file is lying when says Viewport#disposed? is exist
  1788.     #--------------------------------------------------------------------------
  1789.     define_method(:disposed?) { @disposed == true }
  1790.     #--------------------------------------------------------------------------
  1791.     # ● Aliased method: dispose
  1792.     #--------------------------------------------------------------------------
  1793.     def dispose(*a)
  1794.       (disposed? || d3x40932s2(*a) || 0) && @disposed = true
  1795.     end
  1796.   end
  1797.   #--------------------------------------------------------------------------
  1798.   # ● New method: resize
  1799.   #--------------------------------------------------------------------------
  1800.   define_sec_method(:resize) do |*a|
  1801.     self.rect = a.first.is_a?(Rect) ? a.first : Rect.new(*a)
  1802.   end
  1803.   #--------------------------------------------------------------------------
  1804.   # * New method: update_viewport_sizes
  1805.   #--------------------------------------------------------------------------
  1806.   define_sec_method(:update_viewport_sizes) do |*a|
  1807.     map = $game_map
  1808.     w, h = Graphics.width, Graphics.height
  1809.     hor = map.respond_to?(:loop_horizontal?) && map.loop_horizontal?
  1810.     ver = map.respond_to?(:loop_vertical?)   && map.loop_vertical?
  1811.     dx = w > map.width  * 32 && !hor ? (w - map.width  * 32) / 2 : 0
  1812.     dw = hor ? w : [w, map.width * 32].min
  1813.     dy = h > map.height * 32 && !ver ? (h - map.height * 32) / 2 : 0
  1814.     dh = ver ? h : [h, map.height * 32].min
  1815.     resize(Rect.new(dx, dy, dw, dh))
  1816.   end
  1817.   #--------------------------------------------------------------------------
  1818.   # ● New method: x, y, width, height
  1819.   #--------------------------------------------------------------------------
  1820.   define_sec_method(:x)       { self.rect.x      }
  1821.   define_sec_method(:y)       { self.rect.y      }
  1822.   define_sec_method(:width)   { self.rect.width  }
  1823.   define_sec_method(:height)  { self.rect.height }
  1824.   define_sec_method(:x=)      {|x2| resize(x2,y,width,height) }
  1825.   define_sec_method(:y=)      {|y2| resize(x,y2,width,height) }
  1826.   define_sec_method(:width=)  {|w1| resize(x,y,w1,height)     }
  1827.   define_sec_method(:height=) {|h1| resize(x,y,width,h1)      }
  1828. end
  1829. #==============================================================================
  1830. # ** Graphics
  1831. #------------------------------------------------------------------------------
  1832. #  This module handles all Graphics
  1833. #==============================================================================
  1834. class << Graphics
  1835.   #------------------------------------------------------------------------
  1836.   # ● Include AutoUpdate
  1837.   #------------------------------------------------------------------------
  1838.   include_auto_update
  1839.   #------------------------------------------------------------------------
  1840.   # ● Redirect Listing
  1841.   #------------------------------------------------------------------------
  1842.   redirect_method :width,              'LiTTleDRAgo.client_size.at(0)'
  1843.   redirect_method :height,             'LiTTleDRAgo.client_size.at(1)'
  1844.   redirect_method :snap_to_bitmap,     'LiTTleDRAgo.snap_to_bitmap'   
  1845.   redirect_method :disable_alt_enter,  'LiTTleDRAgo.disable_alt_enter'
  1846.   redirect_method :always_on_top,      'LiTTleDRAgo.always_on_top'
  1847.   redirect_method :show_fps,           'LiTTleDRAgo.show_fps'
  1848.   redirect_method :scale_screen,       'LiTTleDRAgo.scale_screen'
  1849.   redirect_method :fill_monitor,       'LiTTleDRAgo.fill_monitor'
  1850.   redirect_method :window,             'LiTTleDRAgo.window'
  1851.   redirect_method :toggle,             'LiTTleDRAgo.toggle'
  1852.   redirect_method :fullscreen,         'LiTTleDRAgo.fullscreen'
  1853.   redirect_method :fullscreen?,        'LiTTleDRAgo.fullscreen?'
  1854.   redirect_method :control_screen_size,'LiTTleDRAgo.control_screen_size'
  1855.   redirect_method :high_priority,      'LiTTleDRAgo.high_priority'
  1856.   redirect_method :high_priority=,     'LiTTleDRAgo.high_priority=args.at(0)'
  1857.   #------------------------------------------------------------------------
  1858.   # ● Alias Listing
  1859.   #------------------------------------------------------------------------
  1860.   alias_sec_method :resize_screen, :scale_screen
  1861.   #--------------------------------------------------------------------------
  1862.   # * New method: fadeoutviewport
  1863.   #--------------------------------------------------------------------------
  1864.   def fadeoutviewport
  1865.     @fadeoutviewport  ||= ((v = Viewport.new(0,0,width,height))
  1866.         (v.color = (v.z = 0x3FFFFFFF) && Color.new(0,0,0,0)) && v)
  1867.   end
  1868.   #--------------------------------------------------------------------------
  1869.   # ● Redefined method:  wait,   brightness
  1870.   #--------------------------------------------------------------------------
  1871.   define_sec_method(:wait)       { |frame| frame.times {|i| update }   }
  1872.   define_sec_method(:brightness) { (255 - fadeoutviewport.color.alpha) }
  1873.   #--------------------------------------------------------------------------
  1874.   # * Redefined method: brightness= (Set Graphics Brightness)
  1875.   #--------------------------------------------------------------------------
  1876.   unless method_defined?(:brightness=)
  1877.     def brightness=(value)
  1878.       fadeoutviewport.color.alpha = 255 - value.clamp(0,255)
  1879.     end
  1880.   end
  1881.   #--------------------------------------------------------------------------
  1882.   # * Redefined method: fadein (Graphics Fade In)
  1883.   #         frame : frame of fade
  1884.   #--------------------------------------------------------------------------
  1885.   unless method_defined?(:fadein)
  1886.     def fadein(frames = 10)
  1887.       return if frames <= 0
  1888.       curvalue, count = brightness, (255 - brightness)
  1889.       frames.times do |i|
  1890.         (self.brightness = curvalue + (count * i / frames)) && update
  1891.       end
  1892.     end
  1893.   end
  1894.   #--------------------------------------------------------------------------
  1895.   # * Redefined method: fadeout (Graphics Fade Out)
  1896.   #         frame : frame of fade
  1897.   #--------------------------------------------------------------------------
  1898.   unless method_defined?(:fadeout)
  1899.     def fadeout(frames = 10)
  1900.       return if frames <= 0
  1901.       curvalue = count = self.brightness
  1902.       frames.times do |i|
  1903.         (self.brightness = curvalue - (count * i / frames)) && update
  1904.       end
  1905.     end
  1906.   end
  1907.   #--------------------------------------------------------------------------
  1908.   # * New method: wait_for_input
  1909.   #--------------------------------------------------------------------------
  1910.   unless method_defined?(:wait_for_input)
  1911.     def wait_for_input
  1912.       [Input,self].update
  1913.       [Input,self].update until press_any_key
  1914.     end
  1915.   end
  1916. end

  1917. #==============================================================================
  1918. # ** Input
  1919. #------------------------------------------------------------------------------
  1920. #  This module handles all Input
  1921. #==============================================================================
  1922. class << Input
  1923.   #------------------------------------------------------------------------
  1924.   # ● Include AutoUpdate
  1925.   #------------------------------------------------------------------------
  1926.   include_auto_update
  1927.   #--------------------------------------------------------------------------
  1928.   # ● Aliased method: :press?, :repeat?, :trigger?
  1929.   #--------------------------------------------------------------------------
  1930.   [:press?,:repeat?,:trigger?].each do |method|
  1931.     next unless method_defined?(:"#{method}")
  1932.     alias_sec_method(:"sym_#{method}", :"#{method}")
  1933.     define_method(:"#{method}") do |*args|
  1934.       if (b = args.first).is_a?(Symbol) || b.is_a?(String)
  1935.         args[0] = Input.const_get("#{b}") rescue nil
  1936.       end
  1937.       (args.first.not.nil?) && send(:"sym_#{method}", *args)
  1938.     end
  1939.   end
  1940. end
  1941. #==============================================================================
  1942. # ** Sprite_Battler
  1943. #------------------------------------------------------------------------------
  1944. #  This sprite is used to display the battler.It observes the Game_Character
  1945. #  class and automatically changes sprite conditions.
  1946. #==============================================================================
  1947. class Sprite_Battler
  1948.   #--------------------------------------------------------------------------
  1949.   # * Frame Update
  1950.   #--------------------------------------------------------------------------
  1951.   define_pre_alias(:update) {  @battler.nil? && @battler_name = nil }
  1952. end

  1953. #==============================================================================
  1954. # ** Spriteset_Map
  1955. #------------------------------------------------------------------------------
  1956. #  This class brings together map screen sprites, tilemaps, etc.
  1957. #  It's used within the Scene_Map class.
  1958. #==============================================================================
  1959. class Spriteset_Map
  1960.   #--------------------------------------------------------------------------
  1961.   # ● New method: sprite_player
  1962.   #--------------------------------------------------------------------------
  1963.   define_sec_method(:sprite_player) { find_character($game_player) }
  1964.   #------------------------------------------------------------------------
  1965.   # ● Public Instance Variables
  1966.   #------------------------------------------------------------------------
  1967.   attr_sec_reader :character_sprites, 'Array.new'
  1968.   attr_reader     :viewport1, :viewport2, :viewport3
  1969.   #--------------------------------------------------------------------------
  1970.   # * Aliased method: update
  1971.   #--------------------------------------------------------------------------
  1972.   define_pre_alias(:update) { update_viewport_size_change }
  1973.   #--------------------------------------------------------------------------
  1974.   # * New method: update_viewport_size_change
  1975.   #--------------------------------------------------------------------------
  1976.   def update_viewport_size_change
  1977.     if viewport_size_change?
  1978.       @viewport_map_width     = $game_map.width
  1979.       @viewport_map_height    = $game_map.height
  1980.       @viewport_screen_width  = Graphics.width
  1981.       @viewport_screen_height = Graphics.height
  1982.       [@viewport1,@viewport2,@viewport3].compact.update_viewport_sizes
  1983.     end
  1984.   end
  1985.   #--------------------------------------------------------------------------
  1986.   # * New method: viewport_size_change?
  1987.   #--------------------------------------------------------------------------
  1988.   unless method_defined?(:viewport_size_change?)
  1989.     def viewport_size_change?
  1990.       return true if @viewport_map_width     != $game_map.width
  1991.       return true if @viewport_map_height    != $game_map.height
  1992.       return true if @viewport_screen_width  != Graphics.width
  1993.       return true if @viewport_screen_height != Graphics.height
  1994.     end
  1995.   end
  1996.   #--------------------------------------------------------------------------
  1997.   # ● New method: redraw_character_sprites
  1998.   #--------------------------------------------------------------------------
  1999.   unless method_defined?(:redraw_character_sprites)
  2000.     def redraw_character_sprites
  2001.       return refresh_characters if self.respond_to?(:refresh_characters)
  2002.       character_sprites.dispose
  2003.       @character_sprites = $game_map.events.keys.sort.map {|i|
  2004.          Sprite_Character.new(@viewport1, $game_map.events[i]) }
  2005.       @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  2006.     end
  2007.   end  
  2008.   #--------------------------------------------------------------------------
  2009.   # ● New method: find_character
  2010.   #--------------------------------------------------------------------------
  2011.   unless method_defined?(:find_character)
  2012.     def find_character(char)
  2013.       character_sprites.detect { |s| s.character == char }
  2014.     end
  2015.   end
  2016.   #---------------------------------------------------------------------------
  2017.   # * New method: viewport_sprite
  2018.   #---------------------------------------------------------------------------
  2019.   def viewport_sprite(*v)
  2020.     v.collect! {|s| s.is_a?(Symbol) ? instance_variable_get(:"@#{s}") : s }
  2021.     v.reject!  {|s| s.not.is_a?(Viewport)}
  2022.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  2023.     all.select {|s| s.respond_to?(:viewport) && v.include?(s.viewport)}
  2024.   end
  2025. end

  2026. #==============================================================================
  2027. # ** Game_Battler
  2028. #------------------------------------------------------------------------------
  2029. #  This class deals with battlers. It's used as a superclass for the Game_Actor
  2030. #  and Game_Enemy classes.
  2031. #==============================================================================
  2032. class Game_Battler
  2033.   #--------------------------------------------------------------------------
  2034.   # ● New method: alive?
  2035.   #--------------------------------------------------------------------------
  2036.   define_sec_method(:alive?) { self.not.dead? }
  2037.   #--------------------------------------------------------------------------
  2038.   # ● New method: hp_percent
  2039.   #--------------------------------------------------------------------------
  2040.   unless method_defined?(:hp_percent)
  2041.     def hp_percent(integer = false, float_points = 2)
  2042.       n = Math.percent(hp,(respond_to?(:mhp) ? mhp : maxhp))
  2043.       return integer ? Integer(n) : n.float_points(float_points)
  2044.     end
  2045.   end
  2046.   #--------------------------------------------------------------------------
  2047.   # ● New method: sp_percent
  2048.   #--------------------------------------------------------------------------
  2049.   unless method_defined?(:sp_percent)
  2050.     def sp_percent(integer = false, float_points = 2)
  2051.       n =  Math.percent((respond_to?(:sp) ? sp : mp),
  2052.       ((respond_to?(:mmp) ? mmp : (respond_to?(:maxsp) ? maxsp : maxmp))))
  2053.       return integer ? Integer(n) : n.float_points(float_points)
  2054.     end
  2055.     alias_method :mp_percent, :sp_percent
  2056.   end
  2057. end

  2058. #==============================================================================
  2059. # ** Game_Character
  2060. #------------------------------------------------------------------------------
  2061. #  This class deals with characters. It's used as a superclass for the
  2062. #  Game_Player and Game_Event classes.
  2063. #==============================================================================
  2064. class Game_Character
  2065.   #--------------------------------------------------------------------------
  2066.   # ● Redirect Listing
  2067.   #--------------------------------------------------------------------------
  2068.   redirect_method :move_down,        'move_straight(2,*args)'
  2069.   redirect_method :move_left,        'move_straight(4,*args)'
  2070.   redirect_method :move_right,       'move_straight(6,*args)'
  2071.   redirect_method :move_up,          'move_straight(8,*args)'
  2072.   redirect_method :turn_down,        'set_direction(2,*args)'
  2073.   redirect_method :turn_left,        'set_direction(4,*args)'
  2074.   redirect_method :turn_right,       'set_direction(6,*args)'
  2075.   redirect_method :turn_up,          'set_direction(8,*args)'
  2076.   redirect_method :move_lower_left,  'move_diagonal(4, 2,*args)'
  2077.   redirect_method :move_lower_right, 'move_diagonal(6, 2,*args)'
  2078.   redirect_method :move_upper_left,  'move_diagonal(4, 8,*args)'
  2079.   redirect_method :move_upper_right, 'move_diagonal(6, 8,*args)'
  2080.   redirect_method :character_sprite, '$game_map.character_sprite(self)'
  2081.   redirect_method :character_above?, '(args.first.y > @y)'
  2082.   redirect_method :character_below?, '(args.first.y < @y)'
  2083.   redirect_method :character_right?, '(args.first.x < @x)'
  2084.   redirect_method :character_left?,  '(args.first.x > @x)'
  2085.   redirect_method :pos,              '[@x, @y]'
  2086.   redirect_method :pos_nt?,          '!@through && pos?'
  2087.   redirect_method :normal_priority?, '@character_name != ""'  
  2088.   redirect_method :map_passable?,    '$game_map.passable?'
  2089.   redirect_method :map_terrain_tag,  '$game_map.terrain_tag'
  2090.   #--------------------------------------------------------------------------
  2091.   # * Redefined method: pos?
  2092.   #                     anime
  2093.   #                     reverse_dir
  2094.   #--------------------------------------------------------------------------
  2095.   define_sec_method(:reverse_dir) {|dir| 10 - dir }
  2096.   define_sec_method(:pos?)        {|x,y| @x == x && @y == y  }
  2097.   define_sec_method(:anime)       {|aid| @animation_id = aid }
  2098.   #--------------------------------------------------------------------------
  2099.   # ● Redefined method: check_event_trigger_touch_front
  2100.   #--------------------------------------------------------------------------
  2101.   unless method_defined?(:check_event_trigger_touch_front)
  2102.     def check_event_trigger_touch_front
  2103.       x2 = $game_map.round_x_with_direction(@x, @direction)
  2104.       y2 = $game_map.round_y_with_direction(@y, @direction)
  2105.       check_event_trigger_touch(x2, y2)
  2106.     end
  2107.   end
  2108.   #--------------------------------------------------------------------------
  2109.   # ● Redefined method: move_straight
  2110.   #--------------------------------------------------------------------------
  2111.   unless method_defined?(:move_straight)
  2112.     def move_straight(d, turn_ok = true)
  2113.       if passable?(@x, @y, d)
  2114.         set_direction(d)
  2115.         @x = $game_map.round_x_with_direction(@x, d)
  2116.         @y = $game_map.round_y_with_direction(@y, d)
  2117.         increase_steps
  2118.       elsif turn_ok
  2119.         set_direction(d)
  2120.         check_event_trigger_touch_front
  2121.       end
  2122.     end
  2123.   end  
  2124.   #--------------------------------------------------------------------------
  2125.   # ● Redefined method: set_direction
  2126.   #--------------------------------------------------------------------------
  2127.   unless method_defined?(:set_direction)
  2128.     def set_direction(d)
  2129.       @direction = d unless @direction_fix || d == 0
  2130.       @stop_count = 0
  2131.     end
  2132.   end
  2133.   #--------------------------------------------------------------------------
  2134.   # ● Redefined method: set_graphic
  2135.   #--------------------------------------------------------------------------
  2136.   unless method_defined?(:set_graphic)
  2137.     def set_graphic(character_name, character_index = 0)
  2138.       @tile_id = 0
  2139.       @character_name = character_name
  2140.       if self.respond_to?(:character_index)
  2141.         @character_index = character_index
  2142.       else
  2143.         @character_hue = character_index
  2144.       end
  2145.       @original_pattern = 1
  2146.     end
  2147.   end
  2148.   #--------------------------------------------------------------------------
  2149.   # ● Redefined method: swap
  2150.   #--------------------------------------------------------------------------
  2151.   unless method_defined?(:swap)
  2152.     def swap(character)
  2153.       new_pos = character.pos
  2154.       character.moveto(x, y)
  2155.       moveto(*new_pos)
  2156.     end
  2157.   end
  2158.   #--------------------------------------------------------------------------
  2159.   # ● Redefined method: rotate_swap_prev
  2160.   #--------------------------------------------------------------------------
  2161.   unless method_defined?(:rotate_swap_prev)
  2162.     def rotate_swap_prev(*character)
  2163.       character.unshift(self)
  2164.       position = character.collect {|c| c.pos}
  2165.       character.each_with_index { |c,i| c.moveto(*position[i-1]) }
  2166.     end
  2167.   end
  2168.   #--------------------------------------------------------------------------
  2169.   # ● Redefined method: rotate_swap_next
  2170.   #--------------------------------------------------------------------------
  2171.   unless method_defined?(:rotate_swap_next)
  2172.     def rotate_swap_next(*character)
  2173.       character.unshift(self)
  2174.       position = character.collect {|c| c.pos}
  2175.       character.each_with_index do |char,index|
  2176.         char.moveto(*position[index + 1 >= position.size ? 0 : index + 1])
  2177.       end
  2178.     end
  2179.   end
  2180.   #--------------------------------------------------------------------------
  2181.   # ● New method: distance_from
  2182.   #--------------------------------------------------------------------------
  2183.   unless method_defined?(:distance_from)
  2184.     def distance_from(character,type= 'xy')
  2185.       character = $game_map.events[character] if character.is_a?(Integer)
  2186.       return 0 if character.nil?
  2187.       return (@x - character.x).abs if type.to_s == 'x'
  2188.       return (@y - character.y).abs if type.to_s == 'y'
  2189.       return Math.hypot(@x - character.x, @y - character.y)
  2190.     end
  2191.   end
  2192.   #--------------------------------------------------------------------------
  2193.   # * Redefined method: distance_x_from
  2194.   #--------------------------------------------------------------------------
  2195.   unless method_defined?(:distance_x_from)
  2196.     def distance_x_from(x)
  2197.       result = @x - x
  2198.       if result.abs > $game_map.width / 2
  2199.         result += result < 0 ? $game_map.width : -$game_map.width
  2200.       end
  2201.       result
  2202.     end
  2203.   end
  2204.   #--------------------------------------------------------------------------
  2205.   # * Redefined method: distance_y_from
  2206.   #--------------------------------------------------------------------------
  2207.   unless method_defined?(:distance_y_from)
  2208.     def distance_y_from(y)
  2209.       result = @y - y
  2210.       if result.abs > $game_map.height / 2
  2211.         result += result < 0 ? $game_map.height : -$game_map.height
  2212.       end
  2213.       result
  2214.     end
  2215.   end
  2216.   #--------------------------------------------------------------------------
  2217.   # ● New method: random_teleport
  2218.   #--------------------------------------------------------------------------
  2219.   unless method_defined?(:random_teleport)
  2220.     def random_teleport
  2221.       1000.times do
  2222.         moveto(rand($game_map.height), rand($game_map.width))
  2223.         vx  = LiTTleDRAgo::VX && !LiTTleDRAgo::VXA
  2224.         arg = vx ? [@x,@y] : [@x,@y,@direction]
  2225.         break if passable?(*arg)
  2226.       end || true
  2227.     end
  2228.   end
  2229.   #--------------------------------------------------------------------------
  2230.   # * Redefined method: diagonal_passable? (for RMXP)
  2231.   #     horz : Horizontal (4 or 6)
  2232.   #     vert : Vertical (2 or 8)
  2233.   #--------------------------------------------------------------------------
  2234.   unless method_defined?(:diagonal_passable?)
  2235.     def diagonal_passable?(x, y, horz, vert)
  2236.       x2 = $game_map.round_x_with_direction(x, horz)
  2237.       y2 = $game_map.round_y_with_direction(y, vert)
  2238.       (passable?(x, y, vert) && passable?(x, y2, horz)) ||
  2239.       (passable?(x, y, horz) && passable?(x2, y, vert))
  2240.     end
  2241.   end
  2242.   #--------------------------------------------------------------------------
  2243.   # * Redefined method: collide_with_characters? (for RMXP)
  2244.   #--------------------------------------------------------------------------
  2245.   unless method_defined?(:collide_with_characters?)
  2246.     def collide_with_characters?(x, y)
  2247.       collide_with_events?(x, y)
  2248.     end
  2249.   end
  2250.   #--------------------------------------------------------------------------
  2251.   # * Redefined method: collide_with_events? (for RMXP)
  2252.   #--------------------------------------------------------------------------
  2253.   unless method_defined?(:collide_with_events?)
  2254.     def collide_with_events?(x, y)
  2255.       $game_map.events_xy_nt(x, y).any? do |event|
  2256.         event.normal_priority? || self.is_a?(Game_Event)
  2257.       end
  2258.     end
  2259.   end
  2260.   #--------------------------------------------------------------------------
  2261.   # * Redefined method: debug_through?
  2262.   #--------------------------------------------------------------------------
  2263.   unless method_defined?(:debug_through?)
  2264.     def debug_through?
  2265.       debug = LiTTleDRAgo::VX ? $TEST : $DEBUG
  2266.       return debug && Input.press?(Input::CTRL) if self.is_a?(Game_Player)
  2267.       return false
  2268.     end
  2269.   end
  2270. end
  2271. #==============================================================================
  2272. # ** Game_Actor
  2273. #------------------------------------------------------------------------------
  2274. #  This class handles actors. It is used within the Game_Actors class
  2275. # ($game_actors), also referenced from the Game_Party class ($game_party).
  2276. #==============================================================================

  2277. class Game_Actor
  2278.   #--------------------------------------------------------------------------
  2279.   # * Get Actor Object
  2280.   #--------------------------------------------------------------------------
  2281.   define_sec_method(:actor)  { $data_actors[@actor_id]  }
  2282.   define_method(:class)      { $data_classes[@class_id] }
  2283. end

  2284. #==============================================================================
  2285. # ** Game_Enemy
  2286. #------------------------------------------------------------------------------
  2287. #  This class handles enemies. It used within the Game_Troop class
  2288. # ($game_troop).
  2289. #==============================================================================

  2290. class Game_Enemy
  2291.   #--------------------------------------------------------------------------
  2292.   # * Get Enemy Object
  2293.   #--------------------------------------------------------------------------
  2294.   define_sec_method(:enemy)  { $data_enemies[@enemy_id] }
  2295. end

  2296. #==============================================================================
  2297. # ** Game_Player
  2298. #------------------------------------------------------------------------------
  2299. #  This class handles the player. It includes event starting determinants and
  2300. # map scrolling functions. The instance of this class is referenced by
  2301. # $game_player.
  2302. #==============================================================================

  2303. class Game_Player
  2304.   #--------------------------------------------------------------------------
  2305.   # ● Redefined method: actor
  2306.   #                     name
  2307.   #--------------------------------------------------------------------------
  2308.   define_sec_method(:actor) { $game_party.leader }
  2309.   define_sec_method(:name)  { actor.name         }        
  2310.   #--------------------------------------------------------------------------
  2311.   # ● New method: method_missing
  2312.   #--------------------------------------------------------------------------
  2313.   def method_missing(val,*a,&b)
  2314.     return actor.send(val.to_s,*a,&b) if actor.respond_to?(val.to_sym)
  2315.     text = "Undefined method #{val} for #{self.inspect}"
  2316.     raise(NoMethodError, text, caller(1))               
  2317.   end
  2318. end
  2319.   
  2320. #==============================================================================
  2321. # ** Game_Event
  2322. #------------------------------------------------------------------------------
  2323. #  This class deals with events. It handles functions including event page
  2324. #  switching via condition determinants, and running parallel process events.
  2325. #  It's used within the Game_Map class.
  2326. #==============================================================================
  2327. class Game_Event < Game_Character
  2328.   #--------------------------------------------------------------------------
  2329.   # ● Public Instance Variables
  2330.   #--------------------------------------------------------------------------
  2331.   method_defined?(:erased) || (attr_reader :erased)
  2332.   method_defined?(:id)     || (attr_reader :id)
  2333.   method_defined?(:event)  || (attr_reader :event)
  2334.   attr_accessor :loaded_event
  2335.   #--------------------------------------------------------------------------
  2336.   # ● New method: name
  2337.   # ● New method: restore
  2338.   #--------------------------------------------------------------------------
  2339.   define_sec_method(:name)    { @event.name }
  2340.   define_sec_method(:restore) { (@erased = false) || refresh }
  2341.   #--------------------------------------------------------------------------
  2342.   # ● New method: destroy
  2343.   #--------------------------------------------------------------------------
  2344.   unless method_defined?(:destroy)
  2345.     def destroy
  2346.       event = $game_map.events.delete(@id)
  2347.       if (s = $game_map.spriteset).is_a?(Spriteset_Map)
  2348.         after = s.character_sprites.select { |e| e if e.character != event }
  2349.         (delet = character_sprite) && delet.dispose
  2350.         s.character_sprites.replace(after)
  2351.       end
  2352.     end
  2353.   end
  2354.   #--------------------------------------------------------------------------
  2355.   # ● New method: eliminate
  2356.   #--------------------------------------------------------------------------
  2357.   unless method_defined?(:eliminate)
  2358.     def eliminate
  2359.       return destroy if self.loaded_event
  2360.       (eliminate = $game_map.eliminate_event)[(id = $game_map.map_id)] ||= []
  2361.       (eliminate[id].include?(@id) || eliminate[id].push(@id)) && destroy
  2362.     end
  2363.   end
  2364.   #--------------------------------------------------------------------------
  2365.   # ● New method: note
  2366.   #--------------------------------------------------------------------------
  2367.   unless method_defined?(:note)
  2368.     def note
  2369.       list = @page ? @page.list.select {|l| [108,408].include?(l.code)} : []
  2370.       notes = list.collect {|l| l.parameters[0] }.join("\n")
  2371.       return notes
  2372.     end
  2373.   end
  2374.   #--------------------------------------------------------------------------
  2375.   # ● New method: proper_page_index
  2376.   #--------------------------------------------------------------------------  
  2377.   unless method_defined?(:proper_page_index)
  2378.     def proper_page_index
  2379.       if respond_to?(:conditions_met?)
  2380.         page = respond_to?(:find_proper_page) ? find_proper_page :
  2381.                @event.pages.reverse.find {|page| conditions_met?(page)}
  2382.         (i = @event.pages.index(page)).is_a?(Integer) ? i + 1 : 0
  2383.       end
  2384.     end
  2385.   end
  2386. end

  2387. #==============================================================================
  2388. # ** Game_Party
  2389. #------------------------------------------------------------------------------
  2390. #  This class handles the party. It includes information on amount of gold
  2391. #  and items. Refer to "$game_party" for the instance of this class.
  2392. #==============================================================================
  2393. class Game_Party
  2394.   #--------------------------------------------------------------------------
  2395.   # ● Alias Listing
  2396.   #--------------------------------------------------------------------------
  2397.   alias_sec_method :drg_ce_item_number, :item_number
  2398.   #--------------------------------------------------------------------------
  2399.   # ● Redirect Listing
  2400.   #--------------------------------------------------------------------------
  2401.   redirect_method :player_pos,      '($game_player.pos)'
  2402.   redirect_method :leader,          '(members.first)'
  2403.   redirect_method :members,         '(actors)'   
  2404.   redirect_method :actors,          '(members)'  
  2405.   #--------------------------------------------------------------------------
  2406.   # ● New method: existing_actors, recover_all
  2407.   #--------------------------------------------------------------------------
  2408.   define_sec_method(:existing_actors) { members.find_all {|a| a.exist?}  }
  2409.   define_sec_method(:recover_all)     { members.each {|a| a.recover_all} }
  2410.   #--------------------------------------------------------------------------
  2411.   # ● New method: has_actors?
  2412.   #--------------------------------------------------------------------------
  2413.   unless method_defined?(:has_actors?)
  2414.     def has_actors?(*actors)
  2415.       party = @actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }
  2416.       actor =  actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }.flatten
  2417.       return party.have_all?(*actor)
  2418.     end
  2419.   end
  2420.   #--------------------------------------------------------------------------
  2421.   # ● New method: has_any_actors?
  2422.   #--------------------------------------------------------------------------
  2423.   unless method_defined?(:has_any_actors?)
  2424.     def has_any_actors?(*actors)
  2425.       party = @actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }
  2426.       actor =  actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }.flatten
  2427.       return party.have_any?(*actor)
  2428.     end
  2429.   end
  2430.   #--------------------------------------------------------------------------
  2431.   # ● New method: swap_previous_actor
  2432.   #--------------------------------------------------------------------------
  2433.   unless method_defined?(:swap_leader_prev)
  2434.     def swap_leader_prev(n = 1)
  2435.       n <= 0 || n.round.times { @actors.previous_item && drg_ce_refresh }
  2436.       n >= 0 || swap_leader_next(n.round.abs)
  2437.     end
  2438.   end
  2439.   #--------------------------------------------------------------------------
  2440.   # ● New method: swap_next_actor
  2441.   #--------------------------------------------------------------------------
  2442.   unless method_defined?(:swap_leader_next)
  2443.     def swap_leader_next(n = 1)
  2444.       n <= 0 || n.round.times { @actors.next_item && drg_ce_refresh }
  2445.       n >= 0 || swap_leader_prev(n.round.abs)
  2446.     end
  2447.   end
  2448.   #--------------------------------------------------------------------------
  2449.   # ● New method: set_leader
  2450.   #--------------------------------------------------------------------------
  2451.   unless method_defined?(:set_leader)
  2452.     def set_leader(id)
  2453.       actor = id.is_a?(Numeric) ? $game_actors[id.to_i] : id
  2454.       if actor.is_a?(Game_Actor) && has_actors?(actor.id)
  2455.         swap_leader_next until $game_party.leader.id == actor.id
  2456.         actor.id
  2457.       end
  2458.     end
  2459.   end
  2460.   #--------------------------------------------------------------------------
  2461.   # ● New method: drg_ce_refresh
  2462.   #--------------------------------------------------------------------------
  2463.   unless method_defined?(:drg_ce_refresh)
  2464.     def drg_ce_refresh
  2465.       return refresh if respond_to?(:refresh)
  2466.       return ($game_map.need_refresh = true) && $game_player.refresh
  2467.     end
  2468.   end
  2469.   #--------------------------------------------------------------------------
  2470.   # * Get Party Name
  2471.   #--------------------------------------------------------------------------
  2472.   unless method_defined?(:name)
  2473.     def name
  2474.       return ""           if existing_actors.size == 0
  2475.       return leader.name  if existing_actors.size == 1
  2476.       return "#{leader.name}'s Party"
  2477.     end
  2478.   end
  2479.   #--------------------------------------------------------------------------
  2480.   # * Aliased method: item_number
  2481.   #--------------------------------------------------------------------------
  2482.   def item_number(item)
  2483.     unless LiTTleDRAgo::VX
  2484.       return drg_ce_item_number(item.id)          if item.is_a?(RPG::Item)
  2485.       return weapon_number(item.id)               if item.is_a?(RPG::Weapon)
  2486.       return armor_number(item.id)                if item.is_a?(RPG::Armor)  
  2487.     else
  2488.       item = $data_items[item.to_i]               if item.is_a?(Numeric)
  2489.     end
  2490.     return skill_number(item)                     if item.is_a?(RPG::Skill)
  2491.     return drg_ce_item_number(item)
  2492.   end
  2493.   #--------------------------------------------------------------------------
  2494.   # * Redefined method: weapon_number
  2495.   #--------------------------------------------------------------------------
  2496.   unless method_defined?(:weapon_number)
  2497.     def weapon_number(weapon)
  2498.       weapon = $data_weapons[weapon.to_i] if weapon.is_a?(Numeric)
  2499.       item_number(weapon)
  2500.     end
  2501.   end
  2502.   #--------------------------------------------------------------------------
  2503.   # * Redefined method: armor_number
  2504.   #--------------------------------------------------------------------------
  2505.   unless method_defined?(:armor_number)
  2506.     def armor_number(armor)
  2507.       armor = $data_armors[armor.to_i] if armor.is_a?(Numeric)
  2508.       item_number(armor)
  2509.     end
  2510.   end
  2511.   #--------------------------------------------------------------------------
  2512.   # * New method: skill_number
  2513.   #--------------------------------------------------------------------------
  2514.   unless method_defined?(:skill_number)
  2515.     def skill_number(skill)
  2516.       skill = $data_skills[skill.to_i] if skill.is_a?(Numeric)
  2517.       s1 = actors.select {|a| a.skill_learn?(skill)    }
  2518.       s2 = actors.select {|a| a.skill_learn?(skill.id) }
  2519.       return s1.size + s2.size
  2520.     end
  2521.   end
  2522.   #--------------------------------------------------------------------------
  2523.   # * New method: gain_all_items
  2524.   #--------------------------------------------------------------------------
  2525.   def gain_all_items(ammount=1)
  2526.     (0..999).to_a.each do |s|
  2527.       next if $data_items[s].nil? || $data_items[s].name == ''
  2528.       $game_party.drg_ce_get_item($data_items[s],ammount)
  2529.     end
  2530.   end
  2531.   #--------------------------------------------------------------------------
  2532.   # * New method: gain_all_weapons
  2533.   #--------------------------------------------------------------------------
  2534.   def gain_all_weapons(ammount=1)
  2535.     (0..999).to_a.each do |s|
  2536.       next if $data_weapons[s].nil? || $data_weapons[s].name == ''
  2537.       drg_ce_get_item($data_weapons[s],ammount)
  2538.     end
  2539.   end  
  2540.   #--------------------------------------------------------------------------
  2541.   # * New method: gain_all_armors
  2542.   #--------------------------------------------------------------------------
  2543.   def gain_all_armors(ammount=1)
  2544.     (0..999).to_a.each do |s|
  2545.       next if $data_armors[s].nil? || $data_armors[s].name == ''
  2546.       drg_ce_get_item($data_armors[s],ammount)
  2547.     end
  2548.   end
  2549.   #--------------------------------------------------------------------------
  2550.   # * New method: drg_ce_get_item
  2551.   #--------------------------------------------------------------------------
  2552.   def drg_ce_get_item(item,ammount)
  2553.     return gain_item(item,ammount)      if LiTTleDRAgo::VX
  2554.     return gain_item(item.id,ammount)   if item.is_a?(RPG::Item)
  2555.     return gain_weapon(item.id,ammount) if item.is_a?(RPG::Weapon)
  2556.     return gain_armor(item.id,ammount)  if item.is_a?(RPG::Armor)
  2557.   end
  2558. end

  2559. #==============================================================================
  2560. # ** Game_Follower
  2561. #------------------------------------------------------------------------------
  2562. #  This class handles followers. A follower is an allied character, other than
  2563. # the front character, displayed in the party. It is referenced within the
  2564. # Game_Followers class.
  2565. #==============================================================================
  2566. class Game_Follower < Game_Character
  2567.   #--------------------------------------------------------------------------
  2568.   # * Redirect Listing
  2569.   #--------------------------------------------------------------------------
  2570.   redirect_method :name, "(actor.nil? ? '' : actor.name)"
  2571. end if defined?(Game_Follower)

  2572. #==============================================================================
  2573. # ** Game_Map
  2574. #------------------------------------------------------------------------------
  2575. #  This class handles maps. It includes scrolling and passage determination
  2576. # functions. The instance of this class is referenced by $game_map.
  2577. #==============================================================================

  2578. class Game_Map
  2579.   #--------------------------------------------------------------------------
  2580.   # * Public Instance Variables
  2581.   #--------------------------------------------------------------------------
  2582.   attr_sec_reader :eliminate_event, 'Hash.new'
  2583.   #--------------------------------------------------------------------------
  2584.   # ● New method: name,        parent_id, base_parent_id
  2585.   #               event_list , map_events
  2586.   #--------------------------------------------------------------------------
  2587.   define_sec_method(:name)             { mapInfo[@map_id].name      }
  2588.   define_sec_method(:parent_id)        { mapInfo[@map_id].parent_id }
  2589.   define_sec_method(:base_parent_id)   { search_parent_id(mapInfo)  }
  2590.   define_sec_method(:event_list)       { events.values }
  2591.   define_sec_method(:map_events)       { @map.events   }
  2592.   define_sec_method(:screen)           { $game_screen  }
  2593.   define_sec_method(:loop_horizontal?) { false }
  2594.   define_sec_method(:loop_vertical?)   { false }
  2595.   define_sec_method(:map_child?)       { |*a|  a & child_ids == a }
  2596.   #--------------------------------------------------------------------------
  2597.   # * Aliased method: setup
  2598.   #--------------------------------------------------------------------------
  2599.   define_post_alias(:setup) do
  2600.     eliminate_event[@map_id] ||= []
  2601.     eliminate_event[@map_id].each { |s| events.delete(s) }
  2602.   end
  2603.   #--------------------------------------------------------------------------
  2604.   # * Redefined method: any_event_strarting? (for RMXP)
  2605.   #--------------------------------------------------------------------------
  2606.   unless method_defined?(:any_event_starting?)
  2607.     def any_event_starting?
  2608.       event_list.any? {|event| event.starting }
  2609.     end
  2610.   end
  2611.   #--------------------------------------------------------------------------
  2612.   # * Redefined method: interpreter (for RMXP)
  2613.   #--------------------------------------------------------------------------
  2614.   unless method_defined?(:interpreter)
  2615.     def interpreter
  2616.       return $game_system.map_interpreter if LiTTleDRAgo.scene.is_a?(Scene_Map)
  2617.       return $game_system.battle_interpreter
  2618.     end
  2619.   end
  2620.   #--------------------------------------------------------------------------
  2621.   # * Redefined method: events_xy (for RMXP)
  2622.   #--------------------------------------------------------------------------
  2623.   unless method_defined?(:events_xy)
  2624.     def events_xy(x, y)
  2625.       event_list.select {|event| event.x == x && event.y == y }
  2626.     end
  2627.   end
  2628.   #--------------------------------------------------------------------------
  2629.   # * Redefined method: events_xy_nt (for RMXP)
  2630.   #--------------------------------------------------------------------------
  2631.   unless method_defined?(:events_xy_nt)
  2632.     def events_xy_nt(x, y)
  2633.       event_list.select {|event| event.pos_nt?(x, y) }
  2634.     end
  2635.   end
  2636.   #--------------------------------------------------------------------------
  2637.   # * Redefined method: round_x, round_y (for RMXP)
  2638.   #--------------------------------------------------------------------------
  2639.   define_sec_method(:round_x) {|x| loop_horizontal? ? (x + width) % width : x }
  2640.   define_sec_method(:round_y) {|y| loop_vertical? ? (y + height) % height : y }
  2641.   #--------------------------------------------------------------------------
  2642.   # * Redefined method: x_with_direction (for RMXP)
  2643.   #--------------------------------------------------------------------------
  2644.   define_sec_method(:x_with_direction) {|x, d| x + (d==6 ? 1 : d==4 ? -1 : 0)}
  2645.   define_sec_method(:y_with_direction) {|y, d| y + (d==2 ? 1 : d==8 ? -1 : 0)}
  2646.   #--------------------------------------------------------------------------
  2647.   # * Redefined method: round_x_with_direction (for RMXP)
  2648.   #--------------------------------------------------------------------------
  2649.   unless method_defined?(:round_x_with_direction)
  2650.     def round_x_with_direction(x, d)
  2651.       round_x(x_with_direction(x, d))
  2652.     end
  2653.   end
  2654.   #--------------------------------------------------------------------------
  2655.   # * Redefined method: round_y_with_direction (for RMXP)
  2656.   #--------------------------------------------------------------------------
  2657.   unless method_defined?(:round_y_with_direction)
  2658.     def round_y_with_direction(y, d)
  2659.       round_y(y_with_direction(y, d))
  2660.     end
  2661.   end
  2662.   #--------------------------------------------------------------------------
  2663.   # * New method: x_diagonal_with_direction (for RMXP)
  2664.   #--------------------------------------------------------------------------
  2665.   unless method_defined?(:x_diagonal_with_direction)
  2666.     def x_diagonal_with_direction(x, d)
  2667.       x + ([9,6,3].include?(d) ? 1 : [7,4,1].include?(d) ? -1 : 0)
  2668.     end
  2669.   end
  2670.   #--------------------------------------------------------------------------
  2671.   # * New method: y_with_direction (for RMXP)
  2672.   #--------------------------------------------------------------------------
  2673.   unless method_defined?(:y_diagonal_with_direction)
  2674.     def y_diagonal_with_direction(y, d)
  2675.       y + ([1,2,3].include?(d) ? 1 : [7,8,9].include?(d) ? -1 : 0)
  2676.     end
  2677.   end
  2678.   #--------------------------------------------------------------------------
  2679.   # ● New method: existing_events
  2680.   #--------------------------------------------------------------------------
  2681.   unless method_defined?(:existing_events)
  2682.     def existing_events
  2683.       event_list.select {|e| e.not.erased }
  2684.     end
  2685.   end
  2686.   #--------------------------------------------------------------------------
  2687.   # ● New method: map_info
  2688.   #--------------------------------------------------------------------------
  2689.   unless method_defined?(:mapInfo)
  2690.     def mapInfo(ext = LiTTleDRAgo.data_default_extension)
  2691.       data = "Data/MapInfos.#{ext}"  
  2692.       @mapinfo ||= load_data(sprintf("#{data}")) rescue draise(
  2693.                    "Fail to load #{data}")
  2694.       return @mapinfo
  2695.     end
  2696.   end
  2697.   #--------------------------------------------------------------------------
  2698.   # ● New method: search_parent_id
  2699.   #--------------------------------------------------------------------------
  2700.   unless method_defined?(:search_parent_id)
  2701.     def search_parent_id(mapInfo, id = @map_id, ancestor = 0)
  2702.       m_id = id
  2703.       loop do
  2704.         _m_id = mapInfo[m_id]
  2705.         p_id = _m_id.respond_to?(:parent_id) ? _m_id.parent_id : nil
  2706.         return p_id if p_id == nil
  2707.         return m_id if p_id == ancestor
  2708.         m_id = p_id
  2709.       end
  2710.     end
  2711.   end
  2712.   #--------------------------------------------------------------------------
  2713.   # ● New method: base_map_name
  2714.   #--------------------------------------------------------------------------
  2715.   unless method_defined?(:base_map_name)
  2716.     def base_map_name
  2717.       map = mapInfo[search_parent_id(mapInfo)]
  2718.       name = map.respond_to?(:name) ? map.name : ''
  2719.       return name
  2720.     end
  2721.   end
  2722.   #--------------------------------------------------------------------------
  2723.   # ● New method: child_ids
  2724.   #--------------------------------------------------------------------------
  2725.   unless method_defined?(:child_ids)
  2726.     def child_ids
  2727.       mapInfo.keys.select {|map_id| mapInfo[map_id].parent_id == @map_id }
  2728.     end
  2729.   end
  2730.   #--------------------------------------------------------------------------
  2731.   # ● New method: descendant?
  2732.   #--------------------------------------------------------------------------
  2733.   unless method_defined?(:map_descendant?)
  2734.     def map_descendant?(*a)
  2735.       a.all? {|map_id| search_parent_id(mapInfo, map_id, @map_id)}
  2736.     end
  2737.   end
  2738.   #--------------------------------------------------------------------------
  2739.   # ● New method: load_event
  2740.   #--------------------------------------------------------------------------
  2741.   unless method_defined?(:load_event)
  2742.     def load_event(*a)
  2743.       case a.size
  2744.       when 5, 4 then (mapid, eventid, x, y = *a)
  2745.       when 3    then (mapid = @map_id) && (eventid, x, y = *a)
  2746.       when 2    then (mapid, y = @map_id, 0) && (eventid, x = *a)
  2747.       when 1    then (mapid, x, y = @map_id, 0,0) && (eventid = a.first)
  2748.       when 0    then return nil
  2749.       end
  2750.       map = load_map_data(mapid)
  2751.       event = map.events.values.detect { |event| event.id == eventid }
  2752.       unless event.nil?
  2753.         (a = a.at(4)) && (b = [a].flatten) && event.pages.reject! do |s|
  2754.           c = b.map {|i| i.is_a?(Range) ? i.to_a : i }
  2755.           c.flatten.not.include?(event.pages.index(s)+1)
  2756.         end
  2757.         return nil if event.pages.empty?
  2758.         c,r = [Array,Range], []
  2759.         c.include?(x.class) && (x = x.to_a.map{|s|s.is_a?(Range) ? s.to_a : s})
  2760.         c.include?(y.class) && (y = y.to_a.map{|s|s.is_a?(Range) ? s.to_a : s})
  2761.         [x].flatten.dproduct([y].flatten).each do |x1,y1|
  2762.           event.instance_variable_set(:@id,(id = next_key_events))
  2763.           r.push(@events[id] = e = Game_Event.new(@map_id, event.clone))
  2764.           e.loaded_event = true
  2765.           e.moveto(x1,y1)
  2766.         end
  2767.         a = r.size == 1 ? r.first : r
  2768.         if r && (s = spriteset).is_a?(Spriteset_Map)
  2769.           sc = s.character_sprites
  2770.           after  = sc.select { |e| e if e.character != $game_player }
  2771.           player = s.sprite_player
  2772.           sc.replace(after)
  2773.           r.each {|e| sc.push(Sprite_Character.new(s.viewport1, e)) }
  2774.           sc.push(player)
  2775.         end
  2776.         return a
  2777.       end
  2778.     end
  2779.   end
  2780.   #--------------------------------------------------------------------------
  2781.   # ● New method: call_event
  2782.   #--------------------------------------------------------------------------
  2783.   unless method_defined?(:call_event)
  2784.     def call_event(*a)
  2785.       case a.size
  2786.       when 3 then (mapid, eventid, page_id = *a)
  2787.       when 2 then (page_id = -1) && (mapid, eventid = *a)
  2788.       when 1 then (mapid, page_id = @map_id, -1) && (eventid = a.first)
  2789.       when 0 then return nil
  2790.       end
  2791.       map = load_map_data(mapid)
  2792.       event = map.events.values.detect { |event| event.id == eventid }
  2793.       unless event.nil?
  2794.         if page_id == -1 && event.respond_to?(:conditions_met?)
  2795.           pages = event.pages.reverse.find {|page| event.conditions_met?(page)}
  2796.         else
  2797.           pages = event.pages[[page_id,1].max-1]
  2798.         end
  2799.         klass = LiTTleDRAgo::VX ? Game_Interpreter : Interpreter
  2800.         child = klass.new(interpreter.instance_variable_get(:@depth) + 1)
  2801.         child.setup(pages.list, interpreter.same_map? ? event.id : 0)
  2802.         if LiTTleDRAgo::VXA
  2803.           child.run rescue FiberError
  2804.         else
  2805.           interpreter.instance_variable_set(:@child_interpreter, child)
  2806.         end
  2807.       end
  2808.     end
  2809.   end
  2810.   #--------------------------------------------------------------------------
  2811.   # ● New method: load_map_data
  2812.   #--------------------------------------------------------------------------
  2813.   unless method_defined?(:load_map_data)
  2814.     def load_map_data(mapid, ext = LiTTleDRAgo.data_default_extension)
  2815.       (map = sprintf("Data/Map%03d.#{ext}", mapid)) && load_data(map)
  2816.     end
  2817.   end
  2818.   #--------------------------------------------------------------------------
  2819.   # ● New method: increment_key_events
  2820.   #--------------------------------------------------------------------------
  2821.   unless method_defined?(:next_key_events)
  2822.     def next_key_events
  2823.       (@events.keys.max || 0) + 1
  2824.     end
  2825.   end
  2826.   #--------------------------------------------------------------------------
  2827.   # ● New method: unused_key_events
  2828.   #--------------------------------------------------------------------------
  2829.   unless method_defined?(:unused_key_events)
  2830.     def unused_key_events(start = 1)
  2831.       start = [start, next_key_events].min
  2832.       (start..next_key_events).detect {|i| @events.keys.not.include?(i)}
  2833.     end
  2834.   end
  2835.   #--------------------------------------------------------------------------
  2836.   # ● New method: spriteset
  2837.   #--------------------------------------------------------------------------
  2838.   unless method_defined?(:spriteset)
  2839.     def spriteset
  2840.       LiTTleDRAgo.scene.instance_variable_get(:@spriteset)
  2841.     end
  2842.   end
  2843.   #--------------------------------------------------------------------------
  2844.   # ● New method: character_sprite
  2845.   #--------------------------------------------------------------------------
  2846.   unless method_defined?(:character_sprite)
  2847.     def character_sprite(id = 0)
  2848.       return unless spriteset.is_a?(Spriteset_Map)
  2849.       id = id.is_a?(Game_Character) ? id : id == 0 ? $game_player : events[id]
  2850.       spriteset.find_character(id)
  2851.     end
  2852.   end
  2853.   #--------------------------------------------------------------------------
  2854.   # ● New method: picture_sprite
  2855.   #--------------------------------------------------------------------------
  2856.   unless method_defined?(:picture_sprite)
  2857.     def picture_sprite(id = nil)
  2858.       return unless spriteset.is_a?(Spriteset_Map)
  2859.       spriteset.update_pictures if spriteset.respond_to?(:update_pictures)
  2860.       result = spriteset.instance_variable_get(:@picture_sprites)
  2861.       id.nil? ? result : result[id]
  2862.     end
  2863.   end
  2864. end
  2865. #==============================================================================
  2866. # ■ RPG::Cache
  2867. #------------------------------------------------------------------------------
  2868. #
  2869. #==============================================================================
  2870. ModCache = LiTTleDRAgo.cache
  2871. class << ModCache
  2872.   #-----------------------------------------------------------------------
  2873.   # ● New method: self.draw_text
  2874.   #-----------------------------------------------------------------------
  2875.   unless method_defined?(:draw_text)
  2876.     def draw_text(
  2877.             width, height, text,
  2878.             font = Font.default_name,
  2879.             size = Font.default_size,
  2880.             bold = Font.default_bold,
  2881.             italic = Font.default_italic,
  2882.             color = Font.default_color,
  2883.             edging = false
  2884.           )
  2885.       cache_index = "text_" + width.to_s + height.to_s + text
  2886.       font_text = ""
  2887.       font.size.times do |i|
  2888.         font_text += font[i].to_s
  2889.       end
  2890.       cache_index += font_text + size.to_s + bold.to_s + italic.to_s
  2891.       cache_index += "#{color.red}#{color.blue}#{color.green}#{color.alpha}"
  2892.       @cache ||= {}
  2893.       if @cache[cache_index].nil? or @cache[cache_index].disposed?
  2894.         bitmap = Bitmap.new(width, height)
  2895.         bitmap.font.name = font
  2896.         bitmap.font.size = size
  2897.         bitmap.font.bold = bold
  2898.         bitmap.font.italic = italic
  2899.         bitmap.font.color = color
  2900.         if edging
  2901.           bitmap.draw_edging_text(0, 0, width, height, text, 0)
  2902.         else
  2903.           bitmap.draw_text(0, 0, width, height, text, 0)
  2904.         end
  2905.         @cache[cache_index] = bitmap
  2906.       end
  2907.       return @cache[cache_index]
  2908.     end
  2909.   end
  2910.   #-----------------------------------------------------------------------
  2911.   # ● New method: self.method_missing
  2912.   #-----------------------------------------------------------------------
  2913.   def method_missing(val,*a,&b)
  2914.     if a.at(0).is_a?(String) && a.size <= 2
  2915.       return load_bitmap("Graphics/#{val}/",*a,&b)
  2916.     end
  2917.     modified = [:invert,:brighten,:darken,:grayscale,:pixelate,:frost]
  2918.     if modified.include?(a.first) && a.at(1).is_a?(String) && a.size <= 3
  2919.       method = a.shift
  2920.       filename = a.join + "-#{method}"
  2921.       unless drago_bitmap_exist?("Graphics/#{val}",filename)
  2922.         bitmap = load_bitmap("Graphics/#{val}/",*a,&b)
  2923.         drago_set_bitmap(bitmap.send(method),"Graphics/#{val}",filename)
  2924.       end
  2925.       return drago_get_bitmap("Graphics/#{val}",filename)
  2926.     end
  2927.     text = "Undefined method #{val} for #{self.inspect}"
  2928.     raise(NoMethodError, text, caller(1))      
  2929.   end
  2930.   #-----------------------------------------------------------------------
  2931.   # ● New method: drago_get_bitmap
  2932.   #-----------------------------------------------------------------------
  2933.   def drago_get_bitmap(folder_name, filename = '', hue = 0)
  2934.     return empty_bitmap if filename.not.is_a?(String) || filename.empty?
  2935.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2936.     path = path.gsub("\","/").gsub("//","/")
  2937.     last = filename.split('.').last
  2938.     filename.gsub!(".png","") if last.is_a?(String) && last[/png/i]
  2939.     load_bitmap_no_rescue(path.downcase,filename.downcase,hue)
  2940.   end
  2941.   #-----------------------------------------------------------------------
  2942.   # ● New method: drago_set_bitmap
  2943.   #-----------------------------------------------------------------------
  2944.   def drago_set_bitmap(bitmap, folder_name = '', filename = 'bitmap')
  2945.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2946.     path = path.gsub("\","/").gsub("//","/")
  2947.     last = filename.split('.').last
  2948.     filename += '.png' unless last.is_a?(String) && last[/png/i]
  2949.     Dir.make_dir(path) unless FileTest.directory?(path)
  2950.     bitmap.export(path + filename)
  2951.     drago_get_bitmap(folder_name, filename)
  2952.   end
  2953.   #-----------------------------------------------------------------------
  2954.   # ● New method: drago_bitmap_exist?
  2955.   #-----------------------------------------------------------------------
  2956.   def drago_bitmap_exist?(folder_name, filename)
  2957.     return false if filename.not.is_a?(String) || filename.empty?
  2958.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2959.     path = path.gsub("\","/").gsub("//","/")
  2960.     last = filename.split('.').last
  2961.     filename += '.png' unless last.is_a?(String) && last[/png/i]
  2962.     FileTest.file?(path + filename)
  2963.   end
  2964.   #--------------------------------------------------------------------------
  2965.   # * Load Bitmap
  2966.   #--------------------------------------------------------------------------
  2967.   define_sec_method(:load_bitmap_no_rescue) do |folder, file, *a|
  2968.     @cache ||= {}
  2969.     if file.empty?
  2970.       empty_bitmap
  2971.     elsif (hue = a.first).is_a?(Numeric) && hue != 0
  2972.       hue_changed_bitmap(folder + file, hue.round)
  2973.     else
  2974.       normal_bitmap(folder + file)
  2975.     end
  2976.   end
  2977.   #--------------------------------------------------------------------------
  2978.   # * Create Empty Bitmap
  2979.   #--------------------------------------------------------------------------
  2980.   define_sec_method(:empty_bitmap) { Bitmap.new(32, 32)}
  2981.   #--------------------------------------------------------------------------
  2982.   # * Create/Get Normal Bitmap
  2983.   #--------------------------------------------------------------------------
  2984.   define_sec_method(:normal_bitmap) do |path|
  2985.     @cache[path] = Bitmap.new(path) unless include?(path)
  2986.     @cache[path]
  2987.   end
  2988.   #--------------------------------------------------------------------------
  2989.   # * Create/Get Hue-Changed Bitmap
  2990.   #--------------------------------------------------------------------------
  2991.   define_sec_method(:hue_changed_bitmap) do |path, hue|
  2992.     key = [path, hue]
  2993.     unless include?(key)
  2994.       @cache[key] = normal_bitmap(path).clone
  2995.       @cache[key].hue_change(hue)
  2996.     end
  2997.     @cache[key]
  2998.   end
  2999.   #--------------------------------------------------------------------------
  3000.   # * Check Cache Existence
  3001.   #--------------------------------------------------------------------------
  3002.   def include?(key)
  3003.     @cache[key] && @cache[key].not.disposed?
  3004.   end
  3005. end
  3006. #==============================================================================
  3007. # ** Window_Base
  3008. #------------------------------------------------------------------------------
  3009. #  This class is for all in-game windows.
  3010. #==============================================================================

  3011. class Window_Base < Window
  3012.   #--------------------------------------------------------------------------
  3013.   # * Redirect Listing
  3014.   #--------------------------------------------------------------------------
  3015.   redirect_method :draw_text,    'contents.draw_text'
  3016.   redirect_method :text_size,    'contents.text_size'
  3017.   redirect_method :change_color, 'contents.change_color'
  3018.   redirect_method :draw_picture, 'contents.draw_picture'
  3019.   redirect_method :draw_icon,    'contents.draw_icon'
  3020.   redirect_method :draw_battler, 'contents.draw_battler'
  3021.   #--------------------------------------------------------------------------
  3022.   # * Redefined method: line_height, translucent_alpha
  3023.   # * New method:       show, hide, activate, deactivate
  3024.   #--------------------------------------------------------------------------
  3025.   define_sec_method(:line_height)       { 32 }
  3026.   define_sec_method(:translucent_alpha) { 160 }
  3027.   define_sec_method(:show)              { self.visible = true  }
  3028.   define_sec_method(:hide)              { self.visible = false }
  3029.   define_sec_method(:activate)          { self.active  = true  }
  3030.   define_sec_method(:deactivate)        { self.active  = false }
  3031.   #--------------------------------------------------------------------------
  3032.   # * New method: center_window
  3033.   #--------------------------------------------------------------------------
  3034.   unless method_defined?(:center_window)
  3035.     def center_window
  3036.       self.x = Graphics.width/2  - self.width/2
  3037.       self.y = Graphics.height/2 - self.height/2
  3038.     end
  3039.   end
  3040.   #--------------------------------------------------------------------------
  3041.   # * Redefined method: disabled_color
  3042.   #--------------------------------------------------------------------------
  3043.   unless method_defined?(:disabled_color)
  3044.     def disabled_color     
  3045.       color = normal_color
  3046.       color.alpha = 128
  3047.       return color
  3048.     end
  3049.   end
  3050.   #--------------------------------------------------------------------------
  3051.   # * Redefined method: draw_text_ex
  3052.   #--------------------------------------------------------------------------
  3053.   unless method_defined?(:draw_text_ex)
  3054.     def draw_text_ex(x, y, text)
  3055.       reset_font_settings
  3056.       text = convert_escape_characters(text)
  3057.       pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  3058.       process_character(text.slice!(0, 1), text, pos) until text.empty?
  3059.     end
  3060.   end
  3061.   #--------------------------------------------------------------------------
  3062.   # * Redefined method: reset_font_settings
  3063.   #--------------------------------------------------------------------------
  3064.   unless method_defined?(:reset_font_settings)
  3065.     def reset_font_settings
  3066.       change_color(normal_color)
  3067.       contents.font.size = Font.default_size
  3068.       contents.font.bold = Font.default_bold
  3069.       contents.font.italic = Font.default_italic
  3070.     end
  3071.   end
  3072.   #--------------------------------------------------------------------------
  3073.   # * Redefined method: convert_escape_characters
  3074.   #--------------------------------------------------------------------------
  3075.   unless method_defined?(:convert_escape_characters)
  3076.     def convert_escape_characters(text)
  3077.       result = text.to_s.clone
  3078.       result.gsub!(/\\/)            { "\e" }
  3079.       result.gsub!(/\e\e/)          { "\" }
  3080.       result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i]   }
  3081.       result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i)        }
  3082.       result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  3083.       result.gsub!(/\eG/i)          { currency_unit }
  3084.       result
  3085.     end
  3086.   end
  3087.   #--------------------------------------------------------------------------
  3088.   # * Redefined method: actor_name
  3089.   #--------------------------------------------------------------------------
  3090.   unless method_defined?(:actor_name)
  3091.     def actor_name(n)
  3092.       actor = n >= 1 ? $game_actors[n] : nil
  3093.       actor ? actor.name : ""
  3094.     end
  3095.   end
  3096.   #--------------------------------------------------------------------------
  3097.   # * Redefined method: party_member_name
  3098.   #--------------------------------------------------------------------------
  3099.   unless method_defined?(:party_member_name)
  3100.     def party_member_name(n)
  3101.       actor = n >= 1 ? $game_party.instance_variable_get(:@actors)[n - 1] : nil
  3102.       actor ? actor.name : ""
  3103.     end
  3104.   end
  3105.   #--------------------------------------------------------------------------
  3106.   # * Redefined method: process_character
  3107.   #--------------------------------------------------------------------------
  3108.   unless method_defined?(:process_character)
  3109.     def process_character(c, text, pos)
  3110.       case c
  3111.       when "\n"   # New line
  3112.         process_new_line(text, pos)
  3113.       when "\f"   # New page
  3114.         process_new_page(text, pos)
  3115.       when "\e"   # Control character
  3116.         process_escape_character(obtain_escape_code(text), text, pos)
  3117.       else        # Normal character
  3118.         process_normal_character(c, pos)
  3119.       end
  3120.     end
  3121.   end
  3122.   #--------------------------------------------------------------------------
  3123.   # * Redefined method: process_normal_character
  3124.   #--------------------------------------------------------------------------
  3125.   unless method_defined?(:process_normal_character)
  3126.     def process_normal_character(c, pos)
  3127.       text_width = text_size(c).width
  3128.       draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  3129.       pos[:x] += text_width
  3130.     end
  3131.   end
  3132.   #--------------------------------------------------------------------------
  3133.   # * Redefined method: process_new_line
  3134.   #--------------------------------------------------------------------------
  3135.   unless method_defined?(:process_new_line)
  3136.     def process_new_line(text, pos)
  3137.       pos[:x] = pos[:new_x]
  3138.       pos[:y] += pos[:height]
  3139.       pos[:height] = calc_line_height(text)
  3140.     end
  3141.   end
  3142.   #--------------------------------------------------------------------------
  3143.   # * Redefined method: process_new_page
  3144.   #--------------------------------------------------------------------------
  3145.   unless method_defined?(:process_new_page)
  3146.     def process_new_page(text, pos)
  3147.     end
  3148.   end
  3149.   #--------------------------------------------------------------------------
  3150.   # * Redefined method: obtain_escape_code
  3151.   #--------------------------------------------------------------------------
  3152.   unless method_defined?(:obtain_escape_code)
  3153.     def obtain_escape_code(text)
  3154.       text.slice!(/^[\$\.\|\^!><\{\}\\]|^[\/\w+\/]+/i)
  3155.     end
  3156.   end
  3157.   #--------------------------------------------------------------------------
  3158.   # * Redefined method: obtain_escape_param
  3159.   #--------------------------------------------------------------------------
  3160.   unless method_defined?(:obtain_escape_param)
  3161.     def obtain_escape_param(text)
  3162.       text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0
  3163.     end
  3164.   end
  3165.   #--------------------------------------------------------------------------
  3166.   # * Redefined method: process_escape_character
  3167.   #--------------------------------------------------------------------------
  3168.   unless method_defined?(:process_escape_character)
  3169.     def process_escape_character(code, text, pos)
  3170.       case code.upcase
  3171.       when 'C' then change_color(text_color(obtain_escape_param(text)))
  3172.       when 'I' then process_draw_icon(obtain_escape_code(text), pos)
  3173.       when '{' then make_font_bigger
  3174.       when '}' then make_font_smaller
  3175.       end
  3176.     end
  3177.   end
  3178.   #--------------------------------------------------------------------------
  3179.   # * Redefined method: process_draw_icon
  3180.   #--------------------------------------------------------------------------
  3181.   unless method_defined?(:process_draw_icon)
  3182.     def process_draw_icon(icon_index, pos)
  3183.       icon_index = icon_index.to_i if icon_index.to_i.to_s == icon_index
  3184.       draw_icon(icon_index, pos[:x], pos[:y])
  3185.       pos[:x] += 24
  3186.     end
  3187.   end
  3188.   #--------------------------------------------------------------------------
  3189.   # * Redefined method: make_font_bigger
  3190.   #--------------------------------------------------------------------------
  3191.   unless method_defined?(:make_font_bigger)
  3192.     def make_font_bigger
  3193.       contents.font.size += 8 if contents.font.size <= 64
  3194.     end
  3195.   end
  3196.   #--------------------------------------------------------------------------
  3197.   # * Redefined method: make_font_smaller
  3198.   #--------------------------------------------------------------------------
  3199.   unless method_defined?(:make_font_smaller)
  3200.     def make_font_smaller
  3201.       contents.font.size -= 8 if contents.font.size >= 16
  3202.     end
  3203.   end
  3204.   #--------------------------------------------------------------------------
  3205.   # * Redefined method: calc_line_height
  3206.   #--------------------------------------------------------------------------
  3207.   unless method_defined?(:calc_line_height)
  3208.     def calc_line_height(text, restore_font_size = true)
  3209.       result = [line_height, contents.font.size].max
  3210.       last_font_size = contents.font.size
  3211.       text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
  3212.         make_font_bigger  if esc == "\e{"
  3213.         make_font_smaller if esc == "\e}"
  3214.         result = [result, contents.font.size].max
  3215.       end
  3216.       contents.font.size = last_font_size if restore_font_size
  3217.       result
  3218.     end
  3219.   end
  3220.   #--------------------------------------------------------------------------
  3221.   # * New method: currency_unit
  3222.   #--------------------------------------------------------------------------
  3223.   unless method_defined?(:currency_unit)
  3224.     def currency_unit
  3225.       gold = $data_system.words.gold
  3226.       return gold
  3227.     end
  3228.   end
  3229.   #--------------------------------------------------------------------------
  3230.   # ● New method: draw_map_name
  3231.   #--------------------------------------------------------------------------
  3232.   unless method_defined?(:draw_map_name)
  3233.     def draw_map_name(x, y, width, height)
  3234.       map_id  = $game_map.map_id
  3235.       mapInfo = $game_map.mapInfo
  3236.       draw_text(x, y, width, height, mapInfo[map_id].name.to_s)
  3237.     end
  3238.   end
  3239.   #--------------------------------------------------------------------------
  3240.   # ● New method: draw_enter_text
  3241.   #--------------------------------------------------------------------------
  3242.   unless method_defined?(:draw_enter_text)
  3243.     def draw_enter_text(x, y, width, height, text)
  3244.       info_box = text.split(/\n/)
  3245.       info_box.size.times do |i|
  3246.         draw_text( x, y + i * line_height, width, line_height, info_box[i])
  3247.         break if (y + i * line_height) > (self.height - line_height)
  3248.       end
  3249.     end
  3250.   end
  3251.   #--------------------------------------------------------------------------
  3252.   # ● New method: draw_picture_number
  3253.   #--------------------------------------------------------------------------
  3254.   unless method_defined?(:draw_picture_number)
  3255.     def draw_picture_number(x, y, value, file_name,align = 0,
  3256.                   space = 0, frame_max = 1,frame_index = 0)     
  3257.       number_image = LiTTleDRAgo.cache.windowskin(file_name)
  3258.       frame_max = [frame_max, 1].max
  3259.       frame_index = frame_max - 1 if frame_index > frame_max - 1
  3260.       align = [[align,2].min,0].max
  3261.       cw = number_image.width / 10
  3262.       ch = number_image.height / frame_max
  3263.       h = ch * frame_index
  3264.       number = value.abs.to_s.split(//)
  3265.       case align
  3266.       when 0 then plus_x = (-cw + space) * number.size
  3267.       when 1 then plus_x = ((-cw + space) * number.size) / 2
  3268.       when 2 then plus_x = 0
  3269.       end
  3270.       for r in 0..number.size - 1      
  3271.         rect = Rect.new(cw * number[r].to_i, h, cw, ch)
  3272.         contents.blt(plus_x + x + ((cw - space) * r), y , number_image, rect)
  3273.       end     
  3274.       number_image.dispose
  3275.     end     
  3276.   end
  3277. end

  3278. #==============================================================================
  3279. # ■ Bitmap
  3280. #------------------------------------------------------------------------------
  3281. #
  3282. #==============================================================================
  3283. class Bitmap  
  3284.   #----------------------------------------------------------------------------
  3285.   # ● Constant
  3286.   #----------------------------------------------------------------------------
  3287.   RtlMoveMemory_pi = LiTTleDRAgo.rtlmemory_pi
  3288.   RtlMoveMemory_ip = LiTTleDRAgo.rtlmemory_ip
  3289.   Blur_Setting     = "{ 'offset' => 2, 'spacing' => 1, 'opacity' => 255 }"
  3290.   #----------------------------------------------------------------------------
  3291.   # ● Public Instance Variables
  3292.   #----------------------------------------------------------------------------
  3293.   attr_sec_accessor :blur_settings,  Blur_Setting
  3294.   #----------------------------------------------------------------------------
  3295.   # ● Redirect Listing
  3296.   #----------------------------------------------------------------------------
  3297.   redirect_method :change_hue,          :hue_change
  3298.   #-------------------------------------------------------------------------
  3299.   # ● Define Secondary Listing
  3300.   #-------------------------------------------------------------------------
  3301.   define_sec_method(:full_fill) { |color|  fill_rect(rect, color) }
  3302.   #----------------------------------------------------------------------------
  3303.   # ● Alias Listing
  3304.   #----------------------------------------------------------------------------
  3305.   alias_sec_method :invert!,            :reversing!  
  3306.   alias_sec_method :grayscale!,         :gray_scale!
  3307.   alias_sec_method :frost,              :diffusion   
  3308.   alias_sec_method :frost!,             :diffusion!  
  3309.   alias_sec_method :drg_ce_stretch_blt, :stretch_blt
  3310.   alias_method     :drg_bitmap_load,    :initialize
  3311.   #--------------------------------------------------------------------------
  3312.   # * Object Initialization
  3313.   #----------------------------------------------------------------------------
  3314.   def initialize(*args)
  3315.     if (a = args.flatten).size == 4 && a.all? {|s| s.is_a?(Table)}
  3316.       bitmap = BitmapDump.read_bitmap_data(*a)
  3317.       drg_bitmap_load(bitmap.width,bitmap.height)
  3318.       return blt(0,0,bitmap,rect) && bitmap.dispose
  3319.     end
  3320.     drg_bitmap_load(*args)
  3321.   end
  3322.   #----------------------------------------------------------------------------
  3323.   # ● New method: address
  3324.   #----------------------------------------------------------------------------
  3325.   unless method_defined?(:address)
  3326.     def address
  3327.       @address ||= (  RtlMoveMemory_pi.call(a="\0"*4, __id__*2+16, 4)
  3328.                       RtlMoveMemory_pi.call(a, a.unpack('L')[0]+8, 4)
  3329.                       RtlMoveMemory_pi.call(a, a.unpack('L')[0]+16, 4)
  3330.                       a.unpack('L')[0]    )
  3331.     end
  3332.   end
  3333.   #----------------------------------------------------------------------------
  3334.   # ● New method: export
  3335.   #----------------------------------------------------------------------------
  3336.   unless method_defined?(:export)
  3337.     def export(filename)
  3338.       file = File.open(filename, 'wb')
  3339.         size, vxace = width * height * 4, LiTTleDRAgo::RGSS3
  3340.         case format = File.extname(filename)
  3341.         when '.bmp'
  3342.           data = String.new
  3343.           RtlMoveMemory_pi.call(empty_rString_struct="\0"*16,data.__id__*2,16)
  3344.           flags = vxace ? 5267461 : 8199
  3345.           klass = empty_rString_struct.unpack('@4L')[0]
  3346.           pack  = [flags,klass,size,address].pack('L4')
  3347.           weiss = [size+54,0,54,40,width,height,1,32,0,size,0,0,0,0]
  3348.           RtlMoveMemory_ip.call(data.__id__*2, pack, 16)
  3349.           file.write("BM#{weiss.pack('L6S2L6')}")
  3350.           file.write(data)
  3351.           RtlMoveMemory_ip.call(data.__id__*2, empty_rString_struct, 16)
  3352.         when '.png'
  3353.           write_chunk = Proc.new do |chunk|
  3354.             file.write([(vxace ? chunk.bytesize : chunk.size)-4].pack('N'))
  3355.             file.write(chunk)
  3356.             file.write([Zlib.crc32(chunk)].pack('N'))
  3357.           end
  3358.           null_char, w4, i, byte = "\0", width*4, 0, (t_Fx = 0)
  3359.           RtlMoveMemory_pi.call(data=null_char*size, address, size)
  3360.           if vxace
  3361.             data.force_encoding('ASCII-8BIT')
  3362.             (0).step(size-4, 4) do |i|
  3363.               Graphics.update if (t_Fx += 1) % 10000 == 0
  3364.               byte = data.getbyte(i)
  3365.               data.setbyte(i, data.getbyte(i+=2))
  3366.               data.setbyte(i, byte)
  3367.             end
  3368.           else
  3369.             (0).step(size-4, 4) do |i|
  3370.               Graphics.update if (t_Fx += 1) % 10000 == 0
  3371.               data[i,3] = data[i,3].reverse!
  3372.             end
  3373.           end
  3374.           deflate = Zlib::Deflate.new(9)
  3375.             (size-w4).step(0, -w4) {|i| deflate << null_char << data[i,w4]}
  3376.             file.write("\211PNG\r\n\32\n")
  3377.             write_chunk.call("IHDR#{[width,height,8,6,0,0,0].pack('N2C5')}")
  3378.             write_chunk.call("IDAT#{deflate.finish}")
  3379.             write_chunk.call('IEND')
  3380.           deflate.close
  3381.         when ''
  3382.           script_report("Error: Export Bitmap Failed\n"+
  3383.               "Extension '#{filename}' is missing.")
  3384.         else         
  3385.           script_report("Error: Export Bitmap Failed\n"+
  3386.                "Extension '#{format}' is not supported.")
  3387.         end
  3388.       file.close
  3389.     end
  3390.   end
  3391.   #----------------------------------------------------------------------------
  3392.   # ● New method: blt_cache
  3393.   #----------------------------------------------------------------------------
  3394.   unless method_defined?(:blt_cache)
  3395.     def blt_cache(x, y, width, height, text, align, edging)
  3396.       cache_bitmap = LiTTleDRAgo.cache.draw_text(
  3397.           width, height, text, self.font.name, self.font.size,
  3398.           self.font.bold, self.font.italic, self.font.color, edging
  3399.       )
  3400.       x_plus = uncache_align_exe(width, text, align)
  3401.       blt(x + x_plus , y , cache_bitmap, Rect.new(0, 0, width, height))
  3402.     end
  3403.   end
  3404.   #----------------------------------------------------------------------------
  3405.   # ● New method: uncache_align_exe
  3406.   #----------------------------------------------------------------------------
  3407.   unless method_defined?(:uncache_align_exe)
  3408.     def uncache_align_exe(width, text, align)
  3409.       recter = self.text_size(text)
  3410.       case align
  3411.       when 0 then x_index = 0
  3412.       when 1 then x_index = (width / 2) - recter.width / 2
  3413.       when 2 then x_index = width - recter.width
  3414.       else
  3415.         raise "Text Cache : align is wrong"
  3416.       end
  3417.       return x_index
  3418.     end
  3419.   end
  3420.   #----------------------------------------------------------------------------
  3421.   # ● New method: draw_cache_text
  3422.   #----------------------------------------------------------------------------
  3423.   unless method_defined?(:draw_cache_text)
  3424.     def draw_cache_text(x, y, width, height, text, align = 0)
  3425.       blt_cache(x, y, width, height, text, align, false)
  3426.     end
  3427.   end
  3428.   #----------------------------------------------------------------------------
  3429.   # ● New method: draw_edging_cache_text
  3430.   #----------------------------------------------------------------------------
  3431.   unless method_defined?(:draw_edging_cache_text)
  3432.     def draw_edging_cache_text(x, y, width, height, text, align = 0)
  3433.       blt_cache(x, y, width, height, text, align, true)
  3434.     end
  3435.   end
  3436.   #----------------------------------------------------------------------------
  3437.   # ● New method: draw_easy_cache_text
  3438.   #----------------------------------------------------------------------------
  3439.   unless method_defined?(:draw_easy_cache_text)
  3440.     def draw_easy_cache_text(x, y, text)
  3441.       t_rect = text_size(text)
  3442.       blt_cache(x, y, t_rect.width, t_rect.height, text, 0, false)
  3443.     end
  3444.   end
  3445.   #----------------------------------------------------------------------------
  3446.   # ● New method: draw_easy_edging_cache_text
  3447.   #----------------------------------------------------------------------------
  3448.   unless method_defined?(:draw_easy_edging_cache_text)
  3449.     def draw_easy_edging_cache_text(x, y, text)
  3450.       t_rect = text_size(text)
  3451.       blt_cache(x, y, t_rect.width, t_rect.height, text, 0, true)
  3452.     end
  3453.   end
  3454.   #--------------------------------------------------------------------------
  3455.   # * New method: change_color
  3456.   #--------------------------------------------------------------------------
  3457.   unless method_defined?(:change_color)
  3458.     def change_color(color, enabled = true)
  3459.       font.color = color
  3460.       font.color.alpha = translucent_alpha unless enabled
  3461.     end
  3462.   end
  3463.   #--------------------------------------------------------------------------
  3464.   # ● New method: draw_picture
  3465.   #--------------------------------------------------------------------------
  3466.   unless method_defined?(:draw_picture)
  3467.     def draw_picture(file_name, x, y, opacity = 255)
  3468.       bitmap = LiTTleDRAgo.cache.picture(file_name)
  3469.       cw = bitmap.width
  3470.       ch = bitmap.height
  3471.       src_rect = Rect.new(0, 0, cw, ch)
  3472.       blt(x, y, bitmap, src_rect, opacity)
  3473.     end
  3474.   end
  3475.   #--------------------------------------------------------------------------
  3476.   # ● New method: draw_icon
  3477.   #--------------------------------------------------------------------------
  3478.   unless method_defined?(:draw_icon)
  3479.     def draw_icon(file_name, x, y, enabled = true)
  3480.       if file_name.is_a?(Numeric)
  3481.         bitmap = LiTTleDRAgo.cache.system("Iconset")
  3482.         src_rect = Rect.new(file_name % 16 * 24, file_name / 16 * 24, 24, 24)
  3483.         blt(x, y, bitmap, src_rect, enabled ? 255 : 160)
  3484.       elsif file_name.is_a?(String)
  3485.         bitmap = LiTTleDRAgo.cache.icon(file_name)
  3486.         src_rect = Rect.new(0, 0, 24, 24)
  3487.         blt(x, y, bitmap, bitmap.rect, enabled ? 255 : 160)
  3488.       end
  3489.     end
  3490.   end
  3491.   #--------------------------------------------------------------------------
  3492.   # ● New method: draw_battler
  3493.   #--------------------------------------------------------------------------
  3494.   unless method_defined?(:draw_battler)
  3495.     def draw_battler(file_name, x, y, hue = 0, enabled = true)
  3496.       bitmap = LiTTleDRAgo.cache.battler(file_name, hue)
  3497.       cw = bitmap.width
  3498.       ch = bitmap.height
  3499.       src_rect = Rect.new(0, 0, cw, ch)
  3500.       blt(x, y, bitmap, src_rect, enabled ? 255 : 160)
  3501.     end
  3502.   end
  3503.   #--------------------------------------------------------------------------
  3504.   # ● New method: draw_bar
  3505.   #--------------------------------------------------------------------------
  3506.   unless method_defined?(:draw_bar)
  3507.     def draw_bar(x, y, current, file)
  3508.       bitmap = LiTTleDRAgo.cache.picture(file)
  3509.       cw = bitmap.width * current / 100
  3510.       ch = bitmap.height
  3511.       src_rect = Rect.new(0, 0, cw, ch)
  3512.       blt(x, y, bitmap, src_rect)
  3513.     end
  3514.   end
  3515.   #--------------------------------------------------------------------------
  3516.   # ● New method: draw_edging_text
  3517.   #--------------------------------------------------------------------------
  3518.   unless method_defined?(:draw_edging_text)
  3519.     def draw_edging_text(x, y, width, height, text, align=0)
  3520.       old_color = font.color.dup
  3521.       font.color = Color.new(0, 0, 0)
  3522.       draw_text(x-1, y-1, width, height, text, align)
  3523.       draw_text(x-1, y+1, width, height, text, align)
  3524.       draw_text(x+1, y-1, width, height, text, align)
  3525.       draw_text(x+1, y+1, width, height, text, align)
  3526.       font.color = old_color
  3527.       draw_text(x, y, width, height, text, align)
  3528.     end
  3529.   end
  3530.   #--------------------------------------------------------------------------
  3531.   # ● New method: draw_enter_text
  3532.   #--------------------------------------------------------------------------
  3533.   unless method_defined?(:draw_enter_text)
  3534.     def draw_enter_text(x, y, width, height, text, align=0)
  3535.       rect = text_size(text)
  3536.       info_box = text.split(/\n/)
  3537.       info_box.size.times do |i|
  3538.         draw_text( x, y+i*rect.height, width, height, info_box[i], align)
  3539.         break if (y+i*rect.height) > self.height
  3540.       end
  3541.     end
  3542.   end
  3543.   #--------------------------------------------------------------------------
  3544.   # ● New method: draw_enter_edging_text
  3545.   #--------------------------------------------------------------------------
  3546.   unless method_defined?(:draw_enter_edging_text)
  3547.     def draw_enter_edging_text(x, y, width, height, text, align=0)
  3548.       rect = text_size(text)
  3549.       info_box = text.split(/\n/)
  3550.       info_box.size.times do |i|
  3551.         draw_edging_text( x, y+i*rect.height,width,height,info_box[i],align)
  3552.         break if (y+i*rect.height) > self.height
  3553.       end
  3554.     end
  3555.   end
  3556.   #--------------------------------------------------------------------------
  3557.   # ● New method: draw_easy_text
  3558.   #--------------------------------------------------------------------------
  3559.   unless method_defined?(:draw_easy_text)
  3560.     def draw_easy_text(x, y, text)
  3561.       rect = text_size(text)
  3562.       draw_text(x, y, rect.width + rect.height/2, rect.height, text)
  3563.     end
  3564.   end
  3565.   #--------------------------------------------------------------------------
  3566.   # ● New method: draw_auto_text
  3567.   #--------------------------------------------------------------------------
  3568.   unless method_defined?(:draw_auto_text)
  3569.     def draw_auto_text(x, y, width, height, text)
  3570.       ini_x = 0
  3571.       law = 0
  3572.       text_box = []
  3573.       text_box[law] = []
  3574.       otxto = text.split(//)
  3575.       otxto.size.times do |i|
  3576.         text_rect = text_size(otxto[i])
  3577.         if (x + ini_x + text_rect.width) < width
  3578.           ini_x += text_rect.width
  3579.         else
  3580.           law += 1
  3581.           ini_x = text_rect.width
  3582.           text_box[law] = []
  3583.         end
  3584.         text_box[law].push(otxto[i])
  3585.       end
  3586.       for l in 0..law
  3587.         ini_x = 0
  3588.         text_box[l].size.times do |i|
  3589.           rect = text_size(text_box[l][i])
  3590.           draw_text(x + ini_x, y+l*height, rect.width, height, text_box[l][i])
  3591.           ini_x += rect.width
  3592.         end
  3593.       end
  3594.     end
  3595.   end
  3596.   #-------------------------------------------------------------------------
  3597.   # ● New method: erase
  3598.   #-------------------------------------------------------------------------
  3599.   unless method_defined?(:erase)
  3600.     def erase(*a)
  3601.       rect = nil
  3602.       if a.at(0).is_a?(Rect) then rect = a.at(0)
  3603.       elsif a.size == 4 then rect = Rect.new(*a)
  3604.       elsif a.size == 0 then rect = Rect.new(0,0,width,height)
  3605.       end
  3606.       fill_rect(rect.x, rect.y, rect.width, rect.height, Color.erase) if rect
  3607.     end
  3608.   end
  3609.   #-------------------------------------------------------------------------
  3610.   # ● New method: stretch
  3611.   #-------------------------------------------------------------------------
  3612.   unless method_defined?(:stretch)
  3613.     def stretch(width, height)
  3614.       dummy = Bitmap.new(width, height)
  3615.       dummy.stretch_blt(*[dummy.rect, self, self.rect])
  3616.       dummy
  3617.     end
  3618.   end
  3619.   #-------------------------------------------------------------------------
  3620.   # ● New method: crop
  3621.   #-------------------------------------------------------------------------
  3622.   unless method_defined?(:crop)
  3623.     def crop(*a)
  3624.       return unless a.size == 1 or a.size == 4
  3625.       rect = rect.at(0)   if a.size == 1 && a.at(0).is_a?(Rect)
  3626.       rect = Rect.new(*a) if a.size == 4
  3627.       cropped = Bitmap.new([rect.width,width-rect.x].min,
  3628.                            [rect.height,height-rect.y].min)
  3629.       cropped.blt(0,0,self,rect)
  3630.       cropped
  3631.     end
  3632.   end
  3633.   #-------------------------------------------------------------------------
  3634.   # ● Aliased method: stretch_blt
  3635.   #-------------------------------------------------------------------------
  3636.   def stretch_blt(*a)
  3637.     if respond_to?(:stretch_blend_blt)
  3638.       a = [a[0..2],0,1,a.at(3)||255].flatten
  3639.       stretch_blend_blt(*a)
  3640.     else
  3641.       drg_ce_stretch_blt(*a)
  3642.     end
  3643.   end
  3644.   #-------------------------------------------------------------------------
  3645.   # ● Aliased method: hue_change
  3646.   #-------------------------------------------------------------------------
  3647.   define_post_alias(:hue_change) { self }
  3648.   #--------------------------------------------------------------------------
  3649.   # ● New method: invert, etc
  3650.   #--------------------------------------------------------------------------
  3651.   [:invert, :brighten, :darken, :grayscale, :pixelate, :frost, :flip_horizontal,
  3652.    :flip_vertical, :rotate90, :rotate180, :rotate270].each do |meth|
  3653.     define_sec_method(meth) do |*args|
  3654.       bitmap = self.clone
  3655.       bitmap.send(:"#{meth}!",*args)
  3656.       return bitmap
  3657.     end
  3658.   end
  3659.   #-------------------------------------------------------------------------
  3660.   # ● New method: flip_horizontal!
  3661.   #-------------------------------------------------------------------------
  3662.   define_sec_method(:flip_horizontal!) do
  3663.     flipped = Bitmap.new(width, height)
  3664.     fliprect = Rect.new(width,0,-width,height)
  3665.     flipped.blt(0,0, self,fliprect)
  3666.     (clear || 0) && blt(0,0,flipped,rect)
  3667.     flipped.dispose
  3668.   end
  3669.   #-------------------------------------------------------------------------
  3670.   # ● New method: flip_vertical!
  3671.   #-------------------------------------------------------------------------
  3672.   define_sec_method(:flip_vertical!) do
  3673.     flipped = Bitmap.new(width, height)
  3674.     fliprect = Rect.new(0,height,width,-height)
  3675.     flipped.blt(0,0, self,fliprect)
  3676.     (clear || 0) && blt(0,0,flipped,rect)
  3677.     flipped.dispose
  3678.   end
  3679.   #-------------------------------------------------------------------------
  3680.   # ● New method: rotate90! (clockwise)
  3681.   #-------------------------------------------------------------------------
  3682.   define_sec_method(:rotate90!) do
  3683.     copy = self.clone
  3684.     (t_Fx = width).times do |i|
  3685.       height.times do |j|
  3686.         Graphics.update if (t_Fx += 1) % 10000 == 0
  3687.         a = (clockwise = true) ? [width - i - 1, j] : [i, height - j - 1]
  3688.         self.set_pixel(a[0],a[1], copy.get_pixel(j, i))
  3689.       end
  3690.     end
  3691.     copy.dispose
  3692.   end
  3693.   #-------------------------------------------------------------------------
  3694.   # ● New method: rotate180!
  3695.   #-------------------------------------------------------------------------
  3696.   define_sec_method(:rotate180!) do
  3697.     flip_vertical!
  3698.     flip_horizontal!
  3699.   end
  3700.   #-------------------------------------------------------------------------
  3701.   # ● New method: rotate270!
  3702.   #-------------------------------------------------------------------------
  3703.   define_sec_method(:rotate270!) do
  3704.     rotate90!
  3705.     rotate180!
  3706.   end  
  3707.   #----------------------------------------------------------------------------
  3708.   # ● New method: invert!
  3709.   #----------------------------------------------------------------------------
  3710.   unless method_defined?(:invert!)
  3711.     def invert!
  3712.       (t_Fx = width).times do |i|
  3713.         height.times do |j|
  3714.            color = get_pixel(i, j)
  3715.            Graphics.update if (t_Fx += 1) % 10000 == 0
  3716.            set_pixel(i, j, color.invert) if color.alpha > 0
  3717.          end
  3718.       end
  3719.     end
  3720.   end
  3721.   #--------------------------------------------------------------------------
  3722.   # * New method: brighten!
  3723.   #--------------------------------------------------------------------------
  3724.   unless method_defined?(:brighten!)
  3725.     def brighten!(amount = 10)
  3726.       (t_Fx = width).times do |w|
  3727.         height.times do |h|
  3728.           color = get_pixel(w, h)
  3729.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3730.           set_pixel(w, h, Color.new([color.red + amount, 255].min,
  3731.                                     [color.green + amount, 255].min,
  3732.                                     [color.blue + amount, 255].min,
  3733.                                     color.alpha)) if color.alpha > 0
  3734.         end
  3735.       end
  3736.     end
  3737.   end
  3738.   #--------------------------------------------------------------------------
  3739.   # * New method: darken!
  3740.   #--------------------------------------------------------------------------
  3741.   unless method_defined?(:darken!)
  3742.     def darken!(amount = 10)
  3743.       (t_Fx = width).times do |w|
  3744.         height.times do |h|
  3745.           color = get_pixel(w, h)
  3746.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3747.           set_pixel(w, h, Color.new([color.red - amount, 0].max,
  3748.                                     [color.green - amount, 0].max,
  3749.                                     [color.blue - amount, 0].max,
  3750.                                     color.alpha)) if color.alpha > 0
  3751.         end
  3752.       end
  3753.     end
  3754.   end
  3755.   #--------------------------------------------------------------------------
  3756.   # * New method: grayscale!
  3757.   # NOTE: calling this method repeatedly has no effect on the bitmap, but will
  3758.   #       still waste processing power. Do not call it repeatedly.
  3759.   #--------------------------------------------------------------------------
  3760.   unless method_defined?(:grayscale!)
  3761.     def grayscale!
  3762.       (t_Fx = width).times do |w|
  3763.         height.times do |h|
  3764.           color = get_pixel(w, h)
  3765.           if (a = color.alpha) > 0
  3766.             Graphics.update if (t_Fx += 1) % 10000 == 0
  3767.             num = (color.red + color.green + color.blue) / 3
  3768.             set_pixel(w, h, Color.new(num, num, num, a))
  3769.           end
  3770.         end
  3771.       end
  3772.     end
  3773.   end
  3774.   #--------------------------------------------------------------------------
  3775.   # * New method: drg_pixelate! (0.2 second)
  3776.   # NOTE: Pixelateing bitmaps to a larger pixel size is less process consuming.
  3777.   #       for best results, don't pixelate to numbers below four.
  3778.   #       This works much better for solid images, due to bugs.
  3779.   #--------------------------------------------------------------------------
  3780.   unless method_defined?(:drg_pixelate!)
  3781.     def drg_pixelate!(size = 10)
  3782.       return self if size <= (t_Fx = 1)
  3783.       c = lambda {|a,b| (a / b**2) * Math.sqrt(b) }
  3784.       for w in 0..((width - 1) / size)
  3785.         w *= size
  3786.         for h in 0..((height - 1) / size)
  3787.           h *= size
  3788.           r, g, b, a = 0, 0, 0, 0
  3789.           size.times do |i|
  3790.             color = get_pixel(w, h)
  3791.             r += color.red
  3792.             g += color.green
  3793.             b += color.blue
  3794.             a += color.alpha
  3795.             color = get_pixel(w + i, h)
  3796.             r += color.red
  3797.             g += color.green
  3798.             b += color.blue
  3799.             a += color.alpha
  3800.             color = get_pixel(w, h + i)
  3801.             r += color.red
  3802.             g += color.green
  3803.             b += color.blue
  3804.             a += color.alpha
  3805.           end
  3806.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3807.           fill_rect(w, h, size, size, Color.new(c.call(r,size),c.call(g,size),
  3808.                                                 c.call(b,size),c.call(a,size)))
  3809.         end
  3810.       end
  3811.     end
  3812.   end
  3813.   #--------------------------------------------------------------------------
  3814.   # * New method: pixelate!
  3815.   #--------------------------------------------------------------------------
  3816.   unless method_defined?(:pixelate!)
  3817.     def pixelate!(size = 10)
  3818.       return mosaic!(size,size) if respond_to?(:mosaic!)
  3819.       return drg_pixelate!(size)
  3820.     end
  3821.   end
  3822.   #--------------------------------------------------------------------------
  3823.   # * New method: drg_frost! (5 second)
  3824.   # NOTE: Frosting a bitmap randomly scatters its pixels. As such, Consistant
  3825.   #       results are impossible to get.
  3826.   #       Frosting a bitmap beyond eight won't result in a more scattered image
  3827.   #--------------------------------------------------------------------------
  3828.   unless method_defined?(:drg_frost!)
  3829.     def drg_frost!(noise = 10)
  3830.       for pass in 1..noise
  3831.         (t_Fx = width).times do |w|
  3832.           height.times do |h|
  3833.             Graphics.update if (t_Fx += 1) % 10000 == 0
  3834.             set_pixel(w, h, get_pixel(w + rand(3) - 1, h + rand(3) - 1))
  3835.           end
  3836.         end
  3837.       end
  3838.     end
  3839.   end
  3840.   #-------------------------------------------------------------------------
  3841.   # ● New method: bltapiinit
  3842.   #-------------------------------------------------------------------------
  3843.   unless method_defined?(:bltapiinit)
  3844.     def bltapiinit
  3845.       info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
  3846.       hWndDC = LiTTleDRAgo.getdc.call(LiTTleDRAgo.hwnd)
  3847.       hMemDC = LiTTleDRAgo.ccdc.call(hWndDC)
  3848.       hMemBM = LiTTleDRAgo.ccbitmap.call(hWndDC, width, height)
  3849.       LiTTleDRAgo.releasedc.call(LiTTleDRAgo.hwnd, hWndDC)
  3850.       LiTTleDRAgo.selectobject.call(hMemDC, hMemBM)
  3851.       LiTTleDRAgo.setdibits.call(hMemDC, hMemBM, 0, height, address, info, 0)
  3852.       return hMemDC, hMemBM, info
  3853.     end
  3854.   end
  3855.   #-------------------------------------------------------------------------
  3856.   # ● New method: bit_blt
  3857.   #-------------------------------------------------------------------------
  3858.   unless method_defined?(:bit_blt)
  3859.     def bit_blt(x, y, src_bmp, src_rect, rastor_operation = 0xCC0020)
  3860.       hDC1, hBM1, info = *self.bltapiinit
  3861.       hDC2, hBM2 = *src_bmp.bltapiinit
  3862.       LiTTleDRAgo.bitblt.call(hDC1, x, y, src_rect.width, src_rect.height,
  3863.                   hDC2, src_rect.x, src_rect.y, rastor_operation)
  3864.       LiTTleDRAgo.getdibits.call(hDC1, hBM1, 0, height, address, info, 0)
  3865.       LiTTleDRAgo.deleteobject.call(hBM1)
  3866.       LiTTleDRAgo.deleteobject.call(hDC1)
  3867.       LiTTleDRAgo.deleteobject.call(hBM2)
  3868.       LiTTleDRAgo.deleteobject.call(hDC2)
  3869.     end
  3870.   end  
  3871.   #-------------------------------------------------------------------------
  3872.   # ● New method: crop_blt
  3873.   #-------------------------------------------------------------------------
  3874.   unless method_defined?(:crop_blt)
  3875.     def crop_blt(x, y, width, height, bitmap, dir = 1, align = 1, opacity = 255)
  3876.       w, h = bitmap.width, bitmap.height
  3877.       if w < width and h < height
  3878.         x += (width - w) / 2 if align == 1
  3879.         x += width - w       if align == 2
  3880.         return full_blt(x, y, bitmap, opacity)
  3881.       end
  3882.       i, j = dir % 3, dir / 3
  3883.       crop_x, crop_y = 0, 0
  3884.       crop_x = (w - width) / 2  if i == 1
  3885.       crop_x = w - width        if i == 2
  3886.       crop_y = (h - height) / 2 if j == 1
  3887.       crop_y = h - height       if j == 2
  3888.       blt(x, y, bitmap, Rect.new(crop_x, crop_y, width, height), opacity)
  3889.     end
  3890.   end
  3891.   #-------------------------------------------------------------------------
  3892.   # ● New method: fit_blt
  3893.   #-------------------------------------------------------------------------
  3894.   unless method_defined?(:fit_blt)  
  3895.     def fit_blt(x, y, width, height, bitmap, opacity = 255, align = 1)
  3896.       w, h = bitmap.width, bitmap.height
  3897.       if w > width or h > height
  3898.         conversion = w / h.to_f
  3899.         zoom_x, zoom_y = width * conversion, height if conversion <= 1
  3900.         zoom_x, zoom_y = width, height / conversion unless conversion <= 1
  3901.         x += (width - zoom_x) / 2 if align == 1
  3902.         x += width - zoom_x       if align == 2
  3903.         dest_rect = Rect.new(x, y, zoom_x, zoom_y)
  3904.         stretch_blt(dest_rect, bitmap, bitmap.rect, opacity)
  3905.       else
  3906.         x += (width - w) / 2 if align == 1
  3907.         x += width - w       if align == 2
  3908.         full_blt(x, y, bitmap, opacity)
  3909.       end
  3910.     end
  3911.   end
  3912.   #-------------------------------------------------------------------------
  3913.   # ● New method: full_blt
  3914.   #-------------------------------------------------------------------------
  3915.   unless method_defined?(:full_blt)
  3916.     def full_blt(x, y, bitmap, opacity = 255)
  3917.       blt(x, y, bitmap, bitmap.rect, opacity)
  3918.     end
  3919.   end
  3920.   #-------------------------------------------------------------------------
  3921.   # ● New method: scale_blt
  3922.   #-------------------------------------------------------------------------
  3923.   unless method_defined?(:scale_blt)
  3924.     def scale_blt(dest_rect, src_bitmap, src_rect = src_bitmap.rect, o = 255)
  3925.       w, h = src_rect.width, src_rect.height
  3926.       scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
  3927.       ow, oh = (w / scale).to_i, (h / scale).to_i
  3928.       ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
  3929.       stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
  3930.         src_bitmap, src_rect, o)
  3931.     end
  3932.   end
  3933.   #-------------------------------------------------------------------------
  3934.   # ● New method: frames_flip_horizontal
  3935.   #-------------------------------------------------------------------------
  3936.   unless method_defined?(:frames_flip_horizontal)
  3937.     def frames_flip_horizontal(frames)
  3938.       frame_width = width / frames
  3939.       frame_bitmap = Bitmap.new(frame_width, height)
  3940.       rect = Rect.new(0, 0, frame_width, height)
  3941.       frames.times do |i|
  3942.         frame_bitmap.clear
  3943.         rect.x = (x = i * frame_width)
  3944.         frame_bitmap.blt(0, 0, self, rect)
  3945.         frame_bitmap.flip_horizontal!
  3946.         blt(x, 0, frame_bitmap, frame_bitmap.rect)
  3947.       end
  3948.       frame_bitmap.dispose
  3949.     end
  3950.   end
  3951.   #-------------------------------------------------------------------------
  3952.   # ● New method: frames_flip_vertical
  3953.   #-------------------------------------------------------------------------
  3954.   unless method_defined?(:frames_flip_vertical)
  3955.     def frames_flip_vertical(frames)
  3956.       frame_height = height / frames
  3957.       frame_bitmap = Bitmap.new(width, frame_height)
  3958.       rect = Rect.new(0, 0, width, frame_height)
  3959.       frames.times do |i|
  3960.         frame_bitmap.clear        
  3961.         rect.y = (y = i * frame_height)
  3962.         frame_bitmap.blt(0, 0, self, rect)
  3963.         frame_bitmap.flip_vertical!
  3964.         blt(0, y, frame_bitmap, frame_bitmap.rect)
  3965.       end
  3966.       frame_bitmap.dispose
  3967.     end
  3968.   end
  3969.   #-------------------------------------------------------------------------
  3970.   # ● New method: blur_area
  3971.   #-------------------------------------------------------------------------
  3972.   unless method_defined?(:blur_area)
  3973.     def blur_area(settings = {})
  3974.       blur_settings.each do |default, setting|
  3975.         settings[default] = setting unless settings.has_key?(default)
  3976.       end
  3977.       keys = settings.keys
  3978.       rect_defined = keys.include?('rect')
  3979.       rect_p_defined = keys.include?('x') && keys.include?('y') &&
  3980.                        keys.include?('w') && keys.include?('h')
  3981.       if rect_defined
  3982.         rect = settings['rect']
  3983.         x, y, w, h = rect.x, rect.y, rect.width, rect.height
  3984.       elsif rect_p_defined
  3985.         x, y, w, h = settings['x'], settings['y'], settings['w'], settings['h']
  3986.       else
  3987.         x, y, w, h = 0, 0, self.width, self.height
  3988.       end
  3989.       dummy = self.dup
  3990.       spacing = settings['spacing']
  3991.       opacity = settings['opacity']
  3992.       settings['offset'].times do |i|
  3993.         src_rects = []
  3994.         src_rects << Rect.new(x + i * spacing, y + i * spacing, w, h)
  3995.         src_rects << Rect.new(x - i * spacing, y + i * spacing, w, h)
  3996.         src_rects << Rect.new(x + i * spacing, y - i * spacing, w, h)
  3997.         src_rects << Rect.new(x - i * spacing, y - i * spacing, w, h)
  3998.         o = Integer(opacity * (settings['offset'] - i) / (settings['offset']))
  3999.         src_rects.each { |src_rect|  blt(x, y, dummy, src_rect, o)}
  4000.       end
  4001.       dummy.dispose
  4002.       self
  4003.     end
  4004.   end
  4005.   #-------------------------------------------------------------------------
  4006.   # ● New method: sub_bitmap_blend
  4007.   #-------------------------------------------------------------------------
  4008.   unless method_defined?(:sub_bitmap_blend)
  4009.     def sub_bitmap_blend(x = 0, y = 0, bitmap = self, src_rect = bitmap.rect)
  4010.       src_rect.width.times do |i|
  4011.         src_rect.height.times do |j|
  4012.           c1 = get_pixel(x + i, y + j)
  4013.           c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4014.           nc = Color.new(c1.red-c2.red, c1.green-c2.green, c1.blue-c2.blue)
  4015.           set_pixel(x + i, y + j, nc) if c2.alpha > 0
  4016.         end
  4017.       end
  4018.     end
  4019.   end
  4020.   #-------------------------------------------------------------------------
  4021.   # ● New method: add_bitmap_blend
  4022.   #-------------------------------------------------------------------------
  4023.   unless method_defined?(:add_bitmap_blend)
  4024.     def add_bitmap_blend(x = 0, y = 0, bitmap = self, src_rect = bitmap.rect)
  4025.       src_rect.width.times do |i|
  4026.         src_rect.height.times do |j|
  4027.           c1 = get_pixel(x + i, y + j)
  4028.           c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4029.           nc = Color.new(c1.red+c2.red, c1.green+c2.green, c1.blue+c2.blue)
  4030.           set_pixel(x + i, y + j, nc) if c2.alpha > 0
  4031.         end
  4032.       end
  4033.     end
  4034.   end
  4035.   #--------------------------------------------------------------------------
  4036.   # * Alias Listing
  4037.   #--------------------------------------------------------------------------
  4038.   alias_sec_method :frost!,      :drg_frost!
  4039.   alias_sec_method :blur,        :blur_area
  4040.   alias_sec_method :entire_fill, :full_fill
  4041.         #--------------------------------------------------------------------------
  4042.         # * Replicated method: gradient_fill_rect
  4043.         #--------------------------------------------------------------------------
  4044.   unless method_defined?(:gradient_fill_rect)
  4045.     def gradient_fill_rect(*a)
  4046.       if a.first.is_a?(Rect)
  4047.         x, y, width, height = a[0].x, a[0].y, a[0].width, a[0].height
  4048.         color1 = a.at(1).dup
  4049.         color2 = a.at(2)
  4050.         vertical = a.at(3)
  4051.       else
  4052.         x, y, width, height = a[0..3]
  4053.         color1 = a.at(4).dup
  4054.         color2 = a.at(5)
  4055.         vertical = a.at(6)
  4056.       end
  4057.       dr = color2.red   - color1.red
  4058.       dg = color2.green - color1.green
  4059.       db = color2.blue  - color1.blue
  4060.       da = color2.alpha - color1.alpha
  4061.       start_rgba = [color1.red, color1.green, color1.blue, color1.alpha]
  4062.       if vertical
  4063.         dr, dg, db, da = dr / height, dg / height, db / height, da / height
  4064.         for i in (y.round...(y + height).round)
  4065.           fill_rect(x, i, width, 1, color1)
  4066.           start_rgba[0] = [start_rgba.at(0) + dr, 0].max.round
  4067.           start_rgba[1] = [start_rgba.at(1) + dg, 0].max.round
  4068.           start_rgba[2] = [start_rgba.at(2) + db, 0].max.round
  4069.           start_rgba[3] = [start_rgba.at(3) + da, 0].max.round
  4070.           color1.set(*start_rgba)
  4071.         end
  4072.       else
  4073.         dr, dg, db, da = dr / width, dg / width, db / width, da / width
  4074.         for i in (x.round...(x + width).round)
  4075.           fill_rect(i, y, 1, height, color1)
  4076.           start_rgba[0] = [start_rgba.at(0) + dr, 0].max.round
  4077.           start_rgba[1] = [start_rgba.at(1) + dg, 0].max.round
  4078.           start_rgba[2] = [start_rgba.at(2) + db, 0].max.round
  4079.           start_rgba[3] = [start_rgba.at(3) + da, 0].max.round
  4080.           color1.set(*start_rgba)
  4081.         end
  4082.       end
  4083.     end
  4084.   end
  4085. end
  4086. #==============================================================================
  4087. # ** String     
  4088. #------------------------------------------------------------------------------
  4089. #  
  4090. #==============================================================================
  4091. class String
  4092.   #-------------------------------------------------------------------------
  4093.   # ● New method: get_int
  4094.   #-------------------------------------------------------------------------
  4095.   unless method_defined?(:get_int)
  4096.     def get_int
  4097.       m = self.scan(/([-]?\d+)/i).flatten
  4098.       return m.join.to_i
  4099.     end
  4100.   end
  4101.   #-------------------------------------------------------------------------
  4102.   # ● New method: get_ints
  4103.   #-------------------------------------------------------------------------
  4104.   unless method_defined?(:get_ints)
  4105.     def get_ints
  4106.       array = self.scan(/([-]?\d+)/i).flatten.relay(:i)
  4107.       return array
  4108.     end
  4109.   end
  4110.   #-------------------------------------------------------------------------
  4111.   # ● New method: encrypt
  4112.   #-------------------------------------------------------------------------
  4113.   unless method_defined?(:encrypt)
  4114.     def encrypt(encryption_string = 'encrypt')
  4115.       encryption_bytes = []
  4116.       encryption_string.each_byte {|c| encryption_bytes << c}
  4117.       string = ''
  4118.       self.size.times do |i|
  4119.         byte = self[i] * encryption_bytes[i % encryption_bytes.size]
  4120.         base, mod = byte / 255, byte % 255
  4121.         string += base.chr + mod.chr
  4122.       end
  4123.       return string
  4124.     end
  4125.   end
  4126.   #-------------------------------------------------------------------------
  4127.   # ● New method: encrypt!
  4128.   #-------------------------------------------------------------------------
  4129.   unless method_defined?(:encrypt!)
  4130.     def encrypt!(encryption_string = 'encrypt')
  4131.       replace(encrypt(encryption_string))
  4132.     end
  4133.   end
  4134.   #-------------------------------------------------------------------------
  4135.   # ● New method: decrypt
  4136.   #-------------------------------------------------------------------------
  4137.   unless method_defined?(:decrypt)
  4138.     def decrypt(encryption_string = 'encrypt')
  4139.       encryption_bytes = []
  4140.       encryption_string.each_byte {|c| encryption_bytes << c}
  4141.       string = ''
  4142.       (self.size / 2).times do |i|
  4143.         b, m = self[i * 2] * 255, self[i * 2 + 1]
  4144.         string += ((b + m) / encryption_bytes[i % encryption_bytes.size]).chr
  4145.       end
  4146.       return string
  4147.     end
  4148.   end
  4149.   #-------------------------------------------------------------------------
  4150.   # ● New method: decrypt!
  4151.   #-------------------------------------------------------------------------
  4152.   unless method_defined?(:decrypt!)
  4153.     def decrypt!(encryption_string = 'encrypt')
  4154.       replace(decrypt(encryption_string))
  4155.     end
  4156.   end
  4157.   #-------------------------------------------------------------------------
  4158.   # ● New method: clear, words, characters
  4159.   #-------------------------------------------------------------------------
  4160.   define_sec_method(:clear)      { replace('')      }
  4161.   define_sec_method(:words)      { split(' ')       }
  4162.   define_sec_method(:characters) { split('')        }
  4163.   define_sec_method(:last)       { characters.last  }
  4164.   define_sec_method(:first)      { characters.first }
  4165. end

  4166. #==============================================================================
  4167. # ** Game_Interpreter
  4168. #------------------------------------------------------------------------------
  4169. #  An interpreter for executing event commands. This class is used within the
  4170. # Game_Map, Game_Troop, and Game_Event classes.
  4171. #==============================================================================
  4172. Klass = LiTTleDRAgo::VX ? Game_Interpreter : Interpreter
  4173. class Klass
  4174.   #--------------------------------------------------------------------------
  4175.   # * Constant
  4176.   #--------------------------------------------------------------------------
  4177.   SCRIPT_WAIT_RESULTS = [:wait, FalseClass]
  4178.   #--------------------------------------------------------------------------
  4179.   # ● Redirect Listing
  4180.   #--------------------------------------------------------------------------
  4181.   redirect_method :picture_sprite,        '$game_map.picture_sprite'
  4182.   #--------------------------------------------------------------------------
  4183.   # ● New method: random_teleport
  4184.   #--------------------------------------------------------------------------
  4185.   unless method_defined?(:random_teleport)
  4186.     def random_teleport(id = 0)
  4187.       character = id.is_a?(Game_Character) ? id : get_character(id)
  4188.       character.random_teleport if character.is_a?(Game_Character)
  4189.     end
  4190.   end
  4191.   #--------------------------------------------------------------------------
  4192.   # ● Redefined method: same_map?, next_event_code
  4193.   #--------------------------------------------------------------------------
  4194.   define_sec_method(:same_map?)       { @map_id == $game_map.map_id    }
  4195.   define_sec_method(:next_event_code) { @list[@index + 1].code         }
  4196.   #--------------------------------------------------------------------------
  4197.   # * Overwriten method: command_355
  4198.   #--------------------------------------------------------------------------
  4199.   def command_355
  4200.     script = @list[index = @index].parameters[0] + "\n"
  4201.     while [655, 355].include?(next_event_code) do
  4202.       script += @list[@index+=1].parameters[0] + "\n"
  4203.     end
  4204.     wait = SCRIPT_WAIT_RESULTS.include?(eval(script)) && LiTTleDRAgo::XP
  4205.     return wait ? !(@index = index) : true
  4206.   end  
  4207. end

  4208. #==============================================================================
  4209. # ** Sprite
  4210. #------------------------------------------------------------------------------
  4211. #  A sprite class for bitmap processing.
  4212. #==============================================================================
  4213. class Sprite
  4214.   #---------------------------------------------------------------------------
  4215.   # * Alias Listing
  4216.   #---------------------------------------------------------------------------
  4217.   alias_sec_method(:angle_fix_alias, :"angle=")
  4218.   alias_sec_method(:drg_core_dispose,:"dispose")
  4219.   alias_sec_method(:set_x_alias,     :"x=")
  4220.   alias_sec_method(:set_y_alias,     :"y=")
  4221.   alias_sec_method(:get_x_alias,     :"x")
  4222.   alias_sec_method(:get_y_alias,     :"y")
  4223.   #---------------------------------------------------------------------------
  4224.   # * New method: method_missing
  4225.   #---------------------------------------------------------------------------
  4226.   def method_missing(val,*a,&b)
  4227.     return bitmap.send(val.to_s,*a,&b) if bitmap.respond_to?(val.to_sym)
  4228.     text = "Undefined method #{val} for #{self.inspect}"
  4229.     raise(NoMethodError, text, caller(1))               
  4230.   end
  4231.   #---------------------------------------------------------------------------
  4232.   # * Aliased method: x=, y=
  4233.   #---------------------------------------------------------------------------
  4234.   define_method(:x=)      {|amt| set_x_alias((@intfloat_x = amt).to_i) }
  4235.   define_method(:y=)      {|amt| set_y_alias((@intfloat_y = amt).to_i) }
  4236.   define_method(:x)       { @intfloat_x ||= get_x_alias }
  4237.   define_method(:y)       { @intfloat_y ||= get_y_alias }
  4238.   define_method(:dispose) { disposed? || drg_core_dispose }
  4239.   define_method(:rotate_correction) { self.ox,self.oy = width/2, height/2 }
  4240.   #---------------------------------------------------------------------------
  4241.   # * Aliased method: angle=
  4242.   #---------------------------------------------------------------------------
  4243.   def angle=(v)
  4244.     return if @angle == v
  4245.     sign = (v % 360 == 180 || v % 180 == 90) ? 1.00001 : 1
  4246.     angle_fix_alias((@angle = v) * sign)
  4247.   end
  4248.   #--------------------------------------------------------------------------
  4249.   # ● Redefined method: width, height
  4250.   #--------------------------------------------------------------------------
  4251.   define_sec_method(:width)       { src_rect.width }
  4252.   define_sec_method(:height)      { src_rect.height }
  4253.   #--------------------------------------------------------------------------
  4254.   # ● Overwriten method: dup
  4255.   #--------------------------------------------------------------------------
  4256.   def dup
  4257.     sprite = self.class.new(self.viewport)
  4258.     sprite.bitmap                = self.bitmap.clone
  4259.     sprite.zoom_x, sprite.zoom_y = self.zoom_x, self.zoom_y
  4260.     sprite.x, sprite.y           = self.x, self.y
  4261.     sprite.ox, sprite.oy         = self.ox, self.oy
  4262.     sprite.color, sprite.tone    = self.color.dup, self.tone.dup
  4263.     sprite.src_rect,sprite.angle = self.src_rect, self.angle
  4264.     return sprite
  4265.   end
  4266.   #--------------------------------------------------------------------------
  4267.   # ● Overwriten method: clone
  4268.   #--------------------------------------------------------------------------
  4269.   def clone
  4270.     (sprite = self.dup) && instance_variables.each do |var|
  4271.       temp = instance_variable_get("#{var}")
  4272.       sprite.instance_variable_set("#{var}",temp) rescue nil
  4273.     end
  4274.     (frozen? && sprite.freeze)
  4275.     return sprite   
  4276.   end
  4277.   #--------------------------------------------------------------------------
  4278.   # ● New method: scale
  4279.   #--------------------------------------------------------------------------
  4280.   unless method_defined?(:scale)
  4281.     def scale(w, h)
  4282.       tmp = self.bitmap.clone
  4283.       self.bitmap = Bitmap.new(w, h)
  4284.       self.bitmap.stretch_blt(Rect.new(0, 0, w, h), tmp, tmp.rect)
  4285.       tmp.dispose
  4286.     end
  4287.   end
  4288.   #--------------------------------------------------------------------------
  4289.   # ● New method: in_rect?
  4290.   #--------------------------------------------------------------------------
  4291.   unless method_defined?(:in_rect?)
  4292.     def in_rect?(*rect)
  4293.       if rect.size == 1
  4294.         x, y, w, h = rect[0].x, rect[0].y, rect[0].width, rect[0].height
  4295.         return self.x.between?(x, x + w) && self.y.between?(y, y + h)
  4296.       elsif rect.size == 4
  4297.         x, y, w, h = rect
  4298.         return self.x.between?(x, x + w) && self.y.between?(y, y + h)
  4299.       end
  4300.       return false
  4301.     end
  4302.   end
  4303. end

  4304. #==============================================================================
  4305. # ** Scheduler
  4306. #------------------------------------------------------------------------------
  4307. #  This class allows to schedule a proc or method call a given amount of frames
  4308. #  into the future with any amount of arguments
  4309. #==============================================================================
  4310. unless defined?(Scheduler)
  4311.   class Scheduler
  4312.     #==========================================================================
  4313.     # ** Order
  4314.     #--------------------------------------------------------------------------
  4315.     #  An order is a proc, method or something else which has 'call' as a
  4316.     #  method, and the arguments to pass along.
  4317.     #==========================================================================
  4318.     unless method_defined?(:update)
  4319.       Order = Struct.new(:callable, :arguments)
  4320.       class Order
  4321.         #----------------------------------------------------------------------
  4322.         # * New Methods: call
  4323.         #----------------------------------------------------------------------
  4324.         define_method(:call) { callable.call(*arguments) }
  4325.       end
  4326.       #========================================================================
  4327.       # ** RecurringOrder
  4328.       #------------------------------------------------------------------------
  4329.       #  An order which is recurring every specified amount of time until
  4330.       #  FalseClass is returned from the call.
  4331.       #  Note that arguments remain the same for each call
  4332.       #========================================================================
  4333.       RecurringOrder = Struct.new(:callable, :arguments, :frames)
  4334.       class RecurringOrder
  4335.         #----------------------------------------------------------------------
  4336.         # * New Methods: call
  4337.         #----------------------------------------------------------------------
  4338.         def call
  4339.           result = callable.call(*arguments)
  4340.           unless result == FalseClass
  4341.             Scheduler.schedule_recurring(frames, frames, callable, *arguments)
  4342.           end
  4343.         end
  4344.       end
  4345.       #========================================================================
  4346.       # ** Mapping
  4347.       #------------------------------------------------------------------------
  4348.       # Maps an index to an array. Values can be added to these value.
  4349.       # Each array starts empty.
  4350.       #========================================================================
  4351.       class Mapping
  4352.         #----------------------------------------------------------------------
  4353.         # * New method: add, get, empty
  4354.         #----------------------------------------------------------------------
  4355.         define_method(:add)   { |i, v| ((@mapping ||= {})[i] ||=[]) << v }
  4356.         define_method(:get)   { |i|    ((@mapping ||= {})[i] || [])   }
  4357.         define_method(:empty) { |i|     (@mapping ||= {}).delete(i)   }
  4358.       end
  4359.       #------------------------------------------------------------------------
  4360.       # * New method: schedule
  4361.       #------------------------------------------------------------------------
  4362.       def schedule(frames, callable, *arguments)
  4363.         order = Order.new(callable, arguments)
  4364.         (@mapping ||= Mapping.new).add(frames + (@tick||=0), order)
  4365.       end
  4366.       #------------------------------------------------------------------------
  4367.       # * New method: schedule_recurring
  4368.       #------------------------------------------------------------------------
  4369.       def schedule_recurring(frames, frames_to_wait, callable, *arguments)
  4370.         order = RecurringOrder.new(callable, arguments, frames_to_wait)
  4371.         (@mapping ||= Mapping.new).add(frames + (@tick||=0), order)
  4372.       end
  4373.       #------------------------------------------------------------------------
  4374.       # * New method: update
  4375.       #------------------------------------------------------------------------
  4376.       def update
  4377.         orders = (@mapping ||= Mapping.new).get((@tick||=0))
  4378.         @mapping.empty(@tick)
  4379.         orders.each {|s| s.call }
  4380.         @tick += 1
  4381.       end
  4382.       #------------------------------------------------------------------------
  4383.       # * Self
  4384.       #------------------------------------------------------------------------
  4385.       @@instance = self.new
  4386.       class << self
  4387.         define_method(:instance) { @@instance }
  4388.         redirect_method :schedule_recurring, 'instance.schedule_recurring'
  4389.         redirect_method :schedule,           'instance.schedule'
  4390.         redirect_method :update,             'instance.update'
  4391.       end
  4392.     end
  4393.   end
  4394.   Graphics.auto_update.push([Scheduler,:update])
  4395. end
  4396. #==============================================================================
  4397. # ** Dir     
  4398. #------------------------------------------------------------------------------
  4399. #
  4400. #==============================================================================
  4401. class << Dir
  4402.   #--------------------------------------------------------------------------
  4403.   # ● New method: make_dir
  4404.   #--------------------------------------------------------------------------
  4405.   def make_dir(path)
  4406.     (dir = path.split("/")).size.times do |i|
  4407.       next if dir == "."
  4408.       Dir.mkdir(dir[0..i].join("/")) rescue nil
  4409.     end
  4410.   end
  4411.   #--------------------------------------------------------------------------
  4412.   # ● New method: files_with_extension
  4413.   #--------------------------------------------------------------------------
  4414.   def files_with_extension(directory, extension)
  4415.     entries(directory).select{|file| File.extname(file) == extension}
  4416.   end
  4417. end

  4418. #==============================================================================
  4419. # ** BitmapDump
  4420. #------------------------------------------------------------------------------
  4421. #
  4422. #==============================================================================
  4423. module BitmapDump; end
  4424. class << BitmapDump
  4425.   #--------------------------------------------------------------------------
  4426.   # ● New method: self.bitmap_data
  4427.   #--------------------------------------------------------------------------
  4428.   unless method_defined?(:bitmap_data)
  4429.     def bitmap_data(bitmap)
  4430.       red = Table.new(bitmap.width, bitmap.height)
  4431.       green, blue, alpha = red.clone, red.clone, red.clone      
  4432.       bitmap.width.times do |i|
  4433.         bitmap.height.times do |j|
  4434.           color = bitmap.get_pixel(i, j)
  4435.           red[i, j],  green[i, j] = color.red, color.green
  4436.           blue[i, j], alpha[i, j] = color.blue, color.alpha
  4437.         end
  4438.       end
  4439.       return [red, green, blue, alpha]
  4440.     end
  4441.   end
  4442.   #--------------------------------------------------------------------------
  4443.   # ● New method: self.read_bitmap_data
  4444.   #--------------------------------------------------------------------------
  4445.   unless method_defined?(:read_bitmap_data)
  4446.     def read_bitmap_data(red, green, blue, alpha)
  4447.       bitmap = Bitmap.new(red.xsize, red.ysize)
  4448.       bitmap.width.times do |i|
  4449.         bitmap.height.times do |j|
  4450.           color_table = [red[i, j], green[i, j], blue[i, j], alpha[i, j]]
  4451.           bitmap.set_pixel(i, j, Color.new(*color_table))
  4452.         end
  4453.       end
  4454.       return bitmap
  4455.     end
  4456.   end
  4457.   #--------------------------------------------------------------------------
  4458.   # ● New method: self.save_bitmap
  4459.   #--------------------------------------------------------------------------
  4460.   unless method_defined?(:save_bitmap)
  4461.     def save_bitmap(bitmap, filename, folder = '')
  4462.       bitmap_data = bitmap_data(bitmap)
  4463.       if folder && folder != ''
  4464.         Dir.make_dir(folder) unless FileTest.directory?(folder)
  4465.         filename = "#{folder}/#{filename}"
  4466.       end
  4467.       filename = filename.gsub("\","/").gsub("//","/")
  4468.       file = File.open(filename,'wb')
  4469.       Marshal.dump(bitmap_data, file)
  4470.       file.close
  4471.     end
  4472.   end
  4473.   #--------------------------------------------------------------------------
  4474.   # ● New method: self.load_bitmap
  4475.   #--------------------------------------------------------------------------
  4476.   unless method_defined?(:load_bitmap)
  4477.     def load_bitmap(filename, folder = '')
  4478.       if folder && folder != ''
  4479.         Dir.make_dir(folder) unless FileTest.directory?(folder)
  4480.         filename = "#{folder}/#{filename}"
  4481.       end
  4482.       filename = filename.gsub("\","/").gsub("//","/")
  4483.       file = File.open(filename,"rb")
  4484.       colors = Marshal.load(file)
  4485.       file.close
  4486.       bitmap = read_bitmap_data(colors)
  4487.       return bitmap
  4488.     end
  4489.   end
  4490. end
复制代码



  1. #==============================================================================
  2. # ** Drago - Custom Resolution
  3. # Version : 2.17
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. ($imported ||= {})[:drg_custom_resolution] = 2.17
  7. #==============================================================================
  8. #
  9. # Introduction :
  10. #
  11. #   Version 2 from previous Drago - Custom Resolution
  12. #
  13. # Issue :
  14. #   
  15. #  - Normal transition didn't work when resolution is more than 640x480
  16. #  - ALT+Enter is disabled by default
  17. #  - Custom menu system will require an edit to match the new resolution
  18. #  - Anything that modify Sprite_Character & Spriteset_Map will require an edit
  19. #
  20. # Script Call :
  21. #
  22. #  Graphics.window
  23. #  Graphics.fullscreen
  24. #  Graphics.fullscreen?     # returns true if game is fullscreen
  25. #
  26. #    $game_map.start_zoom(X, Y, ZOOM_VALUE, DURATION = 20)     
  27. #    $game_map.zoom(X = nil, Y = nil, ZOOM_VALUE)   
  28. #    $game_map.zoom_in(X = nil, Y = nil, DURATION = 20)
  29. #    $game_map.zoom_out(X = nil, Y = nil, DURATION = 20)
  30. #
  31. #    $game_map.reverse(true / false) # Flip the map
  32. #
  33. #    $game_map.start_tilemap_opacity(OPACITY = 255, DURATION = 20)
  34. #    $game_map.start_tilemap_tone(TONE = Tone.new(0,0,0,0), DURATION = 0)
  35. #
  36. #
  37. #    change_tilemap_tone(TONE,*CHARACTER)     # change tilemap tone
  38. #    change_character_tone(TONE,*CHARACTER)   # change character tone without
  39. #                                               changing the tilemap
  40. #
  41. #   X, Y       = Zoom focus
  42. #
  43. #   ZOOM_VALUE = Integer from 1-12
  44. #
  45. #   OPACITY    = Integer from 0-255
  46. #
  47. #   TONE       = [R,G,B,A] or Tone.new(R,G,B,A)
  48. #
  49. #   CHARACTER  = $game_map.events.values # all events
  50. #              = $game_map.events.keys   # all events
  51. #              = $game_player            # player
  52. #              = -1                      # player
  53. #              = 0                       # this event
  54. #              = [2,3,4,6]               # events with selected id
  55. #              = [-1,2,3,4,6]            # player & events with selected id
  56. #              = [0,2,3,4,6]             # this event & events with selected id
  57. #              = (1..99)                 # events in range
  58. #              = [(1..8),20,25,(30..42)] # events in range
  59. #
  60. #    * will not change the character tone if left out
  61. #
  62. # Links :
  63. #
  64. #  - Fantasist's Transitions Pack
  65. #    [url]http://forum.chaos-project.com/index.php/topic[/url],1390.0.html
  66. #  - ForeverZer0's Add-ons
  67. #    [url]http://forum.chaos-project.com/index.php/topic[/url],7862.0.html
  68. #  - ThallionDarkshine's Add-ons
  69. #    [url]http://forum.chaos-project.com/index.php/topic[/url],12655.0.html
  70. #  - Drago Transition Pack
  71. #    [url]http://forum.chaos-project.com/index.php/topic[/url],13488.0.html
  72. #
  73. #  - Adjust Menu Position
  74. #    [url]http://forum.chaos-project.com/index.php/topic[/url],13781.0.html
  75. #
  76. #  - ThallionDarkshine's F12 Fix
  77. #    [url]http://forum.chaos-project.com/index.php/topic[/url],13629.0.html
  78. #  - Zeriab's F12 Pause with images
  79. #    [url]http://forum.chaos-project.com/index.php/topic[/url],3613.0.html
  80. #
  81. # Special Thanks :
  82. #  
  83. # - ForeverZer0 & KK20 for method used in this script
  84. # - Wecoc for autotile addon
  85. #
  86. #==============================================================================

  87. module LiTTleDRAgo
  88.   
  89.   SCREEN_SIZE = [640,490]
  90.   # Define the resolution of the game screen. These values can be anything
  91.   # within reason. Centering, viewports, etc. will all be taken care of, but it
  92.   # is recommended that you use values divisible by 32 for best results.
  93.   
  94.   
  95.   AUTOTILE_SPEED = {}
  96.   
  97.   AUTOTILE_SPEED[:map_id] = :speed
  98.   AUTOTILE_SPEED[0]       = 6                              # default speed
  99.   #AUTOTILE_SPEED[35]      = 0                              # unchanged autotile
  100.   #AUTOTILE_SPEED[159]     = 16                             
  101.   # Speed of the autotile based on map_id
  102.   
  103.   CONTROL_SCREEN_SIZE = false
  104.   # Control screen size with a mouse
  105.   
  106.   HIGH_PRIORITY = true
  107.   # Change Game process priority to high
  108.   
  109.   SPRITE_COMPACT = true
  110.   # Keep the sprite to the very minimum number
  111.   
  112.   CHARACTER_Z_FIX = {
  113.     '178-Switch01'  => 0,
  114.     '180-Switch03'  => 0,
  115.     '181-Switch04'  => 0,
  116.     '199-Support07' => 0,
  117.   }
  118.   # Fix the screen_z value for events based on Graphic name.
  119.   # You can also define z value for event by inserting <z: Z_VALUE>
  120.   # on event name.
  121.   # This way, flat events such as pitfall won't overlap with player z value.
  122.   
  123. end


  124. core = "This script needs Drago - Core Engine ver 1.47 or above"
  125. rmvx = "This script not for RMVX"
  126. implemented = "%1$s has already implemented, Please remove the %1$s script"
  127. zoom = sprintf(implemented,"Map Zoom")
  128. tone = sprintf(implemented,"Tilemap Tone Changer" )

  129. ($imported[:drg_core_engine] || 0) >= 1.47 || raise(core)
  130. LiTTleDRAgo::XP || LiTTleDRAgo::VXA  || raise(rmvx)
  131. $imported[:drg_cr_map_zoom]          && raise(zoom)
  132. $imported[:drg_tilemap_tone_changer] && raise(tone)
  133. #==============================================================================
  134. # ** Graphics
  135. #------------------------------------------------------------------------------
  136. #  This module handles all Graphics
  137. #==============================================================================

  138. class << Graphics
  139.   #-------------------------------------------------------------------------
  140.   # * Alias Listing
  141.   #-------------------------------------------------------------------------
  142.   alias_sec_method :zer0_graphics_transition,            :transition
  143.   alias_sec_method :drg_resolution_change_resize_screen, :resize_screen
  144.   alias_sec_method :drg_resolution_change_update,        :update
  145.   #-------------------------------------------------------------------------
  146.   # * Aliased method: resize_screen
  147.   #-------------------------------------------------------------------------
  148.   def resize_screen(width, height)
  149.     width = (width / 32.0).round * 32
  150.     height = (height / 32.0).round * 32
  151.     if $game_map.respond_to?(:screen_size)
  152.       $game_map.screen_size[0] = width
  153.       $game_map.screen_size[1] = height
  154.     end
  155.     drg_resolution_change_resize_screen(width, height)
  156.   end
  157.   #-------------------------------------------------------------------------
  158.   # * Aliased method: transition
  159.   #-------------------------------------------------------------------------
  160.   def transition(duration = 8, *args)
  161.     if width <= 640 && height <= 480
  162.       return zer0_graphics_transition(duration, *args)
  163.     end
  164.     if duration > 0
  165.       viewport = Viewport.new(0,0,width,height)
  166.       sprite  = Sprite.new(viewport)
  167.       sprite.bitmap = Graphics.snap_to_bitmap
  168.       sprite2 = Sprite.new(viewport)
  169.       sprite2.z = sprite.z - 10
  170.       sprite2.blend_type = 1
  171.       zer0_graphics_transition(0)
  172.       fade = 255 / duration
  173.       if (file = args.at(0)).is_a?(String)
  174.         bitmap = Bitmap.new(file)
  175.         sprite2.bitmap = bitmap.stretch(width,height)
  176.         bitmap.dispose
  177.       end
  178.       duration.times {[sprite,sprite2].each {|s|s.opacity -= fade} && update }
  179.       [sprite.bitmap, sprite2.bitmap, sprite, sprite2, viewport].dispose
  180.     end
  181.     zer0_graphics_transition(0)
  182.   end
  183.   #-------------------------------------------------------------------------
  184.   # * Aliased method: update
  185.   #-------------------------------------------------------------------------
  186.   def update
  187.     drg_resolution_change_update
  188.     update_resolution_adjust
  189.   end
  190.   #-------------------------------------------------------------------------
  191.   # * New method: update_resolution_adjust
  192.   #-------------------------------------------------------------------------
  193.   def update_resolution_adjust
  194.     return unless LiTTleDRAgo::XP && $game_player
  195.     return unless Game_Player.const_defined?(:CENTER_X)
  196.     change   = Game_Player.const_get(:CENTER_X) != $game_player.center_x
  197.     change ||= Game_Player.const_get(:CENTER_Y) != $game_player.center_y
  198.     return unless change
  199.     resize_screen(width,height)
  200.     $game_player.center($game_player.x,$game_player.y)
  201.   end
  202.   #-------------------------------------------------------------------------
  203.   # * Overwriten method: fullscreen
  204.   #-------------------------------------------------------------------------
  205.   def fullscreen
  206.     @fullscreen = true
  207.     fill_monitor
  208.     LiTTleDRAgo.hide_borders
  209.   end
  210.   #-------------------------------------------------------------------------
  211.   # * Overwriten method: window
  212.   #-------------------------------------------------------------------------
  213.   def window
  214.     @fullscreen = false
  215.     LiTTleDRAgo.show_borders
  216.     if $game_map && $game_map.screen_size.all? {|s| s.is_a?(Numeric)}
  217.       x,y = $game_map.screen_size[0..1]
  218.       x += ($game_map.screen_size[2] ||= 1)
  219.       $game_map.screen_size[2] *= -1
  220.       drg_resolution_change_resize_screen(x,y)
  221.     else
  222.       x,y = LiTTleDRAgo::SCREEN_SIZE
  223.     end
  224.     resize_screen(x,y)
  225.   end
  226.   #-------------------------------------------------------------------------
  227.   # * Overwriten method: fullscreen?
  228.   #-------------------------------------------------------------------------
  229.   define_method(:fullscreen?) { @fullscreen == true }
  230. end

  231. Graphics.window
  232. Graphics.disable_alt_enter
  233. Graphics.control_screen_size LiTTleDRAgo::CONTROL_SCREEN_SIZE
  234. Graphics.high_priority     = LiTTleDRAgo::HIGH_PRIORITY
  235. GC.start
  236. #==============================================================================
  237. # ** Game_Map
  238. #------------------------------------------------------------------------------
  239. #  This class handles the map. It includes scrolling and passable determining
  240. #  functions. Refer to "$game_map" for the instance of this class.
  241. #==============================================================================

  242. class Game_Map
  243.   #--------------------------------------------------------------------------
  244.   # * Public Instance Variable
  245.   #--------------------------------------------------------------------------
  246.   attr_sec_accessor :zoom_x, :zoom_y, 'Integer(1)'
  247.   attr_sec_accessor :screen_size,     'LiTTleDRAgo::SCREEN_SIZE'
  248.   attr_sec_accessor :tilemap_tone,    'Tone.new(0,0,0)'
  249.   attr_sec_accessor :tilemap_opacity, 'Integer(255)'
  250.   attr_sec_accessor :tilemap_hue,     'Integer(0)'
  251.   #---------------------------------------------------------------------------
  252.   # * Redirect Listing
  253.   #---------------------------------------------------------------------------
  254.   [:tilemap_tone,:tilemap_opacity].each do |meth|
  255.     redirect_method :"#{meth}_changing?",   "(@#{meth}_duration ||= 0) > 0"
  256.   end
  257.   #---------------------------------------------------------------------------
  258.   # * Define Sec Listing
  259.   #---------------------------------------------------------------------------
  260.   define_sec_method(:zooming?)      {(@zoom_duration ||= 0) > 0}
  261.   define_sec_method(:screen_tile_x) {(Graphics.width  / 32.0).ceil}
  262.   define_sec_method(:screen_tile_y) {(Graphics.height / 32.0).ceil}
  263.   #-------------------------------------------------------------------------
  264.   # * Alias Listing
  265.   #-------------------------------------------------------------------------
  266.   alias_sec_method(:drg_scroll_right_adjust, :scroll_right)
  267.   alias_sec_method(:drg_scroll_down_adjust,  :scroll_down)
  268.   alias_sec_method(:tilemap_effect_update,   :update)
  269.   alias_sec_method(:get_map_data,            :data)
  270.   #--------------------------------------------------------------------------
  271.   # * Aliased method: Scroll Down
  272.   #--------------------------------------------------------------------------
  273.   def scroll_down(distance)
  274.     times = vxa_map_multiplier
  275.     if loop_vertical?
  276.       @display_y += distance
  277.       @display_y %= height * times
  278.       @parallax_y += distance if @parallax_y && @parallax_loop_y
  279.     else
  280.       last_y = @display_y
  281.       result = [@display_y + distance, (map_edge.at(1) / zoom_y)].min
  282.       drg_scroll_down_adjust(distance)
  283.       @display_y = result
  284.     end
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * Aliased method: Scroll Right
  288.   #--------------------------------------------------------------------------
  289.   def scroll_right(distance)
  290.     times = vxa_map_multiplier
  291.     if loop_horizontal?
  292.       @display_x += distance
  293.       @display_x %= width * times
  294.       @parallax_x += distance if @parallax_x && @parallax_loop_x
  295.     else
  296.       last_x = @display_x
  297.       result = [@display_x + distance, (map_edge.at(0) / zoom_x)].min
  298.       drg_scroll_right_adjust(distance)
  299.       @display_x = result
  300.     end
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * New method: zoom
  304.   #--------------------------------------------------------------------------
  305.   def zoom(*zoom)
  306.     if zoom.size == 1
  307.       zoom = (zoom.first)
  308.     elsif zoom.size == 3
  309.       x,y,zoom = zoom[0..2]
  310.     end
  311.     return unless zoom.is_a?(Numeric)
  312.     old_zoom = @zoom_x
  313.     @zoom_x = [[zoom,12].min, 1].max
  314.     @zoom_y = [[zoom,12].min, 1].max
  315.     $game_player.center(x,y) if x && y
  316.   end
  317.   #--------------------------------------------------------------------------
  318.   # * New method: zoom_in
  319.   #--------------------------------------------------------------------------
  320.   def zoom_in(x = nil,y = nil, duration = 20)
  321.     start_zoom(x,y, zoom_x >= 1 ? zoom_x + 1 : 1, duration)
  322.   end   
  323.   #--------------------------------------------------------------------------
  324.   # * New method: zoom_out
  325.   #--------------------------------------------------------------------------
  326.   def zoom_out(x = nil,y = nil,duration = 20)
  327.     start_zoom(x,y, zoom_x - 1 >= 1 ? zoom_x - 1 : zoom_x - 0.5, duration)
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * New method: map_edge
  331.   #--------------------------------------------------------------------------
  332.   def map_edge
  333.     times = vxa_map_multiplier
  334.     [_w = [(width  * zoom_x - screen_tile_x).ceil * times, 0].max,
  335.      _h = [(height * zoom_y - screen_tile_y).ceil * times, 0].max]
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * New method: autotile_speed
  339.   #--------------------------------------------------------------------------
  340.   def autotile_speed(id = @map_id)
  341.     speed = LiTTleDRAgo::AUTOTILE_SPEED
  342.     @autotile_speed.is_a?(Array) || @autotile_speed = []
  343.     @autotile_speed[id] ||= (speed[id] || speed[0] || 0)
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # * New method: autotile_speed=
  347.   #--------------------------------------------------------------------------
  348.   def autotile_speed=(*value)
  349.     @autotile_speed.is_a?(Array) || @autotile_speed = []
  350.     @autotile_speed[@map_id]     = [value.first,0].max if value.size == 1
  351.     @autotile_speed[value.first] = [value.at(1),0].max if value.size > 1
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # * New method: vxa_map_multiplier
  355.   #--------------------------------------------------------------------------
  356.   def vxa_map_multiplier
  357.     LiTTleDRAgo::VXA ? 1 : 128
  358.   end
  359.   #--------------------------------------------------------------------------
  360.   # * New method: screen_is_solid?
  361.   #--------------------------------------------------------------------------
  362.   def screen_is_solid?
  363.     tone = screen.tone.to_s.gsub(/([(),0 ])/i){''}
  364.     return true if tone['255.255.255.']
  365.     return true if tone['255.-255.-255.']
  366.     return true if tone['-255.255.-255.']
  367.     return true if tone['-255.-255.255.']
  368.     return true if tone['255.255.-255.']
  369.     return true if tone['255.-255.255.']
  370.     return true if tone['-255.255.255.']
  371.     return true if tone['-255.-255.-255.']
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Aliased method: data
  375.   #--------------------------------------------------------------------------
  376.   def data
  377.     data = self.reverse ? reverse_data : get_map_data
  378.     data.make_changes = true
  379.     data
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # * New method: reverse_data
  383.   #--------------------------------------------------------------------------
  384.   def reverse_data
  385.     @reverse_data ||= []
  386.     @reverse_data[@map_id] ||= get_map_data.reverse(true,false,false)
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * New method: reverse=
  390.   #--------------------------------------------------------------------------
  391.   def reverse=(val)
  392.     return val if @reverse == val
  393.     @reverse = ((@reverse_data||=[])[@map_id] = nil) || val
  394.     spriteset && spriteset.reload_tilemap
  395.     @reverse
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * New method: reverse
  399.   #--------------------------------------------------------------------------
  400.   def reverse
  401.     @reverse && LiTTleDRAgo::XP
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * New method: start_tilemap_tone
  405.   #--------------------------------------------------------------------------
  406.   def start_tilemap_tone(tone = Tone.new(0,0,0,0), duration = 0)
  407.     @tilemap_tone_target = tone.is_a?(Array) ? Tone.new(*tone) : tone.clone
  408.     @tilemap_tone_duration = duration
  409.     tilemap_tone_changing? || @tilemap_tone = @tilemap_tone_target.clone
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # * New method: start_tilemap_opacity
  413.   #--------------------------------------------------------------------------
  414.   def start_tilemap_opacity(opacity = 255, duration = 0)
  415.     @tilemap_opacity_target = opacity * 1.0
  416.     @tilemap_opacity_duration = duration
  417.     tilemap_opacity_changing? || @tilemap_opacity = @tilemap_opacity_target
  418.   end
  419.   #--------------------------------------------------------------------------
  420.   # * New method: update_tilemap_tone
  421.   #--------------------------------------------------------------------------
  422.   def update_tilemap_tone
  423.     if tilemap_tone_changing?
  424.       d = @tilemap_tone_duration
  425.       target = @tilemap_tone_target
  426.       @tilemap_tone.red   = (@tilemap_tone.red   * (d - 1) + target.red) / d
  427.       @tilemap_tone.green = (@tilemap_tone.green * (d - 1) + target.green) / d
  428.       @tilemap_tone.blue  = (@tilemap_tone.blue  * (d - 1) + target.blue) / d
  429.       @tilemap_tone.gray  = (@tilemap_tone.gray  * (d - 1) + target.gray) / d
  430.       @tilemap_tone_duration -= 1
  431.       tilemap_tone_changing? || @tilemap_tone = @tilemap_tone_target.clone
  432.     end
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   # * New method: update_tilemap_opacity
  436.   #--------------------------------------------------------------------------
  437.   def update_tilemap_opacity
  438.     if tilemap_opacity_changing?
  439.       d = @tilemap_opacity_duration
  440.       @tilemap_opacity = (@tilemap_opacity * (d - 1) +
  441.       @tilemap_opacity_target) / d
  442.       @tilemap_opacity_duration -= 1
  443.       tilemap_opacity_changing? || @tilemap_opacity = @tilemap_opacity_target
  444.     end
  445.   end
  446.   #--------------------------------------------------------------------------
  447.   # * New method: start_zoom
  448.   #--------------------------------------------------------------------------
  449.   def start_zoom(x,y, zoom_target, duration=20)
  450.     @x_zoom = x
  451.     @y_zoom = y
  452.     @zoom_target = zoom_target * 1.0
  453.     @zoom_duration = @zoom_x == @zoom_target ? 0 : duration
  454.     zooming? || zoom(@x_zoom,@y_zoom,@zoom_target)
  455.   end
  456.   #--------------------------------------------------------------------------
  457.   # * New method: update_zooming
  458.   #--------------------------------------------------------------------------
  459.   def update_zooming
  460.     if zooming?
  461.       d = @zoom_duration
  462.       power = (@zoom_x * (d - 1) + @zoom_target) / d
  463.       @zoom_duration -= 1
  464.       zoom(@x_zoom,@y_zoom,power)
  465.       zoom(@x_zoom,@y_zoom,@zoom_target) unless zooming?
  466.     end
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # * Aliased method: update
  470.   #--------------------------------------------------------------------------
  471.   def update(*args)
  472.     tilemap_effect_update(*args)
  473.     update_tilemap_tone
  474.     update_tilemap_opacity
  475.     update_zooming
  476.   end
  477. end
  478. #==============================================================================
  479. # ** Interpreter
  480. #------------------------------------------------------------------------------
  481. #  This interpreter runs event commands. This class is used within the
  482. #  Game_System class and the Game_Event class.
  483. #==============================================================================
  484. unless LiTTleDRAgo::VX  
  485.   class Interpreter
  486.     #---------------------------------------------------------------------------
  487.     # * Redirect Listing
  488.     #---------------------------------------------------------------------------
  489.     redirect_method :zoom,                  '$game_map.zoom'
  490.     redirect_method :zoom_in,               '$game_map.zoom_in'
  491.     redirect_method :zoom_out,              '$game_map.zoom_out'
  492.     redirect_method :start_zoom,            '$game_map.start_zoom'
  493.     redirect_method :start_tilemap_opacity, '$game_map.start_tilemap_opacity'
  494.     redirect_method :start_tilemap_tone,    '$game_map.start_tilemap_tone'
  495.     [:change_tilemap_tone,:change_character_tone].each do |meth|
  496.       redirect_method :"#{meth}", :"$game_map.spriteset.#{meth}"
  497.     end
  498.   end
  499. end

  500. #==============================================================================
  501. # ** Game_Player
  502. #------------------------------------------------------------------------------
  503. #  This class handles the player. Its functions include event starting
  504. #  determinants and map scrolling. Refer to "$game_player" for the one
  505. #  instance of this class.
  506. #==============================================================================
  507. class Game_Player
  508.   #---------------------------------------------------------------------------
  509.   # * Define Sec Listing
  510.   #---------------------------------------------------------------------------
  511.   define_sec_method(:center_x) {((Graphics.width/2)  / $game_map.zoom_x-16) * 4}
  512.   define_sec_method(:center_y) {((Graphics.height/2) / $game_map.zoom_y-16) * 4}
  513.   #-------------------------------------------------------------------------
  514.   # * Alias Listing
  515.   #-------------------------------------------------------------------------
  516.   alias_sec_method(:drg_adjust_viewport_center, :center)
  517.   #-------------------------------------------------------------------------
  518.   # * Aliased method: center
  519.   #-------------------------------------------------------------------------
  520.   def center(x, y)
  521.     if LiTTleDRAgo::XP
  522.       Game_Player.const_set(:CENTER_X, center_x)
  523.       Game_Player.const_set(:CENTER_Y, center_y)
  524.     end
  525.     drg_adjust_viewport_center(x, y)
  526.     max_x = $game_map.map_edge.at(0) / $game_map.zoom_x
  527.     max_y = $game_map.map_edge.at(1) / $game_map.zoom_y
  528.     if LiTTleDRAgo::XP
  529.       $game_map.display_x = [0, [(x * 32*4) - center_x, max_x.ceil].min].max
  530.       $game_map.display_y = [0, [(y * 32*4) - center_y, max_y.ceil].min].max
  531.     elsif $game_map.respond_to?(:set_display_pos)
  532.       $game_map.set_display_pos(x - center_x, y - center_y)
  533.     end
  534.   end  
  535. end

  536. #==============================================================================
  537. # ** Tilemap
  538. #------------------------------------------------------------------------------
  539. #  
  540. #==============================================================================
  541. class Tilemap
  542.   #---------------------------------------------------------------------------
  543.   # * Public Instance Variables
  544.   #---------------------------------------------------------------------------
  545.   method_defined?(:tileset)   || attr_accessor(:tileset)
  546.   method_defined?(:priorities)|| attr_accessor(:priorities)
  547.   method_defined?(:autotiles) || attr_sec_accessor(:autotiles,'Array.new')
  548. end

  549. #==============================================================================
  550. # ** Table
  551. #------------------------------------------------------------------------------
  552. #  
  553. #==============================================================================
  554. class Table
  555.   #--------------------------------------------------------------------------
  556.   # * Public Instance Variable
  557.   #--------------------------------------------------------------------------
  558.   attr_sec_accessor :table_changes, :orig_value, 'Array.new'
  559.   attr_accessor     :make_changes
  560.   #--------------------------------------------------------------------------
  561.   # * Alias Listing
  562.   #--------------------------------------------------------------------------
  563.   alias_sec_method :set_method, :"[]="
  564.   #--------------------------------------------------------------------------
  565.   # * Set Data
  566.   #--------------------------------------------------------------------------
  567.   def []=(*args)
  568.     if @make_changes
  569.       table_changes.push([*args]) && orig_value.push(self[*args[0..-2]])
  570.       @make_changes = false
  571.     end
  572.     set_method(*args)
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # * Reverse
  576.   #--------------------------------------------------------------------------
  577.   def reverse(rx=true,ry=true,rz=true)
  578.     reverse = self.clone
  579.     _x = (0...xsize).to_a
  580.     _y = (0...ysize).to_a
  581.     _z = (0...zsize).to_a
  582.     _x.each do |x|
  583.       _rx = rx ? _x[-1-x] : x
  584.        ysize == 1 && (reverse[x] = self[_rx]) && next
  585.       _y.each do |y|
  586.         _ry = ry ? _y[-1-y] : y
  587.         zsize == 1 && (reverse[x,y] = self[_rx,_ry]) && next
  588.         _z.each do |z|
  589.           _rz = rz ? _z[-1-z] : z
  590.           reverse[x,y,z] = self[_rx,_ry,_rz]
  591.         end
  592.       end
  593.     end
  594.     reverse
  595.   end
  596. end

  597. #==============================================================================
  598. # ** RPG::Cache
  599. #==============================================================================
  600. ModCache = LiTTleDRAgo.cache
  601. module ModCache
  602.   #----------------------------------------------------------------------------
  603.   # * Self
  604.   #----------------------------------------------------------------------------
  605.   class << self
  606.     #--------------------------------------------------------------------------
  607.     # * Constant
  608.     #--------------------------------------------------------------------------
  609.     AUTO_INDEX = [[
  610.       [27,28,33,34],  [ 5,28,33,34],  [27, 6,33,34],  [ 5, 6,33,34],
  611.       [27,28,33,12],  [ 5,28,33,12],  [27, 6,33,12],  [ 5, 6,33,12],
  612.       [27,28,11,34],  [ 5,28,11,34],  [27, 6,11,34],  [ 5, 6,11,34],
  613.       [27,28,11,12],  [ 5,28,11,12],  [27, 6,11,12],  [ 5, 6,11,12],
  614.       [25,26,31,32],  [25, 6,31,32],  [25,26,31,12],  [25, 6,31,12],
  615.       [15,16,21,22],  [15,16,21,12],  [15,16,11,22],  [15,16,11,12],
  616.       [29,30,35,36],  [29,30,11,36],  [ 5,30,35,36],  [ 5,30,11,36],
  617.       [39,40,45,46],  [ 5,40,45,46],  [39, 6,45,46],  [ 5, 6,45,46],
  618.       [25,30,31,36],  [15,16,45,46],  [13,14,19,20],  [13,14,19,12],
  619.       [17,18,23,24],  [17,18,11,24],  [41,42,47,48],  [ 5,42,47,48],
  620.       [37,38,43,44],  [37, 6,43,44],  [13,18,19,24],  [13,14,43,44],
  621.       [37,42,43,48],  [17,18,47,48],  [13,18,43,48],  [ 1, 2, 7, 8]],
  622.       
  623.      [[27,28,33,34],  [49,50,55,56],  [51,52,57,58],  [49,52,55,58],
  624.       [63,64,69,70],  [65,66,71,72],  [51,52,69,70],  [ 5, 6,33,12],
  625.       [61,62,67,68],  [49,50,67,68],  [53,54,59,60],  [ 5, 6,11,34],
  626.       [61,64,67,70],  [ 5,28,11,12],  [27, 6,11,12],  [ 5, 6,11,12],
  627.       [25,26,31,32],  [25, 6,31,32],  [25,26,31,12],  [25, 6,31,12],
  628.       [15,16,21,22],  [15,16,21,12],  [15,16,11,22],  [15,16,11,12],
  629.       [29,30,35,36],  [29,30,11,36],  [ 5,30,35,36],  [ 5,30,11,36],
  630.       [39,40,45,46],  [ 5,40,45,46],  [39, 6,45,46],  [ 5, 6,45,46],
  631.       [25,30,31,36],  [15,16,45,46],  [13,14,19,20],  [13,14,19,12],
  632.       [17,18,23,24],  [17,18,11,24],  [41,42,47,48],  [ 5,42,47,48],
  633.       [37,38,43,44],  [37, 6,43,44],  [13,18,19,24],  [13,14,43,44],
  634.       [37,42,43,48],  [17,18,47,48],  [13,18,43,48],  [ 1, 2, 7, 8]]
  635.     ].freeze
  636.     #--------------------------------------------------------------------------
  637.     # * Public Instance Variable
  638.     #--------------------------------------------------------------------------
  639.     attr_sec_reader :cache, 'Hash.new'
  640.     #--------------------------------------------------------------------------
  641.     # * New method: autotile_cr_tilemap
  642.     #--------------------------------------------------------------------------
  643.     def autotile_cr_tilemap(filename)
  644.       key = "Graphics/Autotiles/CR#{filename}"
  645.       if !@cache.include?(key) || @cache[key].disposed?
  646.         @cache[key] = (filename=='') ? Bitmap.new(128,96) : autotile(filename)
  647.         new_bm = self.format_autotiles(@cache[key], filename)
  648.         @cache[key].dispose
  649.         @cache[key] = new_bm
  650.         @cache[key].instance_variable_set(:@autotile_name, filename)
  651.       end
  652.       return @cache[key]
  653.     end
  654.     #--------------------------------------------------------------------------
  655.     # * New method: include?
  656.     #--------------------------------------------------------------------------
  657.     unless method_defined?(:include?)
  658.       def include?(key)
  659.         @cache[key] && !@cache[key].disposed?
  660.       end
  661.     end
  662.     #--------------------------------------------------------------------------
  663.     # * New method: format_autotiles
  664.     #--------------------------------------------------------------------------
  665.     def format_autotiles(bitmap, filename)
  666.       if bitmap.height > 32
  667.         frames = bitmap.width / 96
  668.         index = bitmap.height == 192 ? AUTO_INDEX[1] : AUTO_INDEX[0]
  669.         template = Bitmap.new(256*frames,192)
  670.         frames.times {|a| (0...6).each { |i| (0...8).each { |j|
  671.           index[8*i+j].each { |number|
  672.             number -= 1
  673.             x, y = 16 * (number % 6), 16 * (number / 6)
  674.             ox, oy = (32 * j + x % 32) + (a * 256), 32 * i + y % 32
  675.             rect = Rect.new(x + (a * 96), y, 16, 16)
  676.             template.blt(ox, oy, bitmap, rect)
  677.         }}}}
  678.         return template
  679.       else
  680.         return bitmap
  681.       end
  682.     end
  683.     #--------------------------------------------------------------------------
  684.     # * New method: tile
  685.     #--------------------------------------------------------------------------
  686.     unless method_defined?(:format_tile)
  687.       def format_tile(bitmap, tile_id, hue)
  688.         filename = bitmap.pathname
  689.         key = [filename, tile_id, hue]
  690.         unless include?(key)
  691.           @cache[key] = empty_bitmap
  692.           x = (tile_id - 384) % 8 * 32
  693.           y = (tile_id - 384) / 8 * 32
  694.           rect = Rect.new(x, y, 32, 32)
  695.           @cache[key].blt(0, 0, bitmap, rect)
  696.           @cache[key].hue_change(hue)
  697.         end
  698.         @cache[key]
  699.       end
  700.     end
  701.     #--------------------------------------------------------------------------
  702.     # * New method: clear_tile_cache
  703.     #--------------------------------------------------------------------------
  704.     def clear_tile_cache
  705.       @cache ||= {}
  706.       @cache.reject! do |keys|
  707.         keys.is_a?(Array) && keys.size == 3 &&
  708.         keys[0].is_a?(String) && keys[0].downcase["tilemap"]
  709.       end
  710.       GC.start
  711.     end
  712.   end
  713. end

  714. #==============================================================================
  715. # ** Bitmap
  716. #------------------------------------------------------------------------------
  717. #  
  718. #==============================================================================
  719. class Bitmap
  720.   #--------------------------------------------------------------------------
  721.   # * Public Instance Variable
  722.   #--------------------------------------------------------------------------
  723.   attr_sec_accessor :pathname, 'String.new'
  724.   #--------------------------------------------------------------------------
  725.   # ● Alias Method
  726.   #--------------------------------------------------------------------------
  727.   $@ || alias_method(:cr_path_init, :initialize)
  728.   #--------------------------------------------------------------------------
  729.   # ● Object Initialization
  730.   #--------------------------------------------------------------------------
  731.   def initialize(*args)
  732.     @pathname = args.at(0) if args.at(0).is_a?(String)
  733.     cr_path_init(*args)
  734.   end
  735. end
  736. #==============================================================================
  737. # ** RPG::Weather
  738. #------------------------------------------------------------------------------
  739. #  A class for weather effects (rain, storm, and snow). It is used within the
  740. # Spriteset_Map class.
  741. #==============================================================================
  742. CRWeather = LiTTleDRAgo::VX ? Spriteset_Weather : RPG::Weather
  743. class CRWeather
  744.   #--------------------------------------------------------------------------
  745.   # * Public Instance Variable
  746.   #--------------------------------------------------------------------------
  747.   attr_reader :viewport
  748.   attr_accessor :zoom_x, :zoom_y
  749.   #--------------------------------------------------------------------------
  750.   # * Alias Listing
  751.   #--------------------------------------------------------------------------
  752.   $@ || alias_method(:init_custom_resolution, :initialize)
  753.   #--------------------------------------------------------------------------
  754.   # * Aliased method: initialize
  755.   #--------------------------------------------------------------------------
  756.   def initialize(viewport)
  757.     @viewport = viewport
  758.     init_custom_resolution(@viewport)
  759.   end
  760.   #--------------------------------------------------------------------------
  761.   # * Overwriten method: update
  762.   #--------------------------------------------------------------------------
  763.   def update
  764.     return if @type == 0
  765.     return if $game_map && $game_map.screen_is_solid?
  766.     update_screen if respond_to?(:update_screen)
  767.     @sprites.each {|sprite| update_sprite(sprite) }
  768.   end
  769.   #--------------------------------------------------------------------------
  770.   # * Update Sprite
  771.   #--------------------------------------------------------------------------
  772.   def update_sprite(sprite)
  773.     sprite.ox = @ox
  774.     sprite.oy = @oy
  775.     case @type
  776.     when 1, :rain  then update_sprite_rain(sprite)
  777.     when 2, :storm then update_sprite_storm(sprite)
  778.     when 3, :snow  then update_sprite_snow(sprite)
  779.     end
  780.     create_new_particle(sprite) if sprite.opacity < 64
  781.   end
  782.   #--------------------------------------------------------------------------
  783.   # * Update Sprite [Rain]
  784.   #--------------------------------------------------------------------------
  785.   def update_sprite_rain(sprite)
  786.     sprite.bitmap = @rain_bitmap
  787.     sprite.x -= 2 * sprite.zoom_x
  788.     sprite.y += 16 * sprite.zoom_y
  789.     sprite.opacity -= 8
  790.   end
  791.   #--------------------------------------------------------------------------
  792.   # * Update Sprite [Storm]
  793.   #--------------------------------------------------------------------------
  794.   def update_sprite_storm(sprite)
  795.     sprite.bitmap = @storm_bitmap
  796.     sprite.x -= 8 * sprite.zoom_x
  797.     sprite.y += 16 * sprite.zoom_y
  798.     sprite.opacity -= 12
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   # * Update Sprite [Snow]
  802.   #--------------------------------------------------------------------------
  803.   def update_sprite_snow(sprite)
  804.     sprite.bitmap = @snow_bitmap
  805.     sprite.x -= 2 * sprite.zoom_x
  806.     sprite.y += 8 * sprite.zoom_y
  807.     sprite.opacity -= 8
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # * Create New Particle
  811.   #--------------------------------------------------------------------------
  812.   def create_new_particle(sprite)
  813.     sprite.x = rand(Graphics.width + 100) - 100 + @ox
  814.     sprite.y = rand(Graphics.height + 200) - 200 + @oy
  815.     sprite.zoom_x = @zoom_x || 1
  816.     sprite.zoom_y = @zoom_y || 1
  817.     sprite.x *= sprite.zoom_x
  818.     sprite.y *= sprite.zoom_y
  819.     sprite.opacity = 160 + rand(96)
  820.   end
  821.   #---------------------------------------------------------------------------
  822.   # * New method: method_missing
  823.   #---------------------------------------------------------------------------
  824.   def method_missing(val,*a,&b)
  825.     en = @sprites.flatten.find_all {|s|s.respond_to?(val.to_sym)}
  826.     if en.empty?
  827.       text = "Undefined method #{val} at #{self.inspect}"
  828.       raise(NoMethodError,text,caller(1))
  829.     end
  830.     return en.map {|s| s.send(val.to_sym,*a,&b)}
  831.   end  
  832. end
  833.   
  834. #==============================================================================
  835. # ** Plane
  836. #------------------------------------------------------------------------------
  837. #  This class is the rewrite of the default plane class
  838. #==============================================================================

  839. class CRPlane < Sprite
  840.   #---------------------------------------------------------------------------
  841.   # * Public Instance Variable
  842.   #---------------------------------------------------------------------------
  843.   attr_reader :bitmap
  844.   #---------------------------------------------------------------------------
  845.   # * New method: z=
  846.   #---------------------------------------------------------------------------
  847.   def z=(z)
  848.     super(z * 1000)
  849.   end
  850.   #---------------------------------------------------------------------------
  851.   # * New method: ox=
  852.   #---------------------------------------------------------------------------
  853.   def ox=(ox)
  854.     return if $game_map && $game_map.screen_is_solid?
  855.     return if bitmap.nil? || bitmap.disposed?
  856.     super(ox % bitmap.width)  if bitmap.is_a?(Bitmap)
  857.   end
  858.   #---------------------------------------------------------------------------
  859.   # * New method: oy=
  860.   #---------------------------------------------------------------------------
  861.   def oy=(oy)
  862.     return if $game_map && $game_map.screen_is_solid?
  863.     return if bitmap.nil? || bitmap.disposed?
  864.     super(oy % bitmap.height) if bitmap.is_a?(Bitmap)
  865.   end
  866.   #---------------------------------------------------------------------------
  867.   # * New method: dispose
  868.   #---------------------------------------------------------------------------
  869.   def dispose
  870.     @plane && (@plane.disposed? || @plane.dispose)
  871.     super unless disposed?
  872.   end
  873.   #---------------------------------------------------------------------------
  874.   # * New method: bitmap=
  875.   #---------------------------------------------------------------------------
  876.   def bitmap=(tile)
  877.     return if @bitmap == tile
  878.     @bitmap = tile
  879.     if @bitmap.is_a?(Bitmap)
  880.       xx = 1 + (Graphics.width.to_f / tile.width).ceil
  881.       yy = 1 + (Graphics.height.to_f / tile.height).ceil
  882.       @plane.dispose if @plane.respond_to?(:dispose) && @plane.not.disposed?
  883.       @plane = Bitmap.new(@bitmap.width * xx, @bitmap.height * yy)
  884.       (0..xx).each {|x| (0..yy).each {|y|
  885.         @plane.blt(x * @bitmap.width, y * @bitmap.height, @bitmap, @bitmap.rect)
  886.       }}
  887.       super(@plane)
  888.     else
  889.       super(nil)
  890.     end
  891.   end
  892.   #---------------------------------------------------------------------------
  893.   # * Undefine methods dealing with coordinates to do nothing.
  894.   #---------------------------------------------------------------------------
  895.   undef :x, :x=, :y, :y=   if method_defined?(:x)
  896. end

  897. #==============================================================================
  898. # ** Viewport
  899. #------------------------------------------------------------------------------
  900. #  
  901. #==============================================================================
  902. class Viewport
  903.   #--------------------------------------------------------------------------
  904.   # * Overwriten method: update_viewport_sizes
  905.   #--------------------------------------------------------------------------
  906.   def update_viewport_sizes
  907.     map = $game_map
  908.     w, h = Graphics.width, Graphics.height
  909.     hor = $game_map.loop_horizontal?
  910.     ver = $game_map.loop_vertical?
  911.     _w = ($game_map.width  * 32 * $game_map.zoom_x).floor
  912.     _h = ($game_map.height * 32 * $game_map.zoom_y).floor
  913.     dx = w > _w && !hor ? ((w - _w).floor.abs / 32) * 16 : 0
  914.     dw = hor ? w : [w, $game_map.width  * 32 * $game_map.zoom_x].min  
  915.     dy = h > _h && !ver ? ((h - _h).floor.abs / 32) * 16 : 0
  916.     dh = ver ? h : [h, $game_map.height * 32 * $game_map.zoom_y].min
  917.     resize(Rect.new(dx, dy, dw, dh))
  918.   end
  919. end
  920. #==============================================================================
  921. # ** ZTilemap
  922. #------------------------------------------------------------------------------
  923. #  This class is the rewrite of the default tilemap class
  924. #==============================================================================

  925. class ZTilemap  
  926.   #---------------------------------------------------------------------------
  927.   # * Public Instance Variables
  928.   #---------------------------------------------------------------------------
  929.   attr_reader       :map_data,  :viewport
  930.   attr_accessor     :tileset,   :tone,    :priorities, :sprite_compact
  931.   attr_sec_accessor :autotiles, 'Array.new'
  932.   attr_sec_accessor :ox, :oy,   :zoom_x,  :zoom_y, :hue, 'Integer(1)'
  933.   attr_sec_accessor :opacity,  'Integer(255)'
  934.   attr_sec_reader   :layers, :bitmap_layers, :extra_map_data, 'Array.new'
  935.   #---------------------------------------------------------------------------
  936.   # * Redirect Listing
  937.   #---------------------------------------------------------------------------
  938.   redirect_method :width,       '$game_map.screen_tile_x + 2'
  939.   redirect_method :height,      '$game_map.screen_tile_y + 2'
  940.   #---------------------------------------------------------------------------
  941.   # * Define Sec Listing
  942.   #---------------------------------------------------------------------------
  943.   define_sec_method(:all_sprites) { layers.flatten.select {|s| is_sprite?(s)}}
  944.   define_sec_method(:is_sprite?)  { |s|  s.is_a?(Sprite) && s.not.disposed?  }
  945.   #---------------------------------------------------------------------------
  946.   # * Alias Listing
  947.   #---------------------------------------------------------------------------
  948.   alias_method :bitmaps, :autotiles
  949.   #---------------------------------------------------------------------------
  950.   # * Object Initialization
  951.   #---------------------------------------------------------------------------
  952.   def initialize(viewport)
  953.     @viewport       = viewport
  954.     @sprite_compact = false#LiTTleDRAgo::SPRITE_COMPACT
  955.     create_sprites
  956.     create_carrot
  957.   end
  958.   #---------------------------------------------------------------------------
  959.   # * New method: create_sprites
  960.   #---------------------------------------------------------------------------
  961.   def create_sprites
  962.     6.times do |i|
  963.       layers[i] ||= []
  964.       (i % 6 == 0 ? 1 : height).times do |s|
  965.         layers[i][s] = Sprite.new(@viewport) unless is_sprite?(layers[i][s])
  966.       end
  967.       layers[i].each_with_index do |s,r|
  968.         next unless is_sprite?(s)
  969.         s.y = r * 32 * zoom_y      
  970.         s.z = (i % 6 == 0) ? 0 : (r * 32 + 32 + (i % 6) * 32)
  971.         s.mirror = $game_map.reverse
  972.       end
  973.     end
  974.   end
  975.   #---------------------------------------------------------------------------
  976.   # * New method: create_carrot
  977.   #---------------------------------------------------------------------------
  978.   def create_carrot
  979.     @draw_tiles = carrot do |x,y,data,prio|
  980.       [0,1,2].each do |r|
  981.         if (id = data[x,y,r]).to_i == 0 || (layer = prio[id]).nil?
  982.           next
  983.         elsif @layer_clear && @layer_clear.not.include?(layer)
  984.           @bitmap_layers[layer].fill_rect(x*32,y*32,32,32,Color.erase)
  985.           @layer_clear.push(layer)
  986.         end
  987.         refresh_tiles(x,y,r,id)
  988.       end
  989.     end
  990.     @change_tone         = carrot {|s| all_sprites.tone    = (@tone = s)   }
  991.     @change_opacity      = carrot {|s| all_sprites.opacity = (@opacity = s)}
  992.     @change_autotile_hue = carrot do |a,old,hue|
  993.       [old.to_i != 0 && a.hue_change((old - 360).abs)] && a.hue_change(hue)
  994.     end
  995.   end
  996.   #---------------------------------------------------------------------------
  997.   # * New method: ox=, oy=, zoom_x=, zoom_y=
  998.   #---------------------------------------------------------------------------
  999.   [:ox, :oy, :zoom_x, :zoom_y].each do |a|
  1000.     meth = "def %1$s=(%1$s) (@%1$s != %1$s) && (@%1$s = %1$s) && %2$s end"
  1001.     module_eval(sprintf(meth, a ,'adjust_sprites'))
  1002.   end
  1003.   #---------------------------------------------------------------------------
  1004.   # * New method: tone=
  1005.   #---------------------------------------------------------------------------
  1006.   def tone=(*tone)
  1007.     new_tone = tone.flatten.size == 4 ? Tone.new(*tone.flatten) :
  1008.                tone.first.is_a?(Tone) ? tone.first : nil
  1009.     @tone.to_s == new_tone.to_s || @change_tone.call(new_tone.clone)
  1010.   end
  1011.   #---------------------------------------------------------------------------
  1012.   # * New method: opacity=
  1013.   #---------------------------------------------------------------------------
  1014.   def opacity=(opacity)
  1015.     opacity = [[opacity.round,255].min,0].max
  1016.     @opacity == opacity || @change_opacity.call(opacity)
  1017.   end
  1018.   #---------------------------------------------------------------------------
  1019.   # * New method: hue=
  1020.   #---------------------------------------------------------------------------
  1021.   def hue=(hue)
  1022.     return if @hue == (hue % 360)
  1023.     old = self.hue
  1024.     @hue = hue % 360
  1025.     all_autotiles = @autotiles + extra_map_data.map {|m| m[:autotiles]}.flatten
  1026.     @change_autotile_hue.call(all_autotiles.uniq, old, @hue)
  1027.     refresh     
  1028.   end
  1029.   #---------------------------------------------------------------------------
  1030.   # * New method: Adjust Sprites
  1031.   #---------------------------------------------------------------------------
  1032.   def adjust_sprites
  1033.     @times_compact ||= []
  1034.     @layers_used && @layers.size.times do |i|
  1035.       layer = @layers[i]
  1036.       (i % 6 == 0 ? 1 : height).times do |r|
  1037.         sprite = layer[r]
  1038.         d = 32
  1039.         _r = 32 + (i % 6) * 32
  1040.         _y = r * 32 * zoom_y
  1041.         _z = i % 6 == 0 ? 0 : r * d + _r # (r * d + _r)
  1042.         unless is_sprite?(sprite)
  1043.           change = _y <= @viewport.height
  1044.           if @sprite_compact
  1045.             change &&= !char_out_range?(_r, (height-1)*d+_r)
  1046.             change &&= @layers_used[i] > 0
  1047.           end
  1048.           change || next
  1049.           sprite = (layer[r] = Sprite.new(@viewport))
  1050.           sprite.bitmap  = bitmap_layers[i]
  1051.           sprite.tone    = tone if tone
  1052.           sprite.opacity = opacity
  1053.           sprite.mirror  = $game_map.reverse
  1054.           sprite.zoom_x, sprite.zoom_y = zoom_x, zoom_y
  1055.         else
  1056.           change = _y > @viewport.height
  1057.           if (@times_compact[i] ||= 0) < 10 && @sprite_compact
  1058.             change ||=  (r > 0 && char_out_range?(_r, (height-1)*d+_r))
  1059.             change ||=  (r > 0 && @layers_used[i] == 0)
  1060.           end
  1061.           sprite.y, sprite.z = _y, _z.ceil
  1062.           change && [sprite.dispose, @times_compact[i] += 1] && next
  1063.         end
  1064.         sprite.y, sprite.z = _y, _z.ceil
  1065.         _wd = @viewport.width/zoom_x
  1066.         _ox = sprite.mirror ? (sprite.bitmap.width-ox)-_wd  : (_wd+=10) && ox
  1067.         if layer.select { |s| is_sprite?(s) }.size == 1
  1068.           sprite.src_rect.set(_ox, oy, _wd, @viewport.height/zoom_x + 10)
  1069.         else
  1070.           sprite.src_rect.set(_ox, (oy + r*32), _wd, 33)
  1071.         end         
  1072.         sprite.zoom_x, sprite.zoom_y = zoom_x, zoom_y
  1073.       end
  1074.     end
  1075.   end
  1076.   #---------------------------------------------------------------------------
  1077.   # * New method: char_out_range?
  1078.   #---------------------------------------------------------------------------
  1079.   def char_out_range?(z1,z2)
  1080.     return false unless (s = $game_map.spriteset).is_a?(Spriteset_Map)
  1081.     s.character_sprites.all? do |d|
  1082.       d.not.disposed? && d.opacity > 0 && d.visible &&
  1083.       (d.z).not.between?(z1,z2)
  1084.     end
  1085.   end
  1086.   #---------------------------------------------------------------------------
  1087.   # * New method: Frame Dispose
  1088.   #---------------------------------------------------------------------------
  1089.   def dispose
  1090.     all_sprites.each   { |s| s.dispose }
  1091.     bitmap  = bitmap_layers
  1092.     bitmap += extra_map_data.map {|m| m[:autotiles]}.flatten - @autotiles
  1093.     bitmap += extra_map_data.map {|m| m[:tileset]}.flatten
  1094.     bitmap.compact.each { |s| s.disposed? || s.dispose }
  1095.     @layers.clear
  1096.     GC.start
  1097.   end
  1098.   #---------------------------------------------------------------------------
  1099.   # * New method: Change Map Data
  1100.   #---------------------------------------------------------------------------
  1101.   def map_data=(data)
  1102.     return if @map_data == data
  1103.     @map_data = data
  1104.     @map_data_reverse = data.reverse(true,false,false)
  1105.     6.times do |i|
  1106.       bitmap_layers[i].dispose if bitmap_layers[i] && bitmap_layers[i].disposed?
  1107.       bitmap_layers[i] =  Bitmap.new($game_map.width*32,$game_map.height*32)
  1108.       layers[i].each { |s| is_sprite?(s) && s.bitmap = bitmap_layers[i] }
  1109.     end
  1110.     refresh
  1111.   end
  1112.   #---------------------------------------------------------------------------
  1113.   # * New method: Map Data
  1114.   #---------------------------------------------------------------------------
  1115.   def map_data
  1116.     $game_map.reverse ? @map_data_reverse : @map_data
  1117.   end
  1118.   #---------------------------------------------------------------------------
  1119.   # * New method: Change priorities
  1120.   #---------------------------------------------------------------------------
  1121.   def priorities=(priorities)
  1122.     return if @priorities == priorities
  1123.     @priorities = priorities
  1124.     refresh
  1125.   end
  1126.   #---------------------------------------------------------------------------
  1127.   # * New method: Frame Refresh
  1128.   #---------------------------------------------------------------------------
  1129.   def refresh   
  1130.     return unless @priorities && @map_data
  1131.     LiTTleDRAgo.cache.clear_tile_cache
  1132.     @animated_tiles   = []
  1133.     @unrefreshed_tile = []
  1134.     @layers_used      = []
  1135.     7.times do |i|
  1136.       @total_frames   = [] if i == 0
  1137.       @current_frame  = [] if i == 0
  1138.       bm = (@current_frame[i] = @layers_used[i] = 0) && autotiles[i]
  1139.       bm.nil? && @total_frames[i] = 1
  1140.       bm.nil? || @total_frames[i] = bm.width / (bm.height > 32 ? 256 : 32)
  1141.       extra_map_data.each do |data|
  1142.         data[:total_frames]  = [] if i == 0
  1143.         data[:current_frame] = [] if i == 0
  1144.         bm = (data[:current_frame][i] = 0) && data[:autotiles][i]
  1145.         bm.nil? && data[:total_frames][i] = 1
  1146.         bm.nil? || data[:total_frames][i] = bm.width / (bm.height>32 ? 256 : 32)
  1147.       end
  1148.     end
  1149.     _w = @viewport.width
  1150.     _h = @viewport.height
  1151.     layers[0][0].src_rect.set(ox, oy, _w/zoom_x, _h/zoom_y )
  1152.     (0...map_data.xsize).each do |x|
  1153.       (0...map_data.ysize).each do |y|
  1154.         if in_range?(x,y)
  1155.           update_map_changes(x,y)
  1156.         else
  1157.           next if @unrefreshed_tile.include?([x,y])
  1158.           @unrefreshed_tile.push([x,y])
  1159.           @unrefreshed_tile.uniq!
  1160.         end
  1161.       end
  1162.     end
  1163.     adjust_sprites
  1164.   end
  1165.   #---------------------------------------------------------------------------
  1166.   # * New method: Refresh Tiles
  1167.   #---------------------------------------------------------------------------
  1168.   def refresh_tiles(x,y,z,i,d = nil)
  1169.     return if i.nil? || i == 0
  1170.     i < 384 ? refresh_autotile(x,y,z,i,d) : refresh_regular_tile(x,y,z,i,d)
  1171.   end
  1172.   #---------------------------------------------------------------------------
  1173.   # * New method: Refresh Autotile
  1174.   #---------------------------------------------------------------------------
  1175.   def refresh_autotile(x,y,z,id,data)
  1176.     layer  = data.nil? ? @priorities[id]        : data[:priorities][id]
  1177.     tframe = data.nil? ? @total_frames          : data[:total_frames]
  1178.     cframe = data.nil? ? @current_frame         : data[:current_frame]
  1179.     bitmap = data.nil? ? @autotiles.at(id/48-1) : data[:autotiles].at(id/48-1)
  1180.     return if bitmap.nil? || layer.nil?
  1181.     div = (fid = id / 48 - 1) &&(id % 48)
  1182.     if @animated_tiles.not.include?([x,y]) && tframe[fid] > 1
  1183.       @animated_tiles.push([x,y])
  1184.       @animated_tiles.uniq!
  1185.     end
  1186.     rect = Rect.new((div % 8)*32 + cframe[fid] * 256, (div / 8)*32, 32, 32)
  1187.     bitmap_layers[layer].blt(x*32, y*32, bitmap, rect)  
  1188.     @layers_used[layer] = [(@layers_used[layer] + 1) % 10000,1].max   
  1189.   end
  1190.   #---------------------------------------------------------------------------
  1191.   # * New method: Refresh Regular Tile
  1192.   #---------------------------------------------------------------------------
  1193.   def refresh_regular_tile(x,y,z,id,data)
  1194.     tileset = data.nil? ? @tileset        : data[:tileset]
  1195.     layer   = data.nil? ? @priorities[id] : data[:priorities][id]
  1196.     return if layer.nil? || tileset.not.is_a?(Bitmap)
  1197.     bitmap  = LiTTleDRAgo.cache.format_tile(tileset, id, hue)
  1198.     bitmap_layers[layer].blt(x*32, y*32, bitmap, Rect.new(0, 0, 32, 32))
  1199.     @layers_used[layer] = [(@layers_used[layer] + 1) % 10000, 1].max  
  1200.   end   
  1201.   #---------------------------------------------------------------------------
  1202.   # * New method: force_refresh
  1203.   #---------------------------------------------------------------------------
  1204.   def force_refresh
  1205.     refresh
  1206.     (@unrefreshed_tile ||= []).each {|x,y| update_map_changes(x,y)}
  1207.     (@unrefreshed_tile.clear)
  1208.   end
  1209.   #---------------------------------------------------------------------------
  1210.   # * New method: Frame Update
  1211.   #---------------------------------------------------------------------------
  1212.   def update
  1213.     update_map_data
  1214.     update_autotile
  1215.     update_unrefreshed_tile
  1216.   end
  1217.   #---------------------------------------------------------------------------
  1218.   # * New method: Update Unrefreshed Tile
  1219.   #---------------------------------------------------------------------------
  1220.   def update_unrefreshed_tile
  1221.     if @unrefreshed_tile && @unrefreshed_tile.not.empty?
  1222.       unrefreshed = @unrefreshed_tile.select { |x,y| in_range?(x,y) }
  1223.       if unrefreshed.not.empty?
  1224.         (unrefreshed).each {|x,y| update_map_changes(x,y)}
  1225.         (@unrefreshed_tile -= unrefreshed) && adjust_sprites
  1226.       end
  1227.     end
  1228.   end
  1229.   #---------------------------------------------------------------------------
  1230.   # * New method: Update Map Data
  1231.   #---------------------------------------------------------------------------
  1232.   def update_map_data
  1233.     if map_data.table_changes.not.empty?
  1234.       map_data.table_changes.each do|item|
  1235.         x,y,z,tile_id = item
  1236.         update_map_changes(x,y)
  1237.       end
  1238.       map_data.table_changes.clear
  1239.       map_data.make_changes = false
  1240.       adjust_sprites
  1241.     end
  1242.   end
  1243.   #---------------------------------------------------------------------------
  1244.   # * New method: Update the autotile
  1245.   #---------------------------------------------------------------------------
  1246.   def update_autotile
  1247.     return if $game_map.screen_is_solid?
  1248.     speed = $game_map.autotile_speed
  1249.     total = [(@autotile_total || 0) / 10, 0].max
  1250.     if speed > 0 && Graphics.frame_count % (speed + total) == 0
  1251.       7.times do |i|
  1252.         extra_map_data.each do |data|
  1253.           next if (total = data[:total_frames].at(i)) == 0
  1254.           data[:current_frame][i] = (data[:current_frame].at(i) + 1) % total
  1255.         end
  1256.         next if (total = @total_frames.at(i)) == 0
  1257.         @current_frame[i] = (@current_frame.at(i) + 1) % total
  1258.       end
  1259.       animated = @animated_tiles.select { |x,y| in_range?(x,y) }
  1260.       animated.each {|x,y| update_map_changes(x,y) }
  1261.       @autotile_total = animated.size
  1262.     end
  1263.   end
  1264.   #---------------------------------------------------------------------------
  1265.   # * New method: in_range?
  1266.   #---------------------------------------------------------------------------
  1267.   def in_range?(x=nil,y=nil)
  1268.     return false if layers[0].nil? || layers[0][0].nil?
  1269.     rect = @layers[0][0].src_rect
  1270.     _x = x && (x * 32).between?(rect.x-32, rect.x + rect.width)
  1271.     _y = y && (y * 32).between?(rect.y-32, rect.y + rect.height)
  1272.     return _x && _y if x && y
  1273.     return _x if x
  1274.     return _y if y
  1275.     return false
  1276.   end
  1277.   #---------------------------------------------------------------------------
  1278.   # * New method: Update Map Changes
  1279.   #---------------------------------------------------------------------------
  1280.   def update_map_changes(x,y)
  1281.     @layer_clear ||= []
  1282.     @layer_clear.clear
  1283.     draw = [[x,y,map_data,priorities]]  
  1284.     draw += extra_map_data.map {|data|[x,y,data[:map].data,data[:priorities]]}
  1285.     draw.each {|data| @draw_tiles.call(*data)}
  1286.   end   
  1287. end
  1288. #==============================================================================
  1289. # ** Game_Character
  1290. #------------------------------------------------------------------------------
  1291. #  This class deals with characters. It's used as a superclass for the
  1292. #  determinants and map scrolling. Refer to "$game_player" for the one
  1293. #  Game_Player and Game_Event classes.
  1294. #==============================================================================
  1295. class Game_Character
  1296.   #--------------------------------------------------------------------------
  1297.   # * Alias Listing
  1298.   #--------------------------------------------------------------------------
  1299.   alias_sec_method(:screen_x_before_zoom, :screen_x)
  1300.   alias_sec_method(:screen_y_before_zoom, :screen_y)
  1301.   alias_sec_method(:screen_z_before_zoom, :screen_z)
  1302.   #--------------------------------------------------------------------------
  1303.   # * Aliased method: screen_x
  1304.   #--------------------------------------------------------------------------
  1305.   def screen_x(*args)
  1306.     screen_x_before_zoom(*args) * $game_map.zoom_x
  1307.   end
  1308.   #--------------------------------------------------------------------------
  1309.   # * Aliased method: screen_y
  1310.   #--------------------------------------------------------------------------
  1311.   def screen_y(*args)
  1312.     screen_y_before_zoom(*args) * $game_map.zoom_y
  1313.   end
  1314.   #--------------------------------------------------------------------------
  1315.   # * Aliased method: screen_z
  1316.   #--------------------------------------------------------------------------
  1317.   def screen_z(*args)
  1318.     if self.is_a?(Game_Event)
  1319.       return 999                  if @always_on_top
  1320.       return $1.to_i              if self.name[/\<Z:\s*([-]?\d+)\s*\>/i]
  1321.       return screen_z_tilemap_fix if screen_z_tilemap_fix.is_a?(Integer)
  1322.     end
  1323.     return screen_z_before_zoom(*args)
  1324.   end
  1325.   #--------------------------------------------------------------------------
  1326.   # * New method: screen_z_tilemap_fix
  1327.   #--------------------------------------------------------------------------
  1328.   def screen_z_tilemap_fix
  1329.     LiTTleDRAgo::CHARACTER_Z_FIX.each do |key,value|
  1330.       if value.is_a?(Array) && key.is_a?(Integer)
  1331.         return key if value.any?{|v|"#{v}".downcase == @character_name.downcase}
  1332.       elsif key.is_a?(Array) && value.is_a?(Integer)
  1333.         return value if key.any?{|v|"#{v}".downcase == @character_name.downcase}
  1334.       elsif (key.is_a?(String) || key.is_a?(Symbol)) && value.is_a?(Integer)
  1335.         return value if "#{key}".downcase == @character_name.downcase
  1336.       end
  1337.     end
  1338.     return nil
  1339.   end
  1340. end

  1341. #==============================================================================
  1342. # ** Sprite_Character
  1343. #------------------------------------------------------------------------------
  1344. #  This sprite is used to display the character.It observes the Game_Character
  1345. #  class and automatically changes sprite conditions.
  1346. #==============================================================================
  1347. class Sprite_Character
  1348.   #--------------------------------------------------------------------------
  1349.   # * Alias Listing
  1350.   #--------------------------------------------------------------------------
  1351.   alias_sec_method(:zoom_update_scrolling, :update)
  1352.   #--------------------------------------------------------------------------
  1353.   # * Aliased method: update
  1354.   #--------------------------------------------------------------------------
  1355.   def update(*args)
  1356.     if @old_character_zoom_x
  1357.       self.zoom_x = @old_character_zoom_x
  1358.       self.zoom_y = @old_character_zoom_y
  1359.     end
  1360.     zoom_update_scrolling(*args)
  1361.     @old_character_zoom_x = self.zoom_x
  1362.     @old_character_zoom_y = self.zoom_y
  1363.     self.zoom_x *= $game_map.zoom_x
  1364.     self.zoom_y *= $game_map.zoom_y
  1365.   end
  1366.   #--------------------------------------------------------------------------
  1367.   # * New method: in_range?
  1368.   #--------------------------------------------------------------------------
  1369.   unless method_defined?(:in_range?)
  1370.     def in_range?
  1371.       cw = self.src_rect ? self.src_rect.width : 32
  1372.       ch = self.src_rect ? self.src_rect.height : 32
  1373.       return @character.screen_x.round.between?(self.viewport.x - cw,
  1374.         self.viewport.x + self.viewport.width) &&
  1375.       @character.screen_y.round.between?(self.viewport.y - ch,
  1376.         self.viewport.y + self.viewport.height)
  1377.     end
  1378.   end
  1379. end

  1380. #==============================================================================
  1381. # ** Spriteset_Map
  1382. #------------------------------------------------------------------------------
  1383. #  This class brings together map screen sprites, tilemaps, etc.
  1384. #  It's used within the Scene_Map class.
  1385. #==============================================================================
  1386. class Spriteset_Map
  1387.   #---------------------------------------------------------------------------
  1388.   # * Public Instance Variables
  1389.   #---------------------------------------------------------------------------
  1390.   attr_reader :character_sprites, :tilemap
  1391.   attr_reader :viewport1, :viewport2, :viewport3
  1392.   #--------------------------------------------------------------------------
  1393.   # * Alias Listing
  1394.   #--------------------------------------------------------------------------
  1395.   $@ || alias_method(:init_drgcr_tilemap, :initialize)
  1396.   alias_sec_method(:update_drgcr_tilemap, :update)
  1397.   #--------------------------------------------------------------------------
  1398.   # * Aliased method: initialize
  1399.   #--------------------------------------------------------------------------
  1400.   def initialize(*args)
  1401.     check_autotile_height
  1402.     init_drgcr_tilemap(*args)
  1403.   end
  1404.   #---------------------------------------------------------------------------
  1405.   # * New method: check_autotile_height
  1406.   #---------------------------------------------------------------------------
  1407.   def check_autotile_height
  1408.     return unless LiTTleDRAgo::XP
  1409.     $game_map.autotile_names.each do |autotile_name|
  1410.       bitmap = ModCache.autotile(autotile_name)
  1411.       [@force_tilemap_enabled = true] && break if bitmap.height == 192
  1412.     end
  1413.   end
  1414.   #--------------------------------------------------------------------------
  1415.   # * Aliased method: update
  1416.   #--------------------------------------------------------------------------
  1417.   def update(*args)
  1418.     adjust_viewport
  1419.     adjust_tilemap
  1420.     adjust_old_zoom
  1421.     update_drgcr_tilemap(*args)
  1422.     update_tilemap_zoom
  1423.   end
  1424.   #---------------------------------------------------------------------------
  1425.   # * New method: adjust_old_zoom
  1426.   #---------------------------------------------------------------------------
  1427.   def adjust_old_zoom
  1428.     if @old_fog_zoom_x
  1429.       @fog.zoom_x = @old_fog_zoom_x
  1430.       @fog.zoom_y = @old_fog_zoom_y
  1431.       @panorama.zoom_x = @old_panorama_zoom_x
  1432.       @panorama.zoom_y = @old_panorama_zoom_y
  1433.     end
  1434.   end
  1435.   #---------------------------------------------------------------------------
  1436.   # * New method: viewport_sprite
  1437.   #---------------------------------------------------------------------------
  1438.   def viewport_sprite(*v)
  1439.     v.collect! {|s| s.is_a?(Symbol) ? instance_variable_get(:"@#{s}") : s }
  1440.     v.reject!  {|s| s.not.is_a?(Viewport)}
  1441.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  1442.     all.select {|s| s.respond_to?(:viewport) && v.include?(s.viewport)}
  1443.   end
  1444.   #---------------------------------------------------------------------------
  1445.   # * New method: change_tilemap_tone
  1446.   #---------------------------------------------------------------------------
  1447.   def change_tilemap_tone(tone = Tone.new(0,0,0,0), *char)
  1448.     if tone.is_a?(Array) && (3..4) === tone.size
  1449.       result = $game_map.tilemap_tone = Tone.new(*tone)
  1450.     elsif tone.is_a?(Tone)
  1451.       result = $game_map.tilemap_tone = tone
  1452.     else
  1453.       return
  1454.     end
  1455.     sprite = viewport_sprite(:viewport1)
  1456.     sprite.reject! {|s| s.is_a?(Sprite_Character)}
  1457.     sprite.each    {|s| s.tone = result if s.respond_to?(:tone=) }
  1458.     change_character_tone(tone, *char) unless char.empty?
  1459.   end
  1460.   #---------------------------------------------------------------------------
  1461.   # * New method: change_character_tone
  1462.   #---------------------------------------------------------------------------
  1463.   def change_character_tone(tone = Tone.new(0,0,0,0), *char)
  1464.     char = char.collect {|c| c.is_a?(Range) ? c.to_a : c}.flatten
  1465.     char = char.collect {|c| c.is_a?(Range) ? c.to_a : c}.flatten
  1466.     char.collect! {|c| c.is_a?(Game_Character) ? c :
  1467.                        $game_map.interpreter.get_character(c)}
  1468.     sprite = viewport_sprite(:viewport1)
  1469.     sprite.reject! {|s| s.not.is_a?(Sprite_Character) }
  1470.     sprite.reject! {|s| char.not.include?(s.character)}
  1471.     if tone.is_a?(Array) && (3..4) === tone.size
  1472.       sprite.tone(:tone=, Tone.new(*tone))
  1473.     elsif tone.is_a?(Tone)
  1474.       sprite.send(:tone=, tone)
  1475.     end
  1476.   end
  1477.   #--------------------------------------------------------------------------
  1478.   # * New method: reload_tilemap
  1479.   #--------------------------------------------------------------------------
  1480.   def reload_tilemap
  1481.     return [dispose_tilemap, create_tilemap] if LiTTleDRAgo::VXA
  1482.     @tilemap.respond_to?(:dispose) && @tilemap.dispose
  1483.     7.times do |i|
  1484.       auto = @tilemap.autotiles[i]
  1485.       auto.respond_to?(:dispose) && (auto.disposed? || auto.dispose)
  1486.     end
  1487.     res = tilemap_enabled? ? ZTilemap : Tilemap
  1488.     @tilemap = res.new(@viewport1)
  1489.     @tilemap.tileset = ModCache.tileset($game_map.tileset_name)
  1490.     7.times do |i|
  1491.       autotile_name = $game_map.autotile_names[i]
  1492.       @tilemap.autotiles[i] = @tilemap.is_a?(ZTilemap) ?
  1493.       ModCache.autotile_cr_tilemap(autotile_name) :
  1494.       ModCache.autotile(autotile_name)
  1495.     end
  1496.     update_tilemap_effect
  1497.     @tilemap.priorities = $game_map.priorities
  1498.     @tilemap.map_data   = $game_map.data
  1499.     @tilemap.update
  1500.     @viewport_screen_width = 0
  1501.   end   
  1502.   #--------------------------------------------------------------------------
  1503.   # * New method: reload_plane
  1504.   #--------------------------------------------------------------------------
  1505.   def reload_plane
  1506.     z1  = @panorama.respond_to?(:z) ? @panorama.z : -1000
  1507.     z2  = @fog.respond_to?(:z)      ? @fog.z      :  5000
  1508.     z1 /= 1000 if @panorama.is_a?(CRPlane)
  1509.     z2 /= 1000 if @fog.is_a?(CRPlane)
  1510.     res =  plane_enabled? ? CRPlane : Plane
  1511.     bitmap1 = @panorama.respond_to?(:bitmap) ? @panorama.bitmap : nil
  1512.     bitmap2 = @fog.respond_to?(:bitmap)      ? @fog.bitmap      : nil
  1513.     @panorama.respond_to?(:dispose) && @panorama.dispose
  1514.     @fog.respond_to?(:dispose) && @fog.dispose      
  1515.     @panorama = res.new(@viewport1)
  1516.     @fog      = res.new(@viewport1)
  1517.     @panorama.bitmap = bitmap1 if bitmap1.is_a?(Bitmap)
  1518.     @fog.bitmap      = bitmap2 if bitmap2.is_a?(Bitmap)
  1519.     @panorama.z, @fog.z = z1, z2
  1520.     @viewport_screen_width = 0
  1521.   end
  1522.   #--------------------------------------------------------------------------
  1523.   # * New method: update_tilemap_zoom
  1524.   #--------------------------------------------------------------------------
  1525.   def update_tilemap_zoom
  1526.     @weather.zoom_x      = $game_map.zoom_x
  1527.     @weather.zoom_y      = $game_map.zoom_y
  1528.     @old_fog_zoom_x      = @fog.zoom_x
  1529.     @old_fog_zoom_y      = @fog.zoom_y
  1530.     @old_panorama_zoom_x = @panorama.zoom_x
  1531.     @old_panorama_zoom_y = @panorama.zoom_y
  1532.     @fog.zoom_x         *= $game_map.zoom_x
  1533.     @fog.zoom_y         *= $game_map.zoom_y
  1534.     @panorama.zoom_x    *= $game_map.zoom_x
  1535.     @panorama.zoom_y    *= $game_map.zoom_y
  1536.     update_tilemap_effect
  1537.   end
  1538.   #--------------------------------------------------------------------------
  1539.   # * New method: update_tilemap_effect
  1540.   #--------------------------------------------------------------------------
  1541.   def update_tilemap_effect
  1542.     return if @tilemap.not.is_a?(ZTilemap)
  1543.     @tilemap.zoom_x  = $game_map.zoom_x
  1544.     @tilemap.zoom_y  = $game_map.zoom_y
  1545.     @tilemap.opacity = $game_map.tilemap_opacity
  1546.     @tilemap.hue     = $game_map.tilemap_hue
  1547.     @tilemap.tone    = $game_map.tilemap_tone
  1548.   end
  1549.   #--------------------------------------------------------------------------
  1550.   # * Overwriten method: viewport_size_change?
  1551.   #--------------------------------------------------------------------------
  1552.   def viewport_size_change?
  1553.     return true if @viewport_map_width  != $game_map.width  * $game_map.zoom_x
  1554.     return true if @viewport_map_height != $game_map.height * $game_map.zoom_y
  1555.     return true if @viewport_screen_width  != Graphics.width
  1556.     return true if @viewport_screen_height != Graphics.height
  1557.   end
  1558.   #--------------------------------------------------------------------------
  1559.   # * New method: adjust_viewport
  1560.   #--------------------------------------------------------------------------
  1561.   def adjust_viewport
  1562.     if viewport_size_change?
  1563.       @viewport_map_width     = $game_map.width * $game_map.zoom_x
  1564.       @viewport_map_height    = $game_map.height * $game_map.zoom_y
  1565.       @viewport_screen_width  = Graphics.width
  1566.       @viewport_screen_height = Graphics.height
  1567.       [@viewport1,@viewport2,@viewport3].compact.update_viewport_sizes
  1568.     end
  1569.   end
  1570.   #--------------------------------------------------------------------------
  1571.   # * New method: adjust_tilemap
  1572.   #--------------------------------------------------------------------------
  1573.   def adjust_tilemap
  1574.     if LiTTleDRAgo::XP
  1575.       if tilemap_enabled?
  1576.         reload_tilemap if @tilemap.is_a?(Tilemap)
  1577.       else
  1578.         reload_tilemap if @tilemap.is_a?(ZTilemap)
  1579.       end
  1580.     end
  1581.     if plane_enabled?
  1582.       reload_plane   if @panorama.is_a?(Plane)   || @fog.is_a?(Plane)
  1583.     else
  1584.       reload_plane   if @panorama.is_a?(CRPlane) || @fog.is_a?(CRPlane)
  1585.     end
  1586.   end
  1587.   #--------------------------------------------------------------------------
  1588.   # * New method: tilemap_enabled?
  1589.   #--------------------------------------------------------------------------
  1590.   def tilemap_enabled?
  1591.     return true if @force_tilemap_enabled
  1592.     return true unless LiTTleDRAgo::RGSS1
  1593.     return true unless @viewport1.width <= 640 && @viewport1.height <= 480
  1594.     return true unless (map = $game_map) && map.zoom_x * map.zoom_y == 1
  1595.     return true unless map.tilemap_opacity >= 255
  1596.     return true unless map.tilemap_hue <= 0
  1597.     return true unless map.tilemap_tone.to_s.get_int == 0
  1598.     return true if map.reverse
  1599.     return false  
  1600.   end
  1601.   #--------------------------------------------------------------------------
  1602.   # * New method: plane_enabled?
  1603.   #--------------------------------------------------------------------------
  1604.   def plane_enabled?
  1605.     return true unless LiTTleDRAgo::RGSS1
  1606.     return true unless @viewport1.width <= 640 && @viewport1.height <= 480
  1607.     return false
  1608.   end
  1609. end
复制代码

评分

参与人数 2赞 +2 收起 理由
Nil2018 + 1 塞糖
Dayn + 1 塞糖

查看全部评分

我是梅林,人称花之魔术师。
梦石
0
星屑
431
在线时间
43 小时
注册时间
2009-5-6
回帖
58
发表于 2019-8-23 17:25:08 | 显示全部楼层
本帖最后由 yumeyuuya 于 2019-8-23 21:41 编辑

谢谢楼主,经测试能在VA里用XP地图了,可是VA的地图编辑器并不显示……它只是用了黑魔法让VA读取XP的地图数据并在运行中显示。编辑时VA地图还是VA的样子。
如果要编辑事件的话,要找到某些位置只能对着XP编辑好的地图数格子?
===============================================
搜索到了旧帖子,感觉这个比较好,能在VA的地图编辑器里面能看得到。
https://rpg.blue/thread-397621-1-1.html
捕获2.PNG

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部