设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3294|回复: 1
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1078
在线时间
127 小时
注册时间
2017-9-27
帖子
42
跳转到指定楼层
1
发表于 2017-12-2 20:42:11 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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



RUBY 代码复制
  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.  
  63. ($imported[:drg_core_engine] || 0) >= 1.44 || raise(core)
  64. ($imported[:drg_multi_layer])&& raise(sprintf(implemented,"Multi Layer"))
  65. #==============================================================================
  66. # ** Game_Map
  67. #------------------------------------------------------------------------------
  68. #  This class handles maps. It includes scrolling and passage determination
  69. # functions. The instance of this class is referenced by $game_map.
  70. #==============================================================================
  71. class Game_Map
  72.   #--------------------------------------------------------------------------
  73.   # * Public Instance Variables
  74.   #--------------------------------------------------------------------------
  75.   attr_sec_accessor :panorama_name, :fog_name,             'String.new'      
  76.   attr_sec_accessor :panorama_hue, :fog_hue, :fog_zoom,    1        
  77.   attr_sec_accessor :fog_opacity, :fog_blend_type,         0
  78.   attr_sec_accessor :fog_sx, :fog_sy, :fog_ox, :fog_oy,    0
  79.   attr_sec_accessor :fog_tone, :fog_tone_target,           'Tone.new(0,0,0)'
  80.   attr_sec_accessor :multi_layer_condition_true,           'Array.new'
  81.   attr_sec_accessor :multi_layer_condition_false,          'Array.new'
  82.   attr_sec_reader   :xpmap,  'Array.new'            
  83.   attr_sec_reader   :vxamap, 'Array.new'
  84.   #--------------------------------------------------------------------------
  85.   # * Class Variable
  86.   #--------------------------------------------------------------------------
  87.   tileset = "Data/Tilesets.rxdata"
  88.   @@tileset_xp = File.exist?(tileset) ? load_data(tileset) : nil
  89.   @@rpgmakerxp = LiTTleDRAgo::XP
  90.   #--------------------------------------------------------------------------
  91.   # * Define Method
  92.   #--------------------------------------------------------------------------
  93.   unless @@rpgmakerxp
  94.     define_method(:zoom_x) { 1 }
  95.     define_method(:zoom_y) { 1 }
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # * Undefine Method
  99.   #--------------------------------------------------------------------------
  100.   if !@@rpgmakerxp && method_defined?(:zoom)
  101.     undef :zoom, :zoom_in, :zoom_out, :zoom_x=, :zoom_y=, :start_zoom
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Alias Listing
  105.   #--------------------------------------------------------------------------
  106.   alias_sec_method :xpmap_loader_setup,         :setup
  107.   alias_sec_method :xpmap_loader_update,        :update
  108.   alias_sec_method :layered_tiles_flag_vxlayer, :layered_tiles_flag?
  109.   #--------------------------------------------------------------------------
  110.   # * Aliased Method : setup
  111.   #--------------------------------------------------------------------------
  112.   def setup(*args)
  113.     xpmap_loader_setup(*args)
  114.     setup_map_xp
  115.     setup_map_layer
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * New Method : setup_map_xp
  119.   #--------------------------------------------------------------------------
  120.   def setup_map_xp
  121.     reset_map_xp
  122.     map = sprintf("Map%03d",@map_id)
  123.     b   = "The dimension on %1$s.rvdata2 %2$s and %1$s.rxdata %3$s is not same"
  124.  
  125.     return unless @@tileset_xp && File.exist?("Data/"+map+".rxdata")
  126.     return if @@rpgmakerxp
  127.     return if self.xpmap.detect {|xp| xp && xp[:map_id] == @map_id }
  128.  
  129.  
  130.     _xp = load_map_data(@map_id,:rxdata)
  131.     _sz   = [@map,_xp].flatten.map {|m| [m.width,m.height]}.uniq
  132.     fail( sprintf( b, map, *_sz.map {|s| s.inspect})) if _sz.size > 1
  133.  
  134.     self.xpmap[0]                   = {}
  135.     self.xpmap[0][:map_id]          = @map_id
  136.     self.xpmap[0][:map]             = _xp
  137.     self.xpmap[0][:tileset_id]      = _xp.tileset_id
  138.     _xp = @@tileset_xp[_xp.tileset_id]
  139.     self.xpmap[0][:tileset_name]    = _xp.tileset_name
  140.     self.xpmap[0][:autotile_names]  = _xp.autotile_names
  141.     self.xpmap[0][:passages]        = _xp.passages
  142.     self.xpmap[0][:priorities]      = _xp.priorities
  143.     self.xpmap[0][:terrain_tags]    = _xp.terrain_tags
  144.  
  145.     @panorama_name   = _xp.panorama_name
  146.     @panorama_hue    = _xp.panorama_hue
  147.     @fog_name        = _xp.fog_name
  148.     @fog_hue         = _xp.fog_hue
  149.     @fog_opacity     = _xp.fog_opacity
  150.     @fog_blend_type  = _xp.fog_blend_type
  151.     @fog_zoom        = _xp.fog_zoom
  152.     @fog_sx          = _xp.fog_sx
  153.     @fog_sy          = _xp.fog_sy
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # * Aliased Method : update
  157.   #--------------------------------------------------------------------------
  158.   def update(*args)
  159.     xpmap_loader_update(*args)
  160.     update_fog unless @@rpgmakerxp
  161.     update_layer_condition
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * New Method : reset_map_xp
  165.   #--------------------------------------------------------------------------
  166.   def reset_map_xp
  167.     self.xpmap.clear
  168.     self.vxamap.clear
  169.     self.multi_layer_condition_true.clear
  170.     self.multi_layer_condition_false.clear
  171.     @mapinfo = nil
  172.     self.clear_panorama unless @@rpgmakerxp
  173.     self.clear_fog      unless @@rpgmakerxp
  174.   end  
  175.   #--------------------------------------------------------------------------
  176.   # * New Method : setup_map_layer
  177.   #--------------------------------------------------------------------------
  178.   def setup_map_layer
  179.     layered = false
  180.     self.child_ids.each_with_index do |submap_id,index|
  181.       next if self.vxamap.detect {|vxa| vxa && vxa[:map_id] == submap_id }
  182.       next if self.xpmap.detect {|xp| xp && xp[:map_id] == submap_id }
  183.       next unless (map_info = mapInfo[submap_id]).not.nil?
  184.       next unless (map_info.parent_id == map_id)
  185.       join = map_info.name[/\[\s*join\s*\]/]
  186.       if map_info.name[/\[\s*join:\s*([-]?\d+)\s*\]/]
  187.         id = $1.to_i
  188.         cond = LiTTleDRAgo::MultiLayerCond.call(id)
  189.         if !cond && multi_layer_condition_true.not.include?(id)
  190.           @multi_layer_condition_true << id
  191.         end
  192.         if cond && multi_layer_condition_false.not.include?(id)
  193.           @multi_layer_condition_false << id
  194.         end
  195.         join ||= cond
  196.       end
  197.       next unless join
  198.       map     = sprintf("Map%03d",submap_id)
  199.       org     = sprintf("Map%03d",map_id)
  200.       notsame = "The dimension of Parent map and Child map must be same"
  201.  
  202.       if @@tileset_xp && File.exist?("Data/"+map+".rxdata")
  203.         _xp = load_map_data(submap_id,:rxdata)
  204.         _sz = [@map,_xp].flatten.map {|m| [m.width,m.height]}.uniq
  205.         _sz.size > 1 && fail(notsame)
  206.  
  207.         self.xpmap[index+1]                   = {}
  208.         self.xpmap[index+1][:map_id]          = submap_id
  209.         self.xpmap[index+1][:map]             = _xp
  210.         self.xpmap[index+1][:tileset_id]      = _xp.tileset_id
  211.         _xp = @@tileset_xp[_xp.tileset_id]
  212.         self.xpmap[index+1][:tileset_name]    = _xp.tileset_name
  213.         self.xpmap[index+1][:autotile_names]  = _xp.autotile_names
  214.         self.xpmap[index+1][:passages]        = _xp.passages
  215.         self.xpmap[index+1][:priorities]      = _xp.priorities
  216.         self.xpmap[index+1][:terrain_tags]    = _xp.terrain_tags
  217.       elsif File.exist?("Data/"+map+".rvdata2")
  218.         _vxa = load_map_data(submap_id,:rvdata2)
  219.         _sz  = [@map,_vxa].flatten.map {|m| [m.width,m.height]}.uniq
  220.         _sz.size > 1 && fail(notsame)
  221.  
  222.         self.vxamap[index] = {}
  223.         self.vxamap[index][:map_id]     = submap_id
  224.         self.vxamap[index][:map]        = _vxa
  225.         self.vxamap[index][:tileset_id] = _vxa.tileset_id
  226.         tileset = $data_tilesets[_vxa.tileset_id]
  227.         self.vxamap[index][:tileset]    = tileset
  228.       end
  229.       layered = _xp || _vxa
  230.     end
  231.     spriteset.create_multi_layer if spriteset
  232.   end  
  233.   #--------------------------------------------------------------------------
  234.   # * New Method : update_layer_condition
  235.   #--------------------------------------------------------------------------
  236.   def update_layer_condition
  237.     meth = LiTTleDRAgo::MultiLayerCond
  238.     condition = multi_layer_condition_true.any?  {|id| meth.call(id)    } ||
  239.                 multi_layer_condition_false.any? {|id| meth.not.call(id)}
  240.     condition && [setup_map_xp, setup_map_layer]
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # * New Method : reset_fog_variable
  244.   #--------------------------------------------------------------------------
  245.   def reset_fog_variable
  246.     @fog_ox               =
  247.     @fog_oy               =
  248.     @fog_tone             =
  249.     @fog_tone_target      = nil
  250.     @fog_tone_duration    =
  251.     @fog_opacity_duration =
  252.     @fog_opacity_target   = 0
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * New Method : start_fog_tone_change
  256.   #--------------------------------------------------------------------------
  257.   unless method_defined?(:start_fog_tone_change)
  258.     def start_fog_tone_change(tone, duration)
  259.       @fog_tone_target = tone.clone
  260.       @fog_tone_duration = duration
  261.       if @fog_tone_duration == 0
  262.         @fog_tone = @fog_tone_target.clone
  263.       end
  264.     end
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * New Method : start_fog_opacity_chang
  268.   #--------------------------------------------------------------------------
  269.   unless method_defined?(:start_fog_opacity_change)
  270.     def start_fog_opacity_change(opacity, duration)
  271.       @fog_opacity_target = opacity * 1.0
  272.       @fog_opacity_duration = duration
  273.       if @fog_opacity_duration == 0
  274.         @fog_opacity = @fog_opacity_target
  275.       end
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * New Method : change_panorama
  280.   #--------------------------------------------------------------------------
  281.   def change_panorama(panorama_name = '',panorama_hue = 0)
  282.     @panorama_name = panorama_name
  283.     @panorama_hue  = panorama_hue
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * New Method : clear_panorama
  287.   #--------------------------------------------------------------------------
  288.   def clear_panorama(*args)
  289.     change_panorama
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * New Method : change_fog
  293.   #--------------------------------------------------------------------------
  294.   def change_fog(name='',hue=0,opac = 60, blend = 0,zoom = 1.0,sx = 0,sy = 0)
  295.     @fog_name       = name
  296.     @fog_hue        = hue
  297.     @fog_opacity    = opac
  298.     @fog_blend_type = blend
  299.     @fog_zoom       = zoom
  300.     @fog_sx         = sx
  301.     @fog_sy         = sy
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * New Method : clear_fog
  305.   #--------------------------------------------------------------------------
  306.   def clear_fog(*args)
  307.     change_fog
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * New Method : update_fog
  311.   #--------------------------------------------------------------------------
  312.   unless method_defined?(:update_fog)
  313.     def update_fog
  314.       @fog_ox = fog_ox - fog_sx / 8.0
  315.       @fog_oy = fog_oy - fog_sy / 8.0
  316.       if (@fog_tone_duration ||= 0) >= 1
  317.         d = (@fog_tone_duration ||= 0)
  318.         target = fog_tone_target
  319.         fog_tone.red   = (fog_tone.red * (d - 1) + target.red) / d
  320.         fog_tone.green = (fog_tone.green * (d - 1) + target.green) / d
  321.         fog_tone.blue  = (fog_tone.blue * (d - 1) + target.blue) / d
  322.         fog_tone.gray  = (fog_tone.gray * (d - 1) + target.gray) / d
  323.         @fog_tone_duration -= 1
  324.       end
  325.       if (@fog_opacity_duration ||= 0) >= 1
  326.         d = (@fog_opacity_duration ||= 0)
  327.         @fog_opacity  = (fog_opacity * (d-1) + (@fog_opacity_target||=0)) / d
  328.         @fog_opacity_duration -= 1
  329.       end
  330.     end
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * New Method : tile_id_obj
  334.   #--------------------------------------------------------------------------
  335.   def tile_id_obj(obj, x, y, z)
  336.     if $game_map.respond_to?(:reverse) && $game_map.reverse && LiTTleDRAgo::XP
  337.       obj.reverse_data[x, y, z] || 0
  338.     else
  339.       obj.data[x, y, z] || 0
  340.     end
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * New Method : collect_flag_tiles_vxa
  344.   #--------------------------------------------------------------------------
  345.   def collect_flag_tiles_vxa(x,y,*flag)
  346.     result = []
  347.     vxamap.compact.each do |map|
  348.       result += [2, 1, 0].collect do |z|
  349.         tile_id = tile_id_obj(map[:map],x, y, z)
  350.         [tile_id] + flag.collect {|s| map[s].flags[tile_id]}
  351.       end
  352.     end
  353.     return result
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * New Method : collect_flag_tiles_xp
  357.   #--------------------------------------------------------------------------
  358.   def collect_flag_tiles_xp(x,y,*flag)
  359.     result = []
  360.     xpmap.compact.each do |map|
  361.       result += [2, 1, 0].collect do |z|
  362.         tile_id = tile_id_obj(map[:map],x, y, z)
  363.         [tile_id] + flag.collect {|s| map[s][tile_id]}
  364.       end
  365.     end
  366.     return result
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # * New Method : collect_flag_tiles_original
  370.   #--------------------------------------------------------------------------
  371.   def collect_flag_tiles_original(x,y,*flag)
  372.     all_tiles_rep(x, y).collect do |t_id|
  373.       @@rpgmakerxp ? [t_id] + flag.collect {|map| map[t_id]} :
  374.       [t_id, tileset.flags[t_id]]
  375.     end
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # * Aliased Method : layered_tiles_flag?
  379.   #--------------------------------------------------------------------------
  380.   def layered_tiles_flag?(x, y, bit)
  381.     xp       = collect_flag_tiles_xp(x,y,:passages)
  382.     vxa      = collect_flag_tiles_vxa(x,y,:tileset)
  383.     original = collect_flag_tiles_original(x,y,@passages)
  384.     if @@rpgmakerxp
  385.       result = (xp + vxa + original).any? { |id,flag| flag & bit != 0 }
  386.     else
  387.       result   = layered_tiles_flag_vxlayer(x, y, bit)
  388.       result ||= (xp + vxa ).any? { |id,flag| flag & bit != 0 }
  389.     end
  390.     return result
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # * Overwriten Method : check_passage
  394.   #--------------------------------------------------------------------------
  395.   def check_passage(x, y, bit)
  396.     original = collect_flag_tiles_original(x,y,@passages)
  397.     xp       = collect_flag_tiles_xp(x,y,:passages)
  398.     vxa      = collect_flag_tiles_vxa(x,y,:tileset)
  399.     ( xp + vxa + original ).each do |t_id,flag,prio|
  400.       next if flag & 0x10 != 0            # [☆]: No effect on passage
  401.       #return true  if flag & bit == 0     # [○] : Passable
  402.       return false if flag & bit != 0     # [×] : Impassable
  403.       return false if flag & bit == bit   # [×] : Impassable
  404.       return true  if prio && prio == 0    # [○] : Passable
  405.     end
  406.     return true#false                          # Impassable
  407.   end
  408.   #--------------------------------------------------------------------------
  409.   # * Overwriten Method : terrain_tag
  410.   #--------------------------------------------------------------------------
  411.   def terrain_tag(x, y)
  412.     return 0 unless valid?(x, y)
  413.     original = collect_flag_tiles_original(x,y,@terrain_tags)
  414.     xp  = collect_flag_tiles_xp(x,y,:terrain_tags)
  415.     vxa = collect_flag_tiles_vxa(x,y,:tileset).map {|t| t >> 12}
  416.     (xp + vxa).each { |t_id,tag| return tag if tag > 0 }
  417.     (original).each do |t_id,flag|
  418.       tag = @@rpgmakerxp ? flag : flag >> 12
  419.       return tag if tag > 0
  420.     end
  421.     return 0
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # * Overwriten Method : passable?
  425.   #--------------------------------------------------------------------------
  426.   if @@rpgmakerxp
  427.     def passable?(x, y, d, s = nil)
  428.       original = (event_tiles(x, y, s) + layered_tiles(x, y)).map do |t_id|
  429.         [t_id, @passages[t_id], @priorities[t_id]]
  430.       end
  431.       xp    = collect_flag_tiles_xp(x,y,:passages,:priorities)
  432.       vxa   = collect_flag_tiles_vxa(x,y,:tileset)
  433.       bit   = (1 << (d / 2 - 1)) & 0x0f
  434.       (xp + vxa + original ).each do |t_id,flag,prio|
  435.         next if flag & 0x10 != 0             # [☆]: No effect on passage
  436.         return false if flag & bit != 0      # [×] : Impassable
  437.         return false if flag & 0x0f == 0x0f  # [×] : Impassable
  438.         return true  if prio && prio == 0    # [○] : Passable
  439.       end
  440.       return true                            # [○] : Passable
  441.     end
  442.     #--------------------------------------------------------------------------
  443.     # * Overwriten Method : bush?
  444.     #--------------------------------------------------------------------------
  445.     def bush?(x, y)
  446.       valid?(x, y) && layered_tiles_flag?(x, y, 0x40)
  447.     end
  448.     #--------------------------------------------------------------------------
  449.     # * Overwriten Method : counter?
  450.     #--------------------------------------------------------------------------
  451.     def counter?(x, y)
  452.       valid?(x, y) && layered_tiles_flag?(x, y, 0x80)
  453.     end
  454.   end
  455.   #--------------------------------------------------------------------------
  456.   # * New Method : event_tiles
  457.   #--------------------------------------------------------------------------
  458.   def event_tiles(x, y, s = nil)
  459.     e = events_xy(x,y).select {|e| e.tile_id > 0 && e != s && !e.through}
  460.     e.collect {|event| event.tile_id }
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # * Replicated Method : layered_tiles
  464.   #--------------------------------------------------------------------------
  465.   unless method_defined?(:layered_tiles)
  466.     def layered_tiles(x, y)
  467.       [2, 1, 0].collect {|z| tile_id_obj(@map, x, y, z) }
  468.     end
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # * Replicated Method : all_tiles_rep
  472.   #--------------------------------------------------------------------------
  473.   unless method_defined?(:all_tiles_rep)
  474.     def all_tiles_rep(x, y)
  475.       event_tiles(x, y) + layered_tiles(x,y)
  476.     end
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Replicated Method : events_xy
  480.   #--------------------------------------------------------------------------
  481.   unless method_defined?(:events_xy)
  482.     def events_xy(x, y)
  483.       @events.values.select {|event| event.x == x && event.y == y }
  484.     end
  485.   end
  486. end
  487.  
  488. #==============================================================================
  489. # ** RPG
  490. #------------------------------------------------------------------------------
  491. #
  492. #==============================================================================
  493. module RPG
  494.   #============================================================================
  495.   # ** Map
  496.   #----------------------------------------------------------------------------
  497.   #
  498.   #============================================================================
  499.   class Map
  500.     attr_accessor     :tileset_id
  501.     attr_sec_accessor :reverse_data, 'data.reverse(true,false,false)'
  502.   end
  503.   #============================================================================
  504.   # ** Tileset
  505.   #----------------------------------------------------------------------------
  506.   #
  507.   #============================================================================
  508.   class Tileset
  509.     #--------------------------------------------------------------------------
  510.     # * Public Instance Variables
  511.     #--------------------------------------------------------------------------
  512.     attr_sec_accessor :tileset_name,  :panorama_name, :fog_name,
  513.                       :battleback_name,                      'String.new'
  514.     attr_sec_accessor :autotile_names,                       '[String.new]*7'
  515.     attr_sec_accessor :panorama_hue, :fog_hue, :fog_blend_type,
  516.                       :fog_sx, :fog_sy,                      0
  517.     attr_sec_accessor :passages, :priorities, :terrain_tags, 'Table.new(384)'
  518.     attr_sec_accessor :fog_zoom,                             200
  519.     attr_sec_accessor :fog_opacity,                          64
  520.   end
  521. end
  522.  
  523. #==============================================================================
  524. # ** Spriteset_Map
  525. #------------------------------------------------------------------------------
  526. #  This class brings together map screen sprites, tilemaps, etc. It's used
  527. # within the Scene_Map class.
  528. #==============================================================================
  529. class Spriteset_Map
  530.   #--------------------------------------------------------------------------
  531.   # * Public Instance Variables
  532.   #--------------------------------------------------------------------------
  533.   attr_sec_reader :tilemap_layer, 'Array.new'
  534.   #--------------------------------------------------------------------------
  535.   # * Class Variable
  536.   #--------------------------------------------------------------------------
  537.   @@rpgmakerxp = LiTTleDRAgo::XP
  538.   @@fog_opacity = @@panorama_opacity = 0
  539.   #--------------------------------------------------------------------------
  540.   # * Alias Listing
  541.   #--------------------------------------------------------------------------
  542.   alias_sec_method :update_multi_layer_cr,         :update
  543.   alias_sec_method :dispose_multi_layer_cr,        :dispose
  544.   alias_sec_method :reload_tilemap_multi_layer_cr, :reload_tilemap
  545.   alias_method     :fog_fix_initialize,            :initialize
  546.   #--------------------------------------------------------------------------
  547.   # * Aliased method: initialize
  548.   #--------------------------------------------------------------------------
  549.   def initialize(*args)
  550.     fog_fix_initialize
  551.     @fog.opacity = @@fog_opacity || 0 if @fog
  552.     @panorama.opacity = @@panorama_opacity || 0 if @panorama
  553.   end
  554.   #--------------------------------------------------------------------------
  555.   # * New Method : create_multi_layer
  556.   #--------------------------------------------------------------------------
  557.   def create_multi_layer
  558.     dispose_multi_layer
  559.     @xpmap_size  = $game_map.xpmap.size
  560.     @vxamap_size = $game_map.vxamap.size
  561.     $game_map.vxamap.compact.each do |data|
  562.       next if @@rpgmakerxp
  563.       tilemap_layer[(i  = tilemap_layer.size)] = Tilemap.new(@viewport1)
  564.       create_layer_tilemap(tilemap_layer[i],data)
  565.     end
  566.     $game_map.xpmap.compact.each do |data|
  567.       _data             = data.clone
  568.       _data[:tileset]   = LiTTleDRAgo.cache.tileset(data[:tileset_name])
  569.       _data[:autotiles] = []
  570.       if (tilemap = ([@tilemap]+tilemap_layer).detect {|t| obj_is_ztilemap?(t)})
  571.         data[:autotile_names].each_with_index do |name, i|
  572.           _data[:autotiles][i] = LiTTleDRAgo.cache.autotile_cr_tilemap(name)
  573.         end
  574.         [tilemap.extra_map_data.push(_data), tilemap.refresh] && next
  575.       end
  576.       unless @@rpgmakerxp
  577.         cr = "This script needs Drago - Custom Resolution ver 2.12 or above"
  578.         ($imported[:drg_custom_resolution] || 0) >= 2.12 || raise(cr)
  579.       end
  580.       klass             = @@rpgmakerxp ? @tilemap.class : ZTilemap
  581.       tilemap_layer[(i  = tilemap_layer.size)] = klass.new(@viewport1)
  582.       create_layer_tilemap(tilemap_layer[i], _data)
  583.     end   
  584.     @viewport_screen_width = 0
  585.   end
  586.   #--------------------------------------------------------------------------
  587.   # * New Method : create_layer_tilemap
  588.   #--------------------------------------------------------------------------
  589.   def create_layer_tilemap(tilemap,data)
  590.     if (@@rpgmakerxp && tilemap.is_a?(Tilemap)) || obj_is_ztilemap?(tilemap)
  591.       if obj_is_ztilemap?(tilemap)
  592.         temp = tilemap.sprite_compact
  593.         tilemap.sprite_compact = false
  594.       end
  595.       (0..6).each do |i|
  596.         name = data[:autotile_names][i]
  597.         bitmap = LiTTleDRAgo.cache.autotile(name)
  598.         @force_tilemap_enabled = true if bitmap.height == 192
  599.         tilemap.autotiles[i] = obj_is_ztilemap?(tilemap) ?
  600.         LiTTleDRAgo.cache.autotile_cr_tilemap(name) : bitmap
  601.       end
  602.       tilemap.tileset     = data[:tileset]
  603.       tilemap.priorities  = data[:priorities]
  604.       tilemap.map_data    = data[:map].data
  605.       update_layer_tilemap(tilemap)
  606.       tilemap.update
  607.       tilemap.sprite_compact = temp  if obj_is_ztilemap?(tilemap)
  608.     else
  609.       tilemap.map_data = data[:map].data
  610.       data[:tileset].tileset_names.each_with_index do |name, i|
  611.         tilemap.bitmaps[i] = LiTTleDRAgo.cache.tileset(name)
  612.       end
  613.       tilemap.flags = data[:tileset].flags
  614.       update_layer_tilemap(tilemap)
  615.       tilemap.update
  616.     end
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   # * Aliased Method : update
  620.   #--------------------------------------------------------------------------
  621.   def update
  622.     unless @@rpgmakerxp                  
  623.       update_panorama
  624.       update_fog
  625.       update_panorama_plane
  626.       update_fog_plane
  627.     end         
  628.     update_multi_layer_cr
  629.     if @xpmap_size != $game_map.xpmap.size ||
  630.       @vxamap_size != $game_map.vxamap.size
  631.       create_multi_layer  
  632.     end
  633.     update_multi_layer
  634.   end
  635.   #--------------------------------------------------------------------------
  636.   # * New Method : dispose_multi_layer
  637.   #--------------------------------------------------------------------------
  638.   def dispose_multi_layer
  639.     tilemap_layer.dispose
  640.     tilemap_layer.clear
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   # * New Method : update_multi_layer
  644.   #--------------------------------------------------------------------------
  645.   def update_multi_layer
  646.     tilemap_layer.each { |t| update_layer_tilemap(t) }
  647.   end
  648.   #--------------------------------------------------------------------------
  649.   # * New Method : update_layer_tilemap
  650.   #--------------------------------------------------------------------------
  651.   def update_layer_tilemap(tilemap)
  652.     if obj_is_ztilemap?(tilemap)
  653.       if @@rpgmakerxp
  654.         tilemap.ox      = @tilemap.ox
  655.         tilemap.oy      = @tilemap.oy
  656.         tilemap.zoom_x  = $game_map.zoom_x
  657.         tilemap.zoom_y  = $game_map.zoom_y
  658.         tilemap.opacity = $game_map.tilemap_opacity
  659.         tilemap.hue     = $game_map.tilemap_hue
  660.         tilemap.tone    = $game_map.tilemap_tone
  661.       else
  662.         tilemap.ox = $game_map.display_x * tilemap_move_multiplier
  663.         tilemap.oy = $game_map.display_y * tilemap_move_multiplier
  664.       end
  665.     else
  666.       tilemap.ox = @tilemap.ox rescue $game_map.display_x * tilemap_move_multiplier
  667.       tilemap.oy = @tilemap.oy rescue $game_map.display_y * tilemap_move_multiplier
  668.     end
  669.     tilemap.update
  670.   end
  671.   #--------------------------------------------------------------------------
  672.   # * New Method : obj_is_ztilemap?
  673.   #--------------------------------------------------------------------------
  674.   def obj_is_ztilemap?(obj)
  675.     defined?(ZTilemap) && obj.is_a?(ZTilemap)
  676.   end
  677.   #--------------------------------------------------------------------------
  678.   # * Aliased Method : dispose
  679.   #--------------------------------------------------------------------------
  680.   def dispose
  681.     dispose_multi_layer
  682.     dispose_multi_layer_cr
  683.     [dispose_fog, dispose_panorama] rescue nil unless @@rpgmakerxp
  684.   end
  685.   #--------------------------------------------------------------------------
  686.   # * Aliased Method : reload_tilemap
  687.   #--------------------------------------------------------------------------
  688.   def reload_tilemap
  689.     reload_tilemap_multi_layer_cr      
  690.     create_multi_layer
  691.   end
  692.   #--------------------------------------------------------------------------
  693.   # * New Method : tilemap_move_multiplier
  694.   #--------------------------------------------------------------------------
  695.   def tilemap_move_multiplier
  696.     n = 1.00 / 4
  697.     n = 1.00 / 8  if LiTTleDRAgo::VX
  698.     n = 1.00 * 32 if LiTTleDRAgo::VXA
  699.     return n
  700.   end  
  701.   #--------------------------------------------------------------------------
  702.   # * New Method : update_panorama
  703.   #--------------------------------------------------------------------------
  704.   unless method_defined?(:update_panorama)
  705.     def update_panorama
  706.       if @panorama.nil?
  707.         @panorama = Plane.new(@viewport1)
  708.         @panorama.opacity = (@@panorama_opacity ||= 0)
  709.         @panorama.z = -1000
  710.       end
  711.       if @panorama_name != $game_map.panorama_name or
  712.           @panorama_hue != $game_map.panorama_hue
  713.         @panorama_name = $game_map.panorama_name
  714.         @panorama_hue = $game_map.panorama_hue
  715.         if @panorama.bitmap.respond_to?(:dispose) &&
  716.           @panorama.bitmap.not.disposed?
  717.           @panorama.bitmap.dispose
  718.           @panorama.bitmap = nil
  719.         end
  720.         if @panorama_name != ''
  721.           @panorama.bitmap =
  722.                 LiTTleDRAgo.cache.panorama(@panorama_name, @panorama_hue)
  723.         end
  724.         Graphics.frame_reset
  725.       end
  726.     end
  727.   end
  728.   #--------------------------------------------------------------------------
  729.   # * New Method : update_fog
  730.   #--------------------------------------------------------------------------  
  731.   unless method_defined?(:update_fog)
  732.     def update_fog
  733.       if @fog.nil?
  734.         @fog = Plane.new(@viewport1)
  735.         @fog.opacity = (@@fog_opacity ||= 0)
  736.         @fog.z = 3000
  737.       end
  738.       if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
  739.         @fog_name = $game_map.fog_name
  740.         @fog_hue  = $game_map.fog_hue
  741.         if @fog.bitmap.respond_to?(:dispose) && @fog.bitmap.not.disposed?
  742.           @fog.bitmap.dispose
  743.           @fog.bitmap = nil
  744.         end
  745.         if @fog_name != ''
  746.           @fog.bitmap = LiTTleDRAgo.cache.fog(@fog_name, @fog_hue)
  747.         end
  748.         Graphics.frame_reset
  749.       end
  750.     end
  751.   end
  752.   #--------------------------------------------------------------------------
  753.   # * New Method : update_panorama_plane
  754.   #--------------------------------------------------------------------------
  755.   unless method_defined?(:update_panorama_plane)
  756.     def update_panorama_plane
  757.       @panorama.ox = $game_map.display_x / 8
  758.       @panorama.oy = $game_map.display_y / 8
  759.     end
  760.   end
  761.   #--------------------------------------------------------------------------
  762.   # * New Method : update_fog_plane
  763.   #--------------------------------------------------------------------------
  764.   unless method_defined?(:update_fog_plane)
  765.     def update_fog_plane
  766.       @fog.zoom_x = $game_map.fog_zoom / 100.0
  767.       @fog.zoom_y = $game_map.fog_zoom / 100.0
  768.       @fog.opacity = $game_map.fog_opacity
  769.       @fog.blend_type = $game_map.fog_blend_type
  770.       @fog.ox = $game_map.display_x*tilemap_move_multiplier + $game_map.fog_ox
  771.       @fog.oy = $game_map.display_y*tilemap_move_multiplier + $game_map.fog_oy
  772.       @fog.tone = $game_map.fog_tone
  773.     end
  774.   end
  775.   #--------------------------------------------------------------------------
  776.   # * New Method : dispose_fog
  777.   #--------------------------------------------------------------------------
  778.   unless method_defined?(:dispose_fog)
  779.     def dispose_fog
  780.       unless @fog.nil? || @fog.disposed?
  781.         @@fog_opacity = @fog.opacity
  782.         @fog.dispose
  783.       end
  784.     end
  785.   end
  786.   #--------------------------------------------------------------------------
  787.   # * New Method : dispose_panorama
  788.   #--------------------------------------------------------------------------
  789.   unless method_defined?(:dispose_panorama)
  790.     def dispose_panorama
  791.       unless @panorama.nil? || @panorama.disposed?
  792.         @@panorama_opacity = @panorama.opacity
  793.         @panorama.dispose
  794.       end
  795.     end
  796.   end
  797. end
  798. #==============================================================================
  799. # ** RPG::Cache
  800. #==============================================================================
  801. ModCache = LiTTleDRAgo.cache
  802. module ModCache
  803.   #----------------------------------------------------------------------------
  804.   # * Self
  805.   #----------------------------------------------------------------------------
  806.   class << self
  807.     #--------------------------------------------------------------------------
  808.     # * Get Autotile Graphic
  809.     #--------------------------------------------------------------------------
  810.     unless method_defined?(:autotile)
  811.       def autotile(filename)
  812.         load_bitmap("Graphics/Autotiles/", filename)
  813.       end
  814.     end
  815.     #--------------------------------------------------------------------------
  816.     # * Get Panorama Graphic
  817.     #--------------------------------------------------------------------------
  818.     unless method_defined?(:panorama)
  819.       def panorama(filename, hue = 0)
  820.         load_bitmap("Graphics/Panoramas/", filename, hue)
  821.       end
  822.     end
  823.     #--------------------------------------------------------------------------
  824.     # * Get Fog Graphic
  825.     #--------------------------------------------------------------------------
  826.     unless method_defined?(:fog)
  827.       def fog(filename, hue = 0)
  828.         load_bitmap("Graphics/Fogs/", filename, hue)
  829.       end
  830.     end
  831.   end
  832. end



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



