Advertisement
LiTTleDRAgo

[RGSS] Throw System

Oct 20th, 2011
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.87 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # [Xp] Throw System
  3. # Version: 1.52
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. #
  7. # Special Thanks to Moghunter
  8. # Ripped from XAS :P
  9. #
  10. #------------------------------------------------------------------------------
  11. #
  12. # The character can pick up and throw objects
  13. #
  14. # Any event can be thrown if <ThrowX> is included in their name field.
  15. # Where X is the number of tiles it can be thrown.
  16. #
  17. # Extra
  18. #    <ThrowSelfSwitch[X]> where X is A,B,C,D (Self switches) activated after
  19. #                event is throwed
  20. #    <BlockThrow> to prevent throwed event to pass through
  21. #    <CarryTimeX> where X is the time (in seconds) player will drop picked event
  22. #
  23. # for Blizz ABS
  24. #    <AtkPowerX> where X is strength of the event to damage enemy
  25. #    <AnimeHitX> where X is animation ID when event hit the enemy
  26. #
  27. #
  28. # You’ll need two images of your character
  29. #  [ACTORNAME]_PICK and [ACTORNAME]_TRW
  30. #
  31. #
  32. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  33. ($imported ||= {})[:drago_throw_system] = 1.52
  34.  
  35. #==============================================================================
  36. # ■ Game_Character
  37. #==============================================================================
  38. class Game_Character  
  39.  
  40.   CANT_THROW_IF_BLOCKED = true
  41.   TERRAIN_DISABLE_THROW = 8
  42.  #--------------------------------------------------------------------------
  43.  # Throw action
  44.  #--------------------------------------------------------------------------
  45.   def throw_action(range)    
  46.     jump_range = range
  47.     dc = $game_player.direction
  48.     unless jumping?        
  49.       p = jump_range
  50.       range.times do
  51.         unless jumping?
  52.           case dc
  53.           when 2 then jump(0,jump_range)  if throw_event?(0,jump_range,p)
  54.           when 4 then jump(-jump_range,0) if throw_event?(-jump_range,0,p)
  55.           when 6 then jump(jump_range,0)  if throw_event?(jump_range,0,p)
  56.           when 8 then jump(0,-jump_range) if throw_event?(0,-jump_range,p)
  57.           end
  58.           jump(0,0)    if jump_range == 1
  59.           return false if jump_range == 1 && CANT_THROW_IF_BLOCKED &&
  60.                [@x,@y] == [$game_player.x,$game_player.y]              
  61.           jump_range -= 1  
  62.           p -= 1
  63.         end              
  64.       end
  65.     end    
  66.   end  
  67.  #--------------------------------------------------------------------------
  68.  # ● Reset Pickup
  69.  #--------------------------------------------------------------------------  
  70.  def reset_pickup
  71.      return if !@pickup_lock
  72.      @pickup_lock = false
  73.      @pickup_lock_time = 0  
  74.      $game_player.sprite_normal unless $BlizzABS
  75.      $game_map.events.each_value {|event|
  76.          if event.throw_active
  77.            event.moveto($game_player.x, $game_player.y)
  78.            event.throw_active = false
  79.            event.move_speed = event.pre_move_speed
  80.            event.jump(0,0)
  81.          end }  
  82.   end  
  83.  #--------------------------------------------------------------------------
  84.  # ● Passable Around?
  85.  #--------------------------------------------------------------------------  
  86.  def passable_around?(x,y)
  87.      direction = [2,4,6,8]
  88.      direction_passable = []
  89.      direction.each {|i| direction_passable.push(i) if passable?(x,y,i) }    
  90.      return true if direction_passable != []
  91.      return false
  92.  end  
  93.  #--------------------------------------------------------------------------
  94.  # ● Passable Here?
  95.  #--------------------------------------------------------------------------  
  96.  def passable_here?(x,y)    
  97.      return false unless $game_map.passable?(x, y, 0, self)
  98.      $game_map.events.each_value {|event|
  99.        if event.x == x and event.y == y
  100.           return false if event.character_name != ""
  101.           return false if event.through == false
  102.        end }    
  103.      return true
  104.  end  
  105.  #--------------------------------------------------------------------------
  106.  # ● Jump Here
  107.  #--------------------------------------------------------------------------  
  108.  def jump_here(x,y)    
  109.      return unless passable_here?(x,y)  
  110.      range_x = x - @x
  111.      range_y = y - @y
  112.      jump(range_x,range_y)
  113.  end
  114.  #--------------------------------------------------------------------------
  115.  # ● Jump position
  116.  #--------------------------------------------------------------------------  
  117.  def jump_position(x,y)  
  118.       if passable_here?(x,y)    
  119.          jump_here(x,y)
  120.        else
  121.         direction = [2,4,6,8]
  122.         direction_passable = []
  123.         d = @direction
  124.         direction.each {|i| direction_passable.push(i) if passable?(x,y,i) }
  125.         if direction_passable != []    
  126.           direction_passable.each {|i|
  127.             if @direction == 2 && direction_passable.include?(8)
  128.               @direction = 8  
  129.             elsif @direction == 8 && direction_passable.include?(2)
  130.               @direction = 2
  131.             elsif @direction == 4 && direction_passable.include?(6)
  132.               @direction = 6                    
  133.             elsif @direction == 6 && direction_passable.include?(4)
  134.               @direction = 4    
  135.             else  
  136.               @direction = i  
  137.             end
  138.           d = @direction
  139.           new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  140.           new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)      
  141.           range_x = new_x - @x
  142.           range_y = new_y - @y
  143.           jump(range_x,range_y) }
  144.         end
  145.      end  
  146.  end
  147.  #--------------------------------------------------------------------------
  148.  # Throw
  149.  #--------------------------------------------------------------------------
  150.   def jump_forward(range)    
  151.   jump_range = range
  152.   dc = @direction
  153.    unless jumping?        
  154.         p = jump_range
  155.         range.times do
  156.           unless jumping?
  157.            if dc == 6              
  158.               jump(jump_range,0) if throw_event?(jump_range,0,p)
  159.            elsif dc == 4
  160.               jump(-jump_range,0) if throw_event?(-jump_range,0,p)
  161.            elsif dc == 2
  162.               jump(0,jump_range) if throw_event?(0,jump_range,p)
  163.            elsif dc == 8
  164.               jump(0,-jump_range) if throw_event?(0,-jump_range,p)
  165.            end
  166.               jump(0,0) if jump_range == 1
  167.               jump_range -= 1  
  168.               p -= 1
  169.            end              
  170.          end
  171.      end            
  172.  end  
  173.  #--------------------------------------------------------------------------
  174.  # ● front_pos?
  175.  #--------------------------------------------------------------------------    
  176.  def front_pos?(x,y)
  177.    d = @direction
  178.    new_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  179.    new_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  180.    return (new_x == x && new_y == y)
  181.  end  
  182.  #--------------------------------------------------------------------------
  183.  # Throw Event?
  184.  #--------------------------------------------------------------------------
  185.  def throw_event?(x_plus, y_plus,p )  
  186.     dir = $game_player.direction
  187.     v = 1
  188.     org_x = @x + x_plus
  189.     org_y = @y + y_plus
  190.     p.times do    
  191.       new_x2 = org_x + (dir == 6 ? -v : dir == 4 ? + v : 0)
  192.       new_y2 = org_y + (dir == 2 ? -v : dir == 8 ? + v : 0)
  193.       terrain_disable = $game_map.terrain_tag(new_x2,new_y2)  
  194.       return false if terrain_disable == TERRAIN_DISABLE_THROW
  195.       $game_map.events.each_value {|event|
  196.         if event.x == new_x2 && event.y == new_y2  
  197.            if event.event.name =~ /<BlockThrow>/i && !event.through
  198.              return false
  199.            end  
  200.            if $BlizzABS && !event.through && event.is_a?(Map_Enemy)
  201.              event.animation_id     = @animethrow if @animethrow
  202.              if @atkpow
  203.                actor = $game_party.actors[0]
  204.                hp_damage = event.battler.hp
  205.                atk = event.battler.attack_effect(actor)
  206.                hp_damage -= event.battler.hp
  207.                if @atkpow
  208.                  hp_damage        += @atkpow.to_i
  209.                  event.battler.hp -= @atkpow.to_i
  210.                end    
  211.                event.battler.hpdamage = hp_damage.to_i
  212.                $BlizzABS.util.request_damage_sprite(event) if hp_damage > 0
  213.              end
  214.              return false
  215.            end  
  216.         end  }    
  217.       v += 1
  218.     end
  219.     return true
  220.  end  
  221.  #--------------------------------------------------------------------------
  222.  # ● Passable Around Move?
  223.  #--------------------------------------------------------------------------  
  224.  def passable_arround_move?(x,y)    
  225.      direction = [2,4,6,8]
  226.      direction_passable = []
  227.      direction.each {|i|  direction_passable.push(i) if passable?(x,y,i) }
  228.      if direction_passable != []
  229.         if direction_passable.include?(@direction)
  230.            move_forward
  231.         else  
  232.            direction_passable.each {|i|
  233.             unless moving?
  234.               if @direction == 2 and direction_passable.include?(8)
  235.                 @direction = 8  
  236.               elsif @direction == 8 and direction_passable.include?(2)
  237.                 @direction = 2
  238.               elsif @direction == 4 and direction_passable.include?(6)
  239.                 @direction = 6                    
  240.               elsif @direction == 6 and direction_passable.include?(4)
  241.                 @direction = 4    
  242.               else  
  243.                 @direction = i  
  244.               end
  245.               move_forward  
  246.             end   }
  247.         end  
  248.      end        
  249.    end
  250.    
  251.   attr_accessor :pre_move_speed,:pre_walk_anime,:pickup_lock,:pickup_lock_time
  252.   attr_accessor :real_x,:real_y,:throw_active,:walk_anime,:character_name
  253.   attr_accessor :throw_active,:throw,:x,:y,:atkpow,:animethrow
  254.   attr_accessor :move_speed,:pre_move_speed,:through,:thssw,:throwed
  255.   attr_accessor :step_anime,:pre_step_anime,:carrytime  
  256.   attr_reader   :erased
  257. end  
  258.  
  259. #==============================================================================
  260. # ** Game_Player / BlizzABS::Controller
  261. #------------------------------------------------------------------------------
  262. #  This class handles the party leader. Its functions include event starting
  263. #  determinants and map scrolling. Some input is processed instantly,
  264. #  while some is converted into commands to be given to the player character
  265. #==============================================================================
  266. Klass = $BlizzABS ? BlizzABS::Controller : Game_Player
  267. #eval_text = "
  268. class Klass
  269.   if $BlizzABS
  270.     alias update_for_throwing update_moving
  271.     alias move_for_throwing move
  272.   else
  273.     alias update_for_throwing update
  274.   end
  275.   alias pickup_check_event_trigger_there check_event_trigger_there
  276.   #--------------------------------------------------------------------------
  277.   # ● Check Event Pickup
  278.   #--------------------------------------------------------------------------
  279.   def check_event_trigger_there(*args)
  280.     throw_event(0)
  281.     pickup_event    
  282.     return if ($game_player.pickup_lock)
  283.     return if ($game_player.pickup_lock_time || 0) > 0
  284.     pickup_check_event_trigger_there(*args)  
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # ● Update Moving (BlizzABS)
  288.   #--------------------------------------------------------------------------
  289.   def update_moving(*args)
  290.     update_for_throwing(*args)
  291.     update_carry_time
  292.     update_throw_position
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # ● Update (Non BlizzABS)
  296.   #--------------------------------------------------------------------------
  297.   def update
  298.     update_for_throwing
  299.     update_carry_time
  300.     update_throw_position
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● Move (BlizzABS)
  304.   #--------------------------------------------------------------------------
  305.   def move(d)
  306.     return if ($game_player.pickup_lock_time || 0) > 0  
  307.     move_for_throwing(d)
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● Update Carry Time
  311.   #--------------------------------------------------------------------------
  312.   def update_carry_time
  313.      if ($game_player.pickup_lock_time || 0) > 0
  314.         $game_player.pickup_lock_time -= 1
  315.         sprite_normal if $game_player.pickup_lock_time == 0 ##
  316.      end
  317.      if (@carry_time || 0) > 0
  318.         @carry_time -= 1
  319.         $game_player.reset_pickup if @carry_time == 0
  320.      end  
  321.    end  
  322.   #--------------------------------------------------------------------------
  323.   # ● Update Throw Position
  324.   #--------------------------------------------------------------------------
  325.   def update_throw_position
  326.     all_throw_event.each {|event|
  327.       if !event.jumping?
  328.         event.real_x = $game_player.real_x
  329.         event.real_y = $game_player.real_y - 128
  330.         event.x = $game_player.x
  331.         event.y = $game_player.y
  332.         sprite_carry
  333.       end  }    
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # ● Throw Event
  337.   #--------------------------------------------------------------------------
  338.   def throw_event(type)
  339.     return if !$game_player.pickup_lock
  340.     return if ($game_player.pickup_lock_time || 0) > 0
  341.     return if $game_system.map_interpreter.running?
  342.     all_throw_event.each {|event|
  343.       if !event.jumping?
  344.         next if !event.throw_action(type == 1 ? 1 : event.throw)
  345.         sprite_throw    
  346.         $game_player.pickup_lock_time = 15      
  347.         event.throw_active = false
  348.         $game_player.pickup_lock = false          
  349.         event.move_speed = event.pre_move_speed
  350.         event.walk_anime = event.pre_walk_anime
  351.         event.throwed = true
  352.         $game_player.step_anime = $game_player.pre_step_anime
  353.       end }    
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # ● Pickup Event
  357.   #--------------------------------------------------------------------------
  358.   def pickup_event    
  359.     return if $game_player.pickup_lock
  360.     return if ($game_player.pickup_lock_time || 0) > 0  
  361.     return if $game_system.map_interpreter.running?
  362.     $game_map.events.each_value {|event|
  363.       if event.is_a?(Game_Event)
  364.         if $game_player.front_pos?(event.x,event.y)
  365.           next if (event.throw || 0) == 0
  366.           next if event.erased || event.through
  367.           next if !sprite_throw
  368.           $game_player.pickup_lock_time = 15
  369.           event.throw_active = true
  370.           $game_player.pickup_lock = true
  371.           event.jump(0,0)
  372.           event.x = $game_player.x
  373.           event.y = $game_player.y
  374.           event.pre_walk_anime = event.walk_anime
  375.           event.pre_move_speed = event.move_speed
  376.           event.move_speed = 7
  377.           event.walk_anime = false
  378.           @carry_time = (event.carrytime || 0) * 40
  379.           $game_player.pre_step_anime = $game_player.step_anime
  380.         end
  381.       end}
  382.     end
  383.   #--------------------------------------------------------------------------
  384.   # ● all_throw_event
  385.   #--------------------------------------------------------------------------
  386.   def all_throw_event
  387.     $game_map.events.values.select {|e| e.throw_active }
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # ● Sprite Throw
  391.   #--------------------------------------------------------------------------
  392.   def sprite_throw
  393.     name = $game_party.actors[0].character_name
  394.     nama = $game_player.character_name
  395.     graphic = [name,"#{name}_pick","#{name}_idl"].map {|s| s.downcase}
  396.     if graphic.include?(nama.downcase)
  397.       if ch_exist?(name + '_TRW')
  398.         $game_player.character_name = name + '_TRW'
  399.       end
  400.       return true
  401.     end
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # ● Sprite Carry
  405.   #--------------------------------------------------------------------------
  406.   def sprite_carry
  407.     name = $game_party.actors[0].character_name
  408.     nama = $game_player.character_name
  409.     graphic = [name,"#{name}_trw","#{name}_idl"].map {|s| s.downcase}
  410.     if graphic.include?(nama.downcase)
  411.       if ch_exist?(name + '_PICK')
  412.         $game_player.character_name = name + '_PICK'  
  413.       end
  414.       return true
  415.     end
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # ● Normal
  419.   #--------------------------------------------------------------------------
  420.   def sprite_normal
  421.     name = $game_party.actors[0].character_name
  422.     nama = $game_player.character_name
  423.     graphic = ["#{name}_pick","#{name}_trw"].map {|s| s.downcase}
  424.     if graphic.include?(nama.downcase)
  425.       $game_player.character_name = name
  426.     end
  427.   end  
  428.   #--------------------------------------------------------------------------
  429.   # ● Character exist?
  430.   #--------------------------------------------------------------------------
  431.   def ch_exist?(x)
  432.     return RPG::Cache.character(x, 0) rescue false
  433.   end
  434. end#"
  435.  
  436. #============================================================================
  437. # BlizzABS::Controls
  438. #----------------------------------------------------------------------------
  439. #  This class handles player input for battle on the map.  Some input is
  440. #  processed instantly, while some is converted into commands to be given to
  441. #  the player character.
  442. #============================================================================
  443. if $BlizzABS
  444.   eval('class Game_System;  def pixel_rate() 0  end  end')
  445.   class BlizzABS::Controls  
  446.     #--------------------------------------------------------------------------
  447.     # update
  448.     #  Processes the player's input.
  449.     #--------------------------------------------------------------------------
  450.     alias update_for_throw update
  451.     def update
  452.       return if $game_player.pickup_lock
  453.       update_for_throw
  454.     end
  455.   end
  456. #==============================================================================
  457. # Map_Battler
  458. #------------------------------------------------------------------------------
  459. #  This class serves as superclass for characters that fight on the map and
  460. #  can use pixel movement.
  461. #==============================================================================
  462.   class Map_Battler < Game_Character
  463.     #---------------------------------------------------------------------------
  464.     # sprite_movement_animation_setup
  465.     #  Sets up movement sprite handling.
  466.     #---------------------------------------------------------------------------
  467.     alias sprite_movement_animation_setup_throw sprite_movement_animation_setup
  468.     def sprite_movement_animation_setup
  469.       return if $game_player.pickup_lock
  470.       sprite_movement_animation_setup_throw
  471.     end    
  472.   end  
  473. end
  474. #==============================================================================
  475. # ** Interpreter
  476. #------------------------------------------------------------------------------
  477. #  This interpreter runs event commands. This class is used within the
  478. #  Game_System class and the Game_Event class.
  479. #==============================================================================
  480.  
  481. class Interpreter
  482.   #--------------------------------------------------------------------------
  483.   # * Transfer Player
  484.   #--------------------------------------------------------------------------
  485.   alias throw_command_201 command_201
  486.   def command_201
  487.     $game_player.reset_pickup
  488.     throw_command_201
  489.   end
  490. end
  491.  
  492. #==============================================================================
  493. # ■ Game_Event
  494. #==============================================================================
  495. class Game_Event < Game_Character
  496.  
  497.   #--------------------------------------------------------------------------
  498.   # ● initialize
  499.   #--------------------------------------------------------------------------
  500.   attr_reader :event
  501.   alias drago_pickup_initialize initialize
  502.   def initialize(map_id, event)
  503.     @throw      = $1.to_i if event.name =~ /<Throw(\d+)>/i
  504.     @atkpow     = $1.to_i if event.name =~ /<AtkPower(\d+)>/i
  505.     @animethrow = $1.to_i if event.name =~ /<AnimeHit(\d+)>/i
  506.     @carrytime  = $1.to_i if event.name =~ /<CarryTime(\d+)>/i
  507.     @thssw      = $1.to_s if event.name =~ /<ThrowSelfSwitch\[(\w+)\]>/i
  508.     drago_pickup_initialize(map_id, event)    
  509.   end      
  510.  #--------------------------------------------------------------------------
  511.  # ● Throw Action
  512.  #--------------------------------------------------------------------------
  513.   alias upd_for_throw update
  514.   def update
  515.     upd_for_throw
  516.     if @throwed && @thssw && !jumping?
  517.       $game_self_switches[[$game_map.map_id,@id,@thssw]] = true
  518.       $game_map.need_refresh = true
  519.       @throwed = false
  520.     end
  521.   end
  522.  #--------------------------------------------------------------------------
  523.  # ● Screen Z
  524.  #--------------------------------------------------------------------------
  525.   alias screen_z_for_throw screen_z
  526.   def screen_z(h=0)
  527.     result = screen_z_for_throw(h)
  528.     result += (2*32) if @throw_active
  529.     return result
  530.   end
  531. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement