- #encoding:utf-8 
- #============================================================================== 
- #   ■ 多帧4_8方图,4_8向行走 
- # 
- #   支持4方图:兼容rmVA原格式图片,4向8向行走 
- #   支持8方图:从上到下方向为:正、左、右、背、左下、右下、左上、右上 
- #             对应小键盘:24681379 
- #   支持开火车,有一定范围的拥挤处理。支持4、8方混合开 
- #   按住方向键时,碰到障碍物会踏步(可选) 
- #   可选4、8向行走,在代码开头设置,默认为8向行走 
- #------------------------------------------------------------------------------ 
- #使用说明:(在编辑器中设置行走图时,有个白框必须放在左上角) 
- #         对原rmVA不支持的格式,需要对文件名实行命名规则 
- #         1.png图片,须仅包含一个人物的全套行走 
- #         2.图片内容,从左到右,小于99帧; 
- #                    从上到下8个方向:正、左、右、背、左下、右下、左上、右上 
- #         3.文件命名 
- #           文件名:角色名+格式串+.png 
- #                  name@D#DD%DD.png   其中%DD可选 
- #          @D表示png文件中, 每一列有多少个图。以一位数表示,如8,即8个方向 
- #          #DD表示png文件中,每一行有多少个图。以两位数表示,如06或6,即6帧 
- #          %DD,可选,调整角色在游戏画面中的高度,单位像素。如20,即调低20像素 
- #          说明:因为如果是精美8方图的话,一般有带阴影,而阴影会比脚低 
- #                这时可通过%DD来调整人物在画面中的高低 
- #                有些图片空白过多,也可用此来调整,不用弄PS。 
- # 
- #小技巧:★可新建一个工程,以RMVA默认的角色领队开火车,可看出是否对齐 
- #        ★若人物在开火车中挤紧在一起,把其每帧的图片加宽,如>=68像素即可。 
- #        ★把文件命名为name@1#DD%DD.png,可作为单行图移动或放事件中播放动画 
- #注意:  ☆rmVA原格式行走图,停下来会停在第2帧(这是rmVA的默认方法) 
- #        ☆自定义格式行走图,停下来会停在第1帧 
- #        ☆格式串前的name必须在characters文件夹下的所有png文件中唯一 
- #        ☆行走图的每一帧之间必须高度相等、宽度相等 
- #      ☆☆没用到的功能关闭掉,以降低冲突及避免无谓的效率影响 
- #------------------------------------------------------------------------------ 
- #  by rmav (有任何问题请毫无顾忌滴提出) 
- # 
- #   v1.09 配合跑步插件更新 
- #============================================================================== 
- $imported ||= {}  
- $imported[:rmav_walk] = 20140204.1 
- module Rmav 
-   #---------行走选项设置---------# 
- Opt_walk={ 
-       dir8_on:     false,     #false则4向行走,本插件系列其他功能仍可以用 
-       step_ext_on: false,     #按着方向键碰到障碍物踏步,若为false则静止(rmVA默认是静止的) 
-   
-       draw_character: true,  #可在窗口中绘制自定义行走图,若窗口太小会按比例缩小, 
-                              ##如默认读档界面 
-   
-       encryption: false,     #打包游戏时,是否选择了加密 
-                              ##若准备加密,那么在打包前,打开此开关并启动一次游戏 
-                              ##再打包即可 
-                              ##若没有启用替换图片功能或待机或跑步功能,可不用管 
-   
-       wait_run_enable: true  #是否使用了待机跑步子插件 
-       } 
-   
-   
-   INPUT_HV=[[0,0],[4,2],[0,2],[6,2],[4,0],[0,0],[6,0],[4,8],[0,8],[6,8]] 
-   Dirs=[1,2,3,4,6,7,8,9] 
-   
-   
-   #-------------------------------------------------------------------------- 
-   # ● 缓存文件夹中所有png文件名 
-   #-------------------------------------------------------------------------- 
-   def self.loadFolder(folderName,custom=true) 
-     @cache_folder||={} 
-     folderName.gsub!(/\\/,'/') 
-     folderName+='/' if folderName[-1]!='/' 
-     folderName.downcase! 
-     unless @cache_folder.include?(folderName) 
-       @cache_folder[folderName]=[] 
-       Dir.glob(folderName+"*.png"){|f| 
-         file_name=f.split('/')[-1].chomp!('.png') 
-         if custom 
-           if file_name.match(/\@\d{1,2}\#\d{1,2}/) 
-             @cache_folder[folderName]<<file_name 
-           end 
-         else 
-           @cache_folder[folderName]<<file_name 
-         end 
-       } 
-     end 
-     @cache_folder[folderName]    
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 分类存储待机图、跑步图 
-   #-------------------------------------------------------------------------- 
-   CharNames||={wait: {}, run: {}} 
-   def self.charFolder_map 
-     self.loadFolder("Graphics/Characters/").each{|f| 
-         f=~%r{(.+)_([wr])\@\d{1,2}\#\d{1,2}(\%\d{1,2})?} 
-         if $1&&$2 
-           case $2 
-             when "w";CharNames[:wait][$1]=f 
-             when "r";CharNames[:run][$1]=f 
-           end 
-         end 
-     } 
-   
-   end 
-   
- end 
-   
- class Sprite_Character   
-   #-------------------------------------------------------------------------- 
-   # ● 设置角色的位图(n方向,n帧) 
-   #-------------------------------------------------------------------------- 
-   alias_method :set_character_bitmap_org_rmav, :set_character_bitmap 
-   def set_character_bitmap 
-     self.bitmap = Cache.character(@character_name) 
-     @fmt_sign = @character_name[/\@(\d{1,2})\#(\d{1,2})(?:\%(\d{1,2}))?/]       
-     if @fmt_sign 
-       @fmt_sign=[$1.to_i,$2.to_i,$3.to_i] 
-   
-       @cw = bitmap.width / @fmt_sign[1]    
-       @ch = bitmap.height / @fmt_sign[0]   
-       self.ox = @cw / 2 
-       self.oy = @ch-@fmt_sign[2]   
-     else 
-       set_character_bitmap_org_rmav 
-     end 
-   
-     if @character 
-       @character.cw=@cw 
-       @character.ch=@ch 
-       @character.fmt_sign=@fmt_sign 
-       @character.original_pattern=0 if @fmt_sign 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 更新源矩形 
-   #-------------------------------------------------------------------------- 
-   def update_src_rect 
-     if @tile_id == 0 
-       index = @character.character_index 
-       pattern = @character.pattern < (@fmt_sign?@fmt_sign[1]:3) \ 
-                 ? @character.pattern : 1 
-       sx = (index % 4 * 3 + pattern) * @cw 
-       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch 
-   
-       case @character.direction 
-         when 1; sy=@fmt_sign?(@fmt_sign[0]==4?0:4)*@ch:(index / 4 * 4 ) * @ch 
-         when 3; sy=@fmt_sign?(@fmt_sign[0]==4?0:5)*@ch:(index / 4 * 4 ) * @ch 
-         when 7; sy=@fmt_sign?(@fmt_sign[0]==4?3:6)*@ch:(index / 4 * 4+3 ) * @ch 
-         when 9; sy=@fmt_sign?(@fmt_sign[0]==4?3:7)*@ch:(index / 4 * 4+3 ) * @ch 
-       end 
-       sy=0 if @fmt_sign&&@fmt_sign[0]==1   
-       self.src_rect.set(sx, sy, @cw, @ch) 
-     end 
-   end 
-   
- end 
-   
-   
-   
-   
- class Game_Player 
- if Rmav::Opt_walk[:dir8_on] 
-   #-------------------------------------------------------------------------- 
-   # ● 由方向键移动,8方向 
-   #-------------------------------------------------------------------------- 
-   def move_by_input 
-     return if !movable? || $game_map.interpreter.running? 
-     input=Input.dir8 
-     move_diagonal(*Rmav::INPUT_HV[input]) if input > 0 
-   end 
- end 
-   
-   #-------------------------------------------------------------------------- 
-   # ● 更新步行/踏步动画 
-   #-------------------------------------------------------------------------- 
-   #alias_method :update_animation_org_rmav,:update_animation 
-   def update_animation 
-     if stopping? && @stop_count<1 && Rmav::Opt_walk[:step_ext_on] 
-       @step_ext_anime=true 
-     else  
-       @step_ext_anime=false 
-     end 
-     super 
-   end 
- end 
-   
-   
-   
- class Game_CharacterBase 
-   attr_accessor :cw,:ch,:fmt_sign,:original_pattern,:step_ext_anime 
-   alias_method :characterBase_init_org_rmav, :initialize 
-   def initialize 
-     characterBase_init_org_rmav 
-     @cw=@ch=0 
-     @fmt_sign=nil 
-     @step_ext_anime=false 
-   end 
-   
-   #-------------------------------------------------------------------------- 
-   # ● 斜向移动 
-   #     horz : 横向(4 or 6) 
-   #     vert : 纵向(2 or 8) 
-   #-------------------------------------------------------------------------- 
-   alias_method :move_diagonal_org_charBase_rmav, :move_diagonal 
-   def move_diagonal(horz, vert, turn_ok = true) 
-   
-     @move_succeed = diagonal_passable?(x, y, horz, vert) 
-     if @move_succeed 
-       set_direction(Rmav::INPUT_HV.index([horz, vert])) 
-       @x = $game_map.round_x_with_direction(@x, horz) 
-       @y = $game_map.round_y_with_direction(@y, vert) 
-       @real_x = $game_map.x_with_direction(@x, reverse_dir(horz)) 
-       @real_y = $game_map.y_with_direction(@y, reverse_dir(vert)) 
-       increase_steps 
-     elsif turn_ok 
-       set_direction(Rmav::INPUT_HV.index([horz, vert])) 
-       check_event_trigger_touch_front 
-     end 
-   
-   end 
-   
-   
-   #-------------------------------------------------------------------------- 
-   # ● 更新动画图案 
-   #-------------------------------------------------------------------------- 
-   def update_anime_pattern 
-     if (!@step_anime && @stop_count > 0) ||  
-       (!@step_anime && stopping? && !@step_ext_anime) 
-       @pattern = @original_pattern 
-     else 
-       @pattern = (@pattern + 1) % (@fmt_sign?@fmt_sign[1]:4) 
-     end 
-   end 
-   
-   #-------------------------------------------------------------------------- 
-   # ● 更新动画计数 
-   #-------------------------------------------------------------------------- 
-   alias_method :update_anime_count_org_rmav,:update_anime_count 
-   def update_anime_count 
-     if Rmav::Opt_walk[:step_ext_on] && !(moving? && @walk_anime) && @step_ext_anime 
-       @anime_count += 1       
-     else 
-       update_anime_count_org_rmav 
-     end  
-   end 
-   
-   
- end 
-   
-   
-   
- class Game_Follower 
-   attr_accessor :gathering 
-   alias_method :follower_initialize_org_rmav, :initialize 
-   def initialize(member_index, preceding_character) 
-     follower_initialize_org_rmav(member_index, preceding_character) 
-     @gathering=false 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 追随带队角色 
-   #-------------------------------------------------------------------------- 
-  def chase_preceding_character 
-     unless moving? 
-       sx = distance_x_from(@preceding_character.x) 
-       sy = distance_y_from(@preceding_character.y) 
-   
-       dx_pix=[(@preceding_character.cw+@cw)/2, 79].min 
-   
-       if !@gathering && dx_pix > sx.abs*32+16 
-         if sy>0 
-           return  if (@ch>32+16&&sy<2)  
-         elsif sy<0 
-           return if (@preceding_character.ch>32+16&&sy.abs<2)  
-         else 
-           return 
-         end         
-       end 
-   
-       if sx != 0 && sy != 0 
-         move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2) 
-       elsif sx != 0 
-         move_straight(sx > 0 ? 4 : 6) 
-       elsif sy != 0 
-         move_straight(sy > 0 ? 8 : 2) 
-       end 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 更新画面 
-   #-------------------------------------------------------------------------- 
-   alias_method :update_org_rmav,:update 
-   def update 
-     @step_ext_anime = $game_player.step_ext_anime 
-     @stop_count=0  if @step_ext_anime 
-     update_org_rmav 
-   end 
- end 
-   
-   
- class Game_Followers 
-   #-------------------------------------------------------------------------- 
-   # ● 集合 
-   #-------------------------------------------------------------------------- 
-   alias_method :gather_org_rmav,:gather 
-   def gather 
-     gather_org_rmav 
-     visible_folloers.each {|follower| follower.gathering=true } 
-   end 
-   
-   #-------------------------------------------------------------------------- 
-   # ● 判定是否集合完毕 
-   #-------------------------------------------------------------------------- 
-   alias_method :gather_org_rmav?,:gather? 
-   def gather? 
-     ok = gather_org_rmav? 
-     if ok 
-       visible_folloers.each {|follower| follower.gathering=false } 
-     end 
-     ok 
-   end 
- end 
-   
- if Rmav::Opt_walk[:draw_character] 
- class Window_Base 
-   #-------------------------------------------------------------------------- 
-   # ● 绘制人物行走图 
-   #-------------------------------------------------------------------------- 
-   alias_method :draw_character_org_rmav,:draw_character 
-   def draw_character(character_name, character_index, x, y,align=true) 
-                                                           #align是否依据%DD调整 
-     return unless character_name     
-     bitmap = Cache.character(character_name) 
-     fmt_sign = character_name[/\@(\d{1,2})\#(\d{1,2})(\%(\d{1,2}))?/]       
-     if fmt_sign 
-       fmt_sign=[$1.to_i,$2.to_i,$4.to_i] 
-   
-       cw = bitmap.width / fmt_sign[1]    
-       ch = bitmap.height / fmt_sign[0]   
-       ch1=(align)?(ch-fmt_sign[2]):(ch) 
-   
-       ch2=(ch1>=contents_height)?(contents_height):(ch1) 
-       cw2=(cw>=contents_width)?(contents_width):(cw) 
-   
-       dh=ch2.fdiv ch1 
-       dw=cw2.fdiv cw 
-   
-       if dh<dw         
-        cw2=cw*ch2/ch1 
-       elsif dh>dw 
-        ch2=ch1*cw2/cw 
-       end 
-       y1=(align)?(fmt_sign[2]*[dh,dw].min):0 
-       src_rect = Rect.new(0, 0, cw, ch) 
-       dst_rect = Rect.new(x - cw2 / 2, y - ch2,cw2,ch2+y1) 
-       contents.stretch_blt(dst_rect, bitmap, src_rect) 
-     else 
-       draw_character_org_rmav(character_name, character_index, x, y) 
-     end 
-   
-   end 
-   
- end 
- end 
-   
- if Rmav::Opt_walk[:encryption] 
-     if Dir.glob("*.rgss3a").size<1 
-       files_tmp=Rmav.loadFolder("Graphics/Characters/") 
-       File.open("Graphics/Characters/characters.rmav","wb"){|f| 
-         Marshal.dump(files_tmp,f) 
-       } 
-     end 
-     def Rmav.loadFolder(folderName) 
-       @cache_folder||={} 
-       folderName.gsub!(/\\/,'/') 
-       folderName+='/' if folderName[-1]!='/' 
-       folderName.downcase! 
-       unless @cache_folder.include?(folderName)         
-         if folderName[/characters\//] 
-           @cache_folder[folderName]=load_data(\ 
-           "Graphics/Characters/characters.rmav") 
-         else 
-           @cache_folder[folderName]=[] 
-         end 
-       end 
-       @cache_folder[folderName]  
-   
-    end 
-  end 
-   
- class Game_Character 
- if Rmav::Opt_walk[:dir8_on] 
-   #-------------------------------------------------------------------------- 
-   # ● 随机移动 
-   #-------------------------------------------------------------------------- 
-   def move_random 
-     direction=Rmav::Dirs[rand(8)] 
-     move_diagonal(*Rmav::INPUT_HV[direction],false) 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 接近人物 
-   #-------------------------------------------------------------------------- 
-   def move_toward_character(character) 
-     sx = distance_x_from(character.x) 
-     sy = distance_y_from(character.y) 
-      o=5 
-      o-=1 if sx>0  
-      o+=1 if sx<0 
-      o-=3 if sy<0 
-      o+=3 if sy>0 
-   
-     move_diagonal(*Rmav::INPUT_HV[o]) if sx!=0 && sy!=0 
-     if !@move_succeed && o!=5 
-       if sx.abs > sy.abs 
-         move_straight(sx > 0 ? 4 : 6) 
-         move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0 
-       elsif sy != 0 
-         move_straight(sy > 0 ? 8 : 2) 
-         move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0 
-       end 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 远离人物 
-   #-------------------------------------------------------------------------- 
-   def move_away_from_character(character) 
-     sx = distance_x_from(character.x) 
-     sy = distance_y_from(character.y) 
-     if sx.abs > sy.abs 
-       move_straight(sx > 0 ? 6 : 4) 
-       move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0 
-     elsif sy != 0 
-       move_straight(sy > 0 ? 2 : 8) 
-       move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 前进一步 
-   #-------------------------------------------------------------------------- 
-   def move_forward 
-        move_diagonal(*Rmav::INPUT_HV[@direction]) 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 后退一步 
-   #-------------------------------------------------------------------------- 
-   def move_backward 
-     last_direction_fix = @direction_fix 
-     @direction_fix = true 
-     move_diagonal(*Rmav::INPUT_HV[reverse_dir(@direction)], false) 
-     @direction_fix = last_direction_fix 
-   end 
- end   
-   
- end 
-   
- if Rmav::Opt_walk[:wait_run_enable] 
- module Cache 
- class <<self 
-   alias_method :character_org_rmav,:character 
-   def character(filename) 
-     if $imported[:rmav_walk_wait]||$imported[:rmav_walk_run] 
-       unless Cache.include?("Graphics/Characters/"+filename) 
-         filename=~%r{(.+)\@\d{1,2}\#\d{1,2}} 
-         if $1 
-           base=$1.sub(/_[wr]\z/,'') 
-           w=Rmav::CharNames[:wait][base] if $imported[:rmav_walk_wait] 
-           r=Rmav::CharNames[:run][base] if $imported[:rmav_walk_run] 
-           character_org_rmav(filename) 
-           character_org_rmav(w) if w 
-           character_org_rmav(r) if r 
-   
-         end 
-       end 
-     end 
-     character_org_rmav(filename)   
-   end 
- end 
- end 
-   
- Rmav.charFolder_map 
- end