=begin ¡áì¹ÔÑ«ë?«ÈѦÒöªÑªï?ª¢ªÃª× RGSS2 DAIpage¡á v0.6 ¡ÜѦÒöªÈÞŪ¤Û°¡Ü ¡¡ì¹ÔÑ«ë?«ÈªÎàâïÒªË ¡¡¡¡?õÌÓ­Ëå×îì¹ÔÑ£¨î¡úªÚªªâÍÅÕ磩 ¡¡¡¡?ò¦ïÒ«¨«ê«¢?«é«ó«À«àì¹ÔÑ£¨«Þ«Ã«×ѦÒöªÎ«¨«ê«¢ªòÞÅéÄ£© ¡¡ªÊªÉªòõÚÊ¥ª·ªÞª¹¡£ ¡¡ªÞª¿¡¢ì¹ÔÑ«¿«¤«×ª¬¡¸«é«ó«À«à¡¹ªÇ«È«ê«¬?ª¬¡¸Ì½ïÒ«Ü«¿«ó¡¹¡¢«×«é«¤«ª«ê«Æ«£ª¬ ¡¡¡¸÷×ßÈ«­«ã«éªÈÔÒª¸¡¹ªÎ«¤«Ù«ó«Èª¬«×«ì«¤«ä?ªËä㪵ªìªÆª¤ªëªÈ¡¢ ¡¡ä㪵ªìª¿Û°ú¾ªËÔѪ­ªÞª¹¡£ïëñéªÊªÉ¡¢?ª¤ªÈª³ªíªÇ«×«ì«¤«ä?ªÎ÷×ú¼ªòÞ÷تª·ªÆª¤ªë ¡¡íÞùêªÊªÉªËÞŪ¨ªÞª¹¡£ ¡¡ì¹ÔÑ«ë?«ÈªÎàâïÒ¡¢ªÞª¿ªÏí»×Èì¹ÔѪΡ¸«««¹«¿«à¡¹?ªÎ«¹«¯«ê«×«ÈªÇò¦ïÒª·ªÞª¹¡£ ¡¼ò¦ïÒêÈöǪËú¾ª±ªÆõÌÓ­ì¹ÔÑ«ë?«ÈªÇìé?ì¹ÔÑ¡½ ¡¡¡Ø x, yªËÙÍøöñ¨øöªòò¦ïÒ¡£ target_p_move_auto(x, y) ¡¼ò¦ïÒ«¨«ê«¢?«é«ó«À«àì¹ÔÑ¡½ªªîñª³ª³ª«ªéõóªÆª¯ªëªÊªÃªÆãÁªË¡£ ¡¡¡Ø idªÇ«¨«ê«¢ªòò¦ïÒ¡£ move_type_area_random(id) ¡¼ò¦ïÒ«­«ã«é«¯«¿?ªËÐΪŪ¯¡½ ¡¡¡Ø idªËÙÍøö«­«ã«é«¯«¿?IDªòò¦ïÒ¡£0ªÇ«×«ì«¤«ä?¡£ target_c_move_auto(id) ¡¼÷×ú¼Ê¦ÒöªÊùÚªêîñòä¡¢÷×ú¼ÜôʦªÇ«é«ó«À«àªËÛ°ú¾?üµ¡½ search_front ¡Üî¢ïÒëùª·ªÆª¤ªëËÍá¶¡Ü Game_Character¡¢Game_Playerªò«¨«¤«ê«¢«¹¡£ ¡¡¡ØÔÒª¸ËÍᶪò?ÌÚª¹ªë«¹«¯«ê«×«ÈªÈ?éĪ·ª¿íÞùêªÏÌæùꪹªëʦÒöàõª¬ª¢ªêªÞª¹¡£ ¡Ü?ÍÅ¡Ü ª³ªÎ«¹«¯«ê«×«ÈªÎìéÝ»ªÎѦÒöªÏì¤ù»ªÎ«µ«¤«È?ªÎªâªÎªò?ÍŪËVXéĪËî¢Ï°õ骷ªÆªªªêªÞª¹¡£ £Ò£Ð£Ç«Ä«¯?«ë«·«¹«Æ«à?ϼãø http://suppy1632.hp.infoseek.co.jp/ =end #============================================================================ # «««¹«¿«Þ«¤«º«Ý«¤«ó«È #============================================================================ module DAI_Move # ò¦ïÒêÈöǪØõÌÓ­Ëå×îì¹ÔÑãÁªÎî¢Íªß©ÊàÌ°??¡£ # ᴪʪ¤ªÛªÉïñÓøªÏÍÔª¤ª¬ñ쪯ªÊªë¡£ P = 2 # «é«ó«À«àì¹ÔÑ«¤«Ù«ó«Èª¬«×«ì«¤«ä?ª«ªéêÀª¶ª«ªëѦÒöªòÞÅéÄ¡£ E = true end #============================================================================== # ¡á Game_Character #============================================================================== class Game_Character #-------------------------------------------------------------------------- # ¡Ü ÍëËÒ«¤«ó«¹«¿«ó«¹?? #-------------------------------------------------------------------------- attr_reader :move_type attr_reader :stop_count attr_reader :move_frequency #-------------------------------------------------------------------------- # ¡Ü ÙÍîÜò¢ªÞªÇªÎõÌÓ­?ÖتòíÂà÷ #-------------------------------------------------------------------------- def search_route(target_x, target_y, type = 0) @route_count = 0 @target_route = [] return false if target_x == @x and target_y == @y @openlist = [@x * 1000 + @y, target_x * 1000 + target_y] @closelist = {@x * 1000 + @y=>0, target_x * 1000 + target_y=>1} @lootlist = [[],[]] @pointer = 0 while @pointer < @openlist.length for i in 1..4 a = way(i) b = @openlist[@pointer] c = @lootlist[@pointer] if @closelist.include?(a) if @closelist[a] != @closelist[b] if @closelist[a] == 0 half_route = c half_route.push 5 - i perfect_route = @lootlist[@openlist.index(a)] else half_route = @lootlist[@openlist.index(a)] perfect_route = c perfect_route.push i end half_route.reverse! perfect_route += half_route @target_route = perfect_route return @target_route end else if type == 0 newloot(a, b, c, i) if dir_passable?(b / 1000, b % 1000, i * 2) else newloot(a, b, c, i) if dir_e_passable?(b / 1000, b % 1000, i * 2) end end end @pointer += 1 end return false end #-------------------------------------------------------------------------- # ¡Ü ñ¨øö?üµ #-------------------------------------------------------------------------- def way(i) case i when 1 ; a = @openlist[@pointer] + 1 when 2 ; a = @openlist[@pointer] - 1000 when 3 ; a = @openlist[@pointer] + 1000 when 4 ; a = @openlist[@pointer] - 1 end return a end #-------------------------------------------------------------------------- # ¡Ü ?ÖØõÚÊ¥ #-------------------------------------------------------------------------- def newloot(a, b, c, i) @openlist.push a @closelist[a] = @closelist[b] loot = c.dup if @closelist[a] == 0 loot.push i else loot.push 5 - i end @lootlist.push loot end #-------------------------------------------------------------------------- # ¡Ü ò¦ïÒñ¨øöª«ªéò¦ïÒÛ°ú¾ªØªÎ÷×ú¼Ê¦Òö÷÷ïÒ #-------------------------------------------------------------------------- def dir_passable?(x, y, d) case d when 2 ; a = passable?(x, y + 1) when 4 ; a = passable?(x - 1, y) when 6 ; a = passable?(x + 1, y) when 8 ; a = passable?(x, y - 1) end return a end #-------------------------------------------------------------------------- # ¡Ü «­«ã«é«¯«¿?ªÈªÎõúÔͪòÍŪ¨ªÊª¤ò¦ïÒÛ°ú¾ªØªÎ÷×ú¼Ê¦Òö÷÷ïÒ #-------------------------------------------------------------------------- def dir_e_passable?(x, y, d) case d when 2 ; a = e_passable?(x, y + 1) when 4 ; a = e_passable?(x - 1, y) when 6 ; a = e_passable?(x + 1, y) when 8 ; a = e_passable?(x, y - 1) end return a end #-------------------------------------------------------------------------- # ¡Ü «­«ã«é«¯«¿?ªÈªÎõúÔͪòÍŪ¨ªÊª¤÷×ú¼Ê¦Òö÷÷ïÒ #-------------------------------------------------------------------------- def e_passable?(x, y) x = $game_map.round_x(x) y = $game_map.round_y(y) return false unless $game_map.valid?(x, y) return true if @through or debug_through? return false unless map_passable?(x, y) return true end #-------------------------------------------------------------------------- # ¡Ü õÌÓ­ì¹ÔÑ«ë?«ÈªÎÛÕÖªªË?ª¤ì¹ÔÑ£¨«¤«Ù«ó«È«³«Þ«ó«É£º«¹«¯«ê«×«È?éÄ£© #-------------------------------------------------------------------------- def target_route_move(x, y) if search_route(x, y, 0) == false search_route(x, y, 1) else search_route(x, y) end move_route = RPG::MoveRoute.new for i in 0...@target_route.length move_route.list[i] = RPG::MoveCommand.new move_route.list[i].code = @target_route[i] end force_move_route(move_route) @target_route = [] return end #-------------------------------------------------------------------------- # ¡Ü õÌÓ­ì¹ÔÑ«ë?«ÈªÎÛÕÖªªË?ª¤ìé?ªÀª±ì¹ÔÑ£¨ì¹ÔÑ«ë?«ÈªÎò¦ïÒ?éÄ£© #-------------------------------------------------------------------------- def target_p_move_auto(x, y) if @route_count == DAI_Move::P or @target_route == nil if search_route(x, y, 0) == false search_route(x, y, 1) else search_route(x, y) end end case @target_route[@route_count] when 1 ; move_down when 2 ; move_left when 3 ; move_right when 4 ; move_up end @route_count += 1 return end #-------------------------------------------------------------------------- # ¡Ü ò¦ïÒ«­«ã«é«¯«¿?ªËÐΪŪ¯£¨ì¹ÔÑ«ë?«ÈªÎò¦ïÒ?éÄ£© #-------------------------------------------------------------------------- def target_c_move_auto(id) if id == 0 target = $game_player else target = $game_map.events[id] end return if target == nil target_p_move_auto(target.x, target.y) end #-------------------------------------------------------------------------- # ¡Ü ÷×ú¼Ê¦ÒöªÊùÚªêîñòä¡¢÷×ú¼ÜôʦªÇ«é«ó«À«àªËÛ°ú¾?üµ #-------------------------------------------------------------------------- def search_front unless moving? if dir_passable?(@x, @y, @direction) move_forward else turn_random end end end #-------------------------------------------------------------------------- # ¡Ü ì¹ÔÑ«¿«¤«× : «¨«ê«¢?«é«ó«À«à #-------------------------------------------------------------------------- def move_type_area_random(id) case rand(6) when 0..1; move_area_random(id) when 2..4; move_forward if dir_passable_in_area?(@direction, id) when 5; @stop_count = 0 end end #-------------------------------------------------------------------------- # ¡Ü «¨«ê«¢?ªò«é«ó«À«àªËì¹ÔÑ #-------------------------------------------------------------------------- def move_area_random(id) a = in_area_passable?(id) return if a.empty? b = rand(a.size) case a[b] when 2 ; move_down(false) when 4 ; move_left(false) when 6 ; move_right(false) when 8 ; move_up(false) end end #-------------------------------------------------------------------------- # ¡Ü «¨«ê«¢?ªÎ÷×ú¼Ê¦ÒöªÊÛ°ú¾ªòö¢Ôð #-------------------------------------------------------------------------- def in_area_passable?(id) a = [] a.push 2 if dir_passable_in_area?(2, id) a.push 4 if dir_passable_in_area?(4, id) a.push 6 if dir_passable_in_area?(6, id) a.push 8 if dir_passable_in_area?(8, id) return a end #-------------------------------------------------------------------------- # ¡Ü ò¦ïÒÛ°ú¾ª¬«¨«ê«¢?ªÇ÷×ú¼Ê¦Òöª«£¿ #-------------------------------------------------------------------------- def dir_passable_in_area?(d, id) case d when 2 return $game_map.in_area?(id, @x, @y + 1) && dir_passable?(@x, @y, 2) when 4 return $game_map.in_area?(id, @x - 1, @y) && dir_passable?(@x, @y, 4) when 6 return $game_map.in_area?(id, @x + 1, @y) && dir_passable?(@x, @y, 4) when 8 return $game_map.in_area?(id, @x, @y - 1) && dir_passable?(@x, @y, 8) end end #-------------------------------------------------------------------------- # ¡Ü ì¹ÔÑ«¿«¤«× : «««¹«¿«à #-------------------------------------------------------------------------- alias dai_custom_move_move_type_custom move_type_custom def move_type_custom return if @move_route.list[@move_route_index] == nil dai_custom_move_move_type_custom end end #============================================================================== # ¡á Game_Player #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ¡Ü ïÈ?«¤«Ù«ó«ÈªÎÑÃÔÑ÷÷ïÒ #-------------------------------------------------------------------------- alias dai_custom_move_check_event_trigger_touch check_event_trigger_touch def check_event_trigger_touch(x, y) for event in $game_map.events_xy(x, y) if event.trigger == 0 && event.priority_type == 1 && DAI_Move::E && event.move_type == 1 && event.stop_count > 30 * (4 - event.move_frequency) event.move_away_from_player end end dai_custom_move_check_event_trigger_touch(x, y) end end #============================================================================== # ¡á Game_Map #============================================================================== class Game_Map #-------------------------------------------------------------------------- # ¡Ü «¨«ê«¢?÷÷ïÒ #-------------------------------------------------------------------------- def in_area?(id, x, y) area = $data_areas[id] return false if area == nil return false if $game_map.map_id != area.map_id return false if x < area.rect.x return false if y < area.rect.y return false if x >= area.rect.x + area.rect.width return false if y >= area.rect.y + area.rect.height return true end end