#============================================================================== # ■ RGSS2 移動ルート:イベントへ接近/遠ざかる Ver1.01 by 星潟 #------------------------------------------------------------------------------ # 移動ルートとして、指定IDのイベントへ接近、もしくは # 指定IDのイベントから遠ざかるという物を設定可能になります。 #============================================================================== # イベントの自律移動:カスタムもしくはイベントコマンドの移動ルートの設定で # 移動コマンド:スクリプトで使用します。 #============================================================================== # move_toward_event(3) # # イベントID3のイベントに接近。 #============================================================================== # move_away_from_event(4) # # イベントID4のイベントから遠ざかる。 #============================================================================== # イベントの自律移動:カスタムで使用します。 # イベントコマンドの移動ルートの設定で移動コマンド:スクリプトでも # 一応使用は出来ますが、基本的にする必要はないと思われます。 #============================================================================== # move_type_toward_event(1,25) # # この場合、ゆらぎを持った移動ルート設定になります。内訳は以下の通り。 # 25歩分以上離れている場合、ランダム移動。その他の場合は確率で分岐。 # 2/3の確率でイベントID1のイベントに接近。 # 1/6の確率でランダム移動。 # 1/6の確率で正面方向へ移動。 #============================================================================== # move_type_away_from_event(2,30) # # この場合、ゆらぎを持った移動ルート設定になります。内訳は以下の通り。 # 30歩分以上離れている場合、ランダム移動。その他の場合は確率で分岐。 # 2/3の確率でイベントID2のイベントから遠ざかる。 # 1/6の確率でランダム移動。 # 1/6の確率で正面方向へ移動。 #============================================================================== # Ver1.01 ループしている場合の処理を少し修正。 #============================================================================== class Game_Character #-------------------------------------------------------------------------- # イベントへ接近(ゆらぎあり) #-------------------------------------------------------------------------- def move_type_toward_event(event_id,d_data = 40) event = $game_map.events[event_id] return unless event sx = @x - event.x sy = @y - event.y return move_random if sx.abs + sy.abs >= d_data case rand(6) when 0..3;move_toward_event(event_id) when 4; move_random when 5; move_forward end end #-------------------------------------------------------------------------- # イベントから遠ざかる(ゆらぎあり) #-------------------------------------------------------------------------- def move_type_away_from_event(event_id,d_data = 40) event = $game_map.events[event_id] return unless event sx = @x - event.x sy = @y - event.y return move_random if sx.abs + sy.abs >= d_data case rand(6) when 0..3;move_away_from_event(event_id) when 4; move_random when 5; move_forward end end #-------------------------------------------------------------------------- # イベントへ接近 #-------------------------------------------------------------------------- def move_toward_event(event_id) event = $game_map.events[event_id] return unless event sx = distance_x_from_event(event) sy = distance_y_from_event(event) return if sx == 0 && sy == 0 if sx.abs > sy.abs sx > 0 ? move_left : move_right sy > 0 ? move_up : move_down if @move_failed and sy != 0 else sy > 0 ? move_up : move_down sx > 0 ? move_left : move_right if @move_failed and sx != 0 end end #-------------------------------------------------------------------------- # イベントから遠ざかる #-------------------------------------------------------------------------- def move_away_from_event(event_id) event = $game_map.events[event_id] return unless event sx = distance_x_from_event(event) sy = distance_y_from_event(event) return if sx == 0 && sy == 0 if sx.abs > sy.abs sx > 0 ? move_right : move_left sy > 0 ? move_down : move_up if @move_failed and sy != 0 else sy > 0 ? move_down : move_up sx > 0 ? move_right : move_left if @move_failed and sx != 0 end end #-------------------------------------------------------------------------- # イベントとの距離(X座標) #-------------------------------------------------------------------------- def distance_x_from_event(event) sx = @x - event.x $game_map.loop_horizontal? && sx.abs > $game_map.width / 2 ? sx - $game_map.width * (sx < 0 ? -1 : 1) : sx end #-------------------------------------------------------------------------- # イベントとの距離(Y座標) #-------------------------------------------------------------------------- def distance_y_from_event(event) sy = @y - event.y $game_map.loop_vertical? && sy.abs > $game_map.height / 2 ? sy - $game_map.height * (sy < 0 ? -1 : 1) : sy end end