#============================================================================== # ■ Game_Character #------------------------------------------------------------------------------ #  キャラクターを扱うクラスです。このクラスは Game_Player クラスと Game_Event # クラスのスーパークラスとして使用されます。 #============================================================================== class Game_Character #-------------------------------------------------------------------------- # ● 移動タイプ : カスタム #-------------------------------------------------------------------------- def move_type_custom # 停止中でなければ中断 if jumping? or moving? return end # ループカウントを下げ、インデックスを戻す if @loop_mark > @move_route_index and @loop_count != 0 @loop_count -= 1 @move_route_index = @current_mark end # 移動コマンドのリストの最後に到達するまでループ while @move_route_index < @move_route.list.size # 移動コマンドを取得 command = @move_route.list[@move_route_index] result = exec_command(command) @move_route_index += 1 if result > 0 return if result < 2 # ループカウントを下げ、インデックスを戻す if @loop_mark > @move_route_index and @loop_count != 0 @loop_count -= 1 @move_route_index = @current_mark end end end #-------------------------------------------------------------------------- # ● 移動コマンドの実行 #-------------------------------------------------------------------------- def exec_command(command) # コマンドコード 0 番 (リストの最後) の場合 if command.code == 0 # オプション [動作を繰り返す] が ON の場合 if @move_route.repeat # 移動ルートのインデックスを最初に戻す @move_route_index = 0 end # オプション [動作を繰り返す] が OFF の場合 unless @move_route.repeat # 移動ルート強制中の場合 if @move_route_forcing and not @move_route.repeat # 移動ルートの強制を解除 @move_route_forcing = false # オリジナルの移動ルートを復帰 @move_route = @original_move_route @move_route_index = @original_move_route_index @original_move_route = nil end # 停止カウントをクリア @stop_count = 0 end return 0 end # 移動系コマンド (下に移動〜ジャンプ) の場合 if command.code <= 14 # コマンドコードで分岐 case command.code when 1 # 下に移動 move_down when 2 # 左に移動 move_left when 3 # 右に移動 move_right when 4 # 上に移動 move_up when 5 # 左下に移動 move_lower_left when 6 # 右下に移動 move_lower_right when 7 # 左上に移動 move_upper_left when 8 # 右上に移動 move_upper_right when 9 # ランダムに移動 move_random when 10 # プレイヤーに近づく move_toward_player when 11 # プレイヤーから遠ざかる move_away_from_player when 12 # 一歩前進 move_forward when 13 # 一歩後退 move_backward when 14 # ジャンプ jump(command.parameters[0], command.parameters[1]) end # オプション [移動できない場合は無視] が OFF で、移動失敗の場合 if not @move_route.skippable and not moving? and not jumping? return 0 end return 1 end # ウェイトの場合 if command.code == 15 # ウェイトカウントを設定 @wait_count = command.parameters[0] * 2 - 1 return 1 end # 向き変更系のコマンドの場合 if command.code >= 16 and command.code <= 26 # コマンドコードで分岐 case command.code when 16 # 下を向く turn_down when 17 # 左を向く turn_left when 18 # 右を向く turn_right when 19 # 上を向く turn_up when 20 # 右に 90 度回転 turn_right_90 when 21 # 左に 90 度回転 turn_left_90 when 22 # 180 度回転 turn_180 when 23 # 右か左に 90 度回転 turn_right_or_left_90 when 24 # ランダムに方向転換 turn_random when 25 # プレイヤーの方を向く turn_toward_player when 26 # プレイヤーの逆を向く turn_away_from_player end return 1 end # その他のコマンドの場合 if command.code >= 27 # コマンドコードで分岐 case command.code when 27 # スイッチ ON $game_switches[command.parameters[0]] = true $game_map.need_refresh = true when 28 # スイッチ OFF $game_switches[command.parameters[0]] = false $game_map.need_refresh = true when 29 # 移動速度の変更 @move_speed = command.parameters[0] when 30 # 移動頻度の変更 @move_frequency = command.parameters[0] when 31 # 移動時アニメ ON @walk_anime = true when 32 # 移動時アニメ OFF @walk_anime = false when 33 # 停止時アニメ ON @step_anime = true when 34 # 停止時アニメ OFF @step_anime = false when 35 # 向き固定 ON @direction_fix = true when 36 # 向き固定 OFF @direction_fix = false when 37 # すり抜け ON @through = true when 38 # すり抜け OFF @through = false when 39 # 最前面に表示 ON @always_on_top = true when 40 # 最前面に表示 OFF @always_on_top = false when 41 # グラフィック変更 @tile_id = 0 @character_name = command.parameters[0] @character_hue = command.parameters[1] if @original_direction != command.parameters[2] @direction = command.parameters[2] @original_direction = @direction @prelock_direction = 0 end if @original_pattern != command.parameters[3] @pattern = command.parameters[3] @original_pattern = @pattern end when 42 # 不透明度の変更 @opacity = command.parameters[0] when 43 # 合成方法の変更 @blend_type = command.parameters[0] when 44 # SE の演奏 $game_system.se_play(command.parameters[0]) when 45 # スクリプト # ランダム行動 if command.parameters[0] =~ /[Rr]and[Aa]ct\((\d+)\)/ random = rand($1.to_i) exec_commend(@move_route_index + random) @move_route_index += ($1.to_i - 1) return 2 # 指定回ループ elsif command.parameters[0] =~ /[Ll]oop[Dd]o\((\d+)(, ?(\d+))?\)/ @current_mark = @move_route_index @loop_mark = @move_route_index + $1.to_i if $2 != nil @loop_count = $3.to_i else @loop_count = -1 end # 条件スキップ elsif command.parameters[0] =~ /[Ii]f[Ss]kip\((.+?), ?(\d+)\)/ unless eval($1) @move_route_index += ($2.to_i - 1) end # 変数使用ジャンプ elsif command.parameters[0] =~ /[Vv][Jj]ump\((\d+), ?(\d+)\)/ jump($game_variables[$1.to_i], $game_variables[$2.to_i]) return 1 # 絶対座標ジャンプ elsif command.parameters[0] =~ /[Aa]bs[Jj]ump\((\d+), ?(\d+)\)/ jump($1.to_i - @x, $2.to_i - @y) return 1 # 変数使用絶対座標ジャンプ elsif command.parameters[0] =~ /[Aa]bs[Vv][Jj]ump\((\d+), ?(\d+)\)/ jump($game_variables[$1.to_i] - @x, $game_variables[$2.to_i] - @y) return 1 # 変数ウェイト elsif command.parameters[0] =~ /[Vv][Ww]ait\((\d+)\)/ # ウェイトカウントをフレーム単位で設定 @wait_count = $1.to_i - 1 return 1 # イベントの方を向く elsif command.parameters[0] =~ /[Tt]urn[Tt]o[Ee]vent\((\d+)\)/ turn_toward_event($1.to_i) return 1 # イベントの逆を向く elsif command.parameters[0] =~ /[Tt]urn[Aa]way[Ee]vent\((\d+)\)/ turn_away_from_event($1.to_i) return 1 # イベントに近づく elsif command.parameters[0] =~ /[Mm]ove[Tt]o[Ee]vent\((\d+)\)/ move_toward_event($1.to_i) return 1 # イベントから遠ざかる elsif command.parameters[0] =~ /[Mm]ove[Aa]way[Ee]vent\((\d+)\)/ move_away_from_event($1.to_i) return 1 # その他 else result = eval(command.parameters[0]) # 続行パターンを指定したい場合、数字で指定 return result if [0, 1, 2].include?(result) end end return 2 end end #-------------------------------------------------------------------------- # ● イベントに近づく #-------------------------------------------------------------------------- def move_toward_event(event_id) # そのIDを持つイベントが無い場合、実行しない return unless $game_map.events.include?(event_id) # イベントの座標との差を求める sx = @x - $game_map.events[event_id].x sy = @y - $game_map.events[event_id].y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 差の絶対値を求める abs_sx = sx.abs abs_sy = sy.abs # 横の距離と縦の距離が等しい場合 if abs_sx == abs_sy # ランダムでどちらかを 1 増やす rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横の距離の方が長い場合 if abs_sx > abs_sy # 左右方向を優先し、イベントのいる方へ移動 sx > 0 ? move_left : move_right unless moving? and sy != 0 sy > 0 ? move_up : move_down end # 縦の距離のほうが長い場合 else # 上下方向を優先し、イベントのいる方へ移動 sy > 0 ? move_up : move_down unless moving? and sx != 0 sx > 0 ? move_left : move_right end end end #-------------------------------------------------------------------------- # ● 移動可能な方向へ移動 #-------------------------------------------------------------------------- def move_movable(durations) for duration in durations if passable?(@x, @y, duration) case duration when 2 move_down when 4 move_left when 6 move_right when 8 move_up end break end end end #-------------------------------------------------------------------------- # ● プレイヤーに近づく #-------------------------------------------------------------------------- def move_toward_player # プレイヤーの座標との差を求める sx = @x - $game_player.x sy = @y - $game_player.y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 差の絶対値を求める abs_sx = sx.abs abs_sy = sy.abs # 横の距離と縦の距離が等しい場合 if abs_sx == abs_sy # ランダムでどちらかを 1 増やす rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横の距離のほうが長い場合 if abs_sx > abs_sy # 左右方向を優先し、プレイヤーのいるほうへ移動 durations = (sx > 0 ? [4, 2, 8, 6] : [6, 8, 2, 4]) # 縦の距離のほうが長い場合 else # 上下方向を優先し、プレイヤーのいるほうへ移動 durations = (sy > 0 ? [8, 4, 6, 2] : [2, 6, 4, 8]) end # 可能な方向へ移動 move_movable(durations) end #-------------------------------------------------------------------------- # ● プレイヤーから遠ざかる #-------------------------------------------------------------------------- def move_away_from_player # プレイヤーの座標との差を求める sx = @x - $game_player.x sy = @y - $game_player.y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 差の絶対値を求める abs_sx = sx.abs abs_sy = sy.abs # 横の距離と縦の距離が等しい場合 if abs_sx == abs_sy # ランダムでどちらかを 1 増やす rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横の距離のほうが長い場合 if abs_sx > abs_sy # 左右方向を優先し、プレイヤーのいないほうへ移動 durations = (sx < 0 ? [4, 2, 8, 6] : [6, 8, 2, 4]) # 縦の距離のほうが長い場合 else # 上下方向を優先し、プレイヤーのいないほうへ移動 durations = (sy < 0 ? [8, 4, 6, 2] : [2, 6, 4, 8]) end # 可能な方向へ移動 move_movable(durations) end #-------------------------------------------------------------------------- # ● イベントに近づく #-------------------------------------------------------------------------- def move_toward_event(event_id) # そのIDを持つイベントが無い場合、実行しない return unless $game_map.events.include?(event_id) # イベントの座標との差を求める sx = @x - $game_map.events[event_id].x sy = @y - $game_map.events[event_id].y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 差の絶対値を求める abs_sx = sx.abs abs_sy = sy.abs # 横の距離と縦の距離が等しい場合 if abs_sx == abs_sy # ランダムでどちらかを 1 増やす rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横の距離のほうが長い場合 if abs_sx > abs_sy # 左右方向を優先し、 イベントのいる方へ移動 durations = (sx > 0 ? [4, 2, 8, 6] : [6, 8, 2, 4]) # 縦の距離のほうが長い場合 else # 上下方向を優先し、イベントのいる方へ移動 durations = (sy > 0 ? [8, 4, 6, 2] : [2, 6, 4, 8]) end # 可能な方向へ移動 move_movable(durations) end #-------------------------------------------------------------------------- # ● イベントから遠ざかる #-------------------------------------------------------------------------- def move_away_from_event(event_id) # そのIDを持つイベントが無い場合、実行しない return unless $game_map.events.include?(event_id) # イベントの座標との差を求める sx = @x - $game_map.events[event_id].x sy = @y - $game_map.events[event_id].y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 差の絶対値を求める abs_sx = sx.abs abs_sy = sy.abs # 横の距離と縦の距離が等しい場合 if abs_sx == abs_sy # ランダムでどちらかを 1 増やす rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横の距離のほうが長い場合 if abs_sx > abs_sy # 左右方向を優先し、イベントのいないほうへ移動 durations = (sx < 0 ? [4, 2, 8, 6] : [6, 8, 2, 4]) # 縦の距離のほうが長い場合 else # 上下方向を優先し、イベントのいないほうへ移動 durations = (sy < 0 ? [8, 4, 6, 2] : [2, 6, 4, 8]) end # 可能な方向へ移動 move_movable(durations) end #-------------------------------------------------------------------------- # ● イベントの方を向く #-------------------------------------------------------------------------- def turn_toward_event(event_id) # そのIDを持つイベントが無い場合、実行しない return unless $game_map.events.include?(event_id) # イベントの座標との差を求める sx = @x - $game_map.events[event_id].x sy = @y - $game_map.events[event_id].y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 横の距離の方が長い場合 if sx.abs > sy.abs # 左右方向でイベントのいる方を向く sx > 0 ? turn_left : turn_right # 縦の距離の方が長い場合 else # 上下方向でイベントのいる方を向く sy > 0 ? turn_up : turn_down end end #-------------------------------------------------------------------------- # ● イベントの逆を向く #-------------------------------------------------------------------------- def turn_away_from_event(event_id) # そのIDを持つイベントが無い場合、実行しない return unless $game_map.events.include?(event_id) # イベントの座標との差を求める sx = @x - $game_map.events[event_id].x sy = @y - $game_map.events[event_id].y # 座標が等しい場合 if sx == 0 and sy == 0 return end # 横の距離の方が長い場合 if sx.abs > sy.abs # 左右方向でイベントのいない方を向く sx > 0 ? turn_right : turn_left # 縦の距離の方が長い場合 else # 上下方向でイベントのいない方を向く sy > 0 ? turn_down : turn_up end end end