RUBY 代码复制
  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. # -----------------------------------------------------------------------------
  136. # Below is the available command in this script
  137. # -----------------------------------------------------------------------------
  138. # * Graphics
  139. # -----------------------------------------------------------------------------
  140. # -----------------------------------------------------------------------------
  141.   This command is not recommended to used in RMXP
  142.  
  143.   Graphics.scale_screen(width,height)
  144.   - Resize the screen and stretched it (if not RMXP) into new resolution
  145.  
  146.   Graphics.fill_monitor
  147.   - Maximize the screen and stretched it (if not RMXP) to fill the monitor
  148.  
  149.   Graphics.control_screen_size(enable = true)
  150.   - Enable or disable screen size control by mouse.
  151.     Resized screen will be stretched (if not RMXP)
  152. # -----------------------------------------------------------------------------
  153.  
  154.   Graphics.width        - Returns screen width
  155.   Graphics.height       - Returns screen height
  156.   Graphics.fullscreen?  - Returns true if Game in fullscreen mode, else false
  157.   Graphics.fullscreen   - Switch to fullscreen mode
  158.   Graphics.window       - Switch to windowed mode
  159.   Graphics.toggle       - Switch between fullscreen mode and windowed mode
  160.   Graphics.wait(frame)    - Wait for frame
  161.   Graphics.wait_for_input - Wait until input is pressed
  162.   Graphics.fadein(frame)  - Fade in the screen
  163.   Graphics.fadeout(frame) - Fade out the screen
  164.   Graphics.snap_to_bitmap - Snap screen to a bitmap object
  165.  
  166.   Graphics.high_priority = true/false - Change process priority to high / normal
  167.   Graphics.disable_alt_enter  - Disable input ALT+Enter (until game is closed)
  168.  
  169. # -----------------------------------------------------------------------------
  170. # * Module
  171. # -----------------------------------------------------------------------------
  172.   Module#attr_sec_reader(symbol, default=0)
  173.   - Create attr_reader with default value
  174.      Example : attr_sec_reader :something, "Sprite.new"
  175.      Equal : def something
  176.                @something ||= Sprite.new
  177.              end
  178.              
  179.   Module#attr_sec_accessor(symbol, *a, &block)
  180.   - Create (sheer of) attr_accessor with default value
  181.      Example : attr_sec_accessor :sprite1, :sprite2, :sprite3, "Sprite.new"
  182.      Equal : attr_writer :sprite1, :sprite2, :sprite3
  183.              attr_sec_reader :sprite1, "Sprite.new"
  184.              attr_sec_reader :sprite2, "Sprite.new"
  185.              attr_sec_reader :sprite3, "Sprite.new"
  186.  
  187.   Module#alias_sec_method(sym = nil, *a, &block)
  188.   - Create alias only if alias name is not defined and target method is exist
  189.      Example : alias_sec_method :alias_method, :target_method
  190.      Equal : if method_defined?(:target) && !method_defined?(:alias)
  191.                alias_method :alias, :target
  192.              end
  193.              
  194.   Module#define_sec_method(sym = nil, *a, &block)
  195.   - Define method only if the method is not defined
  196.      Example : define_sec_method(:some_method) { |*a| block }
  197.      Equal : unless method_defined?(:some_method)
  198.                def some_method(*a)
  199.                  block
  200.                end
  201.              end
  202.  
  203. # -----------------------------------------------------------------------------
  204. # * Array
  205. # -----------------------------------------------------------------------------
  206.   Array Method Distributor
  207.   - Distribute unexisted method in array into each variable
  208.   (will work only if the method isn't exist in Array)
  209.     Example : [Graphics,Input].update
  210.                 # equal => Graphics.update ; Input.update  
  211.               [@string1,@string2,@integer1,@sprite].dispose
  212.                 # equal => @sprite.dispose
  213.                 # (all variable without dispose method is ignored)
  214.               [@string1,@string2,@integer1].dispose
  215.                 # Throws NoMethodError if all method didn't have dispose method
  216.  
  217.   Array#random_each / Array#random_each_with_index
  218.     Example : a = [1,2,3,4,5,6,7]
  219.               a.random_each {|i| puts i} # 4,5,3,2,7,1,6
  220.              
  221.   Array#sum
  222.   Array#prod
  223.   Array#average
  224.     Example : [1,2,3,4].sum         # 10  (1+2+3+4)
  225.               [1,2,3,4].average     # 2.5 (10 / 4)
  226.               [1,2,3,4].prod        # 24  (1*2*3*4)
  227.              
  228.   Array#shuffle / Array#shuffle!  
  229.     Example : [1,2,3,4].shuffle     # [3,2,4,1]  
  230.     
  231.   Array#random / Array#random!
  232.     Example : [1,2,3,4].random      # 3  
  233.  
  234.   Array#switch=(true/false)
  235.   Array#switch_reverse
  236.   - Turn on / off switches all variable in the array
  237.     (will ignored if variable not integer or not an array)
  238.     Example : [1,2,[3,2,'A'],5].switch = true
  239.                 # equal => $game_switches[1] = true
  240.                            $game_switches[2] = true
  241.                            $game_self_switches[[3,2,'A']] = true
  242.                            $game_switches[5] = true
  243.                            
  244.   Array#variable(value = nil, method = "=")   
  245.   - Change all variable value in the array (ignored if variable not integer)
  246.     Example : [1,2,5].variable(10)
  247.                 # equal => $game_variables[1] = 10
  248.                            $game_variables[2] = 10
  249.                            $game_variables[5] = 10
  250.     Example : [1,2,5].variable(10, "+=")
  251.                 # equal => $game_variables[1] += 10
  252.                            $game_variables[2] += 10
  253.                            $game_variables[5] += 10
  254.                            
  255.   Array#have_all?(array)
  256.   - returns true if contains all elements of the array               
  257.   Array#have_any?(array)
  258.   - returns true if contains any elements of the array   
  259. # -----------------------------------------------------------------------------
  260. # * Sprite
  261. # -----------------------------------------------------------------------------
  262.   Sprite#clone
  263.   Sprite#dup
  264.   - Clone sprite without "can't clone sprite error"
  265.     Example : a = Sprite.new
  266.               b = a.clone
  267.               a.dispose
  268.               print a.disposed? # true
  269.               print b.disposed? # false
  270.              
  271. # -----------------------------------------------------------------------------
  272. # * Spriteset_Map
  273. # -----------------------------------------------------------------------------
  274.   Spriteset_Map#sprite_player
  275.   - returns sprite player at @character_sprites in Spriteset_Map
  276.  
  277.   Spriteset_Map#find_character(character)
  278.   - returns character sprite at @character_sprites in Spriteset_Map
  279.  
  280. # -----------------------------------------------------------------------------
  281. # * Game Battler
  282. # -----------------------------------------------------------------------------
  283.   Game_Battler#hp_percent(integer = false, float_points = 2)
  284.   Game_Battler#sp_percent(integer = false, float_points = 2)
  285.   Example : $game_actors[1].hp_percent
  286.                    # returns 0 - 100 based on percentage hp
  287.                    
  288. # -----------------------------------------------------------------------------
  289. # * Bitmap
  290. # -----------------------------------------------------------------------------
  291.   Bitmap#export(filename)
  292.   - exporting bitmap into a file (only support bmp and png)
  293.   Example : bitmap = Bitmap.new(50,20)
  294.             bitmap.export('empty.png')
  295.             
  296.   Bitmap#flip_vertical
  297.   Bitmap#flip_vertical!
  298.   Bitmap#flip_horizontal
  299.   Bitmap#flip_horizontal!
  300.   - flip the bitmap vertically or horizontally (using ! will modify self)
  301.   Example : bitmap = Bitmap.new(50,20)
  302.             bitmap.flip_vertical!
  303.             
  304.   Bitmap#rotate90
  305.   Bitmap#rotate90!
  306.   Bitmap#rotate180
  307.   Bitmap#rotate180!
  308.   Bitmap#rotate270         
  309.   Bitmap#rotate270!            
  310.        
  311.   Additional Bitmap Effects
  312.   Note : calling this method is process consuming, use with caution
  313.     Bitmap#invert
  314.     Bitmap#invert!
  315.     Bitmap#brighten(amount = 10)
  316.     Bitmap#brighten!(amount = 10)
  317.     Bitmap#darken(amount = 10)
  318.     Bitmap#darken!(amount = 10)
  319.     Bitmap#grayscale
  320.     Bitmap#grayscale!
  321.     Bitmap#pixelate(size = 10)
  322.     Bitmap#pixelate!(size = 10)
  323.     Bitmap#frost(noise = 10)
  324.     Bitmap#frost!(noise = 10)
  325. # -----------------------------------------------------------------------------
  326. # * Color
  327. # -----------------------------------------------------------------------------
  328.   Color RGB value shortcut
  329.   List :
  330.     Color.red
  331.     Color.green
  332.     Color.blue
  333.     Color.white
  334.     Color.black
  335.     Color.yellow
  336.     Color.magenta
  337.     Color.cyan
  338.     Color.purple
  339.     Color.gray
  340.     Color.lightgray
  341.     Color.darkgray
  342.     Color.pink
  343.     Color.orange
  344.     Color.brown
  345.     Color.golden
  346.     
  347.     Color.invert
  348.     
  349.   Color Hex
  350.   - You can use hex value as method in color class (not case sensitive)
  351.     (need to include 'x' in front)
  352.   Example : Color.xffffff, Color.x04dacf, etc
  353.  
  354.  
  355. # -----------------------------------------------------------------------------
  356. # * Game_Map
  357. # -----------------------------------------------------------------------------
  358.  
  359.   Game_Map#load_event(mapid, eventid, x, y, page_id)
  360.   Game_Map#load_event(mapid, eventid, x, y)
  361.   Game_Map#load_event(eventid, x, y)   # map_id will be assumed as current map
  362.   - Duplicate an event from another map to current map at position (x, y)
  363.  
  364.   Game_Map#call_event(mapid, eventid, page_id)
  365.   Game_Map#call_event(mapid, eventid)  # page_id will be assumed as -1
  366.   Game_Map#call_event(eventid)         # map_id will be assumed as current map
  367.   - Call an event from another map to current map
  368.       Note that page_id is start from 1, not 0
  369.       If you're using RMVX or RMVXA, setting page_id to -1 will bring you to
  370.       the page with met condition.
  371.       
  372.       
  373. # -----------------------------------------------------------------------------
  374. # * RTP fix
  375. # -----------------------------------------------------------------------------
  376.  
  377.   Longer script call
  378.   - You can stack script call next to each other as many as possible and they
  379.     will be connected.
  380.   - In addition, this also fixes the Interpreter Script call bug when if you
  381.     use $game_system..... = false, game would freeze. This will prevent that.
  382.  
  383. # -----------------------------------------------------------------------------
  384. # * End Documentation
  385. # -----------------------------------------------------------------------------
  386. =end
  387. # =============================================================================
  388.  
  389. #==============================================================================
  390. # ** Module     
  391. #------------------------------------------------------------------------------
  392. #  
  393. #==============================================================================
  394.  
  395. class Module
  396.   #-------------------------------------------------------------------------
  397.   # * New method: attr_sec_reader (Attr Secondary Reader)
  398.   #-------------------------------------------------------------------------
  399.   unless method_defined?(:attr_sec_reader)
  400.     def attr_sec_reader(*sym)
  401.       if (1..2) === sym.size
  402.         module_eval("define_method(:#{sym[0]}) { @#{sym[0]} ||= #{sym[1]||0}}")
  403.       elsif sym.size > 2
  404.         (default = sym.pop) && sym.each {|s| attr_sec_reader(s,default)}
  405.       end
  406.     end
  407.   end
  408.   #-------------------------------------------------------------------------
  409.   # * New method: attr_sec_accessor (Attr Secondary Accessor)
  410.   #-------------------------------------------------------------------------
  411.   def attr_sec_accessor(sym = nil, *args)
  412.     (args.size > 0) | sym.nil? || args.push(0)
  413.     (default = args.pop) && (b = [sym].concat(args).compact)
  414.     (b).each {|a| (attr_writer(a) || 0) && attr_sec_reader(a,default)}
  415.   end
  416.   #-------------------------------------------------------------------------
  417.   # * New method: alias_sec_method (Alias Secondary Method)
  418.   #   Note : This method will create alias only if alias name is not defined
  419.   #          and target alias is exist
  420.   #-------------------------------------------------------------------------
  421.   unless method_defined?(:alias_sec_method)
  422.     private
  423.     def alias_sec_method(sym = nil, *args)
  424.       (args.size > 0) | sym.nil? || args.clear
  425.       (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
  426.         c = (t == :initialize ? true : method_defined?(t))
  427.         method_defined?(a) || (c && alias_method(a, t))
  428.       end
  429.     end
  430.   end
  431.   #-------------------------------------------------------------------------
  432.   # * New method: redirect_method
  433.   #-------------------------------------------------------------------------
  434.   unless method_defined?(:redirect_method)
  435.     private
  436.     def redirect_method(sym = nil, *args, &block)
  437.       (args.size > 0) | sym.nil? || args.clear
  438.       (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
  439.         meth = "def #{a}[*args] #{t}(*args) end"
  440.         meth.gsub!(/(['")}\](\d+)])\(\*args\)/i)  {    $1     }#'
  441.         meth.gsub!(/\[\*args\]/i)                 { '(*args)' }
  442.         method_defined?(a) || module_eval(meth)
  443.       end
  444.     end
  445.   end
  446.   #-------------------------------------------------------------------------
  447.   # * New method: define_sec_method
  448.   #   Note : This method will not defining method if method name already
  449.   #          exist
  450.   #-------------------------------------------------------------------------
  451.   unless method_defined?(:define_sec_method)
  452.     private
  453.     def define_sec_method(sym = nil, *args, &block)
  454.       sym && (method_defined?(s = sym.to_sym) || define_method(s,*args,&block))
  455.     end
  456.   end
  457.   #-------------------------------------------------------------------------
  458.   # * New method: define_third_method
  459.   #   Note : After aliasing, define a method
  460.   #-------------------------------------------------------------------------
  461.   unless method_defined?(:define_third_method)
  462.     private
  463.     def define_third_method(sym = nil, _alias = nil, *args, &block)
  464.       unless sym.nil? || _alias.nil?
  465.         stack = _alias.to_s =~ /stack/i || sym.to_s == 'initialize'
  466.         stack = (!stack && method_defined?(_alias.to_sym))
  467.         stack || alias_method(_alias.to_sym, sym.to_sym)
  468.         define_method(sym.to_sym,*args,&block)
  469.       end
  470.     end
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # ● New method: define_pre_alias
  474.   #--------------------------------------------------------------------------
  475.   unless method_defined?(:define_pre_method)
  476.     private
  477.     def define_pre_alias(sym = nil, *args, &block)
  478.       _time = Time.now
  479.       _alias = :"#{sym}_#{_time.to_i}_#{_time.usec}"
  480.       define_third_method(:"#{sym}",_alias) do  |*args|
  481.         block.bind(self).call
  482.         send(_alias,*args)
  483.       end
  484.     end
  485.     private
  486.     def define_post_alias(sym = nil, *args, &block)
  487.       _time = Time.now
  488.       _alias = :"#{sym}_#{_time.to_i}_#{_time.usec}"
  489.       define_third_method(:"#{sym}",_alias) do  |*args|
  490.         send(_alias,*args)
  491.         block.bind(self).call
  492.       end
  493.     end
  494.   end
  495.   #--------------------------------------------------------------------------
  496.   # ● New method: include_auto_update
  497.   #--------------------------------------------------------------------------
  498.   unless method_defined?(:include_auto_update)
  499.     private
  500.     def include_auto_update
  501.       return if method_defined?(:update_auto_update)
  502.       attr_sec_accessor(:auto_update, "[]")
  503.       define_method(:update_auto_update) do
  504.         return if auto_update.empty?
  505.         auto_update.each do |x|
  506.           (x[1].nil? ? send(x[0]) : (x[2].nil? ? x[0].method(x[1]).call :
  507.           (x[0].method(x[1]).call(*x[2]))))
  508.           (x[3].is_a?(Numeric) && (x[3] -= 1))
  509.         end   
  510.         auto_update.reject! {|x| x[3].is_a?(Numeric) && x[3] <= 0 }
  511.       end
  512.       _time = Time.now
  513.       _alias = :"update_#{_time.to_i}_#{_time.usec}"
  514.       define_third_method(:update,_alias) do  |*args|
  515.         send(_alias,*args)
  516.         update_auto_update
  517.       end
  518.     end
  519.   end  
  520. end
  521. #==============================================================================
  522. # ** LiTTleDRAgo     
  523. #------------------------------------------------------------------------------
  524. #  
  525. #==============================================================================
  526.  
  527. module LiTTleDRAgo
  528.   #-------------------------------------------------------------------------
  529.   # * Constant
  530.   #-------------------------------------------------------------------------
  531.   VX            = defined?(Window_ActorCommand)
  532.   VXA           = defined?(Window_BattleActor)
  533.   XP            = !VX
  534.   RGSS1         = defined?(Hangup)
  535.   RGSS2         = RUBY_VERSION == '1.8.1' && !RGSS1
  536.   RGSS3         = RUBY_VERSION == '1.9.2'  
  537.   APPPATHDRAGO  = "#{ENV['APPDATA']}/Drago/"
  538. end
  539. #==============================================================================
  540. # ** CoreDLL
  541. #------------------------------------------------------------------------------
  542. #  
  543. #==============================================================================
  544. module CoreDLL
  545.   #-------------------------------------------------------------------------
  546.   # * Constant
  547.   #-------------------------------------------------------------------------
  548.   DLL_USED = ['kernel32','msvcrt','user32','gdi32']
  549.   SCENEVXA = "SceneManager.send(:instance_variable_set,:@scene,args.at(0))"
  550.   L        = LiTTleDRAgo
  551.   #-------------------------------------------------------------------------
  552.   # * Public Instance Variables
  553.   #-------------------------------------------------------------------------
  554.   attr_sec_reader :rtlmemory_pi,  "winapi(0,'RtlMoveMemory','pii','i')"
  555.   attr_sec_reader :rtlmemory_ip,  "winapi(0,'RtlMoveMemory','ipi','i')"
  556.   attr_sec_reader :setpriority,   "winapi(0,'SetPriorityClass','pi','i')"
  557.   attr_sec_reader :getprocesstime,"winapi(0,'GetProcessTimes','ipppp','i')"
  558.   attr_sec_reader :getdc,         "winapi(2,'GetDC','i','i')"
  559.   attr_sec_reader :releasedc,     "winapi(2,'ReleaseDC','ii','i')"
  560.   attr_sec_reader :reghotkey,     "winapi(2,'RegisterHotKey', 'liii', 'i')"
  561.   attr_sec_reader :sendinput,     "winapi(2,'SendInput','ipi','i')"
  562.   attr_sec_reader :setwindowlong, "winapi(2,'SetWindowLong','lll','l')"
  563.   attr_sec_reader :getkeysta,     "winapi(2,'GetKeyboardState','p','i')"
  564.   attr_sec_reader :getkeylay,     "winapi(2,'GetKeyboardLayout','l','l')"
  565.   attr_sec_reader :mapvirkey,     "winapi(2,'MapVirtualKeyEx','iil','i')"
  566.   attr_sec_reader :tounicode,     "winapi(2,'ToUnicodeEx','llppill','l')"
  567.   attr_sec_reader :screentoclient,"winapi(2,'ScreenToClient', 'lp', 'i')"
  568.   attr_sec_reader :cursorposition,"winapi(2,'GetCursorPos', 'p', 'i')"
  569.   attr_sec_reader :systemmetrix,  "winapi(2,'GetSystemMetrics', %w(i), 'i')"
  570.   attr_sec_reader :bitblt,        "winapi(3,'BitBlt','iiiiiiiii','i')"
  571.   attr_sec_reader :ccdc,          "winapi(3,'CreateCompatibleDC','i','i')"
  572.   attr_sec_reader :ccbitmap,      "winapi(3,'CreateCompatibleBitmap','iii','i')"
  573.   attr_sec_reader :deleteobject,  "winapi(3,'DeleteObject','i','i')"
  574.   attr_sec_reader :getbitmapbits, "winapi(3,'GetBitmapBits','llp','l')"
  575.   attr_sec_reader :getdibits,     "winapi(3,'GetDIBits','iiiiipi','i')"
  576.   attr_sec_reader :setdibits,     "winapi(3,'SetDIBits','iiiiipi','i')"
  577.   attr_sec_reader :selectobject,  "winapi(3,'SelectObject','ii','i')"
  578.   attr_sec_reader :getpixel,      "winapi(3,'GetPixel','iii','i')"
  579.   attr_sec_reader :setpixel,      "winapi(3,'SetPixel','liil','l')"  
  580.   attr_sec_reader :disabled_key,  "Array.new"
  581.   attr_sec_reader :high_priority, 'false'
  582.   #-------------------------------------------------------------------------
  583.   # * Define Secondary Listing
  584.   #-------------------------------------------------------------------------
  585.   define_sec_method(:disable_alt_enter) { disable_keys(0x0D) }
  586.   define_sec_method(:fullscreen?) { systemmetrix.call(0) == Graphics.width }
  587.   define_sec_method(:fullscreen)  { self.fullscreen? || toggle }
  588.   define_sec_method(:window)      { self.fullscreen? && toggle }
  589.   #-------------------------------------------------------------------------
  590.   # * Redirect Listing
  591.   #-------------------------------------------------------------------------
  592.   redirect_method :cache,      L::VX  ? '(Cache)' : '(RPG::Cache)'
  593.   redirect_method :scene,      L::VXA ? '(SceneManager.scene)':'($scene)'
  594.   redirect_method :scene=,     L::VXA ? SCENEVXA : '($scene = args[0])'
  595.   #-------------------------------------------------------------------------
  596.   # * Enable change window size via mouse (border required)
  597.   #   Screen will not resized if RMXP
  598.   #-------------------------------------------------------------------------
  599.   def control_screen_size(enable = true)
  600.     hid = @hide_border ? 0x14000000 : 0x14CA0000
  601.     set = enable ? (0x10C70000|0x00080000) : hid
  602.     self.setwindowlong.call(self.hwnd,-16, set)
  603.   end
  604.   #-------------------------------------------------------------------------
  605.   # * Hide window border
  606.   #   Screen size can't be controlled via mouse
  607.   #-------------------------------------------------------------------------
  608.   def hide_borders
  609.      control_screen_size((@hide_border = true) && false)
  610.   end
  611.   #-------------------------------------------------------------------------
  612.   # * Show window border
  613.   #   Screen size can't be controlled via mouse
  614.   #-------------------------------------------------------------------------
  615.   def show_borders
  616.     control_screen_size((@hide_border = false))
  617.   end
  618.   #-------------------------------------------------------------------------
  619.   # * Disable Key
  620.   #-------------------------------------------------------------------------
  621.   def disable_keys(*keys)
  622.     keys.each do |key|
  623.       disabled_key.include?(key) || disabled_key.push(key)
  624.       self.reghotkey.call(self.hwnd, 1, 0x0001, key)
  625.     end
  626.   end
  627.   #-------------------------------------------------------------------------
  628.   # * Resize the screen (scaled)
  629.   #   Screen will not resized if RMXP
  630.   #-------------------------------------------------------------------------
  631.   def scale_screen(width, height)
  632.     width  += ((res = self.systemmetrix).call(5) + (res.call(45))) * 2
  633.     height += (res.call(6) + (res.call(46))) * 2 + res.call(4)
  634.     x = [(res.call(0) - width) / 2, 0].max
  635.     y = [(res.call(1) - height) / 2, 0].max
  636.     self.setwindowpos(self.hwnd,0,x,y,width,height,0)
  637.   end
  638.   #-------------------------------------------------------------------------
  639.   # * Scale the game.exe to fill the monitor
  640.   #   Screen will not resized if RMXP
  641.   #-------------------------------------------------------------------------
  642.   def fill_monitor
  643.     setwindowpos(hwnd,0,0,0,(res = systemmetrix).call(0),res.call(1),0)
  644.   end
  645.   #-------------------------------------------------------------------------
  646.   # * setwindowpos
  647.   #-------------------------------------------------------------------------
  648.   def setwindowpos(hwnd = self.hwnd,at = 0,x = 0,y = 0,
  649.       width = 640, height = 480, ni = 0)
  650.     @setwindowpos ||= winapi(2, 'SetWindowPos', 'liiiiip','i')
  651.     @setwindowpos.call(hwnd, at, x, y, width, height, ni)
  652.   end
  653.   #-------------------------------------------------------------------------
  654.   # * Toggle between fullscreen and windowed
  655.   #-------------------------------------------------------------------------
  656.   def toggle
  657.     @keybd ||= winapi(2, 'keybd_event', %w(i i l l), 'v')
  658.     [@keybd.call(0xA4, 0, 0, 0), @keybd.call(13, 0, 0, 0)  ]
  659.     [@keybd.call(13, 0, 2, 0),   @keybd.call(0xA4, 0, 2, 0)]
  660.   end
  661.   #-------------------------------------------------------------------------
  662.   # * Show FPS
  663.   #-------------------------------------------------------------------------
  664.   def show_fps
  665.     @show_fps ||= winapi(2, 'keybd_event', %w(l l l l), '')
  666.     @show_fps.call(0x71,0,0,0)
  667.     sleep(0.1)
  668.     @show_fps.call(0x71,0,2,0)
  669.   end
  670.   #-------------------------------------------------------------------------
  671.   # * Get the Game Window's width and height
  672.   #-------------------------------------------------------------------------
  673.   def client_size   
  674.     @window_c_rect ||= winapi(2, 'GetClientRect', %w(l p), 'i')
  675.     @window_c_rect.call(self.hwnd, (rect = [0, 0, 0, 0].pack('l4')))
  676.     right, bottom = rect.unpack('l4')[2..3]
  677.     return right, bottom
  678.   end  
  679.   #-------------------------------------------------------------------------
  680.   # * Get the game window handle (specific to game)
  681.   #-------------------------------------------------------------------------
  682.   def hwnd
  683.     @game_window ||= winapi(2, 'FindWindowEx', %w(l l p p), 'i').
  684.                             call(0,0,"RGSS Player",0)
  685.   end  
  686.   #-------------------------------------------------------------------------
  687.   # * always_on_top  (cannot be undone)
  688.   #-------------------------------------------------------------------------
  689.   def always_on_top
  690.     res = self.systemmetrix
  691.     width  = Graphics.width  + (res.call(5) + (res.call(45))) * 2
  692.     height = Graphics.height + (res.call(6) + (res.call(46))) * 2 + res.call(4)
  693.     x = [(res.call(0) - width) / 2, 0].max
  694.     y = [(res.call(1) - height) / 2, 0].max
  695.     self.setwindowpos(self.hwnd,-1,x,y,width,height,0x0200)
  696.   end
  697.   #-------------------------------------------------------------------------
  698.   # * Get the value of game.ini
  699.   #-------------------------------------------------------------------------
  700.   def read_ini(field, key, ini = 'Game.ini')
  701.     @gpps ||= winapi(0, 'GetPrivateProfileString', 'pppplp', 'l')
  702.     @gpps.call(field,key,"",result="\0"*256,256,".//#{ini}") rescue return ""
  703.     return result.delete!("\0")
  704.   end
  705.   #-------------------------------------------------------------------------
  706.   # * Data default extension
  707.   #-------------------------------------------------------------------------
  708.   def data_default_extension
  709.     data = read_ini('Game','Scripts')
  710.     data = data.split('.').last || 'rxdata'
  711.     return data
  712.   end
  713.   #-------------------------------------------------------------------------
  714.   # * High Priority (true/false)
  715.   #-------------------------------------------------------------------------
  716.   def high_priority=(value)
  717.     @high_priority = value && true
  718.     setpriority.call(-1, @high_priority ? 0x00000080 : 0x00000020)
  719.   end
  720.   #--------------------------------------------------------------------------
  721.   # * snap_to_bitmap
  722.   #--------------------------------------------------------------------------
  723.   def snap_to_bitmap
  724.     bitmap = Bitmap.new((w = client_size.at(0)),(h = client_size.at(1)))
  725.     info   = [40,w,h,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
  726.     hDC    = ccdc.call((dc = getdc.call(hwnd)))
  727.     deleteobject.call(selectobject.call(hDC, (hBM = ccbitmap.call(dc, w, h))))
  728.     setdibits.call(hDC, hBM, 0, h, (a = bitmap.address), info, 0)
  729.     bitblt.call(hDC, 0, 0, w, h, dc, 0, 0, 0xCC0020)
  730.     getdibits.call(hDC, hBM, 0, h, a, info, 0)
  731.     deleteobject.call(hBM)
  732.     deleteobject.call(hDC)
  733.     return bitmap
  734.   end                           
  735.   #-------------------------------------------------------------------------
  736.   # * Execute Win32API
  737.   #-------------------------------------------------------------------------
  738.   def winapi(*a)
  739.     Win32API.new(*((a[0].is_a?(Integer) ? a[0] = DLL_USED[a[0]] : a) && a))
  740.   end
  741.   #----------------------------------------------------------------------------
  742.   # * unicode_to_utf8
  743.   #  string - string in Unicode format
  744.   #  Converts a string from Unicode format to UTF-8 format as RGSS does not
  745.   #  support Unicode.
  746.   #----------------------------------------------------------------------------
  747.   def unicode_to_utf8(string)
  748.     result = ''
  749.     string.unpack('L*').each do |c|
  750.       if (c1 = c < 0x0080) || (c2 = c < 0x0800) || (c3 = c < 0x10000) ||
  751.         (c4 = c < 0x200000)|| (c5 = c < 0x4000000) || (c6 = c < 0x80000000)
  752.         result += c.chr                           if c1
  753.         result += (0xC0 | (c >> 6)).chr           if c2
  754.         result += (0xE0 | (c >> 12)).chr          if c3
  755.         result += (0xF0 | (c >> 18)).chr          if c4
  756.         result += (0xF8 | (c >> 24)).chr          if c5
  757.         result += (0xFC | (c >> 30)).chr          if c6
  758.         result += (0x80 | ((c >> 24) & 0x3F)).chr if c6
  759.         result += (0x80 | ((c >> 18) & 0x3F)).chr if c5 || c6
  760.         result += (0x80 | ((c >> 12) & 0x3F)).chr if c4 || c5 || c6
  761.         result += (0x80 | ((c >> 6) & 0x3F)).chr  if c3 || c4 || c5 || c6
  762.         result += (0x80 | (c & 0x3F)).chr         if c2 || c3 || c4 || c5 || c6
  763.       end
  764.     end
  765.     return result
  766.   end
  767. end                        
  768. LiTTleDRAgo.extend(CoreDLL)
  769.  
  770. #==============================================================================
  771. # ** RPG
  772. #------------------------------------------------------------------------------
  773. #  
  774. #==============================================================================
  775. module RPG
  776.   #============================================================================
  777.   # ** System
  778.   #----------------------------------------------------------------------------
  779.   #
  780.   #============================================================================
  781.   class System
  782.     #----------------------------------------------------------------------
  783.     # ● Class Variables
  784.     #----------------------------------------------------------------------
  785.     if (VX = LiTTleDRAgo::VX)
  786.       #------------------------------------------------------------------------
  787.       # ● Public Instance Variables
  788.       #------------------------------------------------------------------------
  789.       attr_accessor :magic_number,      :windowskin_name, :gameover_name
  790.       attr_accessor :battle_transition, :battleback_name, :title_name
  791.       #------------------------------------------------------------------------
  792.       # ● Redefined Methods
  793.       #------------------------------------------------------------------------
  794.       redirect_method :sounds,            "$data_system.sounds"
  795.       redirect_method :cursor_se,         "sounds[0]"
  796.       redirect_method :decision_se,       "sounds[1]"
  797.       redirect_method :cancel_se,         "sounds[2]"
  798.       redirect_method :buzzer_se,         "sounds[3]"
  799.       redirect_method :equip_se,          "sounds[4]"
  800.       redirect_method :save_se,           "sounds[5]"
  801.       redirect_method :load_se,           "sounds[6]"
  802.       redirect_method :battle_start_se,   "sounds[7]"
  803.       redirect_method :escape_se,         "sounds[8]"
  804.       if (VXA = LiTTleDRAgo::VXA)
  805.         redirect_method :shop_se,           "sounds[21]"
  806.         redirect_method :actor_collapse_se, "sounds[15]"
  807.       else
  808.         redirect_method :shop_se,           "sounds[17]"
  809.         redirect_method :actor_collapse_se, "sounds[13]"
  810.       end
  811.       redirect_method :enemy_collapse_se, "sounds[11]"
  812.       redirect_method :words,             "@words ||= RPG::System::Words.new()"
  813.       #------------------------------------------------------------------------
  814.       # ● Aliased Methods
  815.       #------------------------------------------------------------------------
  816.       alias_sec_method :battleback_name, :battleback1_name
  817.       alias_sec_method :title_name,      :title1_name      
  818.     end
  819.     #========================================================================
  820.     # ** Words
  821.     #------------------------------------------------------------------------
  822.     #
  823.     #========================================================================
  824.     class Words      
  825.       #----------------------------------------------------------------------
  826.       # ● New Methods
  827.       #----------------------------------------------------------------------
  828.       attr_sec_accessor :params,    !(VXA = LiTTleDRAgo::VXA) ? !VX ?
  829.                                     '[hp,sp,str,dex,agi,int]' :         # XP
  830.                                     '[hp,sp,atk,pdef,int,agi]' :        # VX
  831.                                     '[hp,sp,atk,pdef,int,mdef,agi,luk]' # VXA
  832.       attr_sec_accessor :weapon1,   VX && !VXA ? 'Vocab.weapon1' : "'Weapon 1'"
  833.       attr_sec_accessor :weapon2,   VX && !VXA ? 'Vocab.weapon2' : "'Weapon 2'"
  834.       attr_sec_accessor :status,    VX ? 'Vocab.status'          : "'Status'  "
  835.       attr_sec_accessor :save,      VX ? 'Vocab.save'            : "'Save'    "
  836.       attr_sec_accessor :game_end,  VX ? 'Vocab.game_end'        : "'Game End'"
  837.       attr_sec_accessor :fight,     VX ? 'Vocab.fight'           : "'Fight'   "
  838.       attr_sec_accessor :escape,    VX ? 'Vocab.escape'          : "'Escape'  "
  839.       attr_sec_accessor :new_game,  VX ? 'Vocab.new_game'        : "'New Game'"
  840.       attr_sec_accessor :continue,  VX ? 'Vocab.continue'        : "'Continue'"
  841.       attr_sec_accessor :shutdown,  VX ? 'Vocab.shutdown'        : "'Shutdown'"
  842.       attr_sec_accessor :to_title,  VX ? 'Vocab.to_title'        : "'To Title'"
  843.       attr_sec_accessor :cancel,    VX ? 'Vocab.cancel'          : "'Cancel'  "
  844.       #----------------------------------------------------------------------
  845.       # ● Redirect Listings
  846.       #----------------------------------------------------------------------
  847.       redirect_method :gold,   (VXA ? 'Vocab.currency_unit' : 'Vocab.gold')
  848.       redirect_method :hp,     'Vocab.hp'
  849.       redirect_method :sp,     'Vocab.mp'
  850.       redirect_method :str,    'String.new()'
  851.       redirect_method :dex,    'String.new()'
  852.       redirect_method :luk,    (VXA ? 'Vocab.param(7)' : 'String.new()')
  853.       redirect_method :agi,    (VXA ? 'Vocab.param(6)' : 'Vocab.agi')
  854.       redirect_method :int,    (VXA ? 'Vocab.param(4)' : 'Vocab.spi')
  855.       redirect_method :atk,    (VXA ? 'Vocab.param(2)' : 'Vocab.atk')
  856.       redirect_method :pdef,   (VXA ? 'Vocab.param(3)' : 'Vocab.def')
  857.       redirect_method :mdef,   (VXA ? 'Vocab.param(5)' : 'String.new()')
  858.       redirect_method :weapon, (VXA ? 'Vocab.etype(0)' : 'Vocab.weapon')
  859.       redirect_method :armor1, (VXA ? 'Vocab.etype(1)' : 'Vocab.armor1')
  860.       redirect_method :armor2, (VXA ? 'Vocab.etype(2)' : 'Vocab.armor2')
  861.       redirect_method :armor3, (VXA ? 'Vocab.etype(3)' : 'Vocab.armor3')
  862.       redirect_method :armor4, (VXA ? 'Vocab.etype(4)' : 'Vocab.armor4')
  863.       redirect_method :attack, 'Vocab.attack'
  864.       redirect_method :skill,  'Vocab.skill'
  865.       redirect_method :guard,  'Vocab.guard'
  866.       redirect_method :item,   'Vocab.item'
  867.       redirect_method :equip,  'Vocab.equip'
  868.     end
  869.   end
  870. end
  871. #==============================================================================
  872. # ** RPG_FileTest
  873. #------------------------------------------------------------------------------
  874. #
  875. #==============================================================================
  876. module RPG_FileTest
  877.   #--------------------------------------------------------------------------
  878.   # ● New method: self.exist?
  879.   #--------------------------------------------------------------------------
  880.   def self.exist?(filename)
  881.     dir,ext = File.dirname(filename) + '/', File.extname(filename)
  882.     base = File.basename(filename, ext)
  883.     if ['.png','.jpg','.bmp'].include?(ext.downcase)
  884.       cache = defined?(Cache) ? Cache : RPG::Cache
  885.       (cache.load_bitmap(dir,base) && true) rescue false
  886.     elsif ['.rxdata','.rvdata','.rvdata2','.rb','.txt'].include?(ext.downcase)
  887.       (load_data(filename) && true) rescue false
  888.     else
  889.       File.exist?(filename)
  890.     end
  891.   end
  892. end
  893.  
  894. #==============================================================================
  895. # ** Sound
  896. #------------------------------------------------------------------------------
  897. #  This module plays sound effects. It obtains sound effects specified in the
  898. # database from the global variable $data_system, and plays them.
  899. #==============================================================================
  900. module Sound;  end
  901. class << Sound
  902.   #------------------------------------------------------------------------
  903.   # ● New Method :se_play
  904.   #------------------------------------------------------------------------
  905.   unless method_defined?(:se_play)
  906.     def se_play(type)
  907.       system = ($game_system ||= Game_System.new)
  908.       case type
  909.       when :cursor         then system.se_play($data_system.cursor_se)
  910.       when :decision       then system.se_play($data_system.decision_se)
  911.       when :cancel         then system.se_play($data_system.cancel_se)
  912.       when :buzzer         then system.se_play($data_system.buzzer_se)
  913.       when :shop           then system.se_play($data_system.shop_se)
  914.       when :equip          then system.se_play($data_system.equip_se)
  915.       when :save           then system.se_play($data_system.save_se)
  916.       when :load           then system.se_play($data_system.load_se)
  917.       when :battle_start   then system.se_play($data_system.battle_start_se)
  918.       when :escape         then system.se_play($data_system.escape_se)
  919.       when :actor_collapse then system.se_play($data_system.actor_collapse_se)
  920.       when :enemy_collapse then system.se_play($data_system.enemy_collapse_se)
  921.       end
  922.     end
  923.   end
  924.   #--------------------------------------------------------------------------
  925.   # * Redefined Method
  926.   #--------------------------------------------------------------------------
  927.   define_sec_method(:play_cursor)         { se_play(:cursor)         }
  928.   define_sec_method(:play_decision)       { se_play(:decision)       }
  929.   define_sec_method(:play_cancel)         { se_play(:cancel)         }
  930.   define_sec_method(:play_buzzer)         { se_play(:buzzer)         }
  931.   define_sec_method(:play_equip)          { se_play(:equip)          }
  932.   define_sec_method(:play_save)           { se_play(:save)           }
  933.   define_sec_method(:play_load)           { se_play(:load)           }
  934.   define_sec_method(:play_battle_start)   { se_play(:battle_start)   }
  935.   define_sec_method(:play_escape)         { se_play(:escape)         }
  936.   define_sec_method(:play_enemy_collapse) { se_play(:enemy_collapse) }
  937.   define_sec_method(:play_actor_collapse) { se_play(:actor_collapse) }
  938.   define_sec_method(:play_shop)           { se_play(:shop)           }
  939.   #--------------------------------------------------------------------------
  940.   # * Alias Listing
  941.   #--------------------------------------------------------------------------
  942.   alias_sec_method :play_ok, :play_decision
  943. end
  944.  
  945. #==============================================================================
  946. # ** Game_System
  947. #------------------------------------------------------------------------------
  948. #  This class handles data surrounding the system. Backround music, etc.
  949. #  is managed here as well. Refer to "$game_system" for the instance of
  950. #  this class.
  951. #==============================================================================
  952. class Game_System
  953.   #--------------------------------------------------------------------------
  954.   # * Constant
  955.   #--------------------------------------------------------------------------
  956.   VX = LiTTleDRAgo::VX && !LiTTleDRAgo::VXA
  957.   #--------------------------------------------------------------------------
  958.   # * Public Instance Variable
  959.   #--------------------------------------------------------------------------
  960.   attr_sec_accessor :bgm_volume    , 100
  961.   attr_sec_accessor :bgs_volume    , 100
  962.   attr_sec_accessor :me_volume     , 100
  963.   attr_sec_accessor :se_volume     , 100
  964.   attr_sec_accessor :bgm_pitch     , 100
  965.   attr_sec_accessor :bgs_pitch     , 100
  966.   attr_sec_accessor :me_pitch      , 100
  967.   attr_sec_accessor :se_pitch      , 100
  968.   attr_sec_accessor :volume_control, 'false'
  969.   #--------------------------------------------------------------------------
  970.   # * Redefined method: bgm_memorize, bgm_restore
  971.   #--------------------------------------------------------------------------
  972.   VX && define_sec_method(:bgm_memorize) { @memorized_bgm = @playing_bgm }
  973.   VX && define_sec_method(:bgm_restore)  { bgm_play(@memorized_bgm)     }
  974.   #--------------------------------------------------------------------------
  975.   # * Redirect Listing
  976.   #--------------------------------------------------------------------------
  977.   redirect_method :bgm_stop,     'Audio.bgm_stop'
  978.   redirect_method :bgs_stop,     'Audio.bgs_stop'
  979.   redirect_method :se_stop,      'Audio.se_stop'
  980.   redirect_method :me_stop,      'Audio.me_stop'
  981.   #--------------------------------------------------------------------------
  982.   # * Alias Listing
  983.   #--------------------------------------------------------------------------
  984.   alias_sec_method :bgm_memorize, :save_bgm
  985.   alias_sec_method :bgm_restore,  :replay_bgm
  986.   alias_sec_method :save_bgm,     :bgm_memorize
  987.   alias_sec_method :replay_bgm,   :bgm_restore
  988.   #--------------------------------------------------------------------------
  989.   # * Aliased method: bgm_play, bgs_play, me_play, se_play
  990.   #--------------------------------------------------------------------------
  991.   [:bgm,:bgs,:me,:se].each do |sa|
  992.     next unless method_defined?(:"#{sa}_play")
  993.     alias_sec_method(:"drg_#{sa}_play", :"#{sa}_play")
  994.     define_method(:"#{sa}_play") do |bgm,*a|
  995.       if bgm.is_a?(String) && bgm != ''
  996.         bgm = RPG::AudioFile.new(bgm,send(:"#{sa}_volume"),send(:"#{sa}_pitch"))
  997.       elsif volume_control && bgm.is_a?(RPG::AudioFile) && bgm.name != ""
  998.         bgm = bgm.clone
  999.         bgm.volume = Math.percent(bgm.volume,send(:"#{sa}_volume"))
  1000.         bgm.pitch  = Math.percent(bgm.pitch,send(:"#{sa}_pitch"))
  1001.       end
  1002.       @playing_bgm = bgm if "#{sa}" == 'bgm'
  1003.       @playing_bgs = bgm if "#{sa}" == 'bgs'
  1004.       if respond_to?(:"drg_#{sa}_play")
  1005.         send(:"drg_#{sa}_play", bgm,*a)
  1006.       else
  1007.         if bgm.is_a?(RPG::AudioFile) && bgm.name != ''
  1008.           Audio.send(:"#{sa}_play","Audio/#{sa}/" + bgm.name,
  1009.              bgm.volume.round, bgm.pitch.round,*a)
  1010.         else
  1011.           send(:"#{sa}_stop")
  1012.         end
  1013.         Graphics.frame_reset
  1014.       end
  1015.     end
  1016.   end
  1017. end
  1018.  
  1019. #==============================================================================
  1020. # ** Object
  1021. #------------------------------------------------------------------------------
  1022. #  This class is superclass for all class
  1023. #==============================================================================
  1024. class Object
  1025.   #-------------------------------------------------------------------------
  1026.   # * New method: all_variable_dispose
  1027.   #-------------------------------------------------------------------------
  1028.   def all_variable_dispose
  1029.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  1030.     all.delete_if {|s| s.not.respond_to?(:dispose) }
  1031.     all.delete_if {|s| s.respond_to?(:disposed?) && s.disposed?}
  1032.     all.dispose
  1033.   end
  1034.   #-------------------------------------------------------------------------
  1035.   # * New method: rand_between
  1036.   #-------------------------------------------------------------------------
  1037.   unless method_defined?(:rand_between)
  1038.     def rand_between(min, max)
  1039.       min + rand(max - min + 1) if min.is_a?(Numeric) && max.is_a?(Numeric)
  1040.     end
  1041.   end
  1042.   #-------------------------------------------------------------------------
  1043.   # * New method: get_note
  1044.   #-------------------------------------------------------------------------
  1045.   unless method_defined?(:get_note)
  1046.     def get_note
  1047.       respond_to?(:note) ? note : ""
  1048.     end
  1049.   end
  1050.   #-------------------------------------------------------------------------
  1051.   # * New method: screen_rect
  1052.   #-------------------------------------------------------------------------
  1053.   unless method_defined?(:screen_rect)
  1054.     def screen_rect(as_rect = true)
  1055.       array = [0,0,Graphics.width,Graphics.height]
  1056.       as_rect ? Rect.new(*array) : array
  1057.     end
  1058.   end
  1059.   #-------------------------------------------------------------------------
  1060.   # * New method: forcesave
  1061.   #-------------------------------------------------------------------------
  1062.   unless method_defined?(:forcesave)
  1063.     def forcesave(index)
  1064.       return DataManager.save_game(index) if defined?(DataManager)
  1065.       save = LiTTleDRAgo::VX ? Scene_File.new(0,nil,0) : Scene_Save.new
  1066.       begin
  1067.         file = File.open(save.make_filename(index), "wb")
  1068.         (save.write_save_data(file) && file.close) || true
  1069.       rescue
  1070.         File.delete(save.make_filename(index)) rescue nil
  1071.         (Sound.play_buzzer) && false
  1072.       end
  1073.     end
  1074.   end
  1075.   #--------------------------------------------------------------------------
  1076.   # * sprite_report
  1077.   #--------------------------------------------------------------------------
  1078.   unless method_defined?(:script_report)
  1079.     def script_report(text,font = nil)
  1080.       s = (text.is_a?(String) || (text = text.inspect)) && Sprite.new
  1081.       s.opacity = (s.bitmap = Bitmap.new((g = Graphics).width,g.height)) && 0
  1082.       s.bitmap.font.name = ['Georgia',Font.default_name].flatten
  1083.       s.bitmap.font = (s.z += 9999) && (font || s.bitmap.font)
  1084.       y = (text.split(/\n/).size * s.bitmap.text_size(text).height) / 2
  1085.       s.bitmap.draw_enter_edging_text(0,0-y,g.width,g.height,text,1)
  1086.       (s.opacity += 10) && g.update until s.opacity >= 255
  1087.       g.wait_for_input
  1088.       (s.opacity -= 10) && g.update until s.opacity <= 0
  1089.       s.dispose
  1090.     end
  1091.   end
  1092.   #-------------------------------------------------------------------------
  1093.   # * New method: not
  1094.   #-------------------------------------------------------------------------
  1095.   define_sec_method(:not) { Not.new(self) }
  1096.   #============================================================================
  1097.   # ** Not
  1098.   #----------------------------------------------------------------------------
  1099.   #
  1100.   #============================================================================
  1101.   class Not
  1102.     #-------------------------------------------------------------------------
  1103.     # * Private
  1104.     #-------------------------------------------------------------------------
  1105.     private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ }
  1106.     #-------------------------------------------------------------------------
  1107.     # * Object Initialization
  1108.     #-------------------------------------------------------------------------
  1109.     define_method(:initialize) {|original|  @original = original }
  1110.     #-------------------------------------------------------------------------
  1111.     # * New method: method_missing
  1112.     #-------------------------------------------------------------------------
  1113.     def method_missing(sym, *a, &blk)
  1114.       !@original.send(sym, *a, &blk)
  1115.     end
  1116.   end
  1117. end
  1118.  
  1119. #==============================================================================
  1120. # ** Kernel
  1121. #------------------------------------------------------------------------------
  1122. #  
  1123. #==============================================================================
  1124. module Kernel
  1125.   #-------------------------------------------------------------------------
  1126.   # * Alias Listing
  1127.   #-------------------------------------------------------------------------
  1128.   $@ || alias_method(:carrot, :proc)
  1129.   #-------------------------------------------------------------------------
  1130.   # * Script Check
  1131.   #-------------------------------------------------------------------------
  1132.   if LiTTleDRAgo::XP && LiTTleDRAgo::RGSS3 && !defined?(XPA_CONFIG)
  1133.     $@ || alias_method(:last_before_p,        :p)
  1134.     $@ || alias_method(:last_before_print,    :print)
  1135.     $@ || alias_method(:last_before_msgbox,   :msgbox)
  1136.     $@ || alias_method(:last_before_msgbox_p, :msgbox_p)
  1137.     define_method(:p)       {|*args| last_before_msgbox_p(*args)}
  1138.     define_method(:print)   {|*args| last_before_msgbox(*args)  }
  1139.     define_method(:msgbox)  {|*args| last_before_print(*args)   }
  1140.     define_method(:msgbox_p){|*args| last_before_p(*args)       }
  1141.   end
  1142.   define_method(:draise) {|*args| (dp(*args) && !1) || exit }
  1143.   define_method(:dp)     {|*a| script_report(a.map {|i| i.inspect}.join("\n"))}
  1144.   #-------------------------------------------------------------------------
  1145.   # * New method: dprint
  1146.   #-------------------------------------------------------------------------
  1147.   def dprint(*args)
  1148.     script_report(args.map {|i| i.is_a?(String) ? i : i.inspect}.join)
  1149.   end
  1150.   #-------------------------------------------------------------------------
  1151.   # * New method: press_any_key
  1152.   #-------------------------------------------------------------------------
  1153.   unless method_defined?(:press_any_key)
  1154.     def press_any_key
  1155.       return false if Input.nil?
  1156.       return true if Input.trigger?(Input::A)    ||Input.trigger?(Input::B)
  1157.       return true if Input.trigger?(Input::C)    ||Input.trigger?(Input::X)
  1158.       return true if Input.trigger?(Input::Y)    ||Input.trigger?(Input::Z)
  1159.       return true if Input.trigger?(Input::L)    ||Input.trigger?(Input::R)
  1160.       return true if Input.trigger?(Input::UP)   ||Input.trigger?(Input::DOWN)
  1161.       return true if Input.trigger?(Input::LEFT) ||Input.trigger?(Input::RIGHT)
  1162.       return true if Input.trigger?(Input::SHIFT)||Input.trigger?(Input::CTRL)
  1163.       return true if Input.trigger?(Input::ALT)  ||Input.trigger?(Input::F5)
  1164.       return true if Input.trigger?(Input::F6)   ||Input.trigger?(Input::F7)
  1165.       return true if Input.trigger?(Input::F8)   ||Input.trigger?(Input::F9)
  1166.     end
  1167.   end
  1168.   #-------------------------------------------------------------------------
  1169.   # * New method: inspect_instance_variable
  1170.   #-------------------------------------------------------------------------
  1171.   unless method_defined?(:inspect_instance_variable)
  1172.     def inspect_instance_variable(class_name, variable)
  1173.       Module.const_get(class_name).new.instance_variable_get(:"@#{variable}")
  1174.     end
  1175.   end
  1176. end
  1177.  
  1178. #==============================================================================
  1179. # ** Proc
  1180. #------------------------------------------------------------------------------
  1181. #  
  1182. #==============================================================================
  1183. class Proc
  1184.   #-------------------------------------------------------------------------
  1185.   # * New method: bind
  1186.   #-------------------------------------------------------------------------
  1187.   unless method_defined?(:bind)
  1188.     def bind(object)
  1189.       block, time = self, Time.now
  1190.       class << object
  1191.         self
  1192.       end.class_eval do
  1193.         define_method((name = "__bind_#{time.to_i}_#{time.usec}"), &block)
  1194.         remove_method((method = instance_method(name)) && name)
  1195.         method
  1196.       end.bind(object)
  1197.     end
  1198.   end
  1199. end
  1200. #==============================================================================
  1201. # ** Enumerable
  1202. #------------------------------------------------------------------------------
  1203. #  
  1204. #==============================================================================
  1205. module Enumerable
  1206.   #---------------------------------------------------------------------------
  1207.   # * Redefined method: shuffle
  1208.   #---------------------------------------------------------------------------
  1209.   define_sec_method(:shuffle) {(a = entries) && Array.new(size){ a.random!}}
  1210.   #---------------------------------------------------------------------------
  1211.   # * New method: random_each
  1212.   #---------------------------------------------------------------------------
  1213.   unless method_defined?(:random_each)
  1214.     def random_each() (block_given? ? shuffle.each {|s| yield s } : random) end
  1215.   end
  1216.   #---------------------------------------------------------------------------
  1217.   # * New method: random_each_with_index
  1218.   #---------------------------------------------------------------------------
  1219.   unless method_defined?(:random_each_with_index)
  1220.     def random_each_with_index
  1221.       block_given? ? self.shuffle.each_with_index {|obj, i| yield obj,i } :
  1222.         self.random                                    
  1223.     end
  1224.   end
  1225.   #---------------------------------------------------------------------------
  1226.   # * Redefined method: drop_while
  1227.   #---------------------------------------------------------------------------
  1228.   unless method_defined?(:drop_while)
  1229.     def drop_while(&block)
  1230.       ary, state = [], false
  1231.       self.each do |e|
  1232.         state = true if !state and !block.call(e)
  1233.         ary << e if state
  1234.       end
  1235.       ary
  1236.     end
  1237.   end
  1238.   #---------------------------------------------------------------------------
  1239.   # * Redefined method: take_while
  1240.   #---------------------------------------------------------------------------
  1241.   unless method_defined?(:take_while)
  1242.     def take_while(&block)
  1243.       ary = []
  1244.       self.each do |e|
  1245.         return ary unless block.call(e)
  1246.         ary << e
  1247.       end
  1248.       ary
  1249.     end
  1250.   end
  1251.   #---------------------------------------------------------------------------
  1252.   # * Redefined method: partition
  1253.   #---------------------------------------------------------------------------
  1254.   unless method_defined?(:partition)
  1255.     def partition(&block)
  1256.       ary_T, ary_F = [], []
  1257.       self.each {|val| block.call(val) ? ary_T.push(val) : ary_F.push(val)}
  1258.       return ary_T, ary_F
  1259.     end
  1260.   end
  1261.   #---------------------------------------------------------------------------
  1262.   # * Redefined method: grep
  1263.   #---------------------------------------------------------------------------
  1264.   unless method_defined?(:grep)
  1265.     def grep(pattern, &block)
  1266.       collect {|v| pattern === v && ary.push((block)? block.call(v): v)}
  1267.     end
  1268.   end
  1269.   #---------------------------------------------------------------------------
  1270.   # * Redefined method: each_slice
  1271.   #---------------------------------------------------------------------------
  1272.   unless method_defined?(:each_slice)
  1273.     def each_slice(n, &block)
  1274.       not_integer = "expected Integer for 1st argument"
  1275.       n.is_a?(Integer) || raise(TypeError,not_integer,caller(1))
  1276.       n <= 0 && raise(ArgumentError, "invalid slice size",caller(1))
  1277.       ary = []
  1278.       self.each do |e|
  1279.         ary << e
  1280.         if ary.size == n
  1281.           block.call(ary)
  1282.           ary = []
  1283.         end
  1284.       end
  1285.       block.call(ary) unless ary.empty?
  1286.     end
  1287.   end
  1288.   #---------------------------------------------------------------------------
  1289.   # * Redefined method: minmax
  1290.   #---------------------------------------------------------------------------
  1291.   unless method_defined?(:minmax)
  1292.     def minmax(&block) (a = sort(&block)) && [a.first,a.last]  end
  1293.   end
  1294. end
  1295.  
  1296. #==============================================================================
  1297. # ** Array
  1298. #------------------------------------------------------------------------------
  1299. #  
  1300. #==============================================================================
  1301. class Array
  1302.   #---------------------------------------------------------------------------
  1303.   # * Define Secondary Listing
  1304.   #---------------------------------------------------------------------------
  1305.   define_sec_method(:have_all?)     { |*array| self & array == array        }
  1306.   define_sec_method(:have_any?)     { |*array| self - array != self         }
  1307.   define_sec_method(:relay)         { |type| map {|s| s.send(:"to_#{type}")}}
  1308.   #---------------------------------------------------------------------------
  1309.   # * Redirect method
  1310.   #---------------------------------------------------------------------------
  1311.   redirect_method :switch_on,      'self.switch = (true)'                  
  1312.   redirect_method :switch_off,     'self.switch = (false)'                  
  1313.   redirect_method :random,         'self.at(rand(size))'         
  1314.   redirect_method :random!,        'self.delete_at(rand(size))'
  1315.   redirect_method :sum,            'self.inject(0) {|r, n| r += n}'
  1316.   redirect_method :prod,           'self.inject(1) {|r, n| r *= n}'
  1317.   redirect_method :next_item,      '(item = shift) && push(item) &&  (item)'
  1318.   redirect_method :previous_item,  '(item = pop) && unshift(item) && (item)'
  1319.   redirect_method :nitems,         'count {|x| x.not.nil?}'
  1320.   redirect_method :switch_reverse, 'switch=(:flip)'
  1321.   #---------------------------------------------------------------------------
  1322.   # * New method: method_missing
  1323.   #---------------------------------------------------------------------------
  1324.   def method_missing(val,*a,&b)
  1325.     en = self.entries.find_all {|s|s.respond_to?(val.to_sym)}
  1326.     if self.not.empty? && en.empty?
  1327.       text = "Undefined method #{val} for #{self.inspect}"
  1328.       raise(NoMethodError,text,caller(1))
  1329.     end
  1330.     return en.map {|s| s.send(val.to_s,*a,&b)}
  1331.   end
  1332.   #-------------------------------------------------------------------------
  1333.   # * New method: each_ntuple
  1334.   #-------------------------------------------------------------------------
  1335.   unless method_defined?(:each_ntuple)
  1336.     def each_ntuple(number)
  1337.       0.step(size - size % number - 1, number) {|i| yield(*self[i, number])}
  1338.     end
  1339.   end
  1340.   #-------------------------------------------------------------------------
  1341.   # * New method: each_pair
  1342.   #-------------------------------------------------------------------------
  1343.   unless method_defined?(:each_pair)
  1344.     def each_pair()   each_ntuple(2) {|a,b| yield a, b }       end
  1345.   end
  1346.   #---------------------------------------------------------------------------
  1347.   # * New method: each_triple
  1348.   #---------------------------------------------------------------------------
  1349.   unless method_defined?(:each_triple)
  1350.     def each_triple() each_ntuple(3) {|a,b,c| yield a, b, c }  end
  1351.   end
  1352.   #---------------------------------------------------------------------------
  1353.   # * Redefined method: shuffle! (for RMXP)
  1354.   #---------------------------------------------------------------------------
  1355.   unless method_defined?(:shuffle!)
  1356.     def shuffle!()  self.dup == replace(shuffle) ? nil : self  end
  1357.   end
  1358.   #---------------------------------------------------------------------------
  1359.   # * New method: sort_by!
  1360.   #---------------------------------------------------------------------------
  1361.   unless method_defined?(:sort_by!)
  1362.     def sort_by!(*args,&block)
  1363.       self.dup == replace(sort_by(*args,&block)) ? nil : self
  1364.     end
  1365.   end
  1366.   #---------------------------------------------------------------------------
  1367.   # * New method: recursive_clone
  1368.   #---------------------------------------------------------------------------
  1369.   unless method_defined?(:rclone)
  1370.     def recursive_clone
  1371.       (clon = self.clone).each_index do |i|
  1372.         clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
  1373.       end
  1374.       clon
  1375.     end
  1376.     alias_method(:rclone, :recursive_clone)
  1377.   end
  1378.   #---------------------------------------------------------------------------
  1379.   # * New method: to_hash
  1380.   #---------------------------------------------------------------------------
  1381.   unless method_defined?(:to_hash)
  1382.     def to_hash
  1383.       (hash = Hash.new) && each_index {|i| hash[i] = self[i]} && hash
  1384.     end
  1385.   end  
  1386.   #---------------------------------------------------------------------------
  1387.   # * Redefined method: count
  1388.   #---------------------------------------------------------------------------
  1389.   unless method_defined?(:count)
  1390.     def count(*args, &block)
  1391.       if block_given?
  1392.         find_all {|s| block.call(s)}.size
  1393.       else
  1394.         ary = args.empty? ? self : args.map {|a| find_all{|s| s == a}}
  1395.         ary.compact.size
  1396.       end
  1397.     end
  1398.   end
  1399.   #---------------------------------------------------------------------------
  1400.   # * New method: each_with_next
  1401.   #---------------------------------------------------------------------------
  1402.   unless method_defined?(:each_with_next)
  1403.     def each_with_next(num = 1)
  1404.       (size - num).times {|i| yield(*self[i..(i+num)])}
  1405.     end
  1406.   end
  1407.   #---------------------------------------------------------------------------
  1408.   # * New method: switch=
  1409.   #---------------------------------------------------------------------------
  1410.   unless method_defined?(:switch=)
  1411.     def switch=(value)
  1412.       integer = search_var_key[0]
  1413.       array   = search_var_key[1]
  1414.       if value == :flip
  1415.         integer.each {|i| $game_switches[i] = !$game_switches[i] }
  1416.         array.each {|i| $game_self_switches[i] = !$game_self_switches[i] }
  1417.       else
  1418.         integer.each {|i| $game_switches[i] = value }
  1419.         array.each {|i| $game_self_switches[i] = value }
  1420.       end
  1421.       $game_map.need_refresh = true if $game_map.respond_to?(:need_refresh)
  1422.     end
  1423.   end
  1424.   #---------------------------------------------------------------------------
  1425.   # * New method: variable
  1426.   #---------------------------------------------------------------------------
  1427.   def variable(value = nil,method = "=")
  1428.     integer = search_var_key[0]  
  1429.     integer += search_var_key[1] if $drago_game_variable
  1430.     return integer.map {|i| $game_variables[i]} if value.nil?
  1431.     result = integer.map {|i| eval("$game_variables[i] #{method} #{value}") }
  1432.     $game_map.need_refresh = true if $game_map.respond_to?(:need_refresh)
  1433.     result
  1434.   end
  1435.   #---------------------------------------------------------------------------
  1436.   # * New method: search_var_key
  1437.   #---------------------------------------------------------------------------
  1438.   def search_var_key
  1439.     integer = self.find_all {|s| s.is_a?(Integer)}
  1440.     range   = self.find_all {|s| s.is_a?(Range)  }
  1441.     array   = self.find_all {|s| s.is_a?(Array)  }
  1442.     string  = self.find_all {|s| s.is_a?(String) }
  1443.     integer = integer + range.collect {|s| s.to_a }.flatten
  1444.     $game_switches      ||= Game_Switches.new
  1445.     $game_self_switches ||= Game_SelfSwitches.new
  1446.     $game_variables     ||= Game_Variables.new
  1447.     return [integer.sort.uniq, array.sort.uniq]
  1448.   end
  1449.   #---------------------------------------------------------------------------
  1450.   # * New method: rindexes
  1451.   #---------------------------------------------------------------------------
  1452.   unless method_defined?(:rindexes)
  1453.     def rindexes(*values)
  1454.       array = Array.new
  1455.       each_index {|i| values.include?(self[i]) && array.push(i)}
  1456.       array
  1457.     end
  1458.   end
  1459.   #---------------------------------------------------------------------------
  1460.   # * New method: deep
  1461.   #---------------------------------------------------------------------------
  1462.   unless method_defined?(:deep)
  1463.     def deep(deep = -1)
  1464.       tmp_deep = deep + 1
  1465.       deep = tmp_deep
  1466.       self.each do |i|
  1467.         deep < i.deep(tmp_deep) && deep = i.deep(tmp_deep)  rescue nil
  1468.       end
  1469.       deep
  1470.     end
  1471.   end
  1472.   #---------------------------------------------------------------------------
  1473.   # * New method: recursive_flatten
  1474.   #---------------------------------------------------------------------------
  1475.   unless method_defined?(:rflatten)
  1476.     def recursive_flatten
  1477.       (array = self.recursive_clone).each_index do |i|
  1478.         array[i] = array[i].to_a if array[i].is_a?(Hash)
  1479.         array[i] = array[i].recursive_flatten rescue array[i]
  1480.       end
  1481.       array.flatten!
  1482.       array
  1483.     end
  1484.     alias_method(:rflatten, :recursive_flatten)
  1485.   end
  1486.   #---------------------------------------------------------------------------
  1487.   # * New method: recursive_flatten!
  1488.   #---------------------------------------------------------------------------
  1489.   unless method_defined?(:rflatten!)
  1490.     def recursive_flatten!
  1491.       self.each_index do |i|
  1492.         self[i] = self[i].to_a if self[i].is_a?(Hash)
  1493.         self[i] = self[i].recursive_flatten! rescue self[i]
  1494.       end
  1495.       self.flatten!
  1496.       self
  1497.     end
  1498.     alias_method(:rflatten!, :recursive_flatten!)
  1499.   end
  1500.   #---------------------------------------------------------------------------
  1501.   # * Redefined method: product
  1502.   #---------------------------------------------------------------------------
  1503.   def dproduct(*arrays)
  1504.     (e = "(result = []) && self.each {|i0| ") &&
  1505.     (a = arrays.size).times {|i| e += "arrays[#{i}].each {|i#{i+1}| " }
  1506.     (e += "result.push([i0,") && a.times {|i| e += "i#{i+1}," }
  1507.     (e += "])}" + "}" * a + " && result"  )
  1508.     return eval(e)
  1509.   end
  1510.   alias_sec_method(:product, :dproduct)
  1511.   #---------------------------------------------------------------------------
  1512.   # * New method: geometric_average
  1513.   #---------------------------------------------------------------------------
  1514.   unless method_defined?(:geometric_average)
  1515.     def geometric_average(float = false)
  1516.       average = empty? ? 0 : prod ** (1.0 / size)
  1517.       return (float ? average : average.to_i)
  1518.     end
  1519.   end
  1520.   #---------------------------------------------------------------------------
  1521.   # * New method: average
  1522.   #---------------------------------------------------------------------------
  1523.   unless method_defined?(:average)
  1524.     def average(float = false)
  1525.       sum / [(float ? size.to_f : size.to_i), 1].max
  1526.     end
  1527.   end
  1528.   #---------------------------------------------------------------------------
  1529.   # * Alias method
  1530.   #---------------------------------------------------------------------------
  1531.   alias_sec_method :has_all?, :have_all?
  1532.   alias_sec_method :has_any?, :have_any?
  1533. end
  1534.  
  1535. #==============================================================================
  1536. # ** Hash
  1537. #------------------------------------------------------------------------------
  1538. #  
  1539. #==============================================================================
  1540. class Hash
  1541.   #--------------------------------------------------------------------------
  1542.   # * Define Secondary Listing
  1543.   #--------------------------------------------------------------------------
  1544.   define_sec_method(:reverse!)  { self.dup == replace(reverse) ? nil : self }
  1545.   #--------------------------------------------------------------------------
  1546.   # ● New method: reverse
  1547.   #--------------------------------------------------------------------------
  1548.   unless method_defined?(:reverse)
  1549.     def reverse
  1550.       key, new_hash = self.keys, {}
  1551.       key.reverse.each_with_index {|k,i| new_hash[k] = self[key[i]]}
  1552.       new_hash
  1553.     end
  1554.   end
  1555.   #--------------------------------------------------------------------------
  1556.   # ● New method: recursive_clone
  1557.   #--------------------------------------------------------------------------
  1558.   unless method_defined?(:rclone)
  1559.     def recursive_clone
  1560.       (clon = self.clone).each_key do |i|
  1561.         clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
  1562.       end
  1563.       clon
  1564.     end
  1565.     alias_method(:rclone, :recursive_clone)
  1566.   end
  1567.   #--------------------------------------------------------------------------
  1568.   # ● New method: deep
  1569.   #--------------------------------------------------------------------------
  1570.   unless method_defined?(:deep)
  1571.     def deep(deep = -1)
  1572.       key_deep = value_deep = tmp_deep = deep + 1
  1573.       self.each do |k, v|
  1574.         key_deep = k.deep(tmp_deep)  if key_deep  < k.deep(tmp_deep) rescue nil
  1575.         value_deep = v.deep(tmp_deep)if value_deep< v.deep(tmp_deep) rescue nil
  1576.       end
  1577.       key_deep > value_deep ? key_deep : value_deep
  1578.     end
  1579.   end
  1580.   #--------------------------------------------------------------------------
  1581.   # ● New method: fusion
  1582.   #--------------------------------------------------------------------------
  1583.   unless method_defined?(:fusion)
  1584.     def fusion
  1585.       (array = sort).each_index do |i|
  1586.         array[i] = array[i][0] + array[i][1] rescue array[i]
  1587.       end
  1588.       array
  1589.     end
  1590.   end
  1591. end
  1592. #==============================================================================
  1593. # ** Range     
  1594. #------------------------------------------------------------------------------
  1595. #  
  1596. #==============================================================================
  1597. class Range
  1598.   #--------------------------------------------------------------------------
  1599.   # * Include Comparable
  1600.   #--------------------------------------------------------------------------
  1601.   include(Comparable)
  1602.   #-------------------------------------------------------------------------
  1603.   # ● New method: random
  1604.   #-------------------------------------------------------------------------
  1605.   define_sec_method(:random) { self.to_a.random }
  1606.   define_sec_method(:sum)    { self.to_a.sum }
  1607.   define_sec_method(:prod)   { self.to_a.prod }
  1608.   #-------------------------------------------------------------------------
  1609.   # ● New method: <=>
  1610.   #-------------------------------------------------------------------------
  1611.   unless method_defined?(:"<=>")
  1612.     def <=>(other)
  1613.       temp = first <=> other.first
  1614.       temp = last <=> other.last if temp = 0
  1615.       return temp
  1616.     end
  1617.   end
  1618. end
  1619. #==============================================================================
  1620. # ** NilClass
  1621. #------------------------------------------------------------------------------
  1622. #  
  1623. #==============================================================================
  1624. class NilClass
  1625.   #--------------------------------------------------------------------------
  1626.   # ● Overwriten method: clone, dup
  1627.   #--------------------------------------------------------------------------
  1628.   define_method(:clone) {|*a|}
  1629.   define_method(:dup)   {|*a|}
  1630. end
  1631.  
  1632. #==============================================================================
  1633. # ** Math
  1634. #------------------------------------------------------------------------------
  1635. #  
  1636. #==============================================================================
  1637. module Math
  1638.   #--------------------------------------------------------------------------
  1639.   # ● New method: A (Ackermann function)
  1640.   #--------------------------------------------------------------------------
  1641.   def self.A(m,n)
  1642.     text = 'Ackermann: No negative values allowed.' if m < 0 or n < 0
  1643.     raise(ArgumentError.new(text))                  if m < 0 or n < 0
  1644.     return n + 1 if m == 0
  1645.     return Math.A(m - 1, 1) if n == 0
  1646.     return Math.A(m - 1, Math.A(m, n - 1))
  1647.   end
  1648.   #--------------------------------------------------------------------------
  1649.   # ● New method: percent
  1650.   #--------------------------------------------------------------------------
  1651.   def self.percent(min,max=100)
  1652.     (min / max.to_f) * 100.0
  1653.   end
  1654. end
  1655.  
  1656. #==============================================================================
  1657. # ** Numeric
  1658. #------------------------------------------------------------------------------
  1659. #  
  1660. #==============================================================================
  1661. class Numeric
  1662.   #--------------------------------------------------------------------------
  1663.   # ● Define Secondary Listing: clamp, sign
  1664.   #--------------------------------------------------------------------------
  1665.   define_sec_method(:clamp) {|min,max|  [[self, min].max, max].min}
  1666.   define_sec_method(:sign)  { zero? ? 0 :  (self / self.abs).to_i }
  1667.   #--------------------------------------------------------------------------
  1668.   # ● New method: group
  1669.   #--------------------------------------------------------------------------
  1670.   unless method_defined?(:group)
  1671.     def group
  1672.       self.to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
  1673.     end
  1674.   end
  1675. end
  1676.  
  1677. #==============================================================================
  1678. # ** Integer
  1679. #------------------------------------------------------------------------------
  1680. #  
  1681. #==============================================================================
  1682. class Integer
  1683.   #--------------------------------------------------------------------------
  1684.   # ● Define Secondary Listing: sum_to, factorial
  1685.   #--------------------------------------------------------------------------
  1686.   define_sec_method(:sum_down)  { sum_to(0)}
  1687.   define_sec_method(:factorial) {(sign * (1..(self.abs)).prod)  }
  1688.   #--------------------------------------------------------------------------
  1689.   # * New method: sum_to
  1690.   #--------------------------------------------------------------------------
  1691.   unless method_defined?(:sum_to)
  1692.     def sum_to(v = self) (v > self ? (self..v) : (v..self)).sum   end
  1693.   end
  1694. end
  1695.  
  1696. #==============================================================================
  1697. # ** Float
  1698. #------------------------------------------------------------------------------
  1699. #  
  1700. #==============================================================================
  1701. class Float
  1702.   #--------------------------------------------------------------------------
  1703.   # ● Overwriten method: =~
  1704.   #--------------------------------------------------------------------------
  1705.   # A close float comparison. Because of rounding errors, this comparison will
  1706.   # help compensate for that. Since 0 and 0.0001 are very close to each other,
  1707.   # it's best to use this custom comparison.
  1708.   define_method(:"=~") {|num| (self + 0.0001 >= num && self - 0.0001 <= num) }
  1709.   #--------------------------------------------------------------------------
  1710.   # ● New method: float_points
  1711.   #--------------------------------------------------------------------------
  1712.   unless method_defined?(:float_points)
  1713.     def float_points(points = 2)
  1714.       n = self * 10 ** points
  1715.       n = n.round.to_f / (10.0 ** points)
  1716.       return n
  1717.     end
  1718.   end
  1719. end
  1720.  
  1721. #==============================================================================
  1722. # ** Color
  1723. #------------------------------------------------------------------------------
  1724. #  
  1725. #==============================================================================
  1726. class Color
  1727.   #--------------------------------------------------------------------------
  1728.   # ● Define Secondary Listing
  1729.   #--------------------------------------------------------------------------
  1730.   define_sec_method(:invert)   { set(255-red, 255-green, 255-blue, alpha)}
  1731.   #----------------------------------------------------------------------------
  1732.   # * New method: to_hex
  1733.   #----------------------------------------------------------------------------
  1734.   def to_hex
  1735.     str = [self.blue.to_i, self.green.to_i, self.red.to_i].pack("C*")
  1736.     str.inspect.gsub('\\x','')
  1737.   end  
  1738. end
  1739. class << Color
  1740.   #--------------------------------------------------------------------------
  1741.   # ● Define Secondary Listing: red, green, blue, white, black... etc
  1742.   #--------------------------------------------------------------------------
  1743.   define_sec_method(:red)      {|*a| self.new(255,  0,  0,a.first||255)}
  1744.   define_sec_method(:green)    {|*a| self.new(  0,255,  0,a.first||255)}
  1745.   define_sec_method(:blue)     {|*a| self.new(  0,  0,255,a.first||255)}
  1746.   define_sec_method(:white)    {|*a| self.new(255,255,255,a.first||255)}
  1747.   define_sec_method(:purple)   {|*a| self.new(128,  0,128,a.first||255)}
  1748.   define_sec_method(:gray)     {|*a| self.new(128,128,128,a.first||255)}
  1749.   define_sec_method(:lgray)    {|*a| self.new(211,211,211,a.first||255)}
  1750.   define_sec_method(:dgray)    {|*a| self.new( 64, 64, 64,a.first||255)}
  1751.   define_sec_method(:pink)     {|*a| self.new(255,175,175,a.first||255)}
  1752.   define_sec_method(:orange)   {|*a| self.new(255,165,  0,a.first||255)}
  1753.   define_sec_method(:brown)    {|*a| self.new(128, 64,  0,a.first||255)}
  1754.   define_sec_method(:chocolate){|*a| self.new(210,105, 30,a.first||255)}
  1755.   define_sec_method(:golden)   {|*a| self.new(218,165, 32,a.first||255)}
  1756.   define_sec_method(:silver)   {|*a| self.new(192,192,192,a.first||255)}
  1757.   define_sec_method(:system)   {|*a| self.new(192,224,255,a.first||255)}
  1758.   define_sec_method(:crisis)   {|*a| self.new(255,255, 64,a.first||255)}
  1759.   define_sec_method(:knockout) {|*a| self.new(255, 64,  0,a.first||255)}
  1760.   #--------------------------------------------------------------------------
  1761.   # ● Redirect Listing: cyan, magenta, yellow, black, disabled, erase
  1762.   #--------------------------------------------------------------------------
  1763.   redirect_method :cyan,       '(red(*args).invert  )'
  1764.   redirect_method :magenta,    '(green(*args).invert)'
  1765.   redirect_method :yellow,     '(blue(*args).invert )'
  1766.   redirect_method :black,      '(white(*args).invert)'
  1767.   redirect_method :disabled,   '(black(128).invert  )'
  1768.   redirect_method :erase,      '(white(0).invert    )'
  1769.   #--------------------------------------------------------------------------
  1770.   # ● Alias method: grey, light_grey, dark_grey
  1771.   #--------------------------------------------------------------------------
  1772.   alias_sec_method :normal,    :white
  1773.   alias_sec_method :grey,      :gray
  1774.   alias_sec_method :lightgrey, :lightgray, :light_grey, :light_gray, :lgray
  1775.   alias_sec_method :darkgrey,  :darkgray,  :dark_grey,  :dark_gray,  :dgray
  1776.   #--------------------------------------------------------------------------
  1777.   # ● New method: method_missing
  1778.   #--------------------------------------------------------------------------
  1779.   def method_missing(val,*a)
  1780.     val = "#{val}".gsub(/x/i,'')
  1781.     if "#{val}".size == 6 && "#{val}".gsub(/(\d+|[a-f])/i,'')
  1782.       r = "#{val}"[0..1].hex
  1783.       g = "#{val}"[2..3].hex
  1784.       b = "#{val}"[4..5].hex
  1785.       return self.new(r,g,b,a.first||255)
  1786.     end
  1787.     text = "Undefined method #{val} for #{self.inspect}"
  1788.     raise(NoMethodError, text, caller(1))               
  1789.   end
  1790. end
  1791.  
  1792. #==============================================================================
  1793. # ** Viewport
  1794. #------------------------------------------------------------------------------
  1795. #  
  1796. #==============================================================================
  1797. class Viewport
  1798.   unless method_defined?(:disposed?)
  1799.     #--------------------------------------------------------------------------
  1800.     # ● Alias Listing
  1801.     #--------------------------------------------------------------------------
  1802.     alias_sec_method :d3x40932s2, :dispose
  1803.     #--------------------------------------------------------------------------
  1804.     # ● New method: disposed?
  1805.     #   help file is lying when says Viewport#disposed? is exist
  1806.     #--------------------------------------------------------------------------
  1807.     define_method(:disposed?) { @disposed == true }
  1808.     #--------------------------------------------------------------------------
  1809.     # ● Aliased method: dispose
  1810.     #--------------------------------------------------------------------------
  1811.     def dispose(*a)
  1812.       (disposed? || d3x40932s2(*a) || 0) && @disposed = true
  1813.     end
  1814.   end
  1815.   #--------------------------------------------------------------------------
  1816.   # ● New method: resize
  1817.   #--------------------------------------------------------------------------
  1818.   define_sec_method(:resize) do |*a|
  1819.     self.rect = a.first.is_a?(Rect) ? a.first : Rect.new(*a)
  1820.   end
  1821.   #--------------------------------------------------------------------------
  1822.   # * New method: update_viewport_sizes
  1823.   #--------------------------------------------------------------------------
  1824.   define_sec_method(:update_viewport_sizes) do |*a|
  1825.     map = $game_map
  1826.     w, h = Graphics.width, Graphics.height
  1827.     hor = map.respond_to?(:loop_horizontal?) && map.loop_horizontal?
  1828.     ver = map.respond_to?(:loop_vertical?)   && map.loop_vertical?
  1829.     dx = w > map.width  * 32 && !hor ? (w - map.width  * 32) / 2 : 0
  1830.     dw = hor ? w : [w, map.width * 32].min
  1831.     dy = h > map.height * 32 && !ver ? (h - map.height * 32) / 2 : 0
  1832.     dh = ver ? h : [h, map.height * 32].min
  1833.     resize(Rect.new(dx, dy, dw, dh))
  1834.   end
  1835.   #--------------------------------------------------------------------------
  1836.   # ● New method: x, y, width, height
  1837.   #--------------------------------------------------------------------------
  1838.   define_sec_method(:x)       { self.rect.x      }
  1839.   define_sec_method(:y)       { self.rect.y      }
  1840.   define_sec_method(:width)   { self.rect.width  }
  1841.   define_sec_method(:height)  { self.rect.height }
  1842.   define_sec_method(:x=)      {|x2| resize(x2,y,width,height) }
  1843.   define_sec_method(:y=)      {|y2| resize(x,y2,width,height) }
  1844.   define_sec_method(:width=)  {|w1| resize(x,y,w1,height)     }
  1845.   define_sec_method(:height=) {|h1| resize(x,y,width,h1)      }
  1846. end
  1847. #==============================================================================
  1848. # ** Graphics
  1849. #------------------------------------------------------------------------------
  1850. #  This module handles all Graphics
  1851. #==============================================================================
  1852. class << Graphics
  1853.   #------------------------------------------------------------------------
  1854.   # ● Include AutoUpdate
  1855.   #------------------------------------------------------------------------
  1856.   include_auto_update
  1857.   #------------------------------------------------------------------------
  1858.   # ● Redirect Listing
  1859.   #------------------------------------------------------------------------
  1860.   redirect_method :width,              'LiTTleDRAgo.client_size.at(0)'
  1861.   redirect_method :height,             'LiTTleDRAgo.client_size.at(1)'
  1862.   redirect_method :snap_to_bitmap,     'LiTTleDRAgo.snap_to_bitmap'   
  1863.   redirect_method :disable_alt_enter,  'LiTTleDRAgo.disable_alt_enter'
  1864.   redirect_method :always_on_top,      'LiTTleDRAgo.always_on_top'
  1865.   redirect_method :show_fps,           'LiTTleDRAgo.show_fps'
  1866.   redirect_method :scale_screen,       'LiTTleDRAgo.scale_screen'
  1867.   redirect_method :fill_monitor,       'LiTTleDRAgo.fill_monitor'
  1868.   redirect_method :window,             'LiTTleDRAgo.window'
  1869.   redirect_method :toggle,             'LiTTleDRAgo.toggle'
  1870.   redirect_method :fullscreen,         'LiTTleDRAgo.fullscreen'
  1871.   redirect_method :fullscreen?,        'LiTTleDRAgo.fullscreen?'
  1872.   redirect_method :control_screen_size,'LiTTleDRAgo.control_screen_size'
  1873.   redirect_method :high_priority,      'LiTTleDRAgo.high_priority'
  1874.   redirect_method :high_priority=,     'LiTTleDRAgo.high_priority=args.at(0)'
  1875.   #------------------------------------------------------------------------
  1876.   # ● Alias Listing
  1877.   #------------------------------------------------------------------------
  1878.   alias_sec_method :resize_screen, :scale_screen
  1879.   #--------------------------------------------------------------------------
  1880.   # * New method: fadeoutviewport
  1881.   #--------------------------------------------------------------------------
  1882.   def fadeoutviewport
  1883.     @fadeoutviewport  ||= ((v = Viewport.new(0,0,width,height))
  1884.         (v.color = (v.z = 0x3FFFFFFF) && Color.new(0,0,0,0)) && v)
  1885.   end
  1886.   #--------------------------------------------------------------------------
  1887.   # ● Redefined method:  wait,   brightness
  1888.   #--------------------------------------------------------------------------
  1889.   define_sec_method(:wait)       { |frame| frame.times {|i| update }   }
  1890.   define_sec_method(:brightness) { (255 - fadeoutviewport.color.alpha) }
  1891.   #--------------------------------------------------------------------------
  1892.   # * Redefined method: brightness= (Set Graphics Brightness)
  1893.   #--------------------------------------------------------------------------
  1894.   unless method_defined?(:brightness=)
  1895.     def brightness=(value)
  1896.       fadeoutviewport.color.alpha = 255 - value.clamp(0,255)
  1897.     end
  1898.   end
  1899.   #--------------------------------------------------------------------------
  1900.   # * Redefined method: fadein (Graphics Fade In)
  1901.   #         frame : frame of fade
  1902.   #--------------------------------------------------------------------------
  1903.   unless method_defined?(:fadein)
  1904.     def fadein(frames = 10)
  1905.       return if frames <= 0
  1906.       curvalue, count = brightness, (255 - brightness)
  1907.       frames.times do |i|
  1908.         (self.brightness = curvalue + (count * i / frames)) && update
  1909.       end
  1910.     end
  1911.   end
  1912.   #--------------------------------------------------------------------------
  1913.   # * Redefined method: fadeout (Graphics Fade Out)
  1914.   #         frame : frame of fade
  1915.   #--------------------------------------------------------------------------
  1916.   unless method_defined?(:fadeout)
  1917.     def fadeout(frames = 10)
  1918.       return if frames <= 0
  1919.       curvalue = count = self.brightness
  1920.       frames.times do |i|
  1921.         (self.brightness = curvalue - (count * i / frames)) && update
  1922.       end
  1923.     end
  1924.   end
  1925.   #--------------------------------------------------------------------------
  1926.   # * New method: wait_for_input
  1927.   #--------------------------------------------------------------------------
  1928.   unless method_defined?(:wait_for_input)
  1929.     def wait_for_input
  1930.       [Input,self].update
  1931.       [Input,self].update until press_any_key
  1932.     end
  1933.   end
  1934. end
  1935.  
  1936. #==============================================================================
  1937. # ** Input
  1938. #------------------------------------------------------------------------------
  1939. #  This module handles all Input
  1940. #==============================================================================
  1941. class << Input
  1942.   #------------------------------------------------------------------------
  1943.   # ● Include AutoUpdate
  1944.   #------------------------------------------------------------------------
  1945.   include_auto_update
  1946.   #--------------------------------------------------------------------------
  1947.   # ● Aliased method: :press?, :repeat?, :trigger?
  1948.   #--------------------------------------------------------------------------
  1949.   [:press?,:repeat?,:trigger?].each do |method|
  1950.     next unless method_defined?(:"#{method}")
  1951.     alias_sec_method(:"sym_#{method}", :"#{method}")
  1952.     define_method(:"#{method}") do |*args|
  1953.       if (b = args.first).is_a?(Symbol) || b.is_a?(String)
  1954.         args[0] = Input.const_get("#{b}") rescue nil
  1955.       end
  1956.       (args.first.not.nil?) && send(:"sym_#{method}", *args)
  1957.     end
  1958.   end
  1959. end
  1960. #==============================================================================
  1961. # ** Sprite_Battler
  1962. #------------------------------------------------------------------------------
  1963. #  This sprite is used to display the battler.It observes the Game_Character
  1964. #  class and automatically changes sprite conditions.
  1965. #==============================================================================
  1966. class Sprite_Battler
  1967.   #--------------------------------------------------------------------------
  1968.   # * Frame Update
  1969.   #--------------------------------------------------------------------------
  1970.   define_pre_alias(:update) {  @battler.nil? && @battler_name = nil }
  1971. end
  1972.  
  1973. #==============================================================================
  1974. # ** Spriteset_Map
  1975. #------------------------------------------------------------------------------
  1976. #  This class brings together map screen sprites, tilemaps, etc.
  1977. #  It's used within the Scene_Map class.
  1978. #==============================================================================
  1979. class Spriteset_Map
  1980.   #--------------------------------------------------------------------------
  1981.   # ● New method: sprite_player
  1982.   #--------------------------------------------------------------------------
  1983.   define_sec_method(:sprite_player) { find_character($game_player) }
  1984.   #------------------------------------------------------------------------
  1985.   # ● Public Instance Variables
  1986.   #------------------------------------------------------------------------
  1987.   attr_sec_reader :character_sprites, 'Array.new'
  1988.   attr_reader     :viewport1, :viewport2, :viewport3
  1989.   #--------------------------------------------------------------------------
  1990.   # * Aliased method: update
  1991.   #--------------------------------------------------------------------------
  1992.   define_pre_alias(:update) { update_viewport_size_change }
  1993.   #--------------------------------------------------------------------------
  1994.   # * New method: update_viewport_size_change
  1995.   #--------------------------------------------------------------------------
  1996.   def update_viewport_size_change
  1997.     if viewport_size_change?
  1998.       @viewport_map_width     = $game_map.width
  1999.       @viewport_map_height    = $game_map.height
  2000.       @viewport_screen_width  = Graphics.width
  2001.       @viewport_screen_height = Graphics.height
  2002.       [@viewport1,@viewport2,@viewport3].compact.update_viewport_sizes
  2003.     end
  2004.   end
  2005.   #--------------------------------------------------------------------------
  2006.   # * New method: viewport_size_change?
  2007.   #--------------------------------------------------------------------------
  2008.   unless method_defined?(:viewport_size_change?)
  2009.     def viewport_size_change?
  2010.       return true if @viewport_map_width     != $game_map.width
  2011.       return true if @viewport_map_height    != $game_map.height
  2012.       return true if @viewport_screen_width  != Graphics.width
  2013.       return true if @viewport_screen_height != Graphics.height
  2014.     end
  2015.   end
  2016.   #--------------------------------------------------------------------------
  2017.   # ● New method: redraw_character_sprites
  2018.   #--------------------------------------------------------------------------
  2019.   unless method_defined?(:redraw_character_sprites)
  2020.     def redraw_character_sprites
  2021.       return refresh_characters if self.respond_to?(:refresh_characters)
  2022.       character_sprites.dispose
  2023.       @character_sprites = $game_map.events.keys.sort.map {|i|
  2024.          Sprite_Character.new(@viewport1, $game_map.events[i]) }
  2025.       @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  2026.     end
  2027.   end  
  2028.   #--------------------------------------------------------------------------
  2029.   # ● New method: find_character
  2030.   #--------------------------------------------------------------------------
  2031.   unless method_defined?(:find_character)
  2032.     def find_character(char)
  2033.       character_sprites.detect { |s| s.character == char }
  2034.     end
  2035.   end
  2036.   #---------------------------------------------------------------------------
  2037.   # * New method: viewport_sprite
  2038.   #---------------------------------------------------------------------------
  2039.   def viewport_sprite(*v)
  2040.     v.collect! {|s| s.is_a?(Symbol) ? instance_variable_get(:"@#{s}") : s }
  2041.     v.reject!  {|s| s.not.is_a?(Viewport)}
  2042.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  2043.     all.select {|s| s.respond_to?(:viewport) && v.include?(s.viewport)}
  2044.   end
  2045. end
  2046.  
  2047. #==============================================================================
  2048. # ** Game_Battler
  2049. #------------------------------------------------------------------------------
  2050. #  This class deals with battlers. It's used as a superclass for the Game_Actor
  2051. #  and Game_Enemy classes.
  2052. #==============================================================================
  2053. class Game_Battler
  2054.   #--------------------------------------------------------------------------
  2055.   # ● New method: alive?
  2056.   #--------------------------------------------------------------------------
  2057.   define_sec_method(:alive?) { self.not.dead? }
  2058.   #--------------------------------------------------------------------------
  2059.   # ● New method: hp_percent
  2060.   #--------------------------------------------------------------------------
  2061.   unless method_defined?(:hp_percent)
  2062.     def hp_percent(integer = false, float_points = 2)
  2063.       n = Math.percent(hp,(respond_to?(:mhp) ? mhp : maxhp))
  2064.       return integer ? Integer(n) : n.float_points(float_points)
  2065.     end
  2066.   end
  2067.   #--------------------------------------------------------------------------
  2068.   # ● New method: sp_percent
  2069.   #--------------------------------------------------------------------------
  2070.   unless method_defined?(:sp_percent)
  2071.     def sp_percent(integer = false, float_points = 2)
  2072.       n =  Math.percent((respond_to?(:sp) ? sp : mp),
  2073.       ((respond_to?(:mmp) ? mmp : (respond_to?(:maxsp) ? maxsp : maxmp))))
  2074.       return integer ? Integer(n) : n.float_points(float_points)
  2075.     end
  2076.     alias_method :mp_percent, :sp_percent
  2077.   end
  2078. end
  2079.  
  2080. #==============================================================================
  2081. # ** Game_Character
  2082. #------------------------------------------------------------------------------
  2083. #  This class deals with characters. It's used as a superclass for the
  2084. #  Game_Player and Game_Event classes.
  2085. #==============================================================================
  2086. class Game_Character
  2087.   #--------------------------------------------------------------------------
  2088.   # ● Redirect Listing
  2089.   #--------------------------------------------------------------------------
  2090.   redirect_method :move_down,        'move_straight(2,*args)'
  2091.   redirect_method :move_left,        'move_straight(4,*args)'
  2092.   redirect_method :move_right,       'move_straight(6,*args)'
  2093.   redirect_method :move_up,          'move_straight(8,*args)'
  2094.   redirect_method :turn_down,        'set_direction(2,*args)'
  2095.   redirect_method :turn_left,        'set_direction(4,*args)'
  2096.   redirect_method :turn_right,       'set_direction(6,*args)'
  2097.   redirect_method :turn_up,          'set_direction(8,*args)'
  2098.   redirect_method :move_lower_left,  'move_diagonal(4, 2,*args)'
  2099.   redirect_method :move_lower_right, 'move_diagonal(6, 2,*args)'
  2100.   redirect_method :move_upper_left,  'move_diagonal(4, 8,*args)'
  2101.   redirect_method :move_upper_right, 'move_diagonal(6, 8,*args)'
  2102.   redirect_method :character_sprite, '$game_map.character_sprite(self)'
  2103.   redirect_method :character_above?, '(args.first.y > @y)'
  2104.   redirect_method :character_below?, '(args.first.y < @y)'
  2105.   redirect_method :character_right?, '(args.first.x < @x)'
  2106.   redirect_method :character_left?,  '(args.first.x > @x)'
  2107.   redirect_method :pos,              '[@x, @y]'
  2108.   redirect_method :pos_nt?,          '!@through && pos?'
  2109.   redirect_method :normal_priority?, '@character_name != ""'  
  2110.   redirect_method :map_passable?,    '$game_map.passable?'
  2111.   redirect_method :map_terrain_tag,  '$game_map.terrain_tag'
  2112.   #--------------------------------------------------------------------------
  2113.   # * Redefined method: pos?
  2114.   #                     anime
  2115.   #                     reverse_dir
  2116.   #--------------------------------------------------------------------------
  2117.   define_sec_method(:reverse_dir) {|dir| 10 - dir }
  2118.   define_sec_method(:pos?)        {|x,y| @x == x && @y == y  }
  2119.   define_sec_method(:anime)       {|aid| @animation_id = aid }
  2120.   #--------------------------------------------------------------------------
  2121.   # ● Redefined method: check_event_trigger_touch_front
  2122.   #--------------------------------------------------------------------------
  2123.   unless method_defined?(:check_event_trigger_touch_front)
  2124.     def check_event_trigger_touch_front
  2125.       x2 = $game_map.round_x_with_direction(@x, @direction)
  2126.       y2 = $game_map.round_y_with_direction(@y, @direction)
  2127.       check_event_trigger_touch(x2, y2)
  2128.     end
  2129.   end
  2130.   #--------------------------------------------------------------------------
  2131.   # ● Redefined method: move_straight
  2132.   #--------------------------------------------------------------------------
  2133.   unless method_defined?(:move_straight)
  2134.     def move_straight(d, turn_ok = true)
  2135.       if passable?(@x, @y, d)
  2136.         set_direction(d)
  2137.         @x = $game_map.round_x_with_direction(@x, d)
  2138.         @y = $game_map.round_y_with_direction(@y, d)
  2139.         increase_steps
  2140.       elsif turn_ok
  2141.         set_direction(d)
  2142.         check_event_trigger_touch_front
  2143.       end
  2144.     end
  2145.   end  
  2146.   #--------------------------------------------------------------------------
  2147.   # ● Redefined method: set_direction
  2148.   #--------------------------------------------------------------------------
  2149.   unless method_defined?(:set_direction)
  2150.     def set_direction(d)
  2151.       @direction = d unless @direction_fix || d == 0
  2152.       @stop_count = 0
  2153.     end
  2154.   end
  2155.   #--------------------------------------------------------------------------
  2156.   # ● Redefined method: set_graphic
  2157.   #--------------------------------------------------------------------------
  2158.   unless method_defined?(:set_graphic)
  2159.     def set_graphic(character_name, character_index = 0)
  2160.       @tile_id = 0
  2161.       @character_name = character_name
  2162.       if self.respond_to?(:character_index)
  2163.         @character_index = character_index
  2164.       else
  2165.         @character_hue = character_index
  2166.       end
  2167.       @original_pattern = 1
  2168.     end
  2169.   end
  2170.   #--------------------------------------------------------------------------
  2171.   # ● Redefined method: swap
  2172.   #--------------------------------------------------------------------------
  2173.   unless method_defined?(:swap)
  2174.     def swap(character)
  2175.       new_pos = character.pos
  2176.       character.moveto(x, y)
  2177.       moveto(*new_pos)
  2178.     end
  2179.   end
  2180.   #--------------------------------------------------------------------------
  2181.   # ● Redefined method: rotate_swap_prev
  2182.   #--------------------------------------------------------------------------
  2183.   unless method_defined?(:rotate_swap_prev)
  2184.     def rotate_swap_prev(*character)
  2185.       character.unshift(self)
  2186.       position = character.collect {|c| c.pos}
  2187.       character.each_with_index { |c,i| c.moveto(*position[i-1]) }
  2188.     end
  2189.   end
  2190.   #--------------------------------------------------------------------------
  2191.   # ● Redefined method: rotate_swap_next
  2192.   #--------------------------------------------------------------------------
  2193.   unless method_defined?(:rotate_swap_next)
  2194.     def rotate_swap_next(*character)
  2195.       character.unshift(self)
  2196.       position = character.collect {|c| c.pos}
  2197.       character.each_with_index do |char,index|
  2198.         char.moveto(*position[index + 1 >= position.size ? 0 : index + 1])
  2199.       end
  2200.     end
  2201.   end
  2202.   #--------------------------------------------------------------------------
  2203.   # ● New method: distance_from
  2204.   #--------------------------------------------------------------------------
  2205.   unless method_defined?(:distance_from)
  2206.     def distance_from(character,type= 'xy')
  2207.       character = $game_map.events[character] if character.is_a?(Integer)
  2208.       return 0 if character.nil?
  2209.       return (@x - character.x).abs if type.to_s == 'x'
  2210.       return (@y - character.y).abs if type.to_s == 'y'
  2211.       return Math.hypot(@x - character.x, @y - character.y)
  2212.     end
  2213.   end
  2214.   #--------------------------------------------------------------------------
  2215.   # * Redefined method: distance_x_from
  2216.   #--------------------------------------------------------------------------
  2217.   unless method_defined?(:distance_x_from)
  2218.     def distance_x_from(x)
  2219.       result = @x - x
  2220.       if result.abs > $game_map.width / 2
  2221.         result += result < 0 ? $game_map.width : -$game_map.width
  2222.       end
  2223.       result
  2224.     end
  2225.   end
  2226.   #--------------------------------------------------------------------------
  2227.   # * Redefined method: distance_y_from
  2228.   #--------------------------------------------------------------------------
  2229.   unless method_defined?(:distance_y_from)
  2230.     def distance_y_from(y)
  2231.       result = @y - y
  2232.       if result.abs > $game_map.height / 2
  2233.         result += result < 0 ? $game_map.height : -$game_map.height
  2234.       end
  2235.       result
  2236.     end
  2237.   end
  2238.   #--------------------------------------------------------------------------
  2239.   # ● New method: random_teleport
  2240.   #--------------------------------------------------------------------------
  2241.   unless method_defined?(:random_teleport)
  2242.     def random_teleport
  2243.       1000.times do
  2244.         moveto(rand($game_map.height), rand($game_map.width))
  2245.         vx  = LiTTleDRAgo::VX && !LiTTleDRAgo::VXA
  2246.         arg = vx ? [@x,@y] : [@x,@y,@direction]
  2247.         break if passable?(*arg)
  2248.       end || true
  2249.     end
  2250.   end
  2251.   #--------------------------------------------------------------------------
  2252.   # * Redefined method: diagonal_passable? (for RMXP)
  2253.   #     horz : Horizontal (4 or 6)
  2254.   #     vert : Vertical (2 or 8)
  2255.   #--------------------------------------------------------------------------
  2256.   unless method_defined?(:diagonal_passable?)
  2257.     def diagonal_passable?(x, y, horz, vert)
  2258.       x2 = $game_map.round_x_with_direction(x, horz)
  2259.       y2 = $game_map.round_y_with_direction(y, vert)
  2260.       (passable?(x, y, vert) && passable?(x, y2, horz)) ||
  2261.       (passable?(x, y, horz) && passable?(x2, y, vert))
  2262.     end
  2263.   end
  2264.   #--------------------------------------------------------------------------
  2265.   # * Redefined method: collide_with_characters? (for RMXP)
  2266.   #--------------------------------------------------------------------------
  2267.   unless method_defined?(:collide_with_characters?)
  2268.     def collide_with_characters?(x, y)
  2269.       collide_with_events?(x, y)
  2270.     end
  2271.   end
  2272.   #--------------------------------------------------------------------------
  2273.   # * Redefined method: collide_with_events? (for RMXP)
  2274.   #--------------------------------------------------------------------------
  2275.   unless method_defined?(:collide_with_events?)
  2276.     def collide_with_events?(x, y)
  2277.       $game_map.events_xy_nt(x, y).any? do |event|
  2278.         event.normal_priority? || self.is_a?(Game_Event)
  2279.       end
  2280.     end
  2281.   end
  2282.   #--------------------------------------------------------------------------
  2283.   # * Redefined method: debug_through?
  2284.   #--------------------------------------------------------------------------
  2285.   unless method_defined?(:debug_through?)
  2286.     def debug_through?
  2287.       debug = LiTTleDRAgo::VX ? $TEST : $DEBUG
  2288.       return debug && Input.press?(Input::CTRL) if self.is_a?(Game_Player)
  2289.       return false
  2290.     end
  2291.   end
  2292. end
  2293. #==============================================================================
  2294. # ** Game_Actor
  2295. #------------------------------------------------------------------------------
  2296. #  This class handles actors. It is used within the Game_Actors class
  2297. # ($game_actors), also referenced from the Game_Party class ($game_party).
  2298. #==============================================================================
  2299.  
  2300. class Game_Actor
  2301.   #--------------------------------------------------------------------------
  2302.   # * Get Actor Object
  2303.   #--------------------------------------------------------------------------
  2304.   define_sec_method(:actor)  { $data_actors[@actor_id]  }
  2305.   define_method(:class)      { $data_classes[@class_id] }
  2306. end
  2307.  
  2308. #==============================================================================
  2309. # ** Game_Enemy
  2310. #------------------------------------------------------------------------------
  2311. #  This class handles enemies. It used within the Game_Troop class
  2312. # ($game_troop).
  2313. #==============================================================================
  2314.  
  2315. class Game_Enemy
  2316.   #--------------------------------------------------------------------------
  2317.   # * Get Enemy Object
  2318.   #--------------------------------------------------------------------------
  2319.   define_sec_method(:enemy)  { $data_enemies[@enemy_id] }
  2320. end
  2321.  
  2322. #==============================================================================
  2323. # ** Game_Player
  2324. #------------------------------------------------------------------------------
  2325. #  This class handles the player. It includes event starting determinants and
  2326. # map scrolling functions. The instance of this class is referenced by
  2327. # $game_player.
  2328. #==============================================================================
  2329.  
  2330. class Game_Player
  2331.   #--------------------------------------------------------------------------
  2332.   # ● Redefined method: actor
  2333.   #                     name
  2334.   #--------------------------------------------------------------------------
  2335.   define_sec_method(:actor) { $game_party.leader }
  2336.   define_sec_method(:name)  { actor.name         }        
  2337.   #--------------------------------------------------------------------------
  2338.   # ● New method: method_missing
  2339.   #--------------------------------------------------------------------------
  2340.   def method_missing(val,*a,&b)
  2341.     return actor.send(val.to_s,*a,&b) if actor.respond_to?(val.to_sym)
  2342.     text = "Undefined method #{val} for #{self.inspect}"
  2343.     raise(NoMethodError, text, caller(1))               
  2344.   end
  2345. end
  2346.  
  2347. #==============================================================================
  2348. # ** Game_Event
  2349. #------------------------------------------------------------------------------
  2350. #  This class deals with events. It handles functions including event page
  2351. #  switching via condition determinants, and running parallel process events.
  2352. #  It's used within the Game_Map class.
  2353. #==============================================================================
  2354. class Game_Event < Game_Character
  2355.   #--------------------------------------------------------------------------
  2356.   # ● Public Instance Variables
  2357.   #--------------------------------------------------------------------------
  2358.   method_defined?(:erased) || (attr_reader :erased)
  2359.   method_defined?(:id)     || (attr_reader :id)
  2360.   method_defined?(:event)  || (attr_reader :event)
  2361.   attr_accessor :loaded_event
  2362.   #--------------------------------------------------------------------------
  2363.   # ● New method: name
  2364.   # ● New method: restore
  2365.   #--------------------------------------------------------------------------
  2366.   define_sec_method(:name)    { @event.name }
  2367.   define_sec_method(:restore) { (@erased = false) || refresh }
  2368.   #--------------------------------------------------------------------------
  2369.   # ● New method: destroy
  2370.   #--------------------------------------------------------------------------
  2371.   unless method_defined?(:destroy)
  2372.     def destroy
  2373.       event = $game_map.events.delete(@id)
  2374.       if (s = $game_map.spriteset).is_a?(Spriteset_Map)
  2375.         after = s.character_sprites.select { |e| e if e.character != event }
  2376.         (delet = character_sprite) && delet.dispose
  2377.         s.character_sprites.replace(after)
  2378.       end
  2379.     end
  2380.   end
  2381.   #--------------------------------------------------------------------------
  2382.   # ● New method: eliminate
  2383.   #--------------------------------------------------------------------------
  2384.   unless method_defined?(:eliminate)
  2385.     def eliminate
  2386.       return destroy if self.loaded_event
  2387.       (eliminate = $game_map.eliminate_event)[(id = $game_map.map_id)] ||= []
  2388.       (eliminate[id].include?(@id) || eliminate[id].push(@id)) && destroy
  2389.     end
  2390.   end
  2391.   #--------------------------------------------------------------------------
  2392.   # ● New method: note
  2393.   #--------------------------------------------------------------------------
  2394.   unless method_defined?(:note)
  2395.     def note
  2396.       list = @page ? @page.list.select {|l| [108,408].include?(l.code)} : []
  2397.       notes = list.collect {|l| l.parameters[0] }.join("\n")
  2398.       return notes
  2399.     end
  2400.   end
  2401.   #--------------------------------------------------------------------------
  2402.   # ● New method: proper_page_index
  2403.   #--------------------------------------------------------------------------  
  2404.   unless method_defined?(:proper_page_index)
  2405.     def proper_page_index
  2406.       if respond_to?(:conditions_met?)
  2407.         page = respond_to?(:find_proper_page) ? find_proper_page :
  2408.                @event.pages.reverse.find {|page| conditions_met?(page)}
  2409.         (i = @event.pages.index(page)).is_a?(Integer) ? i + 1 : 0
  2410.       end
  2411.     end
  2412.   end
  2413. end
  2414.  
  2415. #==============================================================================
  2416. # ** Game_Party
  2417. #------------------------------------------------------------------------------
  2418. #  This class handles the party. It includes information on amount of gold
  2419. #  and items. Refer to "$game_party" for the instance of this class.
  2420. #==============================================================================
  2421. class Game_Party
  2422.   #--------------------------------------------------------------------------
  2423.   # ● Alias Listing
  2424.   #--------------------------------------------------------------------------
  2425.   alias_sec_method :drg_ce_item_number, :item_number
  2426.   #--------------------------------------------------------------------------
  2427.   # ● Redirect Listing
  2428.   #--------------------------------------------------------------------------
  2429.   redirect_method :player_pos,      '($game_player.pos)'
  2430.   redirect_method :leader,          '(members.first)'
  2431.   redirect_method :members,         '(actors)'   
  2432.   redirect_method :actors,          '(members)'  
  2433.   #--------------------------------------------------------------------------
  2434.   # ● New method: existing_actors, recover_all
  2435.   #--------------------------------------------------------------------------
  2436.   define_sec_method(:existing_actors) { members.find_all {|a| a.exist?}  }
  2437.   define_sec_method(:recover_all)     { members.each {|a| a.recover_all} }
  2438.   #--------------------------------------------------------------------------
  2439.   # ● New method: has_actors?
  2440.   #--------------------------------------------------------------------------
  2441.   unless method_defined?(:has_actors?)
  2442.     def has_actors?(*actors)
  2443.       party = @actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }
  2444.       actor =  actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }.flatten
  2445.       return party.have_all?(*actor)
  2446.     end
  2447.   end
  2448.   #--------------------------------------------------------------------------
  2449.   # ● New method: has_any_actors?
  2450.   #--------------------------------------------------------------------------
  2451.   unless method_defined?(:has_any_actors?)
  2452.     def has_any_actors?(*actors)
  2453.       party = @actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }
  2454.       actor =  actors.collect {|s| s.is_a?(Game_Actor) ? s.id : s }.flatten
  2455.       return party.have_any?(*actor)
  2456.     end
  2457.   end
  2458.   #--------------------------------------------------------------------------
  2459.   # ● New method: swap_previous_actor
  2460.   #--------------------------------------------------------------------------
  2461.   unless method_defined?(:swap_leader_prev)
  2462.     def swap_leader_prev(n = 1)
  2463.       n <= 0 || n.round.times { @actors.previous_item && drg_ce_refresh }
  2464.       n >= 0 || swap_leader_next(n.round.abs)
  2465.     end
  2466.   end
  2467.   #--------------------------------------------------------------------------
  2468.   # ● New method: swap_next_actor
  2469.   #--------------------------------------------------------------------------
  2470.   unless method_defined?(:swap_leader_next)
  2471.     def swap_leader_next(n = 1)
  2472.       n <= 0 || n.round.times { @actors.next_item && drg_ce_refresh }
  2473.       n >= 0 || swap_leader_prev(n.round.abs)
  2474.     end
  2475.   end
  2476.   #--------------------------------------------------------------------------
  2477.   # ● New method: set_leader
  2478.   #--------------------------------------------------------------------------
  2479.   unless method_defined?(:set_leader)
  2480.     def set_leader(id)
  2481.       actor = id.is_a?(Numeric) ? $game_actors[id.to_i] : id
  2482.       if actor.is_a?(Game_Actor) && has_actors?(actor.id)
  2483.         swap_leader_next until $game_party.leader.id == actor.id
  2484.         actor.id
  2485.       end
  2486.     end
  2487.   end
  2488.   #--------------------------------------------------------------------------
  2489.   # ● New method: drg_ce_refresh
  2490.   #--------------------------------------------------------------------------
  2491.   unless method_defined?(:drg_ce_refresh)
  2492.     def drg_ce_refresh
  2493.       return refresh if respond_to?(:refresh)
  2494.       return ($game_map.need_refresh = true) && $game_player.refresh
  2495.     end
  2496.   end
  2497.   #--------------------------------------------------------------------------
  2498.   # * Get Party Name
  2499.   #--------------------------------------------------------------------------
  2500.   unless method_defined?(:name)
  2501.     def name
  2502.       return ""           if existing_actors.size == 0
  2503.       return leader.name  if existing_actors.size == 1
  2504.       return "#{leader.name}'s Party"
  2505.     end
  2506.   end
  2507.   #--------------------------------------------------------------------------
  2508.   # * Aliased method: item_number
  2509.   #--------------------------------------------------------------------------
  2510.   def item_number(item)
  2511.     unless LiTTleDRAgo::VX
  2512.       return drg_ce_item_number(item.id)          if item.is_a?(RPG::Item)
  2513.       return weapon_number(item.id)               if item.is_a?(RPG::Weapon)
  2514.       return armor_number(item.id)                if item.is_a?(RPG::Armor)  
  2515.     else
  2516.       item = $data_items[item.to_i]               if item.is_a?(Numeric)
  2517.     end
  2518.     return skill_number(item)                     if item.is_a?(RPG::Skill)
  2519.     return drg_ce_item_number(item)
  2520.   end
  2521.   #--------------------------------------------------------------------------
  2522.   # * Redefined method: weapon_number
  2523.   #--------------------------------------------------------------------------
  2524.   unless method_defined?(:weapon_number)
  2525.     def weapon_number(weapon)
  2526.       weapon = $data_weapons[weapon.to_i] if weapon.is_a?(Numeric)
  2527.       item_number(weapon)
  2528.     end
  2529.   end
  2530.   #--------------------------------------------------------------------------
  2531.   # * Redefined method: armor_number
  2532.   #--------------------------------------------------------------------------
  2533.   unless method_defined?(:armor_number)
  2534.     def armor_number(armor)
  2535.       armor = $data_armors[armor.to_i] if armor.is_a?(Numeric)
  2536.       item_number(armor)
  2537.     end
  2538.   end
  2539.   #--------------------------------------------------------------------------
  2540.   # * New method: skill_number
  2541.   #--------------------------------------------------------------------------
  2542.   unless method_defined?(:skill_number)
  2543.     def skill_number(skill)
  2544.       skill = $data_skills[skill.to_i] if skill.is_a?(Numeric)
  2545.       s1 = actors.select {|a| a.skill_learn?(skill)    }
  2546.       s2 = actors.select {|a| a.skill_learn?(skill.id) }
  2547.       return s1.size + s2.size
  2548.     end
  2549.   end
  2550.   #--------------------------------------------------------------------------
  2551.   # * New method: gain_all_items
  2552.   #--------------------------------------------------------------------------
  2553.   def gain_all_items(ammount=1)
  2554.     (0..999).to_a.each do |s|
  2555.       next if $data_items[s].nil? || $data_items[s].name == ''
  2556.       $game_party.drg_ce_get_item($data_items[s],ammount)
  2557.     end
  2558.   end
  2559.   #--------------------------------------------------------------------------
  2560.   # * New method: gain_all_weapons
  2561.   #--------------------------------------------------------------------------
  2562.   def gain_all_weapons(ammount=1)
  2563.     (0..999).to_a.each do |s|
  2564.       next if $data_weapons[s].nil? || $data_weapons[s].name == ''
  2565.       drg_ce_get_item($data_weapons[s],ammount)
  2566.     end
  2567.   end  
  2568.   #--------------------------------------------------------------------------
  2569.   # * New method: gain_all_armors
  2570.   #--------------------------------------------------------------------------
  2571.   def gain_all_armors(ammount=1)
  2572.     (0..999).to_a.each do |s|
  2573.       next if $data_armors[s].nil? || $data_armors[s].name == ''
  2574.       drg_ce_get_item($data_armors[s],ammount)
  2575.     end
  2576.   end
  2577.   #--------------------------------------------------------------------------
  2578.   # * New method: drg_ce_get_item
  2579.   #--------------------------------------------------------------------------
  2580.   def drg_ce_get_item(item,ammount)
  2581.     return gain_item(item,ammount)      if LiTTleDRAgo::VX
  2582.     return gain_item(item.id,ammount)   if item.is_a?(RPG::Item)
  2583.     return gain_weapon(item.id,ammount) if item.is_a?(RPG::Weapon)
  2584.     return gain_armor(item.id,ammount)  if item.is_a?(RPG::Armor)
  2585.   end
  2586. end
  2587.  
  2588. #==============================================================================
  2589. # ** Game_Follower
  2590. #------------------------------------------------------------------------------
  2591. #  This class handles followers. A follower is an allied character, other than
  2592. # the front character, displayed in the party. It is referenced within the
  2593. # Game_Followers class.
  2594. #==============================================================================
  2595. class Game_Follower < Game_Character
  2596.   #--------------------------------------------------------------------------
  2597.   # * Redirect Listing
  2598.   #--------------------------------------------------------------------------
  2599.   redirect_method :name, "(actor.nil? ? '' : actor.name)"
  2600. end if defined?(Game_Follower)
  2601.  
  2602. #==============================================================================
  2603. # ** Game_Map
  2604. #------------------------------------------------------------------------------
  2605. #  This class handles maps. It includes scrolling and passage determination
  2606. # functions. The instance of this class is referenced by $game_map.
  2607. #==============================================================================
  2608.  
  2609. class Game_Map
  2610.   #--------------------------------------------------------------------------
  2611.   # * Public Instance Variables
  2612.   #--------------------------------------------------------------------------
  2613.   attr_sec_reader :eliminate_event, 'Hash.new'
  2614.   #--------------------------------------------------------------------------
  2615.   # ● New method: name,        parent_id, base_parent_id
  2616.   #               event_list , map_events
  2617.   #--------------------------------------------------------------------------
  2618.   define_sec_method(:name)             { mapInfo[@map_id].name      }
  2619.   define_sec_method(:parent_id)        { mapInfo[@map_id].parent_id }
  2620.   define_sec_method(:base_parent_id)   { search_parent_id(mapInfo)  }
  2621.   define_sec_method(:event_list)       { events.values }
  2622.   define_sec_method(:map_events)       { @map.events   }
  2623.   define_sec_method(:screen)           { $game_screen  }
  2624.   define_sec_method(:loop_horizontal?) { false }
  2625.   define_sec_method(:loop_vertical?)   { false }
  2626.   define_sec_method(:map_child?)       { |*a|  a & child_ids == a }
  2627.   #--------------------------------------------------------------------------
  2628.   # * Aliased method: setup
  2629.   #--------------------------------------------------------------------------
  2630.   define_post_alias(:setup) do
  2631.     eliminate_event[@map_id] ||= []
  2632.     eliminate_event[@map_id].each { |s| events.delete(s) }
  2633.   end
  2634.   #--------------------------------------------------------------------------
  2635.   # * Redefined method: any_event_strarting? (for RMXP)
  2636.   #--------------------------------------------------------------------------
  2637.   unless method_defined?(:any_event_starting?)
  2638.     def any_event_starting?
  2639.       event_list.any? {|event| event.starting }
  2640.     end
  2641.   end
  2642.   #--------------------------------------------------------------------------
  2643.   # * Redefined method: interpreter (for RMXP)
  2644.   #--------------------------------------------------------------------------
  2645.   unless method_defined?(:interpreter)
  2646.     def interpreter
  2647.       return $game_system.map_interpreter if LiTTleDRAgo.scene.is_a?(Scene_Map)
  2648.       return $game_system.battle_interpreter
  2649.     end
  2650.   end
  2651.   #--------------------------------------------------------------------------
  2652.   # * Redefined method: events_xy (for RMXP)
  2653.   #--------------------------------------------------------------------------
  2654.   unless method_defined?(:events_xy)
  2655.     def events_xy(x, y)
  2656.       event_list.select {|event| event.x == x && event.y == y }
  2657.     end
  2658.   end
  2659.   #--------------------------------------------------------------------------
  2660.   # * Redefined method: events_xy_nt (for RMXP)
  2661.   #--------------------------------------------------------------------------
  2662.   unless method_defined?(:events_xy_nt)
  2663.     def events_xy_nt(x, y)
  2664.       event_list.select {|event| event.pos_nt?(x, y) }
  2665.     end
  2666.   end
  2667.   #--------------------------------------------------------------------------
  2668.   # * Redefined method: round_x, round_y (for RMXP)
  2669.   #--------------------------------------------------------------------------
  2670.   define_sec_method(:round_x) {|x| loop_horizontal? ? (x + width) % width : x }
  2671.   define_sec_method(:round_y) {|y| loop_vertical? ? (y + height) % height : y }
  2672.   #--------------------------------------------------------------------------
  2673.   # * Redefined method: x_with_direction (for RMXP)
  2674.   #--------------------------------------------------------------------------
  2675.   define_sec_method(:x_with_direction) {|x, d| x + (d==6 ? 1 : d==4 ? -1 : 0)}
  2676.   define_sec_method(:y_with_direction) {|y, d| y + (d==2 ? 1 : d==8 ? -1 : 0)}
  2677.   #--------------------------------------------------------------------------
  2678.   # * Redefined method: round_x_with_direction (for RMXP)
  2679.   #--------------------------------------------------------------------------
  2680.   unless method_defined?(:round_x_with_direction)
  2681.     def round_x_with_direction(x, d)
  2682.       round_x(x_with_direction(x, d))
  2683.     end
  2684.   end
  2685.   #--------------------------------------------------------------------------
  2686.   # * Redefined method: round_y_with_direction (for RMXP)
  2687.   #--------------------------------------------------------------------------
  2688.   unless method_defined?(:round_y_with_direction)
  2689.     def round_y_with_direction(y, d)
  2690.       round_y(y_with_direction(y, d))
  2691.     end
  2692.   end
  2693.   #--------------------------------------------------------------------------
  2694.   # * New method: x_diagonal_with_direction (for RMXP)
  2695.   #--------------------------------------------------------------------------
  2696.   unless method_defined?(:x_diagonal_with_direction)
  2697.     def x_diagonal_with_direction(x, d)
  2698.       x + ([9,6,3].include?(d) ? 1 : [7,4,1].include?(d) ? -1 : 0)
  2699.     end
  2700.   end
  2701.   #--------------------------------------------------------------------------
  2702.   # * New method: y_with_direction (for RMXP)
  2703.   #--------------------------------------------------------------------------
  2704.   unless method_defined?(:y_diagonal_with_direction)
  2705.     def y_diagonal_with_direction(y, d)
  2706.       y + ([1,2,3].include?(d) ? 1 : [7,8,9].include?(d) ? -1 : 0)
  2707.     end
  2708.   end
  2709.   #--------------------------------------------------------------------------
  2710.   # ● New method: existing_events
  2711.   #--------------------------------------------------------------------------
  2712.   unless method_defined?(:existing_events)
  2713.     def existing_events
  2714.       event_list.select {|e| e.not.erased }
  2715.     end
  2716.   end
  2717.   #--------------------------------------------------------------------------
  2718.   # ● New method: map_info
  2719.   #--------------------------------------------------------------------------
  2720.   unless method_defined?(:mapInfo)
  2721.     def mapInfo(ext = LiTTleDRAgo.data_default_extension)
  2722.       data = "Data/MapInfos.#{ext}"  
  2723.       @mapinfo ||= load_data(sprintf("#{data}")) rescue draise(
  2724.                    "Fail to load #{data}")
  2725.       return @mapinfo
  2726.     end
  2727.   end
  2728.   #--------------------------------------------------------------------------
  2729.   # ● New method: search_parent_id
  2730.   #--------------------------------------------------------------------------
  2731.   unless method_defined?(:search_parent_id)
  2732.     def search_parent_id(mapInfo, id = @map_id, ancestor = 0)
  2733.       m_id = id
  2734.       loop do
  2735.         _m_id = mapInfo[m_id]
  2736.         p_id = _m_id.respond_to?(:parent_id) ? _m_id.parent_id : nil
  2737.         return p_id if p_id == nil
  2738.         return m_id if p_id == ancestor
  2739.         m_id = p_id
  2740.       end
  2741.     end
  2742.   end
  2743.   #--------------------------------------------------------------------------
  2744.   # ● New method: base_map_name
  2745.   #--------------------------------------------------------------------------
  2746.   unless method_defined?(:base_map_name)
  2747.     def base_map_name
  2748.       map = mapInfo[search_parent_id(mapInfo)]
  2749.       name = map.respond_to?(:name) ? map.name : ''
  2750.       return name
  2751.     end
  2752.   end
  2753.   #--------------------------------------------------------------------------
  2754.   # ● New method: child_ids
  2755.   #--------------------------------------------------------------------------
  2756.   unless method_defined?(:child_ids)
  2757.     def child_ids
  2758.       mapInfo.keys.select {|map_id| mapInfo[map_id].parent_id == @map_id }
  2759.     end
  2760.   end
  2761.   #--------------------------------------------------------------------------
  2762.   # ● New method: descendant?
  2763.   #--------------------------------------------------------------------------
  2764.   unless method_defined?(:map_descendant?)
  2765.     def map_descendant?(*a)
  2766.       a.all? {|map_id| search_parent_id(mapInfo, map_id, @map_id)}
  2767.     end
  2768.   end
  2769.   #--------------------------------------------------------------------------
  2770.   # ● New method: load_event
  2771.   #--------------------------------------------------------------------------
  2772.   unless method_defined?(:load_event)
  2773.     def load_event(*a)
  2774.       case a.size
  2775.       when 5, 4 then (mapid, eventid, x, y = *a)
  2776.       when 3    then (mapid = @map_id) && (eventid, x, y = *a)
  2777.       when 2    then (mapid, y = @map_id, 0) && (eventid, x = *a)
  2778.       when 1    then (mapid, x, y = @map_id, 0,0) && (eventid = a.first)
  2779.       when 0    then return nil
  2780.       end
  2781.       map = load_map_data(mapid)
  2782.       event = map.events.values.detect { |event| event.id == eventid }
  2783.       unless event.nil?
  2784.         (a = a.at(4)) && (b = [a].flatten) && event.pages.reject! do |s|
  2785.           c = b.map {|i| i.is_a?(Range) ? i.to_a : i }
  2786.           c.flatten.not.include?(event.pages.index(s)+1)
  2787.         end
  2788.         return nil if event.pages.empty?
  2789.         c,r = [Array,Range], []
  2790.         c.include?(x.class) && (x = x.to_a.map{|s|s.is_a?(Range) ? s.to_a : s})
  2791.         c.include?(y.class) && (y = y.to_a.map{|s|s.is_a?(Range) ? s.to_a : s})
  2792.         [x].flatten.dproduct([y].flatten).each do |x1,y1|
  2793.           event.instance_variable_set(:@id,(id = next_key_events))
  2794.           r.push(@events[id] = e = Game_Event.new(@map_id, event.clone))
  2795.           e.loaded_event = true
  2796.           e.moveto(x1,y1)
  2797.         end
  2798.         a = r.size == 1 ? r.first : r
  2799.         if r && (s = spriteset).is_a?(Spriteset_Map)
  2800.           sc = s.character_sprites
  2801.           after  = sc.select { |e| e if e.character != $game_player }
  2802.           player = s.sprite_player
  2803.           sc.replace(after)
  2804.           r.each {|e| sc.push(Sprite_Character.new(s.viewport1, e)) }
  2805.           sc.push(player)
  2806.         end
  2807.         return a
  2808.       end
  2809.     end
  2810.   end
  2811.   #--------------------------------------------------------------------------
  2812.   # ● New method: call_event
  2813.   #--------------------------------------------------------------------------
  2814.   unless method_defined?(:call_event)
  2815.     def call_event(*a)
  2816.       case a.size
  2817.       when 3 then (mapid, eventid, page_id = *a)
  2818.       when 2 then (page_id = -1) && (mapid, eventid = *a)
  2819.       when 1 then (mapid, page_id = @map_id, -1) && (eventid = a.first)
  2820.       when 0 then return nil
  2821.       end
  2822.       map = load_map_data(mapid)
  2823.       event = map.events.values.detect { |event| event.id == eventid }
  2824.       unless event.nil?
  2825.         if page_id == -1 && event.respond_to?(:conditions_met?)
  2826.           pages = event.pages.reverse.find {|page| event.conditions_met?(page)}
  2827.         else
  2828.           pages = event.pages[[page_id,1].max-1]
  2829.         end
  2830.         klass = LiTTleDRAgo::VX ? Game_Interpreter : Interpreter
  2831.         child = klass.new(interpreter.instance_variable_get(:@depth) + 1)
  2832.         child.setup(pages.list, interpreter.same_map? ? event.id : 0)
  2833.         if LiTTleDRAgo::VXA
  2834.           child.run rescue FiberError
  2835.         else
  2836.           interpreter.instance_variable_set(:@child_interpreter, child)
  2837.         end
  2838.       end
  2839.     end
  2840.   end
  2841.   #--------------------------------------------------------------------------
  2842.   # ● New method: load_map_data
  2843.   #--------------------------------------------------------------------------
  2844.   unless method_defined?(:load_map_data)
  2845.     def load_map_data(mapid, ext = LiTTleDRAgo.data_default_extension)
  2846.       (map = sprintf("Data/Map%03d.#{ext}", mapid)) && load_data(map)
  2847.     end
  2848.   end
  2849.   #--------------------------------------------------------------------------
  2850.   # ● New method: increment_key_events
  2851.   #--------------------------------------------------------------------------
  2852.   unless method_defined?(:next_key_events)
  2853.     def next_key_events
  2854.       (@events.keys.max || 0) + 1
  2855.     end
  2856.   end
  2857.   #--------------------------------------------------------------------------
  2858.   # ● New method: unused_key_events
  2859.   #--------------------------------------------------------------------------
  2860.   unless method_defined?(:unused_key_events)
  2861.     def unused_key_events(start = 1)
  2862.       start = [start, next_key_events].min
  2863.       (start..next_key_events).detect {|i| @events.keys.not.include?(i)}
  2864.     end
  2865.   end
  2866.   #--------------------------------------------------------------------------
  2867.   # ● New method: spriteset
  2868.   #--------------------------------------------------------------------------
  2869.   unless method_defined?(:spriteset)
  2870.     def spriteset
  2871.       LiTTleDRAgo.scene.instance_variable_get(:@spriteset)
  2872.     end
  2873.   end
  2874.   #--------------------------------------------------------------------------
  2875.   # ● New method: character_sprite
  2876.   #--------------------------------------------------------------------------
  2877.   unless method_defined?(:character_sprite)
  2878.     def character_sprite(id = 0)
  2879.       return unless spriteset.is_a?(Spriteset_Map)
  2880.       id = id.is_a?(Game_Character) ? id : id == 0 ? $game_player : events[id]
  2881.       spriteset.find_character(id)
  2882.     end
  2883.   end
  2884.   #--------------------------------------------------------------------------
  2885.   # ● New method: picture_sprite
  2886.   #--------------------------------------------------------------------------
  2887.   unless method_defined?(:picture_sprite)
  2888.     def picture_sprite(id = nil)
  2889.       return unless spriteset.is_a?(Spriteset_Map)
  2890.       spriteset.update_pictures if spriteset.respond_to?(:update_pictures)
  2891.       result = spriteset.instance_variable_get(:@picture_sprites)
  2892.       id.nil? ? result : result[id]
  2893.     end
  2894.   end
  2895. end
  2896. #==============================================================================
  2897. # ■ RPG::Cache
  2898. #------------------------------------------------------------------------------
  2899. #
  2900. #==============================================================================
  2901. ModCache = LiTTleDRAgo.cache
  2902. class << ModCache
  2903.   #-----------------------------------------------------------------------
  2904.   # ● New method: self.draw_text
  2905.   #-----------------------------------------------------------------------
  2906.   unless method_defined?(:draw_text)
  2907.     def draw_text(
  2908.             width, height, text,
  2909.             font = Font.default_name,
  2910.             size = Font.default_size,
  2911.             bold = Font.default_bold,
  2912.             italic = Font.default_italic,
  2913.             color = Font.default_color,
  2914.             edging = false
  2915.           )
  2916.       cache_index = "text_" + width.to_s + height.to_s + text
  2917.       font_text = ""
  2918.       font.size.times do |i|
  2919.         font_text += font[i].to_s
  2920.       end
  2921.       cache_index += font_text + size.to_s + bold.to_s + italic.to_s
  2922.       cache_index += "#{color.red}#{color.blue}#{color.green}#{color.alpha}"
  2923.       @cache ||= {}
  2924.       if @cache[cache_index].nil? or @cache[cache_index].disposed?
  2925.         bitmap = Bitmap.new(width, height)
  2926.         bitmap.font.name = font
  2927.         bitmap.font.size = size
  2928.         bitmap.font.bold = bold
  2929.         bitmap.font.italic = italic
  2930.         bitmap.font.color = color
  2931.         if edging
  2932.           bitmap.draw_edging_text(0, 0, width, height, text, 0)
  2933.         else
  2934.           bitmap.draw_text(0, 0, width, height, text, 0)
  2935.         end
  2936.         @cache[cache_index] = bitmap
  2937.       end
  2938.       return @cache[cache_index]
  2939.     end
  2940.   end
  2941.   #-----------------------------------------------------------------------
  2942.   # ● New method: self.method_missing
  2943.   #-----------------------------------------------------------------------
  2944.   def method_missing(val,*a,&b)
  2945.     if a.at(0).is_a?(String) && a.size <= 2
  2946.       return load_bitmap("Graphics/#{val}/",*a,&b)
  2947.     end
  2948.     modified = [:invert,:brighten,:darken,:grayscale,:pixelate,:frost]
  2949.     if modified.include?(a.first) && a.at(1).is_a?(String) && a.size <= 3
  2950.       method = a.shift
  2951.       filename = a.join + "-#{method}"
  2952.       unless drago_bitmap_exist?("Graphics/#{val}",filename)
  2953.         bitmap = load_bitmap("Graphics/#{val}/",*a,&b)
  2954.         drago_set_bitmap(bitmap.send(method),"Graphics/#{val}",filename)
  2955.       end
  2956.       return drago_get_bitmap("Graphics/#{val}",filename)
  2957.     end
  2958.     text = "Undefined method #{val} for #{self.inspect}"
  2959.     raise(NoMethodError, text, caller(1))      
  2960.   end
  2961.   #-----------------------------------------------------------------------
  2962.   # ● New method: drago_get_bitmap
  2963.   #-----------------------------------------------------------------------
  2964.   def drago_get_bitmap(folder_name, filename = '', hue = 0)
  2965.     return empty_bitmap if filename.not.is_a?(String) || filename.empty?
  2966.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2967.     path = path.gsub("\\","/").gsub("//","/")
  2968.     last = filename.split('.').last
  2969.     filename.gsub!(".png","") if last.is_a?(String) && last[/png/i]
  2970.     load_bitmap_no_rescue(path.downcase,filename.downcase,hue)
  2971.   end
  2972.   #-----------------------------------------------------------------------
  2973.   # ● New method: drago_set_bitmap
  2974.   #-----------------------------------------------------------------------
  2975.   def drago_set_bitmap(bitmap, folder_name = '', filename = 'bitmap')
  2976.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2977.     path = path.gsub("\\","/").gsub("//","/")
  2978.     last = filename.split('.').last
  2979.     filename += '.png' unless last.is_a?(String) && last[/png/i]
  2980.     Dir.make_dir(path) unless FileTest.directory?(path)
  2981.     bitmap.export(path + filename)
  2982.     drago_get_bitmap(folder_name, filename)
  2983.   end
  2984.   #-----------------------------------------------------------------------
  2985.   # ● New method: drago_bitmap_exist?
  2986.   #-----------------------------------------------------------------------
  2987.   def drago_bitmap_exist?(folder_name, filename)
  2988.     return false if filename.not.is_a?(String) || filename.empty?
  2989.     path = LiTTleDRAgo::APPPATHDRAGO + "#{folder_name}/"
  2990.     path = path.gsub("\\","/").gsub("//","/")
  2991.     last = filename.split('.').last
  2992.     filename += '.png' unless last.is_a?(String) && last[/png/i]
  2993.     FileTest.file?(path + filename)
  2994.   end
  2995.   #--------------------------------------------------------------------------
  2996.   # * Load Bitmap
  2997.   #--------------------------------------------------------------------------
  2998.   define_sec_method(:load_bitmap_no_rescue) do |folder, file, *a|
  2999.     @cache ||= {}
  3000.     if file.empty?
  3001.       empty_bitmap
  3002.     elsif (hue = a.first).is_a?(Numeric) && hue != 0
  3003.       hue_changed_bitmap(folder + file, hue.round)
  3004.     else
  3005.       normal_bitmap(folder + file)
  3006.     end
  3007.   end
  3008.   #--------------------------------------------------------------------------
  3009.   # * Create Empty Bitmap
  3010.   #--------------------------------------------------------------------------
  3011.   define_sec_method(:empty_bitmap) { Bitmap.new(32, 32)}
  3012.   #--------------------------------------------------------------------------
  3013.   # * Create/Get Normal Bitmap
  3014.   #--------------------------------------------------------------------------
  3015.   define_sec_method(:normal_bitmap) do |path|
  3016.     @cache[path] = Bitmap.new(path) unless include?(path)
  3017.     @cache[path]
  3018.   end
  3019.   #--------------------------------------------------------------------------
  3020.   # * Create/Get Hue-Changed Bitmap
  3021.   #--------------------------------------------------------------------------
  3022.   define_sec_method(:hue_changed_bitmap) do |path, hue|
  3023.     key = [path, hue]
  3024.     unless include?(key)
  3025.       @cache[key] = normal_bitmap(path).clone
  3026.       @cache[key].hue_change(hue)
  3027.     end
  3028.     @cache[key]
  3029.   end
  3030.   #--------------------------------------------------------------------------
  3031.   # * Check Cache Existence
  3032.   #--------------------------------------------------------------------------
  3033.   def include?(key)
  3034.     @cache[key] && @cache[key].not.disposed?
  3035.   end
  3036. end
  3037. #==============================================================================
  3038. # ** Window_Base
  3039. #------------------------------------------------------------------------------
  3040. #  This class is for all in-game windows.
  3041. #==============================================================================
  3042.  
  3043. class Window_Base < Window
  3044.   #--------------------------------------------------------------------------
  3045.   # * Redirect Listing
  3046.   #--------------------------------------------------------------------------
  3047.   redirect_method :draw_text,    'contents.draw_text'
  3048.   redirect_method :text_size,    'contents.text_size'
  3049.   redirect_method :change_color, 'contents.change_color'
  3050.   redirect_method :draw_picture, 'contents.draw_picture'
  3051.   redirect_method :draw_icon,    'contents.draw_icon'
  3052.   redirect_method :draw_battler, 'contents.draw_battler'
  3053.   #--------------------------------------------------------------------------
  3054.   # * Redefined method: line_height, translucent_alpha
  3055.   # * New method:       show, hide, activate, deactivate
  3056.   #--------------------------------------------------------------------------
  3057.   define_sec_method(:line_height)       { 32 }
  3058.   define_sec_method(:translucent_alpha) { 160 }
  3059.   define_sec_method(:show)              { self.visible = true  }
  3060.   define_sec_method(:hide)              { self.visible = false }
  3061.   define_sec_method(:activate)          { self.active  = true  }
  3062.   define_sec_method(:deactivate)        { self.active  = false }
  3063.   #--------------------------------------------------------------------------
  3064.   # * New method: center_window
  3065.   #--------------------------------------------------------------------------
  3066.   unless method_defined?(:center_window)
  3067.     def center_window
  3068.       self.x = Graphics.width/2  - self.width/2
  3069.       self.y = Graphics.height/2 - self.height/2
  3070.     end
  3071.   end
  3072.   #--------------------------------------------------------------------------
  3073.   # * Redefined method: disabled_color
  3074.   #--------------------------------------------------------------------------
  3075.   unless method_defined?(:disabled_color)
  3076.     def disabled_color     
  3077.       color = normal_color
  3078.       color.alpha = 128
  3079.       return color
  3080.     end
  3081.   end
  3082.   #--------------------------------------------------------------------------
  3083.   # * Redefined method: draw_text_ex
  3084.   #--------------------------------------------------------------------------
  3085.   unless method_defined?(:draw_text_ex)
  3086.     def draw_text_ex(x, y, text)
  3087.       reset_font_settings
  3088.       text = convert_escape_characters(text)
  3089.       pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  3090.       process_character(text.slice!(0, 1), text, pos) until text.empty?
  3091.     end
  3092.   end
  3093.   #--------------------------------------------------------------------------
  3094.   # * Redefined method: reset_font_settings
  3095.   #--------------------------------------------------------------------------
  3096.   unless method_defined?(:reset_font_settings)
  3097.     def reset_font_settings
  3098.       change_color(normal_color)
  3099.       contents.font.size = Font.default_size
  3100.       contents.font.bold = Font.default_bold
  3101.       contents.font.italic = Font.default_italic
  3102.     end
  3103.   end
  3104.   #--------------------------------------------------------------------------
  3105.   # * Redefined method: convert_escape_characters
  3106.   #--------------------------------------------------------------------------
  3107.   unless method_defined?(:convert_escape_characters)
  3108.     def convert_escape_characters(text)
  3109.       result = text.to_s.clone
  3110.       result.gsub!(/\\/)            { "\e" }
  3111.       result.gsub!(/\e\e/)          { "\\" }
  3112.       result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i]   }
  3113.       result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i)        }
  3114.       result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  3115.       result.gsub!(/\eG/i)          { currency_unit }
  3116.       result
  3117.     end
  3118.   end
  3119.   #--------------------------------------------------------------------------
  3120.   # * Redefined method: actor_name
  3121.   #--------------------------------------------------------------------------
  3122.   unless method_defined?(:actor_name)
  3123.     def actor_name(n)
  3124.       actor = n >= 1 ? $game_actors[n] : nil
  3125.       actor ? actor.name : ""
  3126.     end
  3127.   end
  3128.   #--------------------------------------------------------------------------
  3129.   # * Redefined method: party_member_name
  3130.   #--------------------------------------------------------------------------
  3131.   unless method_defined?(:party_member_name)
  3132.     def party_member_name(n)
  3133.       actor = n >= 1 ? $game_party.instance_variable_get(:@actors)[n - 1] : nil
  3134.       actor ? actor.name : ""
  3135.     end
  3136.   end
  3137.   #--------------------------------------------------------------------------
  3138.   # * Redefined method: process_character
  3139.   #--------------------------------------------------------------------------
  3140.   unless method_defined?(:process_character)
  3141.     def process_character(c, text, pos)
  3142.       case c
  3143.       when "\n"   # New line
  3144.         process_new_line(text, pos)
  3145.       when "\f"   # New page
  3146.         process_new_page(text, pos)
  3147.       when "\e"   # Control character
  3148.         process_escape_character(obtain_escape_code(text), text, pos)
  3149.       else        # Normal character
  3150.         process_normal_character(c, pos)
  3151.       end
  3152.     end
  3153.   end
  3154.   #--------------------------------------------------------------------------
  3155.   # * Redefined method: process_normal_character
  3156.   #--------------------------------------------------------------------------
  3157.   unless method_defined?(:process_normal_character)
  3158.     def process_normal_character(c, pos)
  3159.       text_width = text_size(c).width
  3160.       draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  3161.       pos[:x] += text_width
  3162.     end
  3163.   end
  3164.   #--------------------------------------------------------------------------
  3165.   # * Redefined method: process_new_line
  3166.   #--------------------------------------------------------------------------
  3167.   unless method_defined?(:process_new_line)
  3168.     def process_new_line(text, pos)
  3169.       pos[:x] = pos[:new_x]
  3170.       pos[:y] += pos[:height]
  3171.       pos[:height] = calc_line_height(text)
  3172.     end
  3173.   end
  3174.   #--------------------------------------------------------------------------
  3175.   # * Redefined method: process_new_page
  3176.   #--------------------------------------------------------------------------
  3177.   unless method_defined?(:process_new_page)
  3178.     def process_new_page(text, pos)
  3179.     end
  3180.   end
  3181.   #--------------------------------------------------------------------------
  3182.   # * Redefined method: obtain_escape_code
  3183.   #--------------------------------------------------------------------------
  3184.   unless method_defined?(:obtain_escape_code)
  3185.     def obtain_escape_code(text)
  3186.       text.slice!(/^[\$\.\|\^!><\{\}\\]|^[\/\w+\/]+/i)
  3187.     end
  3188.   end
  3189.   #--------------------------------------------------------------------------
  3190.   # * Redefined method: obtain_escape_param
  3191.   #--------------------------------------------------------------------------
  3192.   unless method_defined?(:obtain_escape_param)
  3193.     def obtain_escape_param(text)
  3194.       text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0
  3195.     end
  3196.   end
  3197.   #--------------------------------------------------------------------------
  3198.   # * Redefined method: process_escape_character
  3199.   #--------------------------------------------------------------------------
  3200.   unless method_defined?(:process_escape_character)
  3201.     def process_escape_character(code, text, pos)
  3202.       case code.upcase
  3203.       when 'C' then change_color(text_color(obtain_escape_param(text)))
  3204.       when 'I' then process_draw_icon(obtain_escape_code(text), pos)
  3205.       when '{' then make_font_bigger
  3206.       when '}' then make_font_smaller
  3207.       end
  3208.     end
  3209.   end
  3210.   #--------------------------------------------------------------------------
  3211.   # * Redefined method: process_draw_icon
  3212.   #--------------------------------------------------------------------------
  3213.   unless method_defined?(:process_draw_icon)
  3214.     def process_draw_icon(icon_index, pos)
  3215.       icon_index = icon_index.to_i if icon_index.to_i.to_s == icon_index
  3216.       draw_icon(icon_index, pos[:x], pos[:y])
  3217.       pos[:x] += 24
  3218.     end
  3219.   end
  3220.   #--------------------------------------------------------------------------
  3221.   # * Redefined method: make_font_bigger
  3222.   #--------------------------------------------------------------------------
  3223.   unless method_defined?(:make_font_bigger)
  3224.     def make_font_bigger
  3225.       contents.font.size += 8 if contents.font.size <= 64
  3226.     end
  3227.   end
  3228.   #--------------------------------------------------------------------------
  3229.   # * Redefined method: make_font_smaller
  3230.   #--------------------------------------------------------------------------
  3231.   unless method_defined?(:make_font_smaller)
  3232.     def make_font_smaller
  3233.       contents.font.size -= 8 if contents.font.size >= 16
  3234.     end
  3235.   end
  3236.   #--------------------------------------------------------------------------
  3237.   # * Redefined method: calc_line_height
  3238.   #--------------------------------------------------------------------------
  3239.   unless method_defined?(:calc_line_height)
  3240.     def calc_line_height(text, restore_font_size = true)
  3241.       result = [line_height, contents.font.size].max
  3242.       last_font_size = contents.font.size
  3243.       text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
  3244.         make_font_bigger  if esc == "\e{"
  3245.         make_font_smaller if esc == "\e}"
  3246.         result = [result, contents.font.size].max
  3247.       end
  3248.       contents.font.size = last_font_size if restore_font_size
  3249.       result
  3250.     end
  3251.   end
  3252.   #--------------------------------------------------------------------------
  3253.   # * New method: currency_unit
  3254.   #--------------------------------------------------------------------------
  3255.   unless method_defined?(:currency_unit)
  3256.     def currency_unit
  3257.       gold = $data_system.words.gold
  3258.       return gold
  3259.     end
  3260.   end
  3261.   #--------------------------------------------------------------------------
  3262.   # ● New method: draw_map_name
  3263.   #--------------------------------------------------------------------------
  3264.   unless method_defined?(:draw_map_name)
  3265.     def draw_map_name(x, y, width, height)
  3266.       map_id  = $game_map.map_id
  3267.       mapInfo = $game_map.mapInfo
  3268.       draw_text(x, y, width, height, mapInfo[map_id].name.to_s)
  3269.     end
  3270.   end
  3271.   #--------------------------------------------------------------------------
  3272.   # ● New method: draw_enter_text
  3273.   #--------------------------------------------------------------------------
  3274.   unless method_defined?(:draw_enter_text)
  3275.     def draw_enter_text(x, y, width, height, text)
  3276.       info_box = text.split(/\n/)
  3277.       info_box.size.times do |i|
  3278.         draw_text( x, y + i * line_height, width, line_height, info_box[i])
  3279.         break if (y + i * line_height) > (self.height - line_height)
  3280.       end
  3281.     end
  3282.   end
  3283.   #--------------------------------------------------------------------------
  3284.   # ● New method: draw_picture_number
  3285.   #--------------------------------------------------------------------------
  3286.   unless method_defined?(:draw_picture_number)
  3287.     def draw_picture_number(x, y, value, file_name,align = 0,
  3288.                   space = 0, frame_max = 1,frame_index = 0)     
  3289.       number_image = LiTTleDRAgo.cache.windowskin(file_name)
  3290.       frame_max = [frame_max, 1].max
  3291.       frame_index = frame_max - 1 if frame_index > frame_max - 1
  3292.       align = [[align,2].min,0].max
  3293.       cw = number_image.width / 10
  3294.       ch = number_image.height / frame_max
  3295.       h = ch * frame_index
  3296.       number = value.abs.to_s.split(//)
  3297.       case align
  3298.       when 0 then plus_x = (-cw + space) * number.size
  3299.       when 1 then plus_x = ((-cw + space) * number.size) / 2
  3300.       when 2 then plus_x = 0
  3301.       end
  3302.       for r in 0..number.size - 1      
  3303.         rect = Rect.new(cw * number[r].to_i, h, cw, ch)
  3304.         contents.blt(plus_x + x + ((cw - space) * r), y , number_image, rect)
  3305.       end     
  3306.       number_image.dispose
  3307.     end     
  3308.   end
  3309. end
  3310.  
  3311. #==============================================================================
  3312. # ■ Bitmap
  3313. #------------------------------------------------------------------------------
  3314. #
  3315. #==============================================================================
  3316. class Bitmap  
  3317.   #----------------------------------------------------------------------------
  3318.   # ● Constant
  3319.   #----------------------------------------------------------------------------
  3320.   RtlMoveMemory_pi = LiTTleDRAgo.rtlmemory_pi
  3321.   RtlMoveMemory_ip = LiTTleDRAgo.rtlmemory_ip
  3322.   Blur_Setting     = "{ 'offset' => 2, 'spacing' => 1, 'opacity' => 255 }"
  3323.   #----------------------------------------------------------------------------
  3324.   # ● Public Instance Variables
  3325.   #----------------------------------------------------------------------------
  3326.   attr_sec_accessor :blur_settings,  Blur_Setting
  3327.   #----------------------------------------------------------------------------
  3328.   # ● Redirect Listing
  3329.   #----------------------------------------------------------------------------
  3330.   redirect_method :change_hue,          :hue_change
  3331.   #-------------------------------------------------------------------------
  3332.   # ● Define Secondary Listing
  3333.   #-------------------------------------------------------------------------
  3334.   define_sec_method(:full_fill) { |color|  fill_rect(rect, color) }
  3335.   #----------------------------------------------------------------------------
  3336.   # ● Alias Listing
  3337.   #----------------------------------------------------------------------------
  3338.   alias_sec_method :invert!,            :reversing!  
  3339.   alias_sec_method :grayscale!,         :gray_scale!
  3340.   alias_sec_method :frost,              :diffusion   
  3341.   alias_sec_method :frost!,             :diffusion!  
  3342.   alias_sec_method :drg_ce_stretch_blt, :stretch_blt
  3343.   alias_method     :drg_bitmap_load,    :initialize
  3344.   #--------------------------------------------------------------------------
  3345.   # * Object Initialization
  3346.   #----------------------------------------------------------------------------
  3347.   def initialize(*args)
  3348.     if (a = args.flatten).size == 4 && a.all? {|s| s.is_a?(Table)}
  3349.       bitmap = BitmapDump.read_bitmap_data(*a)
  3350.       drg_bitmap_load(bitmap.width,bitmap.height)
  3351.       return blt(0,0,bitmap,rect) && bitmap.dispose
  3352.     end
  3353.     drg_bitmap_load(*args)
  3354.   end
  3355.   #----------------------------------------------------------------------------
  3356.   # ● New method: address
  3357.   #----------------------------------------------------------------------------
  3358.   unless method_defined?(:address)
  3359.     def address
  3360.       @address ||= (  RtlMoveMemory_pi.call(a="\0"*4, __id__*2+16, 4)
  3361.                       RtlMoveMemory_pi.call(a, a.unpack('L')[0]+8, 4)
  3362.                       RtlMoveMemory_pi.call(a, a.unpack('L')[0]+16, 4)
  3363.                       a.unpack('L')[0]    )
  3364.     end
  3365.   end
  3366.   #----------------------------------------------------------------------------
  3367.   # ● New method: export
  3368.   #----------------------------------------------------------------------------
  3369.   unless method_defined?(:export)
  3370.     def export(filename)
  3371.       file = File.open(filename, 'wb')
  3372.         size, vxace = width * height * 4, LiTTleDRAgo::RGSS3
  3373.         case format = File.extname(filename)
  3374.         when '.bmp'
  3375.           data = String.new
  3376.           RtlMoveMemory_pi.call(empty_rString_struct="\0"*16,data.__id__*2,16)
  3377.           flags = vxace ? 5267461 : 8199
  3378.           klass = empty_rString_struct.unpack('@4L')[0]
  3379.           pack  = [flags,klass,size,address].pack('L4')
  3380.           weiss = [size+54,0,54,40,width,height,1,32,0,size,0,0,0,0]
  3381.           RtlMoveMemory_ip.call(data.__id__*2, pack, 16)
  3382.           file.write("BM#{weiss.pack('L6S2L6')}")
  3383.           file.write(data)
  3384.           RtlMoveMemory_ip.call(data.__id__*2, empty_rString_struct, 16)
  3385.         when '.png'
  3386.           write_chunk = Proc.new do |chunk|
  3387.             file.write([(vxace ? chunk.bytesize : chunk.size)-4].pack('N'))
  3388.             file.write(chunk)
  3389.             file.write([Zlib.crc32(chunk)].pack('N'))
  3390.           end
  3391.           null_char, w4, i, byte = "\0", width*4, 0, (t_Fx = 0)
  3392.           RtlMoveMemory_pi.call(data=null_char*size, address, size)
  3393.           if vxace
  3394.             data.force_encoding('ASCII-8BIT')
  3395.             (0).step(size-4, 4) do |i|
  3396.               Graphics.update if (t_Fx += 1) % 10000 == 0
  3397.               byte = data.getbyte(i)
  3398.               data.setbyte(i, data.getbyte(i+=2))
  3399.               data.setbyte(i, byte)
  3400.             end
  3401.           else
  3402.             (0).step(size-4, 4) do |i|
  3403.               Graphics.update if (t_Fx += 1) % 10000 == 0
  3404.               data[i,3] = data[i,3].reverse!
  3405.             end
  3406.           end
  3407.           deflate = Zlib::Deflate.new(9)
  3408.             (size-w4).step(0, -w4) {|i| deflate << null_char << data[i,w4]}
  3409.             file.write("\211PNG\r\n\32\n")
  3410.             write_chunk.call("IHDR#{[width,height,8,6,0,0,0].pack('N2C5')}")
  3411.             write_chunk.call("IDAT#{deflate.finish}")
  3412.             write_chunk.call('IEND')
  3413.           deflate.close
  3414.         when ''
  3415.           script_report("Error: Export Bitmap Failed\n"+
  3416.               "Extension '#{filename}' is missing.")
  3417.         else         
  3418.           script_report("Error: Export Bitmap Failed\n"+
  3419.                "Extension '#{format}' is not supported.")
  3420.         end
  3421.       file.close
  3422.     end
  3423.   end
  3424.   #----------------------------------------------------------------------------
  3425.   # ● New method: blt_cache
  3426.   #----------------------------------------------------------------------------
  3427.   unless method_defined?(:blt_cache)
  3428.     def blt_cache(x, y, width, height, text, align, edging)
  3429.       cache_bitmap = LiTTleDRAgo.cache.draw_text(
  3430.           width, height, text, self.font.name, self.font.size,
  3431.           self.font.bold, self.font.italic, self.font.color, edging
  3432.       )
  3433.       x_plus = uncache_align_exe(width, text, align)
  3434.       blt(x + x_plus , y , cache_bitmap, Rect.new(0, 0, width, height))
  3435.     end
  3436.   end
  3437.   #----------------------------------------------------------------------------
  3438.   # ● New method: uncache_align_exe
  3439.   #----------------------------------------------------------------------------
  3440.   unless method_defined?(:uncache_align_exe)
  3441.     def uncache_align_exe(width, text, align)
  3442.       recter = self.text_size(text)
  3443.       case align
  3444.       when 0 then x_index = 0
  3445.       when 1 then x_index = (width / 2) - recter.width / 2
  3446.       when 2 then x_index = width - recter.width
  3447.       else
  3448.         raise "Text Cache : align is wrong"
  3449.       end
  3450.       return x_index
  3451.     end
  3452.   end
  3453.   #----------------------------------------------------------------------------
  3454.   # ● New method: draw_cache_text
  3455.   #----------------------------------------------------------------------------
  3456.   unless method_defined?(:draw_cache_text)
  3457.     def draw_cache_text(x, y, width, height, text, align = 0)
  3458.       blt_cache(x, y, width, height, text, align, false)
  3459.     end
  3460.   end
  3461.   #----------------------------------------------------------------------------
  3462.   # ● New method: draw_edging_cache_text
  3463.   #----------------------------------------------------------------------------
  3464.   unless method_defined?(:draw_edging_cache_text)
  3465.     def draw_edging_cache_text(x, y, width, height, text, align = 0)
  3466.       blt_cache(x, y, width, height, text, align, true)
  3467.     end
  3468.   end
  3469.   #----------------------------------------------------------------------------
  3470.   # ● New method: draw_easy_cache_text
  3471.   #----------------------------------------------------------------------------
  3472.   unless method_defined?(:draw_easy_cache_text)
  3473.     def draw_easy_cache_text(x, y, text)
  3474.       t_rect = text_size(text)
  3475.       blt_cache(x, y, t_rect.width, t_rect.height, text, 0, false)
  3476.     end
  3477.   end
  3478.   #----------------------------------------------------------------------------
  3479.   # ● New method: draw_easy_edging_cache_text
  3480.   #----------------------------------------------------------------------------
  3481.   unless method_defined?(:draw_easy_edging_cache_text)
  3482.     def draw_easy_edging_cache_text(x, y, text)
  3483.       t_rect = text_size(text)
  3484.       blt_cache(x, y, t_rect.width, t_rect.height, text, 0, true)
  3485.     end
  3486.   end
  3487.   #--------------------------------------------------------------------------
  3488.   # * New method: change_color
  3489.   #--------------------------------------------------------------------------
  3490.   unless method_defined?(:change_color)
  3491.     def change_color(color, enabled = true)
  3492.       font.color = color
  3493.       font.color.alpha = translucent_alpha unless enabled
  3494.     end
  3495.   end
  3496.   #--------------------------------------------------------------------------
  3497.   # ● New method: draw_picture
  3498.   #--------------------------------------------------------------------------
  3499.   unless method_defined?(:draw_picture)
  3500.     def draw_picture(file_name, x, y, opacity = 255)
  3501.       bitmap = LiTTleDRAgo.cache.picture(file_name)
  3502.       cw = bitmap.width
  3503.       ch = bitmap.height
  3504.       src_rect = Rect.new(0, 0, cw, ch)
  3505.       blt(x, y, bitmap, src_rect, opacity)
  3506.     end
  3507.   end
  3508.   #--------------------------------------------------------------------------
  3509.   # ● New method: draw_icon
  3510.   #--------------------------------------------------------------------------
  3511.   unless method_defined?(:draw_icon)
  3512.     def draw_icon(file_name, x, y, enabled = true)
  3513.       if file_name.is_a?(Numeric)
  3514.         bitmap = LiTTleDRAgo.cache.system("Iconset")
  3515.         src_rect = Rect.new(file_name % 16 * 24, file_name / 16 * 24, 24, 24)
  3516.         blt(x, y, bitmap, src_rect, enabled ? 255 : 160)
  3517.       elsif file_name.is_a?(String)
  3518.         bitmap = LiTTleDRAgo.cache.icon(file_name)
  3519.         src_rect = Rect.new(0, 0, 24, 24)
  3520.         blt(x, y, bitmap, bitmap.rect, enabled ? 255 : 160)
  3521.       end
  3522.     end
  3523.   end
  3524.   #--------------------------------------------------------------------------
  3525.   # ● New method: draw_battler
  3526.   #--------------------------------------------------------------------------
  3527.   unless method_defined?(:draw_battler)
  3528.     def draw_battler(file_name, x, y, hue = 0, enabled = true)
  3529.       bitmap = LiTTleDRAgo.cache.battler(file_name, hue)
  3530.       cw = bitmap.width
  3531.       ch = bitmap.height
  3532.       src_rect = Rect.new(0, 0, cw, ch)
  3533.       blt(x, y, bitmap, src_rect, enabled ? 255 : 160)
  3534.     end
  3535.   end
  3536.   #--------------------------------------------------------------------------
  3537.   # ● New method: draw_bar
  3538.   #--------------------------------------------------------------------------
  3539.   unless method_defined?(:draw_bar)
  3540.     def draw_bar(x, y, current, file)
  3541.       bitmap = LiTTleDRAgo.cache.picture(file)
  3542.       cw = bitmap.width * current / 100
  3543.       ch = bitmap.height
  3544.       src_rect = Rect.new(0, 0, cw, ch)
  3545.       blt(x, y, bitmap, src_rect)
  3546.     end
  3547.   end
  3548.   #--------------------------------------------------------------------------
  3549.   # ● New method: draw_edging_text
  3550.   #--------------------------------------------------------------------------
  3551.   unless method_defined?(:draw_edging_text)
  3552.     def draw_edging_text(x, y, width, height, text, align=0)
  3553.       old_color = font.color.dup
  3554.       font.color = Color.new(0, 0, 0)
  3555.       draw_text(x-1, y-1, width, height, text, align)
  3556.       draw_text(x-1, y+1, width, height, text, align)
  3557.       draw_text(x+1, y-1, width, height, text, align)
  3558.       draw_text(x+1, y+1, width, height, text, align)
  3559.       font.color = old_color
  3560.       draw_text(x, y, width, height, text, align)
  3561.     end
  3562.   end
  3563.   #--------------------------------------------------------------------------
  3564.   # ● New method: draw_enter_text
  3565.   #--------------------------------------------------------------------------
  3566.   unless method_defined?(:draw_enter_text)
  3567.     def draw_enter_text(x, y, width, height, text, align=0)
  3568.       rect = text_size(text)
  3569.       info_box = text.split(/\n/)
  3570.       info_box.size.times do |i|
  3571.         draw_text( x, y+i*rect.height, width, height, info_box[i], align)
  3572.         break if (y+i*rect.height) > self.height
  3573.       end
  3574.     end
  3575.   end
  3576.   #--------------------------------------------------------------------------
  3577.   # ● New method: draw_enter_edging_text
  3578.   #--------------------------------------------------------------------------
  3579.   unless method_defined?(:draw_enter_edging_text)
  3580.     def draw_enter_edging_text(x, y, width, height, text, align=0)
  3581.       rect = text_size(text)
  3582.       info_box = text.split(/\n/)
  3583.       info_box.size.times do |i|
  3584.         draw_edging_text( x, y+i*rect.height,width,height,info_box[i],align)
  3585.         break if (y+i*rect.height) > self.height
  3586.       end
  3587.     end
  3588.   end
  3589.   #--------------------------------------------------------------------------
  3590.   # ● New method: draw_easy_text
  3591.   #--------------------------------------------------------------------------
  3592.   unless method_defined?(:draw_easy_text)
  3593.     def draw_easy_text(x, y, text)
  3594.       rect = text_size(text)
  3595.       draw_text(x, y, rect.width + rect.height/2, rect.height, text)
  3596.     end
  3597.   end
  3598.   #--------------------------------------------------------------------------
  3599.   # ● New method: draw_auto_text
  3600.   #--------------------------------------------------------------------------
  3601.   unless method_defined?(:draw_auto_text)
  3602.     def draw_auto_text(x, y, width, height, text)
  3603.       ini_x = 0
  3604.       law = 0
  3605.       text_box = []
  3606.       text_box[law] = []
  3607.       otxto = text.split(//)
  3608.       otxto.size.times do |i|
  3609.         text_rect = text_size(otxto[i])
  3610.         if (x + ini_x + text_rect.width) < width
  3611.           ini_x += text_rect.width
  3612.         else
  3613.           law += 1
  3614.           ini_x = text_rect.width
  3615.           text_box[law] = []
  3616.         end
  3617.         text_box[law].push(otxto[i])
  3618.       end
  3619.       for l in 0..law
  3620.         ini_x = 0
  3621.         text_box[l].size.times do |i|
  3622.           rect = text_size(text_box[l][i])
  3623.           draw_text(x + ini_x, y+l*height, rect.width, height, text_box[l][i])
  3624.           ini_x += rect.width
  3625.         end
  3626.       end
  3627.     end
  3628.   end
  3629.   #-------------------------------------------------------------------------
  3630.   # ● New method: erase
  3631.   #-------------------------------------------------------------------------
  3632.   unless method_defined?(:erase)
  3633.     def erase(*a)
  3634.       rect = nil
  3635.       if a.at(0).is_a?(Rect) then rect = a.at(0)
  3636.       elsif a.size == 4 then rect = Rect.new(*a)
  3637.       elsif a.size == 0 then rect = Rect.new(0,0,width,height)
  3638.       end
  3639.       fill_rect(rect.x, rect.y, rect.width, rect.height, Color.erase) if rect
  3640.     end
  3641.   end
  3642.   #-------------------------------------------------------------------------
  3643.   # ● New method: stretch
  3644.   #-------------------------------------------------------------------------
  3645.   unless method_defined?(:stretch)
  3646.     def stretch(width, height)
  3647.       dummy = Bitmap.new(width, height)
  3648.       dummy.stretch_blt(*[dummy.rect, self, self.rect])
  3649.       dummy
  3650.     end
  3651.   end
  3652.   #-------------------------------------------------------------------------
  3653.   # ● New method: crop
  3654.   #-------------------------------------------------------------------------
  3655.   unless method_defined?(:crop)
  3656.     def crop(*a)
  3657.       return unless a.size == 1 or a.size == 4
  3658.       rect = rect.at(0)   if a.size == 1 && a.at(0).is_a?(Rect)
  3659.       rect = Rect.new(*a) if a.size == 4
  3660.       cropped = Bitmap.new([rect.width,width-rect.x].min,
  3661.                            [rect.height,height-rect.y].min)
  3662.       cropped.blt(0,0,self,rect)
  3663.       cropped
  3664.     end
  3665.   end
  3666.   #-------------------------------------------------------------------------
  3667.   # ● Aliased method: stretch_blt
  3668.   #-------------------------------------------------------------------------
  3669.   def stretch_blt(*a)
  3670.     if respond_to?(:stretch_blend_blt)
  3671.       a = [a[0..2],0,1,a.at(3)||255].flatten
  3672.       stretch_blend_blt(*a)
  3673.     else
  3674.       drg_ce_stretch_blt(*a)
  3675.     end
  3676.   end
  3677.   #-------------------------------------------------------------------------
  3678.   # ● Aliased method: hue_change
  3679.   #-------------------------------------------------------------------------
  3680.   define_post_alias(:hue_change) { self }
  3681.   #--------------------------------------------------------------------------
  3682.   # ● New method: invert, etc
  3683.   #--------------------------------------------------------------------------
  3684.   [:invert, :brighten, :darken, :grayscale, :pixelate, :frost, :flip_horizontal,
  3685.    :flip_vertical, :rotate90, :rotate180, :rotate270].each do |meth|
  3686.     define_sec_method(meth) do |*args|
  3687.       bitmap = self.clone
  3688.       bitmap.send(:"#{meth}!",*args)
  3689.       return bitmap
  3690.     end
  3691.   end
  3692.   #-------------------------------------------------------------------------
  3693.   # ● New method: flip_horizontal!
  3694.   #-------------------------------------------------------------------------
  3695.   define_sec_method(:flip_horizontal!) do
  3696.     flipped = Bitmap.new(width, height)
  3697.     fliprect = Rect.new(width,0,-width,height)
  3698.     flipped.blt(0,0, self,fliprect)
  3699.     (clear || 0) && blt(0,0,flipped,rect)
  3700.     flipped.dispose
  3701.   end
  3702.   #-------------------------------------------------------------------------
  3703.   # ● New method: flip_vertical!
  3704.   #-------------------------------------------------------------------------
  3705.   define_sec_method(:flip_vertical!) do
  3706.     flipped = Bitmap.new(width, height)
  3707.     fliprect = Rect.new(0,height,width,-height)
  3708.     flipped.blt(0,0, self,fliprect)
  3709.     (clear || 0) && blt(0,0,flipped,rect)
  3710.     flipped.dispose
  3711.   end
  3712.   #-------------------------------------------------------------------------
  3713.   # ● New method: rotate90! (clockwise)
  3714.   #-------------------------------------------------------------------------
  3715.   define_sec_method(:rotate90!) do
  3716.     copy = self.clone
  3717.     (t_Fx = width).times do |i|
  3718.       height.times do |j|
  3719.         Graphics.update if (t_Fx += 1) % 10000 == 0
  3720.         a = (clockwise = true) ? [width - i - 1, j] : [i, height - j - 1]
  3721.         self.set_pixel(a[0],a[1], copy.get_pixel(j, i))
  3722.       end
  3723.     end
  3724.     copy.dispose
  3725.   end
  3726.   #-------------------------------------------------------------------------
  3727.   # ● New method: rotate180!
  3728.   #-------------------------------------------------------------------------
  3729.   define_sec_method(:rotate180!) do
  3730.     flip_vertical!
  3731.     flip_horizontal!
  3732.   end
  3733.   #-------------------------------------------------------------------------
  3734.   # ● New method: rotate270!
  3735.   #-------------------------------------------------------------------------
  3736.   define_sec_method(:rotate270!) do
  3737.     rotate90!
  3738.     rotate180!
  3739.   end  
  3740.   #----------------------------------------------------------------------------
  3741.   # ● New method: invert!
  3742.   #----------------------------------------------------------------------------
  3743.   unless method_defined?(:invert!)
  3744.     def invert!
  3745.       (t_Fx = width).times do |i|
  3746.         height.times do |j|
  3747.            color = get_pixel(i, j)
  3748.            Graphics.update if (t_Fx += 1) % 10000 == 0
  3749.            set_pixel(i, j, color.invert) if color.alpha > 0
  3750.          end
  3751.       end
  3752.     end
  3753.   end
  3754.   #--------------------------------------------------------------------------
  3755.   # * New method: brighten!
  3756.   #--------------------------------------------------------------------------
  3757.   unless method_defined?(:brighten!)
  3758.     def brighten!(amount = 10)
  3759.       (t_Fx = width).times do |w|
  3760.         height.times do |h|
  3761.           color = get_pixel(w, h)
  3762.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3763.           set_pixel(w, h, Color.new([color.red + amount, 255].min,
  3764.                                     [color.green + amount, 255].min,
  3765.                                     [color.blue + amount, 255].min,
  3766.                                     color.alpha)) if color.alpha > 0
  3767.         end
  3768.       end
  3769.     end
  3770.   end
  3771.   #--------------------------------------------------------------------------
  3772.   # * New method: darken!
  3773.   #--------------------------------------------------------------------------
  3774.   unless method_defined?(:darken!)
  3775.     def darken!(amount = 10)
  3776.       (t_Fx = width).times do |w|
  3777.         height.times do |h|
  3778.           color = get_pixel(w, h)
  3779.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3780.           set_pixel(w, h, Color.new([color.red - amount, 0].max,
  3781.                                     [color.green - amount, 0].max,
  3782.                                     [color.blue - amount, 0].max,
  3783.                                     color.alpha)) if color.alpha > 0
  3784.         end
  3785.       end
  3786.     end
  3787.   end
  3788.   #--------------------------------------------------------------------------
  3789.   # * New method: grayscale!
  3790.   # NOTE: calling this method repeatedly has no effect on the bitmap, but will
  3791.   #       still waste processing power. Do not call it repeatedly.
  3792.   #--------------------------------------------------------------------------
  3793.   unless method_defined?(:grayscale!)
  3794.     def grayscale!
  3795.       (t_Fx = width).times do |w|
  3796.         height.times do |h|
  3797.           color = get_pixel(w, h)
  3798.           if (a = color.alpha) > 0
  3799.             Graphics.update if (t_Fx += 1) % 10000 == 0
  3800.             num = (color.red + color.green + color.blue) / 3
  3801.             set_pixel(w, h, Color.new(num, num, num, a))
  3802.           end
  3803.         end
  3804.       end
  3805.     end
  3806.   end
  3807.   #--------------------------------------------------------------------------
  3808.   # * New method: drg_pixelate! (0.2 second)
  3809.   # NOTE: Pixelateing bitmaps to a larger pixel size is less process consuming.
  3810.   #       for best results, don't pixelate to numbers below four.
  3811.   #       This works much better for solid images, due to bugs.
  3812.   #--------------------------------------------------------------------------
  3813.   unless method_defined?(:drg_pixelate!)
  3814.     def drg_pixelate!(size = 10)
  3815.       return self if size <= (t_Fx = 1)
  3816.       c = lambda {|a,b| (a / b**2) * Math.sqrt(b) }
  3817.       for w in 0..((width - 1) / size)
  3818.         w *= size
  3819.         for h in 0..((height - 1) / size)
  3820.           h *= size
  3821.           r, g, b, a = 0, 0, 0, 0
  3822.           size.times do |i|
  3823.             color = get_pixel(w, h)
  3824.             r += color.red
  3825.             g += color.green
  3826.             b += color.blue
  3827.             a += color.alpha
  3828.             color = get_pixel(w + i, h)
  3829.             r += color.red
  3830.             g += color.green
  3831.             b += color.blue
  3832.             a += color.alpha
  3833.             color = get_pixel(w, h + i)
  3834.             r += color.red
  3835.             g += color.green
  3836.             b += color.blue
  3837.             a += color.alpha
  3838.           end
  3839.           Graphics.update if (t_Fx += 1) % 10000 == 0
  3840.           fill_rect(w, h, size, size, Color.new(c.call(r,size),c.call(g,size),
  3841.                                                 c.call(b,size),c.call(a,size)))
  3842.         end
  3843.       end
  3844.     end
  3845.   end
  3846.   #--------------------------------------------------------------------------
  3847.   # * New method: pixelate!
  3848.   #--------------------------------------------------------------------------
  3849.   unless method_defined?(:pixelate!)
  3850.     def pixelate!(size = 10)
  3851.       return mosaic!(size,size) if respond_to?(:mosaic!)
  3852.       return drg_pixelate!(size)
  3853.     end
  3854.   end
  3855.   #--------------------------------------------------------------------------
  3856.   # * New method: drg_frost! (5 second)
  3857.   # NOTE: Frosting a bitmap randomly scatters its pixels. As such, Consistant
  3858.   #       results are impossible to get.
  3859.   #       Frosting a bitmap beyond eight won't result in a more scattered image
  3860.   #--------------------------------------------------------------------------
  3861.   unless method_defined?(:drg_frost!)
  3862.     def drg_frost!(noise = 10)
  3863.       for pass in 1..noise
  3864.         (t_Fx = width).times do |w|
  3865.           height.times do |h|
  3866.             Graphics.update if (t_Fx += 1) % 10000 == 0
  3867.             set_pixel(w, h, get_pixel(w + rand(3) - 1, h + rand(3) - 1))
  3868.           end
  3869.         end
  3870.       end
  3871.     end
  3872.   end
  3873.   #-------------------------------------------------------------------------
  3874.   # ● New method: bltapiinit
  3875.   #-------------------------------------------------------------------------
  3876.   unless method_defined?(:bltapiinit)
  3877.     def bltapiinit
  3878.       info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
  3879.       hWndDC = LiTTleDRAgo.getdc.call(LiTTleDRAgo.hwnd)
  3880.       hMemDC = LiTTleDRAgo.ccdc.call(hWndDC)
  3881.       hMemBM = LiTTleDRAgo.ccbitmap.call(hWndDC, width, height)
  3882.       LiTTleDRAgo.releasedc.call(LiTTleDRAgo.hwnd, hWndDC)
  3883.       LiTTleDRAgo.selectobject.call(hMemDC, hMemBM)
  3884.       LiTTleDRAgo.setdibits.call(hMemDC, hMemBM, 0, height, address, info, 0)
  3885.       return hMemDC, hMemBM, info
  3886.     end
  3887.   end
  3888.   #-------------------------------------------------------------------------
  3889.   # ● New method: bit_blt
  3890.   #-------------------------------------------------------------------------
  3891.   unless method_defined?(:bit_blt)
  3892.     def bit_blt(x, y, src_bmp, src_rect, rastor_operation = 0xCC0020)
  3893.       hDC1, hBM1, info = *self.bltapiinit
  3894.       hDC2, hBM2 = *src_bmp.bltapiinit
  3895.       LiTTleDRAgo.bitblt.call(hDC1, x, y, src_rect.width, src_rect.height,
  3896.                   hDC2, src_rect.x, src_rect.y, rastor_operation)
  3897.       LiTTleDRAgo.getdibits.call(hDC1, hBM1, 0, height, address, info, 0)
  3898.       LiTTleDRAgo.deleteobject.call(hBM1)
  3899.       LiTTleDRAgo.deleteobject.call(hDC1)
  3900.       LiTTleDRAgo.deleteobject.call(hBM2)
  3901.       LiTTleDRAgo.deleteobject.call(hDC2)
  3902.     end
  3903.   end  
  3904.   #-------------------------------------------------------------------------
  3905.   # ● New method: crop_blt
  3906.   #-------------------------------------------------------------------------
  3907.   unless method_defined?(:crop_blt)
  3908.     def crop_blt(x, y, width, height, bitmap, dir = 1, align = 1, opacity = 255)
  3909.       w, h = bitmap.width, bitmap.height
  3910.       if w < width and h < height
  3911.         x += (width - w) / 2 if align == 1
  3912.         x += width - w       if align == 2
  3913.         return full_blt(x, y, bitmap, opacity)
  3914.       end
  3915.       i, j = dir % 3, dir / 3
  3916.       crop_x, crop_y = 0, 0
  3917.       crop_x = (w - width) / 2  if i == 1
  3918.       crop_x = w - width        if i == 2
  3919.       crop_y = (h - height) / 2 if j == 1
  3920.       crop_y = h - height       if j == 2
  3921.       blt(x, y, bitmap, Rect.new(crop_x, crop_y, width, height), opacity)
  3922.     end
  3923.   end
  3924.   #-------------------------------------------------------------------------
  3925.   # ● New method: fit_blt
  3926.   #-------------------------------------------------------------------------
  3927.   unless method_defined?(:fit_blt)  
  3928.     def fit_blt(x, y, width, height, bitmap, opacity = 255, align = 1)
  3929.       w, h = bitmap.width, bitmap.height
  3930.       if w > width or h > height
  3931.         conversion = w / h.to_f
  3932.         zoom_x, zoom_y = width * conversion, height if conversion <= 1
  3933.         zoom_x, zoom_y = width, height / conversion unless conversion <= 1
  3934.         x += (width - zoom_x) / 2 if align == 1
  3935.         x += width - zoom_x       if align == 2
  3936.         dest_rect = Rect.new(x, y, zoom_x, zoom_y)
  3937.         stretch_blt(dest_rect, bitmap, bitmap.rect, opacity)
  3938.       else
  3939.         x += (width - w) / 2 if align == 1
  3940.         x += width - w       if align == 2
  3941.         full_blt(x, y, bitmap, opacity)
  3942.       end
  3943.     end
  3944.   end
  3945.   #-------------------------------------------------------------------------
  3946.   # ● New method: full_blt
  3947.   #-------------------------------------------------------------------------
  3948.   unless method_defined?(:full_blt)
  3949.     def full_blt(x, y, bitmap, opacity = 255)
  3950.       blt(x, y, bitmap, bitmap.rect, opacity)
  3951.     end
  3952.   end
  3953.   #-------------------------------------------------------------------------
  3954.   # ● New method: scale_blt
  3955.   #-------------------------------------------------------------------------
  3956.   unless method_defined?(:scale_blt)
  3957.     def scale_blt(dest_rect, src_bitmap, src_rect = src_bitmap.rect, o = 255)
  3958.       w, h = src_rect.width, src_rect.height
  3959.       scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
  3960.       ow, oh = (w / scale).to_i, (h / scale).to_i
  3961.       ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
  3962.       stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
  3963.         src_bitmap, src_rect, o)
  3964.     end
  3965.   end
  3966.   #-------------------------------------------------------------------------
  3967.   # ● New method: frames_flip_horizontal
  3968.   #-------------------------------------------------------------------------
  3969.   unless method_defined?(:frames_flip_horizontal)
  3970.     def frames_flip_horizontal(frames)
  3971.       frame_width = width / frames
  3972.       frame_bitmap = Bitmap.new(frame_width, height)
  3973.       rect = Rect.new(0, 0, frame_width, height)
  3974.       frames.times do |i|
  3975.         frame_bitmap.clear
  3976.         rect.x = (x = i * frame_width)
  3977.         frame_bitmap.blt(0, 0, self, rect)
  3978.         frame_bitmap.flip_horizontal!
  3979.         blt(x, 0, frame_bitmap, frame_bitmap.rect)
  3980.       end
  3981.       frame_bitmap.dispose
  3982.     end
  3983.   end
  3984.   #-------------------------------------------------------------------------
  3985.   # ● New method: frames_flip_vertical
  3986.   #-------------------------------------------------------------------------
  3987.   unless method_defined?(:frames_flip_vertical)
  3988.     def frames_flip_vertical(frames)
  3989.       frame_height = height / frames
  3990.       frame_bitmap = Bitmap.new(width, frame_height)
  3991.       rect = Rect.new(0, 0, width, frame_height)
  3992.       frames.times do |i|
  3993.         frame_bitmap.clear        
  3994.         rect.y = (y = i * frame_height)
  3995.         frame_bitmap.blt(0, 0, self, rect)
  3996.         frame_bitmap.flip_vertical!
  3997.         blt(0, y, frame_bitmap, frame_bitmap.rect)
  3998.       end
  3999.       frame_bitmap.dispose
  4000.     end
  4001.   end
  4002.   #-------------------------------------------------------------------------
  4003.   # ● New method: blur_area
  4004.   #-------------------------------------------------------------------------
  4005.   unless method_defined?(:blur_area)
  4006.     def blur_area(settings = {})
  4007.       blur_settings.each do |default, setting|
  4008.         settings[default] = setting unless settings.has_key?(default)
  4009.       end
  4010.       keys = settings.keys
  4011.       rect_defined = keys.include?('rect')
  4012.       rect_p_defined = keys.include?('x') && keys.include?('y') &&
  4013.                        keys.include?('w') && keys.include?('h')
  4014.       if rect_defined
  4015.         rect = settings['rect']
  4016.         x, y, w, h = rect.x, rect.y, rect.width, rect.height
  4017.       elsif rect_p_defined
  4018.         x, y, w, h = settings['x'], settings['y'], settings['w'], settings['h']
  4019.       else
  4020.         x, y, w, h = 0, 0, self.width, self.height
  4021.       end
  4022.       dummy = self.dup
  4023.       spacing = settings['spacing']
  4024.       opacity = settings['opacity']
  4025.       settings['offset'].times do |i|
  4026.         src_rects = []
  4027.         src_rects << Rect.new(x + i * spacing, y + i * spacing, w, h)
  4028.         src_rects << Rect.new(x - i * spacing, y + i * spacing, w, h)
  4029.         src_rects << Rect.new(x + i * spacing, y - i * spacing, w, h)
  4030.         src_rects << Rect.new(x - i * spacing, y - i * spacing, w, h)
  4031.         o = Integer(opacity * (settings['offset'] - i) / (settings['offset']))
  4032.         src_rects.each { |src_rect|  blt(x, y, dummy, src_rect, o)}
  4033.       end
  4034.       dummy.dispose
  4035.       self
  4036.     end
  4037.   end
  4038.   #-------------------------------------------------------------------------
  4039.   # ● New method: sub_bitmap_blend
  4040.   #-------------------------------------------------------------------------
  4041.   unless method_defined?(:sub_bitmap_blend)
  4042.     def sub_bitmap_blend(x = 0, y = 0, bitmap = self, src_rect = bitmap.rect)
  4043.       src_rect.width.times do |i|
  4044.         src_rect.height.times do |j|
  4045.           c1 = get_pixel(x + i, y + j)
  4046.           c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4047.           nc = Color.new(c1.red-c2.red, c1.green-c2.green, c1.blue-c2.blue)
  4048.           set_pixel(x + i, y + j, nc) if c2.alpha > 0
  4049.         end
  4050.       end
  4051.     end
  4052.   end
  4053.   #-------------------------------------------------------------------------
  4054.   # ● New method: add_bitmap_blend
  4055.   #-------------------------------------------------------------------------
  4056.   unless method_defined?(:add_bitmap_blend)
  4057.     def add_bitmap_blend(x = 0, y = 0, bitmap = self, src_rect = bitmap.rect)
  4058.       src_rect.width.times do |i|
  4059.         src_rect.height.times do |j|
  4060.           c1 = get_pixel(x + i, y + j)
  4061.           c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4062.           nc = Color.new(c1.red+c2.red, c1.green+c2.green, c1.blue+c2.blue)
  4063.           set_pixel(x + i, y + j, nc) if c2.alpha > 0
  4064.         end
  4065.       end
  4066.     end
  4067.   end
  4068.   #--------------------------------------------------------------------------
  4069.   # * Alias Listing
  4070.   #--------------------------------------------------------------------------
  4071.   alias_sec_method :frost!,      :drg_frost!
  4072.   alias_sec_method :blur,        :blur_area
  4073.   alias_sec_method :entire_fill, :full_fill
  4074.         #--------------------------------------------------------------------------
  4075.         # * Replicated method: gradient_fill_rect
  4076.         #--------------------------------------------------------------------------
  4077.   unless method_defined?(:gradient_fill_rect)
  4078.     def gradient_fill_rect(*a)
  4079.       if a.first.is_a?(Rect)
  4080.         x, y, width, height = a[0].x, a[0].y, a[0].width, a[0].height
  4081.         color1 = a.at(1).dup
  4082.         color2 = a.at(2)
  4083.         vertical = a.at(3)
  4084.       else
  4085.         x, y, width, height = a[0..3]
  4086.         color1 = a.at(4).dup
  4087.         color2 = a.at(5)
  4088.         vertical = a.at(6)
  4089.       end
  4090.       dr = color2.red   - color1.red
  4091.       dg = color2.green - color1.green
  4092.       db = color2.blue  - color1.blue
  4093.       da = color2.alpha - color1.alpha
  4094.       start_rgba = [color1.red, color1.green, color1.blue, color1.alpha]
  4095.       if vertical
  4096.         dr, dg, db, da = dr / height, dg / height, db / height, da / height
  4097.         for i in (y.round...(y + height).round)
  4098.           fill_rect(x, i, width, 1, color1)
  4099.           start_rgba[0] = [start_rgba.at(0) + dr, 0].max.round
  4100.           start_rgba[1] = [start_rgba.at(1) + dg, 0].max.round
  4101.           start_rgba[2] = [start_rgba.at(2) + db, 0].max.round
  4102.           start_rgba[3] = [start_rgba.at(3) + da, 0].max.round
  4103.           color1.set(*start_rgba)
  4104.         end
  4105.       else
  4106.         dr, dg, db, da = dr / width, dg / width, db / width, da / width
  4107.         for i in (x.round...(x + width).round)
  4108.           fill_rect(i, y, 1, height, color1)
  4109.           start_rgba[0] = [start_rgba.at(0) + dr, 0].max.round
  4110.           start_rgba[1] = [start_rgba.at(1) + dg, 0].max.round
  4111.           start_rgba[2] = [start_rgba.at(2) + db, 0].max.round
  4112.           start_rgba[3] = [start_rgba.at(3) + da, 0].max.round
  4113.           color1.set(*start_rgba)
  4114.         end
  4115.       end
  4116.     end
  4117.   end
  4118. end
  4119. #==============================================================================
  4120. # ** String     
  4121. #------------------------------------------------------------------------------
  4122. #  
  4123. #==============================================================================
  4124. class String
  4125.   #-------------------------------------------------------------------------
  4126.   # ● New method: get_int
  4127.   #-------------------------------------------------------------------------
  4128.   unless method_defined?(:get_int)
  4129.     def get_int
  4130.       m = self.scan(/([-]?\d+)/i).flatten
  4131.       return m.join.to_i
  4132.     end
  4133.   end
  4134.   #-------------------------------------------------------------------------
  4135.   # ● New method: get_ints
  4136.   #-------------------------------------------------------------------------
  4137.   unless method_defined?(:get_ints)
  4138.     def get_ints
  4139.       array = self.scan(/([-]?\d+)/i).flatten.relay(:i)
  4140.       return array
  4141.     end
  4142.   end
  4143.   #-------------------------------------------------------------------------
  4144.   # ● New method: encrypt
  4145.   #-------------------------------------------------------------------------
  4146.   unless method_defined?(:encrypt)
  4147.     def encrypt(encryption_string = 'encrypt')
  4148.       encryption_bytes = []
  4149.       encryption_string.each_byte {|c| encryption_bytes << c}
  4150.       string = ''
  4151.       self.size.times do |i|
  4152.         byte = self[i] * encryption_bytes[i % encryption_bytes.size]
  4153.         base, mod = byte / 255, byte % 255
  4154.         string += base.chr + mod.chr
  4155.       end
  4156.       return string
  4157.     end
  4158.   end
  4159.   #-------------------------------------------------------------------------
  4160.   # ● New method: encrypt!
  4161.   #-------------------------------------------------------------------------
  4162.   unless method_defined?(:encrypt!)
  4163.     def encrypt!(encryption_string = 'encrypt')
  4164.       replace(encrypt(encryption_string))
  4165.     end
  4166.   end
  4167.   #-------------------------------------------------------------------------
  4168.   # ● New method: decrypt
  4169.   #-------------------------------------------------------------------------
  4170.   unless method_defined?(:decrypt)
  4171.     def decrypt(encryption_string = 'encrypt')
  4172.       encryption_bytes = []
  4173.       encryption_string.each_byte {|c| encryption_bytes << c}
  4174.       string = ''
  4175.       (self.size / 2).times do |i|
  4176.         b, m = self[i * 2] * 255, self[i * 2 + 1]
  4177.         string += ((b + m) / encryption_bytes[i % encryption_bytes.size]).chr
  4178.       end
  4179.       return string
  4180.     end
  4181.   end
  4182.   #-------------------------------------------------------------------------
  4183.   # ● New method: decrypt!
  4184.   #-------------------------------------------------------------------------
  4185.   unless method_defined?(:decrypt!)
  4186.     def decrypt!(encryption_string = 'encrypt')
  4187.       replace(decrypt(encryption_string))
  4188.     end
  4189.   end
  4190.   #-------------------------------------------------------------------------
  4191.   # ● New method: clear, words, characters
  4192.   #-------------------------------------------------------------------------
  4193.   define_sec_method(:clear)      { replace('')      }
  4194.   define_sec_method(:words)      { split(' ')       }
  4195.   define_sec_method(:characters) { split('')        }
  4196.   define_sec_method(:last)       { characters.last  }
  4197.   define_sec_method(:first)      { characters.first }
  4198. end
  4199.  
  4200. #==============================================================================
  4201. # ** Game_Interpreter
  4202. #------------------------------------------------------------------------------
  4203. #  An interpreter for executing event commands. This class is used within the
  4204. # Game_Map, Game_Troop, and Game_Event classes.
  4205. #==============================================================================
  4206. Klass = LiTTleDRAgo::VX ? Game_Interpreter : Interpreter
  4207. class Klass
  4208.   #--------------------------------------------------------------------------
  4209.   # * Constant
  4210.   #--------------------------------------------------------------------------
  4211.   SCRIPT_WAIT_RESULTS = [:wait, FalseClass]
  4212.   #--------------------------------------------------------------------------
  4213.   # ● Redirect Listing
  4214.   #--------------------------------------------------------------------------
  4215.   redirect_method :picture_sprite,        '$game_map.picture_sprite'
  4216.   #--------------------------------------------------------------------------
  4217.   # ● New method: random_teleport
  4218.   #--------------------------------------------------------------------------
  4219.   unless method_defined?(:random_teleport)
  4220.     def random_teleport(id = 0)
  4221.       character = id.is_a?(Game_Character) ? id : get_character(id)
  4222.       character.random_teleport if character.is_a?(Game_Character)
  4223.     end
  4224.   end
  4225.   #--------------------------------------------------------------------------
  4226.   # ● Redefined method: same_map?, next_event_code
  4227.   #--------------------------------------------------------------------------
  4228.   define_sec_method(:same_map?)       { @map_id == $game_map.map_id    }
  4229.   define_sec_method(:next_event_code) { @list[@index + 1].code         }
  4230.   #--------------------------------------------------------------------------
  4231.   # * Overwriten method: command_355
  4232.   #--------------------------------------------------------------------------
  4233.   def command_355
  4234.     script = @list[index = @index].parameters[0] + "\n"
  4235.     while [655, 355].include?(next_event_code) do
  4236.       script += @list[@index+=1].parameters[0] + "\n"
  4237.     end
  4238.     wait = SCRIPT_WAIT_RESULTS.include?(eval(script)) && LiTTleDRAgo::XP
  4239.     return wait ? !(@index = index) : true
  4240.   end  
  4241. end
  4242.  
  4243. #==============================================================================
  4244. # ** Sprite
  4245. #------------------------------------------------------------------------------
  4246. #  A sprite class for bitmap processing.
  4247. #==============================================================================
  4248. class Sprite
  4249.   #---------------------------------------------------------------------------
  4250.   # * Alias Listing
  4251.   #---------------------------------------------------------------------------
  4252.   alias_sec_method(:angle_fix_alias, :"angle=")
  4253.   alias_sec_method(:drg_core_dispose,:"dispose")
  4254.   alias_sec_method(:set_x_alias,     :"x=")
  4255.   alias_sec_method(:set_y_alias,     :"y=")
  4256.   alias_sec_method(:get_x_alias,     :"x")
  4257.   alias_sec_method(:get_y_alias,     :"y")
  4258.   #---------------------------------------------------------------------------
  4259.   # * New method: method_missing
  4260.   #---------------------------------------------------------------------------
  4261.   def method_missing(val,*a,&b)
  4262.     return bitmap.send(val.to_s,*a,&b) if bitmap.respond_to?(val.to_sym)
  4263.     text = "Undefined method #{val} for #{self.inspect}"
  4264.     raise(NoMethodError, text, caller(1))               
  4265.   end
  4266.   #---------------------------------------------------------------------------
  4267.   # * Aliased method: x=, y=
  4268.   #---------------------------------------------------------------------------
  4269.   define_method(:x=)      {|amt| set_x_alias((@intfloat_x = amt).to_i) }
  4270.   define_method(:y=)      {|amt| set_y_alias((@intfloat_y = amt).to_i) }
  4271.   define_method(:x)       { @intfloat_x ||= get_x_alias }
  4272.   define_method(:y)       { @intfloat_y ||= get_y_alias }
  4273.   define_method(:dispose) { disposed? || drg_core_dispose }
  4274.   define_method(:rotate_correction) { self.ox,self.oy = width/2, height/2 }
  4275.   #---------------------------------------------------------------------------
  4276.   # * Aliased method: angle=
  4277.   #---------------------------------------------------------------------------
  4278.   def angle=(v)
  4279.     return if @angle == v
  4280.     sign = (v % 360 == 180 || v % 180 == 90) ? 1.00001 : 1
  4281.     angle_fix_alias((@angle = v) * sign)
  4282.   end
  4283.   #--------------------------------------------------------------------------
  4284.   # ● Redefined method: width, height
  4285.   #--------------------------------------------------------------------------
  4286.   define_sec_method(:width)       { src_rect.width }
  4287.   define_sec_method(:height)      { src_rect.height }
  4288.   #--------------------------------------------------------------------------
  4289.   # ● Overwriten method: dup
  4290.   #--------------------------------------------------------------------------
  4291.   def dup
  4292.     sprite = self.class.new(self.viewport)
  4293.     sprite.bitmap                = self.bitmap.clone
  4294.     sprite.zoom_x, sprite.zoom_y = self.zoom_x, self.zoom_y
  4295.     sprite.x, sprite.y           = self.x, self.y
  4296.     sprite.ox, sprite.oy         = self.ox, self.oy
  4297.     sprite.color, sprite.tone    = self.color.dup, self.tone.dup
  4298.     sprite.src_rect,sprite.angle = self.src_rect, self.angle
  4299.     return sprite
  4300.   end
  4301.   #--------------------------------------------------------------------------
  4302.   # ● Overwriten method: clone
  4303.   #--------------------------------------------------------------------------
  4304.   def clone
  4305.     (sprite = self.dup) && instance_variables.each do |var|
  4306.       temp = instance_variable_get("#{var}")
  4307.       sprite.instance_variable_set("#{var}",temp) rescue nil
  4308.     end
  4309.     (frozen? && sprite.freeze)
  4310.     return sprite   
  4311.   end
  4312.   #--------------------------------------------------------------------------
  4313.   # ● New method: scale
  4314.   #--------------------------------------------------------------------------
  4315.   unless method_defined?(:scale)
  4316.     def scale(w, h)
  4317.       tmp = self.bitmap.clone
  4318.       self.bitmap = Bitmap.new(w, h)
  4319.       self.bitmap.stretch_blt(Rect.new(0, 0, w, h), tmp, tmp.rect)
  4320.       tmp.dispose
  4321.     end
  4322.   end
  4323.   #--------------------------------------------------------------------------
  4324.   # ● New method: in_rect?
  4325.   #--------------------------------------------------------------------------
  4326.   unless method_defined?(:in_rect?)
  4327.     def in_rect?(*rect)
  4328.       if rect.size == 1
  4329.         x, y, w, h = rect[0].x, rect[0].y, rect[0].width, rect[0].height
  4330.         return self.x.between?(x, x + w) && self.y.between?(y, y + h)
  4331.       elsif rect.size == 4
  4332.         x, y, w, h = rect
  4333.         return self.x.between?(x, x + w) && self.y.between?(y, y + h)
  4334.       end
  4335.       return false
  4336.     end
  4337.   end
  4338. end
  4339.  
  4340. #==============================================================================
  4341. # ** Scheduler
  4342. #------------------------------------------------------------------------------
  4343. #  This class allows to schedule a proc or method call a given amount of frames
  4344. #  into the future with any amount of arguments
  4345. #==============================================================================
  4346. unless defined?(Scheduler)
  4347.   class Scheduler
  4348.     #==========================================================================
  4349.     # ** Order
  4350.     #--------------------------------------------------------------------------
  4351.     #  An order is a proc, method or something else which has 'call' as a
  4352.     #  method, and the arguments to pass along.
  4353.     #==========================================================================
  4354.     unless method_defined?(:update)
  4355.       Order = Struct.new(:callable, :arguments)
  4356.       class Order
  4357.         #----------------------------------------------------------------------
  4358.         # * New Methods: call
  4359.         #----------------------------------------------------------------------
  4360.         define_method(:call) { callable.call(*arguments) }
  4361.       end
  4362.       #========================================================================
  4363.       # ** RecurringOrder
  4364.       #------------------------------------------------------------------------
  4365.       #  An order which is recurring every specified amount of time until
  4366.       #  FalseClass is returned from the call.
  4367.       #  Note that arguments remain the same for each call
  4368.       #========================================================================
  4369.       RecurringOrder = Struct.new(:callable, :arguments, :frames)
  4370.       class RecurringOrder
  4371.         #----------------------------------------------------------------------
  4372.         # * New Methods: call
  4373.         #----------------------------------------------------------------------
  4374.         def call
  4375.           result = callable.call(*arguments)
  4376.           unless result == FalseClass
  4377.             Scheduler.schedule_recurring(frames, frames, callable, *arguments)
  4378.           end
  4379.         end
  4380.       end
  4381.       #========================================================================
  4382.       # ** Mapping
  4383.       #------------------------------------------------------------------------
  4384.       # Maps an index to an array. Values can be added to these value.
  4385.       # Each array starts empty.
  4386.       #========================================================================
  4387.       class Mapping
  4388.         #----------------------------------------------------------------------
  4389.         # * New method: add, get, empty
  4390.         #----------------------------------------------------------------------
  4391.         define_method(:add)   { |i, v| ((@mapping ||= {})[i] ||=[]) << v }
  4392.         define_method(:get)   { |i|    ((@mapping ||= {})[i] || [])   }
  4393.         define_method(:empty) { |i|     (@mapping ||= {}).delete(i)   }
  4394.       end
  4395.       #------------------------------------------------------------------------
  4396.       # * New method: schedule
  4397.       #------------------------------------------------------------------------
  4398.       def schedule(frames, callable, *arguments)
  4399.         order = Order.new(callable, arguments)
  4400.         (@mapping ||= Mapping.new).add(frames + (@tick||=0), order)
  4401.       end
  4402.       #------------------------------------------------------------------------
  4403.       # * New method: schedule_recurring
  4404.       #------------------------------------------------------------------------
  4405.       def schedule_recurring(frames, frames_to_wait, callable, *arguments)
  4406.         order = RecurringOrder.new(callable, arguments, frames_to_wait)
  4407.         (@mapping ||= Mapping.new).add(frames + (@tick||=0), order)
  4408.       end
  4409.       #------------------------------------------------------------------------
  4410.       # * New method: update
  4411.       #------------------------------------------------------------------------
  4412.       def update
  4413.         orders = (@mapping ||= Mapping.new).get((@tick||=0))
  4414.         @mapping.empty(@tick)
  4415.         orders.each {|s| s.call }
  4416.         @tick += 1
  4417.       end
  4418.       #------------------------------------------------------------------------
  4419.       # * Self
  4420.       #------------------------------------------------------------------------
  4421.       @@instance = self.new
  4422.       class << self
  4423.         define_method(:instance) { @@instance }
  4424.         redirect_method :schedule_recurring, 'instance.schedule_recurring'
  4425.         redirect_method :schedule,           'instance.schedule'
  4426.         redirect_method :update,             'instance.update'
  4427.       end
  4428.     end
  4429.   end
  4430.   Graphics.auto_update.push([Scheduler,:update])
  4431. end
  4432. #==============================================================================
  4433. # ** Dir     
  4434. #------------------------------------------------------------------------------
  4435. #
  4436. #==============================================================================
  4437. class << Dir
  4438.   #--------------------------------------------------------------------------
  4439.   # ● New method: make_dir
  4440.   #--------------------------------------------------------------------------
  4441.   def make_dir(path)
  4442.     (dir = path.split("/")).size.times do |i|
  4443.       next if dir == "."
  4444.       Dir.mkdir(dir[0..i].join("/")) rescue nil
  4445.     end
  4446.   end
  4447.   #--------------------------------------------------------------------------
  4448.   # ● New method: files_with_extension
  4449.   #--------------------------------------------------------------------------
  4450.   def files_with_extension(directory, extension)
  4451.     entries(directory).select{|file| File.extname(file) == extension}
  4452.   end
  4453. end
  4454.  
  4455. #==============================================================================
  4456. # ** BitmapDump
  4457. #------------------------------------------------------------------------------
  4458. #
  4459. #==============================================================================
  4460. module BitmapDump; end
  4461. class << BitmapDump
  4462.   #--------------------------------------------------------------------------
  4463.   # ● New method: self.bitmap_data
  4464.   #--------------------------------------------------------------------------
  4465.   unless method_defined?(:bitmap_data)
  4466.     def bitmap_data(bitmap)
  4467.       red = Table.new(bitmap.width, bitmap.height)
  4468.       green, blue, alpha = red.clone, red.clone, red.clone      
  4469.       bitmap.width.times do |i|
  4470.         bitmap.height.times do |j|
  4471.           color = bitmap.get_pixel(i, j)
  4472.           red[i, j],  green[i, j] = color.red, color.green
  4473.           blue[i, j], alpha[i, j] = color.blue, color.alpha
  4474.         end
  4475.       end
  4476.       return [red, green, blue, alpha]
  4477.     end
  4478.   end
  4479.   #--------------------------------------------------------------------------
  4480.   # ● New method: self.read_bitmap_data
  4481.   #--------------------------------------------------------------------------
  4482.   unless method_defined?(:read_bitmap_data)
  4483.     def read_bitmap_data(red, green, blue, alpha)
  4484.       bitmap = Bitmap.new(red.xsize, red.ysize)
  4485.       bitmap.width.times do |i|
  4486.         bitmap.height.times do |j|
  4487.           color_table = [red[i, j], green[i, j], blue[i, j], alpha[i, j]]
  4488.           bitmap.set_pixel(i, j, Color.new(*color_table))
  4489.         end
  4490.       end
  4491.       return bitmap
  4492.     end
  4493.   end
  4494.   #--------------------------------------------------------------------------
  4495.   # ● New method: self.save_bitmap
  4496.   #--------------------------------------------------------------------------
  4497.   unless method_defined?(:save_bitmap)
  4498.     def save_bitmap(bitmap, filename, folder = '')
  4499.       bitmap_data = bitmap_data(bitmap)
  4500.       if folder && folder != ''
  4501.         Dir.make_dir(folder) unless FileTest.directory?(folder)
  4502.         filename = "#{folder}/#{filename}"
  4503.       end
  4504.       filename = filename.gsub("\\","/").gsub("//","/")
  4505.       file = File.open(filename,'wb')
  4506.       Marshal.dump(bitmap_data, file)
  4507.       file.close
  4508.     end
  4509.   end
  4510.   #--------------------------------------------------------------------------
  4511.   # ● New method: self.load_bitmap
  4512.   #--------------------------------------------------------------------------
  4513.   unless method_defined?(:load_bitmap)
  4514.     def load_bitmap(filename, folder = '')
  4515.       if folder && folder != ''
  4516.         Dir.make_dir(folder) unless FileTest.directory?(folder)
  4517.         filename = "#{folder}/#{filename}"
  4518.       end
  4519.       filename = filename.gsub("\\","/").gsub("//","/")
  4520.       file = File.open(filename,"rb")
  4521.       colors = Marshal.load(file)
  4522.       file.close
  4523.       bitmap = read_bitmap_data(colors)
  4524.       return bitmap
  4525.     end
  4526.   end
  4527. end



RUBY 代码复制
  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.  
  88. module LiTTleDRAgo
  89.  
  90.   SCREEN_SIZE = [640,490]
  91.   # Define the resolution of the game screen. These values can be anything
  92.   # within reason. Centering, viewports, etc. will all be taken care of, but it
  93.   # is recommended that you use values divisible by 32 for best results.
  94.  
  95.  
  96.   AUTOTILE_SPEED = {}
  97.  
  98.   AUTOTILE_SPEED[:map_id] = :speed
  99.   AUTOTILE_SPEED[0]       = 6                              # default speed
  100.   #AUTOTILE_SPEED[35]      = 0                              # unchanged autotile
  101.   #AUTOTILE_SPEED[159]     = 16                             
  102.   # Speed of the autotile based on map_id
  103.  
  104.   CONTROL_SCREEN_SIZE = false
  105.   # Control screen size with a mouse
  106.  
  107.   HIGH_PRIORITY = true
  108.   # Change Game process priority to high
  109.  
  110.   SPRITE_COMPACT = true
  111.   # Keep the sprite to the very minimum number
  112.  
  113.   CHARACTER_Z_FIX = {
  114.     '178-Switch01'  => 0,
  115.     '180-Switch03'  => 0,
  116.     '181-Switch04'  => 0,
  117.     '199-Support07' => 0,
  118.   }
  119.   # Fix the screen_z value for events based on Graphic name.
  120.   # You can also define z value for event by inserting <z: Z_VALUE>
  121.   # on event name.
  122.   # This way, flat events such as pitfall won't overlap with player z value.
  123.  
  124. end
  125.  
  126.  
  127. core = "This script needs Drago - Core Engine ver 1.47 or above"
  128. rmvx = "This script not for RMVX"
  129. implemented = "%1$s has already implemented, Please remove the %1$s script"
  130. zoom = sprintf(implemented,"Map Zoom")
  131. tone = sprintf(implemented,"Tilemap Tone Changer" )
  132.  
  133. ($imported[:drg_core_engine] || 0) >= 1.47 || raise(core)
  134. LiTTleDRAgo::XP || LiTTleDRAgo::VXA  || raise(rmvx)
  135. $imported[:drg_cr_map_zoom]          && raise(zoom)
  136. $imported[:drg_tilemap_tone_changer] && raise(tone)
  137. #==============================================================================
  138. # ** Graphics
  139. #------------------------------------------------------------------------------
  140. #  This module handles all Graphics
  141. #==============================================================================
  142.  
  143. class << Graphics
  144.   #-------------------------------------------------------------------------
  145.   # * Alias Listing
  146.   #-------------------------------------------------------------------------
  147.   alias_sec_method :zer0_graphics_transition,            :transition
  148.   alias_sec_method :drg_resolution_change_resize_screen, :resize_screen
  149.   alias_sec_method :drg_resolution_change_update,        :update
  150.   #-------------------------------------------------------------------------
  151.   # * Aliased method: resize_screen
  152.   #-------------------------------------------------------------------------
  153.   def resize_screen(width, height)
  154.     width = (width / 32.0).round * 32
  155.     height = (height / 32.0).round * 32
  156.     if $game_map.respond_to?(:screen_size)
  157.       $game_map.screen_size[0] = width
  158.       $game_map.screen_size[1] = height
  159.     end
  160.     drg_resolution_change_resize_screen(width, height)
  161.   end
  162.   #-------------------------------------------------------------------------
  163.   # * Aliased method: transition
  164.   #-------------------------------------------------------------------------
  165.   def transition(duration = 8, *args)
  166.     if width <= 640 && height <= 480
  167.       return zer0_graphics_transition(duration, *args)
  168.     end
  169.     if duration > 0
  170.       viewport = Viewport.new(0,0,width,height)
  171.       sprite  = Sprite.new(viewport)
  172.       sprite.bitmap = Graphics.snap_to_bitmap
  173.       sprite2 = Sprite.new(viewport)
  174.       sprite2.z = sprite.z - 10
  175.       sprite2.blend_type = 1
  176.       zer0_graphics_transition(0)
  177.       fade = 255 / duration
  178.       if (file = args.at(0)).is_a?(String)
  179.         bitmap = Bitmap.new(file)
  180.         sprite2.bitmap = bitmap.stretch(width,height)
  181.         bitmap.dispose
  182.       end
  183.       duration.times {[sprite,sprite2].each {|s|s.opacity -= fade} && update }
  184.       [sprite.bitmap, sprite2.bitmap, sprite, sprite2, viewport].dispose
  185.     end
  186.     zer0_graphics_transition(0)
  187.   end
  188.   #-------------------------------------------------------------------------
  189.   # * Aliased method: update
  190.   #-------------------------------------------------------------------------
  191.   def update
  192.     drg_resolution_change_update
  193.     update_resolution_adjust
  194.   end
  195.   #-------------------------------------------------------------------------
  196.   # * New method: update_resolution_adjust
  197.   #-------------------------------------------------------------------------
  198.   def update_resolution_adjust
  199.     return unless LiTTleDRAgo::XP && $game_player
  200.     return unless Game_Player.const_defined?(:CENTER_X)
  201.     change   = Game_Player.const_get(:CENTER_X) != $game_player.center_x
  202.     change ||= Game_Player.const_get(:CENTER_Y) != $game_player.center_y
  203.     return unless change
  204.     resize_screen(width,height)
  205.     $game_player.center($game_player.x,$game_player.y)
  206.   end
  207.   #-------------------------------------------------------------------------
  208.   # * Overwriten method: fullscreen
  209.   #-------------------------------------------------------------------------
  210.   def fullscreen
  211.     @fullscreen = true
  212.     fill_monitor
  213.     LiTTleDRAgo.hide_borders
  214.   end
  215.   #-------------------------------------------------------------------------
  216.   # * Overwriten method: window
  217.   #-------------------------------------------------------------------------
  218.   def window
  219.     @fullscreen = false
  220.     LiTTleDRAgo.show_borders
  221.     if $game_map && $game_map.screen_size.all? {|s| s.is_a?(Numeric)}
  222.       x,y = $game_map.screen_size[0..1]
  223.       x += ($game_map.screen_size[2] ||= 1)
  224.       $game_map.screen_size[2] *= -1
  225.       drg_resolution_change_resize_screen(x,y)
  226.     else
  227.       x,y = LiTTleDRAgo::SCREEN_SIZE
  228.     end
  229.     resize_screen(x,y)
  230.   end
  231.   #-------------------------------------------------------------------------
  232.   # * Overwriten method: fullscreen?
  233.   #-------------------------------------------------------------------------
  234.   define_method(:fullscreen?) { @fullscreen == true }
  235. end
  236.  
  237. Graphics.window
  238. Graphics.disable_alt_enter
  239. Graphics.control_screen_size LiTTleDRAgo::CONTROL_SCREEN_SIZE
  240. Graphics.high_priority     = LiTTleDRAgo::HIGH_PRIORITY
  241. GC.start
  242. #==============================================================================
  243. # ** Game_Map
  244. #------------------------------------------------------------------------------
  245. #  This class handles the map. It includes scrolling and passable determining
  246. #  functions. Refer to "$game_map" for the instance of this class.
  247. #==============================================================================
  248.  
  249. class Game_Map
  250.   #--------------------------------------------------------------------------
  251.   # * Public Instance Variable
  252.   #--------------------------------------------------------------------------
  253.   attr_sec_accessor :zoom_x, :zoom_y, 'Integer(1)'
  254.   attr_sec_accessor :screen_size,     'LiTTleDRAgo::SCREEN_SIZE'
  255.   attr_sec_accessor :tilemap_tone,    'Tone.new(0,0,0)'
  256.   attr_sec_accessor :tilemap_opacity, 'Integer(255)'
  257.   attr_sec_accessor :tilemap_hue,     'Integer(0)'
  258.   #---------------------------------------------------------------------------
  259.   # * Redirect Listing
  260.   #---------------------------------------------------------------------------
  261.   [:tilemap_tone,:tilemap_opacity].each do |meth|
  262.     redirect_method :"#{meth}_changing?",   "(@#{meth}_duration ||= 0) > 0"
  263.   end
  264.   #---------------------------------------------------------------------------
  265.   # * Define Sec Listing
  266.   #---------------------------------------------------------------------------
  267.   define_sec_method(:zooming?)      {(@zoom_duration ||= 0) > 0}
  268.   define_sec_method(:screen_tile_x) {(Graphics.width  / 32.0).ceil}
  269.   define_sec_method(:screen_tile_y) {(Graphics.height / 32.0).ceil}
  270.   #-------------------------------------------------------------------------
  271.   # * Alias Listing
  272.   #-------------------------------------------------------------------------
  273.   alias_sec_method(:drg_scroll_right_adjust, :scroll_right)
  274.   alias_sec_method(:drg_scroll_down_adjust,  :scroll_down)
  275.   alias_sec_method(:tilemap_effect_update,   :update)
  276.   alias_sec_method(:get_map_data,            :data)
  277.   #--------------------------------------------------------------------------
  278.   # * Aliased method: Scroll Down
  279.   #--------------------------------------------------------------------------
  280.   def scroll_down(distance)
  281.     times = vxa_map_multiplier
  282.     if loop_vertical?
  283.       @display_y += distance
  284.       @display_y %= height * times
  285.       @parallax_y += distance if @parallax_y && @parallax_loop_y
  286.     else
  287.       last_y = @display_y
  288.       result = [@display_y + distance, (map_edge.at(1) / zoom_y)].min
  289.       drg_scroll_down_adjust(distance)
  290.       @display_y = result
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Aliased method: Scroll Right
  295.   #--------------------------------------------------------------------------
  296.   def scroll_right(distance)
  297.     times = vxa_map_multiplier
  298.     if loop_horizontal?
  299.       @display_x += distance
  300.       @display_x %= width * times
  301.       @parallax_x += distance if @parallax_x && @parallax_loop_x
  302.     else
  303.       last_x = @display_x
  304.       result = [@display_x + distance, (map_edge.at(0) / zoom_x)].min
  305.       drg_scroll_right_adjust(distance)
  306.       @display_x = result
  307.     end
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * New method: zoom
  311.   #--------------------------------------------------------------------------
  312.   def zoom(*zoom)
  313.     if zoom.size == 1
  314.       zoom = (zoom.first)
  315.     elsif zoom.size == 3
  316.       x,y,zoom = zoom[0..2]
  317.     end
  318.     return unless zoom.is_a?(Numeric)
  319.     old_zoom = @zoom_x
  320.     @zoom_x = [[zoom,12].min, 1].max
  321.     @zoom_y = [[zoom,12].min, 1].max
  322.     $game_player.center(x,y) if x && y
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * New method: zoom_in
  326.   #--------------------------------------------------------------------------
  327.   def zoom_in(x = nil,y = nil, duration = 20)
  328.     start_zoom(x,y, zoom_x >= 1 ? zoom_x + 1 : 1, duration)
  329.   end   
  330.   #--------------------------------------------------------------------------
  331.   # * New method: zoom_out
  332.   #--------------------------------------------------------------------------
  333.   def zoom_out(x = nil,y = nil,duration = 20)
  334.     start_zoom(x,y, zoom_x - 1 >= 1 ? zoom_x - 1 : zoom_x - 0.5, duration)
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * New method: map_edge
  338.   #--------------------------------------------------------------------------
  339.   def map_edge
  340.     times = vxa_map_multiplier
  341.     [_w = [(width  * zoom_x - screen_tile_x).ceil * times, 0].max,
  342.      _h = [(height * zoom_y - screen_tile_y).ceil * times, 0].max]
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * New method: autotile_speed
  346.   #--------------------------------------------------------------------------
  347.   def autotile_speed(id = @map_id)
  348.     speed = LiTTleDRAgo::AUTOTILE_SPEED
  349.     @autotile_speed.is_a?(Array) || @autotile_speed = []
  350.     @autotile_speed[id] ||= (speed[id] || speed[0] || 0)
  351.   end
  352.   #--------------------------------------------------------------------------
  353.   # * New method: autotile_speed=
  354.   #--------------------------------------------------------------------------
  355.   def autotile_speed=(*value)
  356.     @autotile_speed.is_a?(Array) || @autotile_speed = []
  357.     @autotile_speed[@map_id]     = [value.first,0].max if value.size == 1
  358.     @autotile_speed[value.first] = [value.at(1),0].max if value.size > 1
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # * New method: vxa_map_multiplier
  362.   #--------------------------------------------------------------------------
  363.   def vxa_map_multiplier
  364.     LiTTleDRAgo::VXA ? 1 : 128
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * New method: screen_is_solid?
  368.   #--------------------------------------------------------------------------
  369.   def screen_is_solid?
  370.     tone = screen.tone.to_s.gsub(/([(),0 ])/i){''}
  371.     return true if tone['255.255.255.']
  372.     return true if tone['255.-255.-255.']
  373.     return true if tone['-255.255.-255.']
  374.     return true if tone['-255.-255.255.']
  375.     return true if tone['255.255.-255.']
  376.     return true if tone['255.-255.255.']
  377.     return true if tone['-255.255.255.']
  378.     return true if tone['-255.-255.-255.']
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * Aliased method: data
  382.   #--------------------------------------------------------------------------
  383.   def data
  384.     data = self.reverse ? reverse_data : get_map_data
  385.     data.make_changes = true
  386.     data
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * New method: reverse_data
  390.   #--------------------------------------------------------------------------
  391.   def reverse_data
  392.     @reverse_data ||= []
  393.     @reverse_data[@map_id] ||= get_map_data.reverse(true,false,false)
  394.   end
  395.   #--------------------------------------------------------------------------
  396.   # * New method: reverse=
  397.   #--------------------------------------------------------------------------
  398.   def reverse=(val)
  399.     return val if @reverse == val
  400.     @reverse = ((@reverse_data||=[])[@map_id] = nil) || val
  401.     spriteset && spriteset.reload_tilemap
  402.     @reverse
  403.   end
  404.   #--------------------------------------------------------------------------
  405.   # * New method: reverse
  406.   #--------------------------------------------------------------------------
  407.   def reverse
  408.     @reverse && LiTTleDRAgo::XP
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * New method: start_tilemap_tone
  412.   #--------------------------------------------------------------------------
  413.   def start_tilemap_tone(tone = Tone.new(0,0,0,0), duration = 0)
  414.     @tilemap_tone_target = tone.is_a?(Array) ? Tone.new(*tone) : tone.clone
  415.     @tilemap_tone_duration = duration
  416.     tilemap_tone_changing? || @tilemap_tone = @tilemap_tone_target.clone
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # * New method: start_tilemap_opacity
  420.   #--------------------------------------------------------------------------
  421.   def start_tilemap_opacity(opacity = 255, duration = 0)
  422.     @tilemap_opacity_target = opacity * 1.0
  423.     @tilemap_opacity_duration = duration
  424.     tilemap_opacity_changing? || @tilemap_opacity = @tilemap_opacity_target
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * New method: update_tilemap_tone
  428.   #--------------------------------------------------------------------------
  429.   def update_tilemap_tone
  430.     if tilemap_tone_changing?
  431.       d = @tilemap_tone_duration
  432.       target = @tilemap_tone_target
  433.       @tilemap_tone.red   = (@tilemap_tone.red   * (d - 1) + target.red) / d
  434.       @tilemap_tone.green = (@tilemap_tone.green * (d - 1) + target.green) / d
  435.       @tilemap_tone.blue  = (@tilemap_tone.blue  * (d - 1) + target.blue) / d
  436.       @tilemap_tone.gray  = (@tilemap_tone.gray  * (d - 1) + target.gray) / d
  437.       @tilemap_tone_duration -= 1
  438.       tilemap_tone_changing? || @tilemap_tone = @tilemap_tone_target.clone
  439.     end
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   # * New method: update_tilemap_opacity
  443.   #--------------------------------------------------------------------------
  444.   def update_tilemap_opacity
  445.     if tilemap_opacity_changing?
  446.       d = @tilemap_opacity_duration
  447.       @tilemap_opacity = (@tilemap_opacity * (d - 1) +
  448.       @tilemap_opacity_target) / d
  449.       @tilemap_opacity_duration -= 1
  450.       tilemap_opacity_changing? || @tilemap_opacity = @tilemap_opacity_target
  451.     end
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * New method: start_zoom
  455.   #--------------------------------------------------------------------------
  456.   def start_zoom(x,y, zoom_target, duration=20)
  457.     @x_zoom = x
  458.     @y_zoom = y
  459.     @zoom_target = zoom_target * 1.0
  460.     @zoom_duration = @zoom_x == @zoom_target ? 0 : duration
  461.     zooming? || zoom(@x_zoom,@y_zoom,@zoom_target)
  462.   end
  463.   #--------------------------------------------------------------------------
  464.   # * New method: update_zooming
  465.   #--------------------------------------------------------------------------
  466.   def update_zooming
  467.     if zooming?
  468.       d = @zoom_duration
  469.       power = (@zoom_x * (d - 1) + @zoom_target) / d
  470.       @zoom_duration -= 1
  471.       zoom(@x_zoom,@y_zoom,power)
  472.       zoom(@x_zoom,@y_zoom,@zoom_target) unless zooming?
  473.     end
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # * Aliased method: update
  477.   #--------------------------------------------------------------------------
  478.   def update(*args)
  479.     tilemap_effect_update(*args)
  480.     update_tilemap_tone
  481.     update_tilemap_opacity
  482.     update_zooming
  483.   end
  484. end
  485. #==============================================================================
  486. # ** Interpreter
  487. #------------------------------------------------------------------------------
  488. #  This interpreter runs event commands. This class is used within the
  489. #  Game_System class and the Game_Event class.
  490. #==============================================================================
  491. unless LiTTleDRAgo::VX  
  492.   class Interpreter
  493.     #---------------------------------------------------------------------------
  494.     # * Redirect Listing
  495.     #---------------------------------------------------------------------------
  496.     redirect_method :zoom,                  '$game_map.zoom'
  497.     redirect_method :zoom_in,               '$game_map.zoom_in'
  498.     redirect_method :zoom_out,              '$game_map.zoom_out'
  499.     redirect_method :start_zoom,            '$game_map.start_zoom'
  500.     redirect_method :start_tilemap_opacity, '$game_map.start_tilemap_opacity'
  501.     redirect_method :start_tilemap_tone,    '$game_map.start_tilemap_tone'
  502.     [:change_tilemap_tone,:change_character_tone].each do |meth|
  503.       redirect_method :"#{meth}", :"$game_map.spriteset.#{meth}"
  504.     end
  505.   end
  506. end
  507.  
  508. #==============================================================================
  509. # ** Game_Player
  510. #------------------------------------------------------------------------------
  511. #  This class handles the player. Its functions include event starting
  512. #  determinants and map scrolling. Refer to "$game_player" for the one
  513. #  instance of this class.
  514. #==============================================================================
  515. class Game_Player
  516.   #---------------------------------------------------------------------------
  517.   # * Define Sec Listing
  518.   #---------------------------------------------------------------------------
  519.   define_sec_method(:center_x) {((Graphics.width/2)  / $game_map.zoom_x-16) * 4}
  520.   define_sec_method(:center_y) {((Graphics.height/2) / $game_map.zoom_y-16) * 4}
  521.   #-------------------------------------------------------------------------
  522.   # * Alias Listing
  523.   #-------------------------------------------------------------------------
  524.   alias_sec_method(:drg_adjust_viewport_center, :center)
  525.   #-------------------------------------------------------------------------
  526.   # * Aliased method: center
  527.   #-------------------------------------------------------------------------
  528.   def center(x, y)
  529.     if LiTTleDRAgo::XP
  530.       Game_Player.const_set(:CENTER_X, center_x)
  531.       Game_Player.const_set(:CENTER_Y, center_y)
  532.     end
  533.     drg_adjust_viewport_center(x, y)
  534.     max_x = $game_map.map_edge.at(0) / $game_map.zoom_x
  535.     max_y = $game_map.map_edge.at(1) / $game_map.zoom_y
  536.     if LiTTleDRAgo::XP
  537.       $game_map.display_x = [0, [(x * 32*4) - center_x, max_x.ceil].min].max
  538.       $game_map.display_y = [0, [(y * 32*4) - center_y, max_y.ceil].min].max
  539.     elsif $game_map.respond_to?(:set_display_pos)
  540.       $game_map.set_display_pos(x - center_x, y - center_y)
  541.     end
  542.   end  
  543. end
  544.  
  545. #==============================================================================
  546. # ** Tilemap
  547. #------------------------------------------------------------------------------
  548. #  
  549. #==============================================================================
  550. class Tilemap
  551.   #---------------------------------------------------------------------------
  552.   # * Public Instance Variables
  553.   #---------------------------------------------------------------------------
  554.   method_defined?(:tileset)   || attr_accessor(:tileset)
  555.   method_defined?(:priorities)|| attr_accessor(:priorities)
  556.   method_defined?(:autotiles) || attr_sec_accessor(:autotiles,'Array.new')
  557. end
  558.  
  559. #==============================================================================
  560. # ** Table
  561. #------------------------------------------------------------------------------
  562. #  
  563. #==============================================================================
  564. class Table
  565.   #--------------------------------------------------------------------------
  566.   # * Public Instance Variable
  567.   #--------------------------------------------------------------------------
  568.   attr_sec_accessor :table_changes, :orig_value, 'Array.new'
  569.   attr_accessor     :make_changes
  570.   #--------------------------------------------------------------------------
  571.   # * Alias Listing
  572.   #--------------------------------------------------------------------------
  573.   alias_sec_method :set_method, :"[]="
  574.   #--------------------------------------------------------------------------
  575.   # * Set Data
  576.   #--------------------------------------------------------------------------
  577.   def []=(*args)
  578.     if @make_changes
  579.       table_changes.push([*args]) && orig_value.push(self[*args[0..-2]])
  580.       @make_changes = false
  581.     end
  582.     set_method(*args)
  583.   end
  584.   #--------------------------------------------------------------------------
  585.   # * Reverse
  586.   #--------------------------------------------------------------------------
  587.   def reverse(rx=true,ry=true,rz=true)
  588.     reverse = self.clone
  589.     _x = (0...xsize).to_a
  590.     _y = (0...ysize).to_a
  591.     _z = (0...zsize).to_a
  592.     _x.each do |x|
  593.       _rx = rx ? _x[-1-x] : x
  594.        ysize == 1 && (reverse[x] = self[_rx]) && next
  595.       _y.each do |y|
  596.         _ry = ry ? _y[-1-y] : y
  597.         zsize == 1 && (reverse[x,y] = self[_rx,_ry]) && next
  598.         _z.each do |z|
  599.           _rz = rz ? _z[-1-z] : z
  600.           reverse[x,y,z] = self[_rx,_ry,_rz]
  601.         end
  602.       end
  603.     end
  604.     reverse
  605.   end
  606. end
  607.  
  608. #==============================================================================
  609. # ** RPG::Cache
  610. #==============================================================================
  611. ModCache = LiTTleDRAgo.cache
  612. module ModCache
  613.   #----------------------------------------------------------------------------
  614.   # * Self
  615.   #----------------------------------------------------------------------------
  616.   class << self
  617.     #--------------------------------------------------------------------------
  618.     # * Constant
  619.     #--------------------------------------------------------------------------
  620.     AUTO_INDEX = [[
  621.       [27,28,33,34],  [ 5,28,33,34],  [27, 6,33,34],  [ 5, 6,33,34],
  622.       [27,28,33,12],  [ 5,28,33,12],  [27, 6,33,12],  [ 5, 6,33,12],
  623.       [27,28,11,34],  [ 5,28,11,34],  [27, 6,11,34],  [ 5, 6,11,34],
  624.       [27,28,11,12],  [ 5,28,11,12],  [27, 6,11,12],  [ 5, 6,11,12],
  625.       [25,26,31,32],  [25, 6,31,32],  [25,26,31,12],  [25, 6,31,12],
  626.       [15,16,21,22],  [15,16,21,12],  [15,16,11,22],  [15,16,11,12],
  627.       [29,30,35,36],  [29,30,11,36],  [ 5,30,35,36],  [ 5,30,11,36],
  628.       [39,40,45,46],  [ 5,40,45,46],  [39, 6,45,46],  [ 5, 6,45,46],
  629.       [25,30,31,36],  [15,16,45,46],  [13,14,19,20],  [13,14,19,12],
  630.       [17,18,23,24],  [17,18,11,24],  [41,42,47,48],  [ 5,42,47,48],
  631.       [37,38,43,44],  [37, 6,43,44],  [13,18,19,24],  [13,14,43,44],
  632.       [37,42,43,48],  [17,18,47,48],  [13,18,43,48],  [ 1, 2, 7, 8]],
  633.  
  634.      [[27,28,33,34],  [49,50,55,56],  [51,52,57,58],  [49,52,55,58],
  635.       [63,64,69,70],  [65,66,71,72],  [51,52,69,70],  [ 5, 6,33,12],
  636.       [61,62,67,68],  [49,50,67,68],  [53,54,59,60],  [ 5, 6,11,34],
  637.       [61,64,67,70],  [ 5,28,11,12],  [27, 6,11,12],  [ 5, 6,11,12],
  638.       [25,26,31,32],  [25, 6,31,32],  [25,26,31,12],  [25, 6,31,12],
  639.       [15,16,21,22],  [15,16,21,12],  [15,16,11,22],  [15,16,11,12],
  640.       [29,30,35,36],  [29,30,11,36],  [ 5,30,35,36],  [ 5,30,11,36],
  641.       [39,40,45,46],  [ 5,40,45,46],  [39, 6,45,46],  [ 5, 6,45,46],
  642.       [25,30,31,36],  [15,16,45,46],  [13,14,19,20],  [13,14,19,12],
  643.       [17,18,23,24],  [17,18,11,24],  [41,42,47,48],  [ 5,42,47,48],
  644.       [37,38,43,44],  [37, 6,43,44],  [13,18,19,24],  [13,14,43,44],
  645.       [37,42,43,48],  [17,18,47,48],  [13,18,43,48],  [ 1, 2, 7, 8]]
  646.     ].freeze
  647.     #--------------------------------------------------------------------------
  648.     # * Public Instance Variable
  649.     #--------------------------------------------------------------------------
  650.     attr_sec_reader :cache, 'Hash.new'
  651.     #--------------------------------------------------------------------------
  652.     # * New method: autotile_cr_tilemap
  653.     #--------------------------------------------------------------------------
  654.     def autotile_cr_tilemap(filename)
  655.       key = "Graphics/Autotiles/CR#{filename}"
  656.       if !@cache.include?(key) || @cache[key].disposed?
  657.         @cache[key] = (filename=='') ? Bitmap.new(128,96) : autotile(filename)
  658.         new_bm = self.format_autotiles(@cache[key], filename)
  659.         @cache[key].dispose
  660.         @cache[key] = new_bm
  661.         @cache[key].instance_variable_set(:@autotile_name, filename)
  662.       end
  663.       return @cache[key]
  664.     end
  665.     #--------------------------------------------------------------------------
  666.     # * New method: include?
  667.     #--------------------------------------------------------------------------
  668.     unless method_defined?(:include?)
  669.       def include?(key)
  670.         @cache[key] && !@cache[key].disposed?
  671.       end
  672.     end
  673.     #--------------------------------------------------------------------------
  674.     # * New method: format_autotiles
  675.     #--------------------------------------------------------------------------
  676.     def format_autotiles(bitmap, filename)
  677.       if bitmap.height > 32
  678.         frames = bitmap.width / 96
  679.         index = bitmap.height == 192 ? AUTO_INDEX[1] : AUTO_INDEX[0]
  680.         template = Bitmap.new(256*frames,192)
  681.         frames.times {|a| (0...6).each { |i| (0...8).each { |j|
  682.           index[8*i+j].each { |number|
  683.             number -= 1
  684.             x, y = 16 * (number % 6), 16 * (number / 6)
  685.             ox, oy = (32 * j + x % 32) + (a * 256), 32 * i + y % 32
  686.             rect = Rect.new(x + (a * 96), y, 16, 16)
  687.             template.blt(ox, oy, bitmap, rect)
  688.         }}}}
  689.         return template
  690.       else
  691.         return bitmap
  692.       end
  693.     end
  694.     #--------------------------------------------------------------------------
  695.     # * New method: tile
  696.     #--------------------------------------------------------------------------
  697.     unless method_defined?(:format_tile)
  698.       def format_tile(bitmap, tile_id, hue)
  699.         filename = bitmap.pathname
  700.         key = [filename, tile_id, hue]
  701.         unless include?(key)
  702.           @cache[key] = empty_bitmap
  703.           x = (tile_id - 384) % 8 * 32
  704.           y = (tile_id - 384) / 8 * 32
  705.           rect = Rect.new(x, y, 32, 32)
  706.           @cache[key].blt(0, 0, bitmap, rect)
  707.           @cache[key].hue_change(hue)
  708.         end
  709.         @cache[key]
  710.       end
  711.     end
  712.     #--------------------------------------------------------------------------
  713.     # * New method: clear_tile_cache
  714.     #--------------------------------------------------------------------------
  715.     def clear_tile_cache
  716.       @cache ||= {}
  717.       @cache.reject! do |keys|
  718.         keys.is_a?(Array) && keys.size == 3 &&
  719.         keys[0].is_a?(String) && keys[0].downcase["tilemap"]
  720.       end
  721.       GC.start
  722.     end
  723.   end
  724. end
  725.  
  726. #==============================================================================
  727. # ** Bitmap
  728. #------------------------------------------------------------------------------
  729. #  
  730. #==============================================================================
  731. class Bitmap
  732.   #--------------------------------------------------------------------------
  733.   # * Public Instance Variable
  734.   #--------------------------------------------------------------------------
  735.   attr_sec_accessor :pathname, 'String.new'
  736.   #--------------------------------------------------------------------------
  737.   # ● Alias Method
  738.   #--------------------------------------------------------------------------
  739.   $@ || alias_method(:cr_path_init, :initialize)
  740.   #--------------------------------------------------------------------------
  741.   # ● Object Initialization
  742.   #--------------------------------------------------------------------------
  743.   def initialize(*args)
  744.     @pathname = args.at(0) if args.at(0).is_a?(String)
  745.     cr_path_init(*args)
  746.   end
  747. end
  748. #==============================================================================
  749. # ** RPG::Weather
  750. #------------------------------------------------------------------------------
  751. #  A class for weather effects (rain, storm, and snow). It is used within the
  752. # Spriteset_Map class.
  753. #==============================================================================
  754. CRWeather = LiTTleDRAgo::VX ? Spriteset_Weather : RPG::Weather
  755. class CRWeather
  756.   #--------------------------------------------------------------------------
  757.   # * Public Instance Variable
  758.   #--------------------------------------------------------------------------
  759.   attr_reader :viewport
  760.   attr_accessor :zoom_x, :zoom_y
  761.   #--------------------------------------------------------------------------
  762.   # * Alias Listing
  763.   #--------------------------------------------------------------------------
  764.   $@ || alias_method(:init_custom_resolution, :initialize)
  765.   #--------------------------------------------------------------------------
  766.   # * Aliased method: initialize
  767.   #--------------------------------------------------------------------------
  768.   def initialize(viewport)
  769.     @viewport = viewport
  770.     init_custom_resolution(@viewport)
  771.   end
  772.   #--------------------------------------------------------------------------
  773.   # * Overwriten method: update
  774.   #--------------------------------------------------------------------------
  775.   def update
  776.     return if @type == 0
  777.     return if $game_map && $game_map.screen_is_solid?
  778.     update_screen if respond_to?(:update_screen)
  779.     @sprites.each {|sprite| update_sprite(sprite) }
  780.   end
  781.   #--------------------------------------------------------------------------
  782.   # * Update Sprite
  783.   #--------------------------------------------------------------------------
  784.   def update_sprite(sprite)
  785.     sprite.ox = @ox
  786.     sprite.oy = @oy
  787.     case @type
  788.     when 1, :rain  then update_sprite_rain(sprite)
  789.     when 2, :storm then update_sprite_storm(sprite)
  790.     when 3, :snow  then update_sprite_snow(sprite)
  791.     end
  792.     create_new_particle(sprite) if sprite.opacity < 64
  793.   end
  794.   #--------------------------------------------------------------------------
  795.   # * Update Sprite [Rain]
  796.   #--------------------------------------------------------------------------
  797.   def update_sprite_rain(sprite)
  798.     sprite.bitmap = @rain_bitmap
  799.     sprite.x -= 2 * sprite.zoom_x
  800.     sprite.y += 16 * sprite.zoom_y
  801.     sprite.opacity -= 8
  802.   end
  803.   #--------------------------------------------------------------------------
  804.   # * Update Sprite [Storm]
  805.   #--------------------------------------------------------------------------
  806.   def update_sprite_storm(sprite)
  807.     sprite.bitmap = @storm_bitmap
  808.     sprite.x -= 8 * sprite.zoom_x
  809.     sprite.y += 16 * sprite.zoom_y
  810.     sprite.opacity -= 12
  811.   end
  812.   #--------------------------------------------------------------------------
  813.   # * Update Sprite [Snow]
  814.   #--------------------------------------------------------------------------
  815.   def update_sprite_snow(sprite)
  816.     sprite.bitmap = @snow_bitmap
  817.     sprite.x -= 2 * sprite.zoom_x
  818.     sprite.y += 8 * sprite.zoom_y
  819.     sprite.opacity -= 8
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   # * Create New Particle
  823.   #--------------------------------------------------------------------------
  824.   def create_new_particle(sprite)
  825.     sprite.x = rand(Graphics.width + 100) - 100 + @ox
  826.     sprite.y = rand(Graphics.height + 200) - 200 + @oy
  827.     sprite.zoom_x = @zoom_x || 1
  828.     sprite.zoom_y = @zoom_y || 1
  829.     sprite.x *= sprite.zoom_x
  830.     sprite.y *= sprite.zoom_y
  831.     sprite.opacity = 160 + rand(96)
  832.   end
  833.   #---------------------------------------------------------------------------
  834.   # * New method: method_missing
  835.   #---------------------------------------------------------------------------
  836.   def method_missing(val,*a,&b)
  837.     en = @sprites.flatten.find_all {|s|s.respond_to?(val.to_sym)}
  838.     if en.empty?
  839.       text = "Undefined method #{val} at #{self.inspect}"
  840.       raise(NoMethodError,text,caller(1))
  841.     end
  842.     return en.map {|s| s.send(val.to_sym,*a,&b)}
  843.   end  
  844. end
  845.  
  846. #==============================================================================
  847. # ** Plane
  848. #------------------------------------------------------------------------------
  849. #  This class is the rewrite of the default plane class
  850. #==============================================================================
  851.  
  852. class CRPlane < Sprite
  853.   #---------------------------------------------------------------------------
  854.   # * Public Instance Variable
  855.   #---------------------------------------------------------------------------
  856.   attr_reader :bitmap
  857.   #---------------------------------------------------------------------------
  858.   # * New method: z=
  859.   #---------------------------------------------------------------------------
  860.   def z=(z)
  861.     super(z * 1000)
  862.   end
  863.   #---------------------------------------------------------------------------
  864.   # * New method: ox=
  865.   #---------------------------------------------------------------------------
  866.   def ox=(ox)
  867.     return if $game_map && $game_map.screen_is_solid?
  868.     return if bitmap.nil? || bitmap.disposed?
  869.     super(ox % bitmap.width)  if bitmap.is_a?(Bitmap)
  870.   end
  871.   #---------------------------------------------------------------------------
  872.   # * New method: oy=
  873.   #---------------------------------------------------------------------------
  874.   def oy=(oy)
  875.     return if $game_map && $game_map.screen_is_solid?
  876.     return if bitmap.nil? || bitmap.disposed?
  877.     super(oy % bitmap.height) if bitmap.is_a?(Bitmap)
  878.   end
  879.   #---------------------------------------------------------------------------
  880.   # * New method: dispose
  881.   #---------------------------------------------------------------------------
  882.   def dispose
  883.     @plane && (@plane.disposed? || @plane.dispose)
  884.     super unless disposed?
  885.   end
  886.   #---------------------------------------------------------------------------
  887.   # * New method: bitmap=
  888.   #---------------------------------------------------------------------------
  889.   def bitmap=(tile)
  890.     return if @bitmap == tile
  891.     @bitmap = tile
  892.     if @bitmap.is_a?(Bitmap)
  893.       xx = 1 + (Graphics.width.to_f / tile.width).ceil
  894.       yy = 1 + (Graphics.height.to_f / tile.height).ceil
  895.       @plane.dispose if @plane.respond_to?(:dispose) && @plane.not.disposed?
  896.       @plane = Bitmap.new(@bitmap.width * xx, @bitmap.height * yy)
  897.       (0..xx).each {|x| (0..yy).each {|y|
  898.         @plane.blt(x * @bitmap.width, y * @bitmap.height, @bitmap, @bitmap.rect)
  899.       }}
  900.       super(@plane)
  901.     else
  902.       super(nil)
  903.     end
  904.   end
  905.   #---------------------------------------------------------------------------
  906.   # * Undefine methods dealing with coordinates to do nothing.
  907.   #---------------------------------------------------------------------------
  908.   undef :x, :x=, :y, :y=   if method_defined?(:x)
  909. end
  910.  
  911. #==============================================================================
  912. # ** Viewport
  913. #------------------------------------------------------------------------------
  914. #  
  915. #==============================================================================
  916. class Viewport
  917.   #--------------------------------------------------------------------------
  918.   # * Overwriten method: update_viewport_sizes
  919.   #--------------------------------------------------------------------------
  920.   def update_viewport_sizes
  921.     map = $game_map
  922.     w, h = Graphics.width, Graphics.height
  923.     hor = $game_map.loop_horizontal?
  924.     ver = $game_map.loop_vertical?
  925.     _w = ($game_map.width  * 32 * $game_map.zoom_x).floor
  926.     _h = ($game_map.height * 32 * $game_map.zoom_y).floor
  927.     dx = w > _w && !hor ? ((w - _w).floor.abs / 32) * 16 : 0
  928.     dw = hor ? w : [w, $game_map.width  * 32 * $game_map.zoom_x].min  
  929.     dy = h > _h && !ver ? ((h - _h).floor.abs / 32) * 16 : 0
  930.     dh = ver ? h : [h, $game_map.height * 32 * $game_map.zoom_y].min
  931.     resize(Rect.new(dx, dy, dw, dh))
  932.   end
  933. end
  934. #==============================================================================
  935. # ** ZTilemap
  936. #------------------------------------------------------------------------------
  937. #  This class is the rewrite of the default tilemap class
  938. #==============================================================================
  939.  
  940. class ZTilemap  
  941.   #---------------------------------------------------------------------------
  942.   # * Public Instance Variables
  943.   #---------------------------------------------------------------------------
  944.   attr_reader       :map_data,  :viewport
  945.   attr_accessor     :tileset,   :tone,    :priorities, :sprite_compact
  946.   attr_sec_accessor :autotiles, 'Array.new'
  947.   attr_sec_accessor :ox, :oy,   :zoom_x,  :zoom_y, :hue, 'Integer(1)'
  948.   attr_sec_accessor :opacity,  'Integer(255)'
  949.   attr_sec_reader   :layers, :bitmap_layers, :extra_map_data, 'Array.new'
  950.   #---------------------------------------------------------------------------
  951.   # * Redirect Listing
  952.   #---------------------------------------------------------------------------
  953.   redirect_method :width,       '$game_map.screen_tile_x + 2'
  954.   redirect_method :height,      '$game_map.screen_tile_y + 2'
  955.   #---------------------------------------------------------------------------
  956.   # * Define Sec Listing
  957.   #---------------------------------------------------------------------------
  958.   define_sec_method(:all_sprites) { layers.flatten.select {|s| is_sprite?(s)}}
  959.   define_sec_method(:is_sprite?)  { |s|  s.is_a?(Sprite) && s.not.disposed?  }
  960.   #---------------------------------------------------------------------------
  961.   # * Alias Listing
  962.   #---------------------------------------------------------------------------
  963.   alias_method :bitmaps, :autotiles
  964.   #---------------------------------------------------------------------------
  965.   # * Object Initialization
  966.   #---------------------------------------------------------------------------
  967.   def initialize(viewport)
  968.     @viewport       = viewport
  969.     @sprite_compact = false#LiTTleDRAgo::SPRITE_COMPACT
  970.     create_sprites
  971.     create_carrot
  972.   end
  973.   #---------------------------------------------------------------------------
  974.   # * New method: create_sprites
  975.   #---------------------------------------------------------------------------
  976.   def create_sprites
  977.     6.times do |i|
  978.       layers[i] ||= []
  979.       (i % 6 == 0 ? 1 : height).times do |s|
  980.         layers[i][s] = Sprite.new(@viewport) unless is_sprite?(layers[i][s])
  981.       end
  982.       layers[i].each_with_index do |s,r|
  983.         next unless is_sprite?(s)
  984.         s.y = r * 32 * zoom_y      
  985.         s.z = (i % 6 == 0) ? 0 : (r * 32 + 32 + (i % 6) * 32)
  986.         s.mirror = $game_map.reverse
  987.       end
  988.     end
  989.   end
  990.   #---------------------------------------------------------------------------
  991.   # * New method: create_carrot
  992.   #---------------------------------------------------------------------------
  993.   def create_carrot
  994.     @draw_tiles = carrot do |x,y,data,prio|
  995.       [0,1,2].each do |r|
  996.         if (id = data[x,y,r]).to_i == 0 || (layer = prio[id]).nil?
  997.           next
  998.         elsif @layer_clear && @layer_clear.not.include?(layer)
  999.           @bitmap_layers[layer].fill_rect(x*32,y*32,32,32,Color.erase)
  1000.           @layer_clear.push(layer)
  1001.         end
  1002.         refresh_tiles(x,y,r,id)
  1003.       end
  1004.     end
  1005.     @change_tone         = carrot {|s| all_sprites.tone    = (@tone = s)   }
  1006.     @change_opacity      = carrot {|s| all_sprites.opacity = (@opacity = s)}
  1007.     @change_autotile_hue = carrot do |a,old,hue|
  1008.       [old.to_i != 0 && a.hue_change((old - 360).abs)] && a.hue_change(hue)
  1009.     end
  1010.   end
  1011.   #---------------------------------------------------------------------------
  1012.   # * New method: ox=, oy=, zoom_x=, zoom_y=
  1013.   #---------------------------------------------------------------------------
  1014.   [:ox, :oy, :zoom_x, :zoom_y].each do |a|
  1015.     meth = "def %1$s=(%1$s) (@%1$s != %1$s) && (@%1$s = %1$s) && %2$s end"
  1016.     module_eval(sprintf(meth, a ,'adjust_sprites'))
  1017.   end
  1018.   #---------------------------------------------------------------------------
  1019.   # * New method: tone=
  1020.   #---------------------------------------------------------------------------
  1021.   def tone=(*tone)
  1022.     new_tone = tone.flatten.size == 4 ? Tone.new(*tone.flatten) :
  1023.                tone.first.is_a?(Tone) ? tone.first : nil
  1024.     @tone.to_s == new_tone.to_s || @change_tone.call(new_tone.clone)
  1025.   end
  1026.   #---------------------------------------------------------------------------
  1027.   # * New method: opacity=
  1028.   #---------------------------------------------------------------------------
  1029.   def opacity=(opacity)
  1030.     opacity = [[opacity.round,255].min,0].max
  1031.     @opacity == opacity || @change_opacity.call(opacity)
  1032.   end
  1033.   #---------------------------------------------------------------------------
  1034.   # * New method: hue=
  1035.   #---------------------------------------------------------------------------
  1036.   def hue=(hue)
  1037.     return if @hue == (hue % 360)
  1038.     old = self.hue
  1039.     @hue = hue % 360
  1040.     all_autotiles = @autotiles + extra_map_data.map {|m| m[:autotiles]}.flatten
  1041.     @change_autotile_hue.call(all_autotiles.uniq, old, @hue)
  1042.     refresh     
  1043.   end
  1044.   #---------------------------------------------------------------------------
  1045.   # * New method: Adjust Sprites
  1046.   #---------------------------------------------------------------------------
  1047.   def adjust_sprites
  1048.     @times_compact ||= []
  1049.     @layers_used && @layers.size.times do |i|
  1050.       layer = @layers[i]
  1051.       (i % 6 == 0 ? 1 : height).times do |r|
  1052.         sprite = layer[r]
  1053.         d = 32
  1054.         _r = 32 + (i % 6) * 32
  1055.         _y = r * 32 * zoom_y
  1056.         _z = i % 6 == 0 ? 0 : r * d + _r # (r * d + _r)
  1057.         unless is_sprite?(sprite)
  1058.           change = _y <= @viewport.height
  1059.           if @sprite_compact
  1060.             change &&= !char_out_range?(_r, (height-1)*d+_r)
  1061.             change &&= @layers_used[i] > 0
  1062.           end
  1063.           change || next
  1064.           sprite = (layer[r] = Sprite.new(@viewport))
  1065.           sprite.bitmap  = bitmap_layers[i]
  1066.           sprite.tone    = tone if tone
  1067.           sprite.opacity = opacity
  1068.           sprite.mirror  = $game_map.reverse
  1069.           sprite.zoom_x, sprite.zoom_y = zoom_x, zoom_y
  1070.         else
  1071.           change = _y > @viewport.height
  1072.           if (@times_compact[i] ||= 0) < 10 && @sprite_compact
  1073.             change ||=  (r > 0 && char_out_range?(_r, (height-1)*d+_r))
  1074.             change ||=  (r > 0 && @layers_used[i] == 0)
  1075.           end
  1076.           sprite.y, sprite.z = _y, _z.ceil
  1077.           change && [sprite.dispose, @times_compact[i] += 1] && next
  1078.         end
  1079.         sprite.y, sprite.z = _y, _z.ceil
  1080.         _wd = @viewport.width/zoom_x
  1081.         _ox = sprite.mirror ? (sprite.bitmap.width-ox)-_wd  : (_wd+=10) && ox
  1082.         if layer.select { |s| is_sprite?(s) }.size == 1
  1083.           sprite.src_rect.set(_ox, oy, _wd, @viewport.height/zoom_x + 10)
  1084.         else
  1085.           sprite.src_rect.set(_ox, (oy + r*32), _wd, 33)
  1086.         end         
  1087.         sprite.zoom_x, sprite.zoom_y = zoom_x, zoom_y
  1088.       end
  1089.     end
  1090.   end
  1091.   #---------------------------------------------------------------------------
  1092.   # * New method: char_out_range?
  1093.   #---------------------------------------------------------------------------
  1094.   def char_out_range?(z1,z2)
  1095.     return false unless (s = $game_map.spriteset).is_a?(Spriteset_Map)
  1096.     s.character_sprites.all? do |d|
  1097.       d.not.disposed? && d.opacity > 0 && d.visible &&
  1098.       (d.z).not.between?(z1,z2)
  1099.     end
  1100.   end
  1101.   #---------------------------------------------------------------------------
  1102.   # * New method: Frame Dispose
  1103.   #---------------------------------------------------------------------------
  1104.   def dispose
  1105.     all_sprites.each   { |s| s.dispose }
  1106.     bitmap  = bitmap_layers
  1107.     bitmap += extra_map_data.map {|m| m[:autotiles]}.flatten - @autotiles
  1108.     bitmap += extra_map_data.map {|m| m[:tileset]}.flatten
  1109.     bitmap.compact.each { |s| s.disposed? || s.dispose }
  1110.     @layers.clear
  1111.     GC.start
  1112.   end
  1113.   #---------------------------------------------------------------------------
  1114.   # * New method: Change Map Data
  1115.   #---------------------------------------------------------------------------
  1116.   def map_data=(data)
  1117.     return if @map_data == data
  1118.     @map_data = data
  1119.     @map_data_reverse = data.reverse(true,false,false)
  1120.     6.times do |i|
  1121.       bitmap_layers[i].dispose if bitmap_layers[i] && bitmap_layers[i].disposed?
  1122.       bitmap_layers[i] =  Bitmap.new($game_map.width*32,$game_map.height*32)
  1123.       layers[i].each { |s| is_sprite?(s) && s.bitmap = bitmap_layers[i] }
  1124.     end
  1125.     refresh
  1126.   end
  1127.   #---------------------------------------------------------------------------
  1128.   # * New method: Map Data
  1129.   #---------------------------------------------------------------------------
  1130.   def map_data
  1131.     $game_map.reverse ? @map_data_reverse : @map_data
  1132.   end
  1133.   #---------------------------------------------------------------------------
  1134.   # * New method: Change priorities
  1135.   #---------------------------------------------------------------------------
  1136.   def priorities=(priorities)
  1137.     return if @priorities == priorities
  1138.     @priorities = priorities
  1139.     refresh
  1140.   end
  1141.   #---------------------------------------------------------------------------
  1142.   # * New method: Frame Refresh
  1143.   #---------------------------------------------------------------------------
  1144.   def refresh   
  1145.     return unless @priorities && @map_data
  1146.     LiTTleDRAgo.cache.clear_tile_cache
  1147.     @animated_tiles   = []
  1148.     @unrefreshed_tile = []
  1149.     @layers_used      = []
  1150.     7.times do |i|
  1151.       @total_frames   = [] if i == 0
  1152.       @current_frame  = [] if i == 0
  1153.       bm = (@current_frame[i] = @layers_used[i] = 0) && autotiles[i]
  1154.       bm.nil? && @total_frames[i] = 1
  1155.       bm.nil? || @total_frames[i] = bm.width / (bm.height > 32 ? 256 : 32)
  1156.       extra_map_data.each do |data|
  1157.         data[:total_frames]  = [] if i == 0
  1158.         data[:current_frame] = [] if i == 0
  1159.         bm = (data[:current_frame][i] = 0) && data[:autotiles][i]
  1160.         bm.nil? && data[:total_frames][i] = 1
  1161.         bm.nil? || data[:total_frames][i] = bm.width / (bm.height>32 ? 256 : 32)
  1162.       end
  1163.     end
  1164.     _w = @viewport.width
  1165.     _h = @viewport.height
  1166.     layers[0][0].src_rect.set(ox, oy, _w/zoom_x, _h/zoom_y )
  1167.     (0...map_data.xsize).each do |x|
  1168.       (0...map_data.ysize).each do |y|
  1169.         if in_range?(x,y)
  1170.           update_map_changes(x,y)
  1171.         else
  1172.           next if @unrefreshed_tile.include?([x,y])
  1173.           @unrefreshed_tile.push([x,y])
  1174.           @unrefreshed_tile.uniq!
  1175.         end
  1176.       end
  1177.     end
  1178.     adjust_sprites
  1179.   end
  1180.   #---------------------------------------------------------------------------
  1181.   # * New method: Refresh Tiles
  1182.   #---------------------------------------------------------------------------
  1183.   def refresh_tiles(x,y,z,i,d = nil)
  1184.     return if i.nil? || i == 0
  1185.     i < 384 ? refresh_autotile(x,y,z,i,d) : refresh_regular_tile(x,y,z,i,d)
  1186.   end
  1187.   #---------------------------------------------------------------------------
  1188.   # * New method: Refresh Autotile
  1189.   #---------------------------------------------------------------------------
  1190.   def refresh_autotile(x,y,z,id,data)
  1191.     layer  = data.nil? ? @priorities[id]        : data[:priorities][id]
  1192.     tframe = data.nil? ? @total_frames          : data[:total_frames]
  1193.     cframe = data.nil? ? @current_frame         : data[:current_frame]
  1194.     bitmap = data.nil? ? @autotiles.at(id/48-1) : data[:autotiles].at(id/48-1)
  1195.     return if bitmap.nil? || layer.nil?
  1196.     div = (fid = id / 48 - 1) &&(id % 48)
  1197.     if @animated_tiles.not.include?([x,y]) && tframe[fid] > 1
  1198.       @animated_tiles.push([x,y])
  1199.       @animated_tiles.uniq!
  1200.     end
  1201.     rect = Rect.new((div % 8)*32 + cframe[fid] * 256, (div / 8)*32, 32, 32)
  1202.     bitmap_layers[layer].blt(x*32, y*32, bitmap, rect)  
  1203.     @layers_used[layer] = [(@layers_used[layer] + 1) % 10000,1].max   
  1204.   end
  1205.   #---------------------------------------------------------------------------
  1206.   # * New method: Refresh Regular Tile
  1207.   #---------------------------------------------------------------------------
  1208.   def refresh_regular_tile(x,y,z,id,data)
  1209.     tileset = data.nil? ? @tileset        : data[:tileset]
  1210.     layer   = data.nil? ? @priorities[id] : data[:priorities][id]
  1211.     return if layer.nil? || tileset.not.is_a?(Bitmap)
  1212.     bitmap  = LiTTleDRAgo.cache.format_tile(tileset, id, hue)
  1213.     bitmap_layers[layer].blt(x*32, y*32, bitmap, Rect.new(0, 0, 32, 32))
  1214.     @layers_used[layer] = [(@layers_used[layer] + 1) % 10000, 1].max  
  1215.   end   
  1216.   #---------------------------------------------------------------------------
  1217.   # * New method: force_refresh
  1218.   #---------------------------------------------------------------------------
  1219.   def force_refresh
  1220.     refresh
  1221.     (@unrefreshed_tile ||= []).each {|x,y| update_map_changes(x,y)}
  1222.     (@unrefreshed_tile.clear)
  1223.   end
  1224.   #---------------------------------------------------------------------------
  1225.   # * New method: Frame Update
  1226.   #---------------------------------------------------------------------------
  1227.   def update
  1228.     update_map_data
  1229.     update_autotile
  1230.     update_unrefreshed_tile
  1231.   end
  1232.   #---------------------------------------------------------------------------
  1233.   # * New method: Update Unrefreshed Tile
  1234.   #---------------------------------------------------------------------------
  1235.   def update_unrefreshed_tile
  1236.     if @unrefreshed_tile && @unrefreshed_tile.not.empty?
  1237.       unrefreshed = @unrefreshed_tile.select { |x,y| in_range?(x,y) }
  1238.       if unrefreshed.not.empty?
  1239.         (unrefreshed).each {|x,y| update_map_changes(x,y)}
  1240.         (@unrefreshed_tile -= unrefreshed) && adjust_sprites
  1241.       end
  1242.     end
  1243.   end
  1244.   #---------------------------------------------------------------------------
  1245.   # * New method: Update Map Data
  1246.   #---------------------------------------------------------------------------
  1247.   def update_map_data
  1248.     if map_data.table_changes.not.empty?
  1249.       map_data.table_changes.each do|item|
  1250.         x,y,z,tile_id = item
  1251.         update_map_changes(x,y)
  1252.       end
  1253.       map_data.table_changes.clear
  1254.       map_data.make_changes = false
  1255.       adjust_sprites
  1256.     end
  1257.   end
  1258.   #---------------------------------------------------------------------------
  1259.   # * New method: Update the autotile
  1260.   #---------------------------------------------------------------------------
  1261.   def update_autotile
  1262.     return if $game_map.screen_is_solid?
  1263.     speed = $game_map.autotile_speed
  1264.     total = [(@autotile_total || 0) / 10, 0].max
  1265.     if speed > 0 && Graphics.frame_count % (speed + total) == 0
  1266.       7.times do |i|
  1267.         extra_map_data.each do |data|
  1268.           next if (total = data[:total_frames].at(i)) == 0
  1269.           data[:current_frame][i] = (data[:current_frame].at(i) + 1) % total
  1270.         end
  1271.         next if (total = @total_frames.at(i)) == 0
  1272.         @current_frame[i] = (@current_frame.at(i) + 1) % total
  1273.       end
  1274.       animated = @animated_tiles.select { |x,y| in_range?(x,y) }
  1275.       animated.each {|x,y| update_map_changes(x,y) }
  1276.       @autotile_total = animated.size
  1277.     end
  1278.   end
  1279.   #---------------------------------------------------------------------------
  1280.   # * New method: in_range?
  1281.   #---------------------------------------------------------------------------
  1282.   def in_range?(x=nil,y=nil)
  1283.     return false if layers[0].nil? || layers[0][0].nil?
  1284.     rect = @layers[0][0].src_rect
  1285.     _x = x && (x * 32).between?(rect.x-32, rect.x + rect.width)
  1286.     _y = y && (y * 32).between?(rect.y-32, rect.y + rect.height)
  1287.     return _x && _y if x && y
  1288.     return _x if x
  1289.     return _y if y
  1290.     return false
  1291.   end
  1292.   #---------------------------------------------------------------------------
  1293.   # * New method: Update Map Changes
  1294.   #---------------------------------------------------------------------------
  1295.   def update_map_changes(x,y)
  1296.     @layer_clear ||= []
  1297.     @layer_clear.clear
  1298.     draw = [[x,y,map_data,priorities]]  
  1299.     draw += extra_map_data.map {|data|[x,y,data[:map].data,data[:priorities]]}
  1300.     draw.each {|data| @draw_tiles.call(*data)}
  1301.   end   
  1302. end
  1303. #==============================================================================
  1304. # ** Game_Character
  1305. #------------------------------------------------------------------------------
  1306. #  This class deals with characters. It's used as a superclass for the
  1307. #  determinants and map scrolling. Refer to "$game_player" for the one
  1308. #  Game_Player and Game_Event classes.
  1309. #==============================================================================
  1310. class Game_Character
  1311.   #--------------------------------------------------------------------------
  1312.   # * Alias Listing
  1313.   #--------------------------------------------------------------------------
  1314.   alias_sec_method(:screen_x_before_zoom, :screen_x)
  1315.   alias_sec_method(:screen_y_before_zoom, :screen_y)
  1316.   alias_sec_method(:screen_z_before_zoom, :screen_z)
  1317.   #--------------------------------------------------------------------------
  1318.   # * Aliased method: screen_x
  1319.   #--------------------------------------------------------------------------
  1320.   def screen_x(*args)
  1321.     screen_x_before_zoom(*args) * $game_map.zoom_x
  1322.   end
  1323.   #--------------------------------------------------------------------------
  1324.   # * Aliased method: screen_y
  1325.   #--------------------------------------------------------------------------
  1326.   def screen_y(*args)
  1327.     screen_y_before_zoom(*args) * $game_map.zoom_y
  1328.   end
  1329.   #--------------------------------------------------------------------------
  1330.   # * Aliased method: screen_z
  1331.   #--------------------------------------------------------------------------
  1332.   def screen_z(*args)
  1333.     if self.is_a?(Game_Event)
  1334.       return 999                  if @always_on_top
  1335.       return $1.to_i              if self.name[/\<Z:\s*([-]?\d+)\s*\>/i]
  1336.       return screen_z_tilemap_fix if screen_z_tilemap_fix.is_a?(Integer)
  1337.     end
  1338.     return screen_z_before_zoom(*args)
  1339.   end
  1340.   #--------------------------------------------------------------------------
  1341.   # * New method: screen_z_tilemap_fix
  1342.   #--------------------------------------------------------------------------
  1343.   def screen_z_tilemap_fix
  1344.     LiTTleDRAgo::CHARACTER_Z_FIX.each do |key,value|
  1345.       if value.is_a?(Array) && key.is_a?(Integer)
  1346.         return key if value.any?{|v|"#{v}".downcase == @character_name.downcase}
  1347.       elsif key.is_a?(Array) && value.is_a?(Integer)
  1348.         return value if key.any?{|v|"#{v}".downcase == @character_name.downcase}
  1349.       elsif (key.is_a?(String) || key.is_a?(Symbol)) && value.is_a?(Integer)
  1350.         return value if "#{key}".downcase == @character_name.downcase
  1351.       end
  1352.     end
  1353.     return nil
  1354.   end
  1355. end
  1356.  
  1357. #==============================================================================
  1358. # ** Sprite_Character
  1359. #------------------------------------------------------------------------------
  1360. #  This sprite is used to display the character.It observes the Game_Character
  1361. #  class and automatically changes sprite conditions.
  1362. #==============================================================================
  1363. class Sprite_Character
  1364.   #--------------------------------------------------------------------------
  1365.   # * Alias Listing
  1366.   #--------------------------------------------------------------------------
  1367.   alias_sec_method(:zoom_update_scrolling, :update)
  1368.   #--------------------------------------------------------------------------
  1369.   # * Aliased method: update
  1370.   #--------------------------------------------------------------------------
  1371.   def update(*args)
  1372.     if @old_character_zoom_x
  1373.       self.zoom_x = @old_character_zoom_x
  1374.       self.zoom_y = @old_character_zoom_y
  1375.     end
  1376.     zoom_update_scrolling(*args)
  1377.     @old_character_zoom_x = self.zoom_x
  1378.     @old_character_zoom_y = self.zoom_y
  1379.     self.zoom_x *= $game_map.zoom_x
  1380.     self.zoom_y *= $game_map.zoom_y
  1381.   end
  1382.   #--------------------------------------------------------------------------
  1383.   # * New method: in_range?
  1384.   #--------------------------------------------------------------------------
  1385.   unless method_defined?(:in_range?)
  1386.     def in_range?
  1387.       cw = self.src_rect ? self.src_rect.width : 32
  1388.       ch = self.src_rect ? self.src_rect.height : 32
  1389.       return @character.screen_x.round.between?(self.viewport.x - cw,
  1390.         self.viewport.x + self.viewport.width) &&
  1391.       @character.screen_y.round.between?(self.viewport.y - ch,
  1392.         self.viewport.y + self.viewport.height)
  1393.     end
  1394.   end
  1395. end
  1396.  
  1397. #==============================================================================
  1398. # ** Spriteset_Map
  1399. #------------------------------------------------------------------------------
  1400. #  This class brings together map screen sprites, tilemaps, etc.
  1401. #  It's used within the Scene_Map class.
  1402. #==============================================================================
  1403. class Spriteset_Map
  1404.   #---------------------------------------------------------------------------
  1405.   # * Public Instance Variables
  1406.   #---------------------------------------------------------------------------
  1407.   attr_reader :character_sprites, :tilemap
  1408.   attr_reader :viewport1, :viewport2, :viewport3
  1409.   #--------------------------------------------------------------------------
  1410.   # * Alias Listing
  1411.   #--------------------------------------------------------------------------
  1412.   $@ || alias_method(:init_drgcr_tilemap, :initialize)
  1413.   alias_sec_method(:update_drgcr_tilemap, :update)
  1414.   #--------------------------------------------------------------------------
  1415.   # * Aliased method: initialize
  1416.   #--------------------------------------------------------------------------
  1417.   def initialize(*args)
  1418.     check_autotile_height
  1419.     init_drgcr_tilemap(*args)
  1420.   end
  1421.   #---------------------------------------------------------------------------
  1422.   # * New method: check_autotile_height
  1423.   #---------------------------------------------------------------------------
  1424.   def check_autotile_height
  1425.     return unless LiTTleDRAgo::XP
  1426.     $game_map.autotile_names.each do |autotile_name|
  1427.       bitmap = ModCache.autotile(autotile_name)
  1428.       [@force_tilemap_enabled = true] && break if bitmap.height == 192
  1429.     end
  1430.   end
  1431.   #--------------------------------------------------------------------------
  1432.   # * Aliased method: update
  1433.   #--------------------------------------------------------------------------
  1434.   def update(*args)
  1435.     adjust_viewport
  1436.     adjust_tilemap
  1437.     adjust_old_zoom
  1438.     update_drgcr_tilemap(*args)
  1439.     update_tilemap_zoom
  1440.   end
  1441.   #---------------------------------------------------------------------------
  1442.   # * New method: adjust_old_zoom
  1443.   #---------------------------------------------------------------------------
  1444.   def adjust_old_zoom
  1445.     if @old_fog_zoom_x
  1446.       @fog.zoom_x = @old_fog_zoom_x
  1447.       @fog.zoom_y = @old_fog_zoom_y
  1448.       @panorama.zoom_x = @old_panorama_zoom_x
  1449.       @panorama.zoom_y = @old_panorama_zoom_y
  1450.     end
  1451.   end
  1452.   #---------------------------------------------------------------------------
  1453.   # * New method: viewport_sprite
  1454.   #---------------------------------------------------------------------------
  1455.   def viewport_sprite(*v)
  1456.     v.collect! {|s| s.is_a?(Symbol) ? instance_variable_get(:"@#{s}") : s }
  1457.     v.reject!  {|s| s.not.is_a?(Viewport)}
  1458.     all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
  1459.     all.select {|s| s.respond_to?(:viewport) && v.include?(s.viewport)}
  1460.   end
  1461.   #---------------------------------------------------------------------------
  1462.   # * New method: change_tilemap_tone
  1463.   #---------------------------------------------------------------------------
  1464.   def change_tilemap_tone(tone = Tone.new(0,0,0,0), *char)
  1465.     if tone.is_a?(Array) && (3..4) === tone.size
  1466.       result = $game_map.tilemap_tone = Tone.new(*tone)
  1467.     elsif tone.is_a?(Tone)
  1468.       result = $game_map.tilemap_tone = tone
  1469.     else
  1470.       return
  1471.     end
  1472.     sprite = viewport_sprite(:viewport1)
  1473.     sprite.reject! {|s| s.is_a?(Sprite_Character)}
  1474.     sprite.each    {|s| s.tone = result if s.respond_to?(:tone=) }
  1475.     change_character_tone(tone, *char) unless char.empty?
  1476.   end
  1477.   #---------------------------------------------------------------------------
  1478.   # * New method: change_character_tone
  1479.   #---------------------------------------------------------------------------
  1480.   def change_character_tone(tone = Tone.new(0,0,0,0), *char)
  1481.     char = char.collect {|c| c.is_a?(Range) ? c.to_a : c}.flatten
  1482.     char = char.collect {|c| c.is_a?(Range) ? c.to_a : c}.flatten
  1483.     char.collect! {|c| c.is_a?(Game_Character) ? c :
  1484.                        $game_map.interpreter.get_character(c)}
  1485.     sprite = viewport_sprite(:viewport1)
  1486.     sprite.reject! {|s| s.not.is_a?(Sprite_Character) }
  1487.     sprite.reject! {|s| char.not.include?(s.character)}
  1488.     if tone.is_a?(Array) && (3..4) === tone.size
  1489.       sprite.tone(:tone=, Tone.new(*tone))
  1490.     elsif tone.is_a?(Tone)
  1491.       sprite.send(:tone=, tone)
  1492.     end
  1493.   end
  1494.   #--------------------------------------------------------------------------
  1495.   # * New method: reload_tilemap
  1496.   #--------------------------------------------------------------------------
  1497.   def reload_tilemap
  1498.     return [dispose_tilemap, create_tilemap] if LiTTleDRAgo::VXA
  1499.     @tilemap.respond_to?(:dispose) && @tilemap.dispose
  1500.     7.times do |i|
  1501.       auto = @tilemap.autotiles[i]
  1502.       auto.respond_to?(:dispose) && (auto.disposed? || auto.dispose)
  1503.     end
  1504.     res = tilemap_enabled? ? ZTilemap : Tilemap
  1505.     @tilemap = res.new(@viewport1)
  1506.     @tilemap.tileset = ModCache.tileset($game_map.tileset_name)
  1507.     7.times do |i|
  1508.       autotile_name = $game_map.autotile_names[i]
  1509.       @tilemap.autotiles[i] = @tilemap.is_a?(ZTilemap) ?
  1510.       ModCache.autotile_cr_tilemap(autotile_name) :
  1511.       ModCache.autotile(autotile_name)
  1512.     end
  1513.     update_tilemap_effect
  1514.     @tilemap.priorities = $game_map.priorities
  1515.     @tilemap.map_data   = $game_map.data
  1516.     @tilemap.update
  1517.     @viewport_screen_width = 0
  1518.   end   
  1519.   #--------------------------------------------------------------------------
  1520.   # * New method: reload_plane
  1521.   #--------------------------------------------------------------------------
  1522.   def reload_plane
  1523.     z1  = @panorama.respond_to?(:z) ? @panorama.z : -1000
  1524.     z2  = @fog.respond_to?(:z)      ? @fog.z      :  5000
  1525.     z1 /= 1000 if @panorama.is_a?(CRPlane)
  1526.     z2 /= 1000 if @fog.is_a?(CRPlane)
  1527.     res =  plane_enabled? ? CRPlane : Plane
  1528.     bitmap1 = @panorama.respond_to?(:bitmap) ? @panorama.bitmap : nil
  1529.     bitmap2 = @fog.respond_to?(:bitmap)      ? @fog.bitmap      : nil
  1530.     @panorama.respond_to?(:dispose) && @panorama.dispose
  1531.     @fog.respond_to?(:dispose) && @fog.dispose      
  1532.     @panorama = res.new(@viewport1)
  1533.     @fog      = res.new(@viewport1)
  1534.     @panorama.bitmap = bitmap1 if bitmap1.is_a?(Bitmap)
  1535.     @fog.bitmap      = bitmap2 if bitmap2.is_a?(Bitmap)
  1536.     @panorama.z, @fog.z = z1, z2
  1537.     @viewport_screen_width = 0
  1538.   end
  1539.   #--------------------------------------------------------------------------
  1540.   # * New method: update_tilemap_zoom
  1541.   #--------------------------------------------------------------------------
  1542.   def update_tilemap_zoom
  1543.     @weather.zoom_x      = $game_map.zoom_x
  1544.     @weather.zoom_y      = $game_map.zoom_y
  1545.     @old_fog_zoom_x      = @fog.zoom_x
  1546.     @old_fog_zoom_y      = @fog.zoom_y
  1547.     @old_panorama_zoom_x = @panorama.zoom_x
  1548.     @old_panorama_zoom_y = @panorama.zoom_y
  1549.     @fog.zoom_x         *= $game_map.zoom_x
  1550.     @fog.zoom_y         *= $game_map.zoom_y
  1551.     @panorama.zoom_x    *= $game_map.zoom_x
  1552.     @panorama.zoom_y    *= $game_map.zoom_y
  1553.     update_tilemap_effect
  1554.   end
  1555.   #--------------------------------------------------------------------------
  1556.   # * New method: update_tilemap_effect
  1557.   #--------------------------------------------------------------------------
  1558.   def update_tilemap_effect
  1559.     return if @tilemap.not.is_a?(ZTilemap)
  1560.     @tilemap.zoom_x  = $game_map.zoom_x
  1561.     @tilemap.zoom_y  = $game_map.zoom_y
  1562.     @tilemap.opacity = $game_map.tilemap_opacity
  1563.     @tilemap.hue     = $game_map.tilemap_hue
  1564.     @tilemap.tone    = $game_map.tilemap_tone
  1565.   end
  1566.   #--------------------------------------------------------------------------
  1567.   # * Overwriten method: viewport_size_change?
  1568.   #--------------------------------------------------------------------------
  1569.   def viewport_size_change?
  1570.     return true if @viewport_map_width  != $game_map.width  * $game_map.zoom_x
  1571.     return true if @viewport_map_height != $game_map.height * $game_map.zoom_y
  1572.     return true if @viewport_screen_width  != Graphics.width
  1573.     return true if @viewport_screen_height != Graphics.height
  1574.   end
  1575.   #--------------------------------------------------------------------------
  1576.   # * New method: adjust_viewport
  1577.   #--------------------------------------------------------------------------
  1578.   def adjust_viewport
  1579.     if viewport_size_change?
  1580.       @viewport_map_width     = $game_map.width * $game_map.zoom_x
  1581.       @viewport_map_height    = $game_map.height * $game_map.zoom_y
  1582.       @viewport_screen_width  = Graphics.width
  1583.       @viewport_screen_height = Graphics.height
  1584.       [@viewport1,@viewport2,@viewport3].compact.update_viewport_sizes
  1585.     end
  1586.   end
  1587.   #--------------------------------------------------------------------------
  1588.   # * New method: adjust_tilemap
  1589.   #--------------------------------------------------------------------------
  1590.   def adjust_tilemap
  1591.     if LiTTleDRAgo::XP
  1592.       if tilemap_enabled?
  1593.         reload_tilemap if @tilemap.is_a?(Tilemap)
  1594.       else
  1595.         reload_tilemap if @tilemap.is_a?(ZTilemap)
  1596.       end
  1597.     end
  1598.     if plane_enabled?
  1599.       reload_plane   if @panorama.is_a?(Plane)   || @fog.is_a?(Plane)
  1600.     else
  1601.       reload_plane   if @panorama.is_a?(CRPlane) || @fog.is_a?(CRPlane)
  1602.     end
  1603.   end
  1604.   #--------------------------------------------------------------------------
  1605.   # * New method: tilemap_enabled?
  1606.   #--------------------------------------------------------------------------
  1607.   def tilemap_enabled?
  1608.     return true if @force_tilemap_enabled
  1609.     return true unless LiTTleDRAgo::RGSS1
  1610.     return true unless @viewport1.width <= 640 && @viewport1.height <= 480
  1611.     return true unless (map = $game_map) && map.zoom_x * map.zoom_y == 1
  1612.     return true unless map.tilemap_opacity >= 255
  1613.     return true unless map.tilemap_hue <= 0
  1614.     return true unless map.tilemap_tone.to_s.get_int == 0
  1615.     return true if map.reverse
  1616.     return false  
  1617.   end
  1618.   #--------------------------------------------------------------------------
  1619.   # * New method: plane_enabled?
  1620.   #--------------------------------------------------------------------------
  1621.   def plane_enabled?
  1622.     return true unless LiTTleDRAgo::RGSS1
  1623.     return true unless @viewport1.width <= 640 && @viewport1.height <= 480
  1624.     return false
  1625.   end
  1626. end

评分

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

查看全部评分

我是梅林,人称花之魔术师。

Lv2.观梦者

梦石
0
星屑
431
在线时间
43 小时
注册时间
2009-5-6
帖子
62
2
发表于 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


回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-22 06:52

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表