#--------------------------------------------------------------------------
# ● 缓存文件夹中所有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
}
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)
#--------------------------------------------------------------------------
# ● 更新动画计数
#--------------------------------------------------------------------------
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]
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_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