Advertisement
Falmc

Mog chain command modified

Sep 19th, 2012
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.42 KB | None | 0 0
  1. #===============================================================================
  2. # +++ MOG - Chain Commands (v1.4) +++
  3. #===============================================================================
  4. # By Moghunter                                                                
  5. # http://www.atelier-rgss.com                      
  6. #===============================================================================
  7. # Sistema de sequência de botões para ativar switchs.
  8. #
  9. # Serão necessárias as seguintes imagens. (Graphics/System)
  10. #
  11. # Chain_Cursor.png
  12. # Chain_Command.png
  13. # Chain_Layout.png
  14. # Chain_Timer_Layout.png
  15. # Chain_Timer_Meter.png
  16. #
  17. #===============================================================================
  18. #
  19. # Para ativar o script use o comando abaixo.  (*Call Script)
  20. #
  21. # NEW CALL $game_chain_cmd.chain_commands(ID)
  22. #
  23. # ID - Id da switch.
  24. #
  25. #===============================================================================
  26.  
  27. #==============================================================================
  28. # ● Histórico (Version History)
  29. #==============================================================================
  30. # v 1.4 - Correção do crash aleatório.
  31. # v 1.3 - Melhoria no sistema de dispose
  32. # v 1.2 - Melhoria na codificação e correção de alguns glitches.
  33. # v 1.1 - Animação de fade ao sair da cena de chain.
  34. #       - Opção de definir a prioridade da hud na tela.
  35. #==============================================================================
  36.  
  37. module MOG_CHAIN_COMMANDS
  38.  #==============================================================================
  39.  # CHAIN_COMMAND = { SWITCH_ID => [COMMAND] }
  40.  #
  41.  # SWITCH_ID = ID da switch
  42.  # COMMANDS = Defina aqui a sequência de botões.
  43.  #            (Para fazer a sequência use os comandos abaixo)  
  44.  #  
  45.  # "Down" ,"Up" ,"Left" ,"Right" ,"Shift" ,"D" ,"S" ,"A" ,"Z" ,"X" ,"Q" ,"W"
  46.  #
  47.  # Exemplo de utilização
  48.  #
  49.  # CHAIN_SWITCH_COMMAND = {
  50.  # 25=>["Down","D","S","Right"],
  51.  # 59=>["Down","Up","Left","Right","Shift","D","S","A","Z","X","Q","W"],
  52.  # 80=>["Shift","D"]
  53.  # }
  54.  #==============================================================================
  55.  CHAIN_SWITCH_COMMAND = {
  56.  5=>["X","Right","Left","Z","Z"],
  57.  6=>["Left","Right","Left","Right","Left","Right","Q","Z","Up","A","S",
  58.       "Down","D","Z","Right","Up","Up","Z","W","Left","Down","D","A","W"],
  59.  8=>["Up","Down","Left","Right","Z"]}
  60.  #Duração para colocar os comandos. (A duração é multiplicado pela quantidade
  61.  #de comandos) *60 = 1 sec
  62.  CHAIN_INPUT_DURATION = 30
  63.  #Som ao acertar.
  64.  CHAIN_RIGHT_SE = "Chime1"
  65.  #Som ao errar.
  66.  CHAIN_WRONG_SE = "Buzzer1"
  67.  #Switch que ativa o modo automático.
  68.  CHAIN_AUTOMATIC_MODE_SWITCH_ID = 20
  69.  #Definição da prioridade da hud na tela
  70.  CHAIN_HUD_Z = 300
  71. end
  72.  
  73. #===============================================================================
  74. # ■ Chain Commands
  75. #===============================================================================
  76. class Chain_Commands
  77.    include MOG_CHAIN_COMMANDS
  78.  #--------------------------------------------------------------------------
  79.  # ● Initialize
  80.  #--------------------------------------------------------------------------      
  81.   def initialize
  82.  
  83.   end
  84.    
  85.   def chain_commands(switch_id = 0)
  86.       return if switch_id <= 0
  87.       $game_temp.chain_switch_id = switch_id
  88.       @action_id = $game_temp.chain_switch_id
  89.       @chain_command = CHAIN_SWITCH_COMMAND[@action_id]
  90.       @chain_command = ["?"] if @chain_command == nil  
  91.       duration = [[CHAIN_INPUT_DURATION, 1].max, 9999].min
  92.       @timer_max = duration * @chain_command.size
  93.       @timer = @timer_max
  94.       @slide_time = [[60 / duration, 10].max, 60].min
  95.       @change_time = 0
  96.       if $game_switches[CHAIN_AUTOMATIC_MODE_SWITCH_ID]
  97.          @auto = true
  98.       else
  99.          @auto = false
  100.       end
  101.       @com = 0  
  102.     start_process
  103.   end
  104.  
  105.  
  106.  def start_process
  107.      dispose
  108.      create_chain_command
  109.      create_cusrsor
  110.      create_layout
  111.      create_meter
  112.      create_text
  113.      create_number
  114.      $game_temp.showing_chain_cmd = true
  115.  end  
  116.      
  117.  #--------------------------------------------------------------------------
  118.  # ● Create Cursor
  119.  #--------------------------------------------------------------------------            
  120.  def create_cusrsor
  121.      @fy_time = 0
  122.      @fy = 0
  123.      @com_index = 0
  124.      @cursor = Sprite.new
  125.      @cursor.bitmap = Cache.system("Chain_Cursor")
  126.      @cursor.z = 4 + CHAIN_HUD_Z
  127.      @cursor_space = ((@bitmap_cw + 5) * @chain_command.size) / 2
  128.      if @chain_command.size <= 20
  129.         @cursor.x = (544 / 2) - @cursor_space + @cursor_space * @com_index
  130.      else  
  131.         @cursor.x = (544 / 2)
  132.      end  
  133.      @cursor.y = (416 / 2) + 30    
  134.  end
  135.  
  136.  #--------------------------------------------------------------------------
  137.  # ● Create Chain Command
  138.  #--------------------------------------------------------------------------      
  139.  def create_chain_command
  140.      @image = Cache.system("Chain_Command")    
  141.      width_max = ((@image.width / 13) + 5) * @chain_command.size
  142.      @bitmap = Bitmap.new(width_max,@image.height * 2)
  143.      @bitmap_cw = @image.width / 13
  144.      @bitmap_ch = @image.height  
  145.      index = 0
  146.      for i in @chain_command
  147.          command_list_check(i)
  148.          bitmap_src_rect = Rect.new(@com * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
  149.          if index == 0
  150.             @bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
  151.          else
  152.             @bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch, @image, bitmap_src_rect)
  153.          end
  154.          index += 1
  155.      end
  156.      @sprite = Sprite.new
  157.      @sprite.bitmap = @bitmap
  158.      if @chain_command.size <= 15
  159.         @sprite.x = (544 / 2) - ((@bitmap_cw + 5) * @chain_command.size) / 2
  160.         @new_x = 0
  161.      else  
  162.         @sprite.x = (544 / 2)
  163.         @new_x = @sprite.x
  164.      end  
  165.      @sprite.y = (416 / 2) + 30  - @bitmap_ch  - 15
  166.      @sprite.z = 3 + CHAIN_HUD_Z
  167.      @sprite.zoom_x = 1.5
  168.      @sprite.zoom_y = 1.5
  169.  end
  170.  
  171.  #--------------------------------------------------------------------------
  172.  # * create_layout
  173.  #--------------------------------------------------------------------------  
  174.  def create_layout
  175.      @back = Plane.new
  176.      @back.bitmap = Cache.system("Chain_Layout")
  177.      @back.z = 0
  178.      @layout = Sprite.new
  179.      @layout.bitmap = Cache.system("Chain_Timer_Layout")
  180.      @layout.z = 1 + CHAIN_HUD_Z
  181.      @layout.x = 160
  182.      @layout.y = 150
  183.   end
  184.  
  185.  #--------------------------------------------------------------------------
  186.  # * create_meter
  187.  #--------------------------------------------------------------------------  
  188.  def create_meter
  189.      @meter_flow = 0
  190.      @meter_image = Cache.system("Chain_Timer_Meter")
  191.      @meter_bitmap = Bitmap.new(@meter_image.width,@meter_image.height)
  192.      @meter_range = @meter_image.width / 3
  193.      @meter_width = @meter_range * @timer / @timer_max
  194.      @meter_height = @meter_image.height
  195.      @meter_src_rect = Rect.new(@meter_range, 0, @meter_width, @meter_height)
  196.      @meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)
  197.      @meter_sprite = Sprite.new
  198.      @meter_sprite.bitmap = @meter_bitmap
  199.      @meter_sprite.z = 2 + CHAIN_HUD_Z
  200.      @meter_sprite.x = 220
  201.      @meter_sprite.y = 159
  202.      update_flow
  203.  end  
  204.  
  205.  #--------------------------------------------------------------------------
  206.  # ● Create Text
  207.  #--------------------------------------------------------------------------        
  208.  def create_text
  209.      @text = Sprite.new
  210.      @text.bitmap = Bitmap.new(200,32)
  211.      @text.z = 2 + CHAIN_HUD_Z
  212.      @text.bitmap.font.name = "Georgia"
  213.      @text.bitmap.font.size = 25
  214.      @text.bitmap.font.bold = true
  215.      @text.bitmap.font.italic = true
  216.      @text.bitmap.font.color.set(255, 255, 255,220)
  217.      @text.x = 230
  218.      @text.y = 100
  219.  end
  220.  
  221.  #--------------------------------------------------------------------------
  222.  # ● Create Number
  223.  #--------------------------------------------------------------------------        
  224.  def create_number
  225.      @combo = 0
  226.      @number = Sprite.new
  227.      @number.bitmap = Bitmap.new(200,64)
  228.      @number.z = 2 + CHAIN_HUD_Z
  229.      @number.bitmap.font.name = "Arial"
  230.      @number.bitmap.font.size = 24
  231.      @number.bitmap.font.bold = true
  232.      @number.bitmap.font.color.set(0, 255, 255,200)
  233.      @number.bitmap.draw_text(0, 0, 200, 32, "Ready",1)        
  234.      @number.x = 30
  235.      @number.y = 100
  236.  end
  237.  
  238.  #--------------------------------------------------------------------------
  239.  # ● Pre Dispose
  240.  #--------------------------------------------------------------------------      
  241.  def exit
  242.      loop do
  243.          Graphics.update
  244.          @sprite.x += 5
  245.          @layout.x -= 5
  246.          @meter_sprite.x -= 5
  247.          @text.x -= 2
  248.          @text.opacity -= 5
  249.          @sprite.opacity -= 5
  250.          @layout.opacity -= 5
  251.          @meter_sprite.opacity -= 5
  252.          @number.opacity -= 5
  253.          @back.opacity -= 5
  254.          @cursor.visible = false    
  255.          break if @sprite.opacity == 0
  256.        end
  257.        $game_temp.showing_chain_cmd = false
  258.      dispose
  259.  end
  260.    
  261.  #--------------------------------------------------------------------------
  262.  # ● Dispose
  263.  #--------------------------------------------------------------------------      
  264.  def dispose
  265.      return if @layout == nil
  266.      @bitmap.dispose
  267.      @sprite.bitmap.dispose
  268.      @sprite.dispose
  269.      @cursor.bitmap.dispose
  270.      @cursor.dispose  
  271.      @meter_image.dispose
  272.      @meter_bitmap.dispose
  273.      @meter_sprite.bitmap.dispose
  274.      @meter_sprite.dispose
  275.      @layout.bitmap.dispose  
  276.      @layout.dispose
  277.      @layout = nil
  278.      @back.bitmap.dispose
  279.      @back.dispose
  280.      @text.bitmap.dispose
  281.      @text.dispose
  282.      @number.bitmap.dispose
  283.      @number.dispose
  284.      @image.dispose
  285.      @bitmap = @sprite = @cursor = @meter_image = @meter_bitmap = nil
  286.      @meter_sprite = @layout = @back = @text = @number = @image  = nil
  287.  end
  288.  
  289.  #--------------------------------------------------------------------------
  290.  # ● Update
  291.  #--------------------------------------------------------------------------      
  292.  def update
  293.      update_command
  294.      update_cursor_slide
  295.      update_flow
  296.      update_change_time
  297.  end
  298.  
  299.  #--------------------------------------------------------------------------
  300.  # ● Change_Time
  301.  #--------------------------------------------------------------------------        
  302.  def update_change_time
  303.      return unless @auto
  304.      @change_time += 1
  305.      check_command(-1) if @change_time >= CHAIN_INPUT_DURATION - 1
  306.  end
  307.  
  308.  #--------------------------------------------------------------------------
  309.  # ● Update Flow
  310.  #--------------------------------------------------------------------------      
  311.  def update_flow
  312.      return if @meter_sprite.nil?
  313.      @timer -= 1
  314.      @meter_sprite.bitmap.clear
  315.      @meter_width = @meter_range * @timer / @timer_max
  316.      @meter_src_rect = Rect.new(@meter_flow, 0, @meter_width, @meter_height)
  317.      @meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)  
  318.      @meter_flow += 20
  319.      @meter_flow = 0 if @meter_flow >= @meter_image.width - @meter_range      
  320.      wrong_command if @timer == 0 and @auto == false
  321.   end  
  322.    
  323.  #--------------------------------------------------------------------------
  324.  # ● Update Command
  325.  #--------------------------------------------------------------------------      
  326.  def update_command
  327.      return if @auto
  328.      if Input.trigger?(Input::X)
  329.         check_command(0)
  330.      elsif Input.trigger?(Input::Z)  
  331.         check_command(1)
  332.      elsif Input.trigger?(Input::Y)  
  333.         check_command(2)
  334.      elsif Input.trigger?(Input::A)    
  335.         check_command(3)
  336.      elsif Input.trigger?(Input::C)          
  337.         check_command(4)
  338.      elsif Input.trigger?(Input::B)        
  339.         check_command(5)
  340.      elsif Input.trigger?(Input::L)        
  341.         check_command(6)
  342.      elsif Input.trigger?(Input::R)        
  343.         check_command(7)        
  344.      elsif Input.trigger?(Input::RIGHT)      
  345.         check_command(8)
  346.      elsif Input.trigger?(Input::LEFT)
  347.         check_command(9)
  348.      elsif Input.trigger?(Input::DOWN)
  349.         check_command(10)
  350.      elsif Input.trigger?(Input::UP)  
  351.         check_command(11)
  352.      end  
  353.  end  
  354.    
  355.  #--------------------------------------------------------------------------
  356.  # ● command_list_check
  357.  #--------------------------------------------------------------------------      
  358.  def command_list_check(command)
  359.      case command
  360.          when "A"
  361.             @com = 0  
  362.          when "D"
  363.             @com = 1  
  364.          when "S"
  365.             @com = 2
  366.          when "Shift"
  367.             @com = 3
  368.          when "Z"
  369.             @com = 4
  370.          when "X"
  371.             @com = 5
  372.          when "Q"
  373.             @com = 6
  374.          when "W"
  375.             @com = 7            
  376.          when "Right"
  377.             @com = 8
  378.          when "Left"
  379.             @com = 9
  380.          when "Down"
  381.             @com = 10
  382.          when "Up"  
  383.             @com = 11
  384.          else  
  385.             @com = 12          
  386.      end
  387.  end  
  388.  
  389.  #--------------------------------------------------------------------------
  390.  # ● check_command
  391.  #--------------------------------------------------------------------------            
  392.  def check_command(com)
  393.      index = 0
  394.      if com != -1
  395.         right_input = false
  396.         for i in @chain_command
  397.            if index == @com_index
  398.               command_list_check(i)
  399.               right_input = true if @com == com
  400.            end  
  401.           index += 1  
  402.        end  
  403.      else  
  404.        command_list_check(@com_index)
  405.        @change_time = 0
  406.        right_input = true
  407.      end  
  408.      if right_input
  409.         refresh_number
  410.         next_command
  411.      else  
  412.         wrong_command
  413.      end  
  414.  end  
  415.    
  416.  #--------------------------------------------------------------------------
  417.  # ● Next Command
  418.  #--------------------------------------------------------------------------            
  419.  def next_command  
  420.      @com_index += 1  
  421.      Audio.se_play("Audio/SE/" + CHAIN_RIGHT_SE, 100, 100)
  422.      if @com_index == @chain_command.size
  423.         $game_switches[@action_id] = true
  424.         exit
  425.         $game_map.need_refresh = true
  426.      end  
  427.      refresh_command
  428.      refresh_text(0)
  429.  end    
  430.  
  431.  #--------------------------------------------------------------------------
  432.  # ● wrong_command
  433.  #--------------------------------------------------------------------------              
  434.  def wrong_command
  435.      Audio.se_play("Audio/SE/" + CHAIN_WRONG_SE, 100, 100)
  436.      refresh_text(1)
  437.      exit
  438.      $game_player.jump(0,0)
  439.  end
  440.    
  441.  #--------------------------------------------------------------------------
  442.  # ● Refresh Command
  443.  #--------------------------------------------------------------------------                
  444.  def refresh_command
  445.      return if @sprite.nil?
  446.      @sprite.bitmap.clear
  447.      index = 0
  448.      for i in @chain_command
  449.          command_list_check(i)
  450.          bitmap_src_rect = Rect.new(@com * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
  451.          if @com_index == index
  452.             @bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
  453.          else
  454.             @bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch, @image, bitmap_src_rect)
  455.          end
  456.          index += 1
  457.        end
  458.      if @chain_command.size > 15  
  459.         @new_x = (544 / 2) - ((@bitmap_cw + 5) * @com_index)
  460.      else  
  461.         @cursor.x = (544 / 2) - @cursor_space + ((@bitmap_cw + 5) * @com_index)
  462.      end
  463.  end  
  464.  
  465.  #--------------------------------------------------------------------------
  466.  # ● Refresh Text
  467.  #--------------------------------------------------------------------------              
  468.  def refresh_text(type)
  469.     return if @text.nil?
  470.      @text.bitmap.clear
  471.      if type == 0
  472.         if @com_index == @chain_command.size
  473.            @text.bitmap.font.color.set(55, 255, 55,220)
  474.            @text.bitmap.draw_text(0, 0, 200, 32, "Perfect!",1)              
  475.         else  
  476.            @text.bitmap.font.color.set(55, 155, 255,220)
  477.            @text.bitmap.draw_text(0, 0, 200, 32, "Success!",1)              
  478.         end
  479.      else
  480.         @text.bitmap.font.color.set(255, 155, 55,220)
  481.         if @timer == 0
  482.            @text.bitmap.draw_text(0, 0, 200, 32, "Time Limit!",1)  
  483.         else  
  484.            @text.bitmap.draw_text(0, 0, 200, 32, "Fail!",1)  
  485.         end
  486.      end  
  487.      @text.x = 230  
  488.      @text.opacity = 255
  489.  end
  490.  
  491.  #--------------------------------------------------------------------------
  492.  # ● Refresh Number
  493.  #--------------------------------------------------------------------------              
  494.  def refresh_number
  495.      return if @number.nil?
  496.      @combo += 1
  497.      @number.bitmap.clear
  498.      @number.bitmap.font.size = 34
  499.      @number.bitmap.draw_text(0, 0, 200, 32, @combo.to_s,1)          
  500.      @number.opacity = 255
  501.      @number.zoom_x = 2
  502.      @number.zoom_y = 2
  503.  end
  504.  
  505.  #--------------------------------------------------------------------------
  506.  # ● Update Cursor Slide
  507.  #--------------------------------------------------------------------------          
  508.  def update_cursor_slide  
  509.      return if @sprite.nil?
  510.      @sprite.zoom_x -= 0.1 if @sprite.zoom_x > 1
  511.      @sprite.zoom_y -= 0.1 if @sprite.zoom_y > 1
  512.      @text.x -= 2 if @text.x > 210
  513.      @text.opacity -= 5 if @text.opacity > 0
  514.      @sprite.x -= @slide_time if @sprite.x > @new_x and @chain_command.size > 15
  515.      if @number.zoom_x > 1
  516.         @number.zoom_x -= 0.1
  517.         @number.zoom_y -= 0.1
  518.      end
  519.      if @fy_time > 15
  520.         @fy += 1
  521.      elsif @fy_time > 0
  522.         @fy -= 1
  523.      else  
  524.         @fy = 0
  525.         @fy_time = 30
  526.      end  
  527.      @fy_time -= 1
  528.      @cursor.oy = @fy    
  529.  end  
  530. end
  531.  
  532. #==============================================================================
  533. # ■ Game Temp
  534. #==============================================================================
  535. class Game_Temp
  536.  
  537.  attr_accessor :chain_switch_id
  538.  attr_accessor :showing_chain_cmd
  539.  #--------------------------------------------------------------------------
  540.  # ● Initialize
  541.  #--------------------------------------------------------------------------        
  542.   alias mog_chain_commands_initialize initialize
  543.   def initialize
  544.       @chain_switch_id = 0
  545.       @showing_chain_cmd = false
  546.       mog_chain_commands_initialize
  547.   end  
  548.    
  549. end
  550.  
  551. $game_chain_cmd = Chain_Commands.new
  552.  
  553. class << Input
  554.   unless self.method_defined?(:falcao503_ch_update)
  555.     alias_method :falcao503_ch_update,   :update
  556.   end
  557.  
  558.   def update
  559.     $game_chain_cmd.update if !$game_temp.nil? and $game_temp.showing_chain_cmd
  560.     falcao503_ch_update
  561.   end
  562. end
  563.  
  564. class Window_Selectable < Window_Base
  565.   alias falcao503_process_cursor_move process_cursor_move
  566.   def process_cursor_move
  567.     return if $game_temp.showing_chain_cmd
  568.     falcao503_process_cursor_move
  569.   end
  570.  
  571.   alias falcao503_process_handling process_handling
  572.   def process_handling
  573.     return if $game_temp.showing_chain_cmd
  574.     falcao503_process_handling
  575.   end
  576. end
  577.  
  578. class Game_Player < Game_Character
  579.   alias falcao503_move_straight move_straight
  580.   def move_straight(d, turn_ok = true)
  581.     return if $game_temp.showing_chain_cmd
  582.     falcao503_move_straight(d, turn_ok = true)
  583.   end
  584. end
  585.  
  586. class Scene_Map < Scene_Base
  587.   alias falcao503_update_call_menu update_call_menu
  588.   def update_call_menu
  589.     return if $game_temp.showing_chain_cmd
  590.     falcao503_update_call_menu
  591.   end
  592. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement