Advertisement
LiTTleDRAgo

[RGSS] Blizz-ABS Smart Auto Targeting

Oct 21st, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.92 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Blizz ABS Smart Auto Targeting                                                
  3. # Version: 1.05
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  6.  
  7. module LiTTleDRAgo
  8.  
  9.   TARGET_ANIMATION_ID = nil # 141
  10.   TARGET_CHANGE_KEY   = Input::Key['W']
  11.   AUTO_CHANGE_TARGET  = true
  12.  
  13.  
  14. end
  15.  
  16.  
  17. #==============================================================================
  18. # BlizzABS::Controls
  19. #==============================================================================
  20.  
  21. class BlizzABS::Controls
  22.  
  23.   alias update_attack_autotarget_later update_attack
  24.   def update_attack
  25.  
  26.     if $BlizzABS.autotarget == nil
  27.         targets = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?}
  28.         $BlizzABS.autotarget = targets[0] if targets.size > 0
  29.     elsif Input.repeat?(LiTTleDRAgo::TARGET_CHANGE_KEY)  
  30.       targets = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?}
  31.       index = targets.index($BlizzABS.autotarget)
  32.       $BlizzABS.autotarget = targets[(index + 1) % targets.size] if index != nil
  33.     end
  34.     if $BlizzABS.autotarget != nil && (!$BlizzABS.autotarget.in_screen? ||
  35.         !$BlizzABS.autotarget.valid?)
  36.       $BlizzABS.autotarget = nil
  37.     end
  38.     return update_attack_autotarget_later
  39.   end
  40.  
  41.   alias update_skill_autotarget_later update_skill
  42.   def update_skill
  43.     result = update_skill_autotarget_later
  44.     if result && $BlizzABS.autotarget != nil && $game_temp.select_data != nil
  45.       characters = []
  46.       $game_temp.select_data[3].each {|s| characters.push(s.character)}
  47.       if characters.include?($BlizzABS.autotarget)
  48.         $game_player.ai.target = $BlizzABS.autotarget
  49.         $game_player.use_skill($game_temp.select_data[0])
  50.       else
  51.         $BlizzABS.autotarget = nil
  52.         update_skill
  53.       end
  54.       $game_temp.select_data = nil
  55.     end
  56.     return result
  57.   end
  58.  
  59.   alias update_item_autotarget_later update_item
  60.   def update_item
  61.     result = update_item_autotarget_later
  62.     if result && $BlizzABS.autotarget != nil && $game_temp.select_data != nil
  63.       characters = []
  64.       $game_temp.select_data[3].each {|s| characters.push(s.character)}
  65.       if characters.include?($BlizzABS.autotarget)
  66.         $game_player.ai.target = $BlizzABS.autotarget
  67.         $game_player.use_item($game_temp.select_data[0])
  68.       else
  69.         $BlizzABS.autotarget = nil
  70.         update_item
  71.       end
  72.       $game_temp.select_data = nil
  73.     end
  74.     return result
  75.   end
  76.  
  77. end
  78.  
  79. #==============================================================================
  80. # BlizzABS::Processor
  81. #==============================================================================
  82.  
  83. class BlizzABS::Processor
  84.  
  85.   attr_accessor :autotarget
  86.  
  87. end
  88.  
  89. #==============================================================================
  90. # Spriteset_Map
  91. #==============================================================================
  92.  
  93. class Sprite_Targeter < RPG::Sprite
  94.  
  95.   attr_accessor :character
  96.  
  97.   def initialize(viewport, character = nil)
  98.     super(viewport)
  99.     self.bitmap = Bitmap.new(1, 1)
  100.     @character = character
  101.     update
  102.   end
  103.  
  104.   def update
  105.     @character = $BlizzABS.autotarget
  106.     if @character == nil
  107.       @loop_animation_id = 0
  108.       loop_animation(nil)
  109.       return
  110.     end
  111.     super
  112.     if @loop_animation_id == 0
  113.       @loop_animation_id = LiTTleDRAgo::TARGET_ANIMATION_ID
  114.       loop_animation($data_animations[@loop_animation_id])
  115.     end
  116.     self.x = @character.screen_x
  117.     self.y = @character.screen_y
  118.     self.z = @character.screen_z(0)
  119.   end
  120.  
  121. end
  122.  
  123. #==============================================================================
  124. # Spriteset_Map
  125. #==============================================================================
  126.  
  127. class Spriteset_Map
  128.  
  129.   alias init_autotarget_later initialize
  130.   def initialize
  131.     if LiTTleDRAgo::TARGET_ANIMATION_ID != nil
  132.      @autotarget = Sprite_Targeter.new(@viewport1)
  133.     end
  134.     init_autotarget_later
  135.   end
  136.  
  137.   alias update_autotarget_later update
  138.   def update
  139.     @autotarget.update if @autotarget != nil
  140.     update_autotarget_later
  141.   end
  142.  
  143.   alias dispose_autotarget_later dispose
  144.   def dispose
  145.     if @autotarget != nil
  146.       @autotarget.dispose
  147.       @autotarget = nil
  148.     end
  149.     dispose_autotarget_later
  150.   end
  151.  
  152. end
  153.  
  154. #==============================================================================
  155. # Scene_Map
  156. #==============================================================================
  157.  
  158. class Scene_Map
  159.  
  160.   alias initer_update update
  161.   def update
  162.     initer_update
  163.     changetarget if LiTTleDRAgo::AUTO_CHANGE_TARGET
  164.   end
  165.  
  166.     def changetarget
  167.     if $BlizzABS.autotarget != nil
  168.       @char, char = $BlizzABS.autotarget, $game_player
  169.       sx, sy = @char.x - $game_player.x, @char.y - $game_player.y
  170.       return if sx == 0 and sy == 0
  171.       dir = sx.abs > sy.abs ? sx > 0 ? 6 : 4 : sy > 0 ? 2 : 8
  172.       if  (dir != nil && $game_player.direction != dir)
  173.         targets, pix = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?},
  174.                        $BlizzABS.pixel
  175.         targets.sort! {|a, b|
  176.             Math.hypot(char.x / pix - a.x / pix, char.y / pix - a.y / pix) <=>
  177.             Math.hypot(char.x / pix - b.x / pix, char.y / pix - b.y / pix)}
  178.         if targets.size > 0
  179.           sx, sy = targets[0].x - $game_player.x, targets[0].y - $game_player.y
  180.           return if sx == 0 and sy == 0
  181.           dir = sx.abs > sy.abs ? sx > 0 ? 6 : 4 : sy > 0 ? 2 : 8  
  182.           if !(($game_player.direction == 6 && dir == 4) ||
  183.                ($game_player.direction == 4 && dir == 6) ||
  184.                ($game_player.direction == 2 && dir == 8) ||
  185.                ($game_player.direction == 8 && dir == 2))
  186.             $BlizzABS.autotarget = targets[0]
  187.           end
  188.         end
  189.       end
  190.     end
  191.   end
  192. end
  193.  
  194. $BlizzABS = BlizzABS::Processor.new
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement