#==============================================================================
# ■ Game_Map
#------------------------------------------------------------------------------
# 管理地图的类。拥有卷动地图以及判断通行度的功能。
# 本类的实例请参考 $game_map 。
# 添加内容:添加读取地图备注内容并更改一部分通行判定。alias:2个,新定义:2个
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● セットアップ
# map_id : マップ ID
# enable : 所属レイヤーの変更
#--------------------------------------------------------------------------
alias region_effect_setup setup
def setup(map_id)
@encountwalk_region = {}
@passagechange_region = {}
@canjump_region = {}
@region_switch = {}
@forcemove_region = {}
@move_diag_region = {}
region_effect_setup(map_id)
@map.note.each_line{|line|
case line
when /\<(?:遇敌步数更改|ENCOUNTWALK_REGION)[ ]**(\d+)(?:\,(\d+))*\>/
@encountwalk_region[$1.to_i] = $2 == nil ? 0 : $2.to_i
when /\<(?:更改通行区域|PASSAGECHANGE_REGION)[ ]*(\d+)(?:\,(\d+))*\>/
push_passage_region($1.to_i,$2)
when /\<(?:可跳跃区域|JUMP_REGION)[ ]*(\d+)(?:\,([2468]+))*\>/
push_jump_region($1.to_i,$2)
when /\<(?:区域开关|REGION_SWITCH)[ ]*(\d+)(?:\,(\d+))*\>/
@region_switch[$1.to_i] = $2.to_i
when /\<(?:强制移动区域|FORCEMOVE_REGION)[ ]*(\d+)(?:\,([2468]+))*\>/
@forcemove_region[$1.to_i] = $2.to_i
when /\<(?:斜向移动|MOVE_DIAG)[ ]*(\d+)(?:\,([28]+))\>/
@move_diag_region[$1.to_i] = $2.to_i
end
}
end
#--------------------------------------------------------------------------
# ● 添加通行区域
#--------------------------------------------------------------------------
def push_passage_region(region_id,direction)
directions = []
if direction
direction.scan(/./){|d|
case d
when /2/
directions.push(0x0001)
when /4/
directions.push(0x0002)
when /6/
directions.push(0x0004)
when /8/
directions.push(0x0008)
end
}
end
@passagechange_region[region_id] = directions
end
#--------------------------------------------------------------------------
# ● 添加跳跃区域
#--------------------------------------------------------------------------
def push_jump_region(region_id,direction)
directions = []
if direction
direction.scan(/./){|d|
case d
when /2/
directions.push(2)
when /4/
directions.push(4)
when /6/
directions.push(6)
when /8/
directions.push(8)
end
}
else
directions = [2,4,6,8]
end
@canjump_region[region_id] = directions
end
alias region_change_check_passage check_passage
#--------------------------------------------------------------------------
# ● 通行检查
# alias:添加区域通行判定
#--------------------------------------------------------------------------
def check_passage(x, y, bit)
change = @passagechange_region[region_id(x,y)]
return change.include?(bit) if change
return region_change_check_passage(x,y,bit)
end
attr_reader :encountwalk_region
attr_reader :canjump_region
attr_reader :region_switch
attr_reader :forcemove_region
attr_reader :move_diag_region
end
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# 处理玩家人物的类。拥有事件启动的判定、地图的卷动等功能。
# 本类的实例请参考 $game_player 。
# 添加内容:添加有关移动的处理内容。 alias:3个 新定义:3个
#==============================================================================
class Game_Player < Game_Character
alias _Kine_no_encount_region_encounter_progress_value encounter_progress_value
#--------------------------------------------------------------------------
# ● 获取遇敌进行值
# alias:在结果添加区域遇敌值
#--------------------------------------------------------------------------
def encounter_progress_value
value = _Kine_no_encount_region_encounter_progress_value
v2 = $game_map.encountwalk_region[region_id]
value = v2 if v2
value
end
alias jump_move_by_input move_by_input
#--------------------------------------------------------------------------
# ● 由方向键移动
# alias:添加强制移动区域与跳跃处理
#--------------------------------------------------------------------------
def move_by_input
@input_jump = false
return if force_move_by_region
jump_move_by_input
unless @move_succeed
jump_by_input(Input.dir4)
end
end
#--------------------------------------------------------------------------
# ● 由方向键跳跃
#--------------------------------------------------------------------------
def jump_by_input(d)
return if d == 0
x1 = $game_map.x_with_direction(@x,d)
y1 = $game_map.y_with_direction(@y,d)
x2 = $game_map.x_with_direction(x1,d)
y2 = $game_map.y_with_direction(y1,d)
if can_jump?(x1,x2,y1,y2,d)
jump(x2 - @x,y2 - @y)
@input_jump = true
@move_succeed = true
end
end
#--------------------------------------------------------------------------
# ● 可以跳跃?
#--------------------------------------------------------------------------
def can_jump?(x1,x2,y1,y2,d)
return false unless movable?
return false unless [2,4,6,8].any?{|di| map_passable?(x2,y2,di)}
return false if $game_map.canjump_region[$game_map.region_id(x1,y1)] == nil
return false unless $game_map.canjump_region[$game_map.region_id(x1,y1)].include?(d)
return true
end
#--------------------------------------------------------------------------
# ● 由区域强制移动
#--------------------------------------------------------------------------
def force_move_by_region
return false if !movable? || $game_map.interpreter.running?
if $game_map.forcemove_region.include?(region_id)
move_straight($game_map.forcemove_region[region_id])
return true
end
return false
end
alias region_switch_update update
#--------------------------------------------------------------------------
# ● 更新画面
# alias:添加区域开关控制内容
#--------------------------------------------------------------------------
def update
last_region_id = region_id
region_switch_update
if last_region_id != region_id
$game_map.region_switch.each{|k,v|
$game_switches[v] = region_id == k
}
end
end
end
#==============================================================================
# ■ Game_CharacterBase
#------------------------------------------------------------------------------
# 管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。
#==============================================================================
class Game_CharacterBase
#--------------------------------------------------------------------------
# ● 径向移动
# d : 方向(2,4,6,8)
# turn_ok : 是否可以改变方向
#--------------------------------------------------------------------------
alias move_diag_region_move_straight move_straight
def move_straight(d, turn_ok = true)
if $game_map.move_diag_region.keys.include?(region_id)
if [4,6].include?(d)
x2 = $game_map.round_x_with_direction(@x,d)
d2 = $game_map.move_diag_region[region_id]
[d2,10-d2].collect{|yd| $game_map.round_y_with_direction(@y,yd)}.each do |y2|
if $game_map.region_id(x2,y2) == region_id
vert = d
horz = y2 - @y > 0 ? 2 : 8
@through = true
return move_diagonal(vert,horz).tap{|x| @through = false}.tap{|x| set_direction(d)}
end
end
end
end
move_diag_region_move_straight(d,turn_ok)
end
end