Advertisement
Raizen

Akea Battle Input Trigger

Mar 15th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.18 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Battle Input Trigger
  3. # Autor: Raizen
  4. # Comunidade: http://www.centrorpg.com/
  5. # Compatibilidade: RMVXAce
  6. #
  7. #=======================================================
  8. # O Script permite que uma tecla ou várias, sejam apertadas para
  9. # tanto conjurar skills adicionais, quanto defender de skills adicionais
  10. # do adversário
  11. ($imported ||= {})[:akea_bit] = true
  12. module Akea_ITT
  13. # ============== Não Modificar! ==================
  14. Input = Array.new
  15. #--------------------------------------------------------
  16. # ==================== Instruções =======================
  17. #--------------------------------------------------------
  18. # Para adicionar um Input a uma skill ou arma, basta adicionar
  19. # isso ao bloco de notas,
  20. # <getinput n|id|chance>
  21. # Aonde:
  22.  # n = n da input configurável abaixo no script
  23.  # id = id da skill que será acionada
  24.  # chance = chance em % da input ser acionada
  25.  
  26. # Um exemplo, se quero usar as configurações do Input[0],
  27. # com a skill de id 55 no database, e ter 50% de chance de ocorrer
  28. # bastaria
  29. # <getinput 0|55|50> dentro da notetag ou de uma skill ou de uma arma
  30.  
  31. #--------------------------------------------------------
  32. # ================= Configurações ========================
  33. #--------------------------------------------------------
  34.  
  35. # IMPORTANTE: As imagens devem estar na pasta Graphics/Akea do seu projeto!!
  36.  
  37. # Imagens das Huds
  38. #Imagem da Base
  39. Base_Hud = 'base_input_hud'
  40.  
  41. #Imagem da Barra
  42. Bar_Hud = 'bar_input'
  43. # Todas as posições seguem o seguinte padrão
  44. # [Pos em x, Pos em y, Pos em z]
  45. # Pos em Z é apenas necessário para imagens, configure apenas
  46. # se houver alguma imagem sobreposta na imagem de hud
  47.  
  48. # Imagem base da Hud(Base da posição é a posição dos Inputs)
  49. Base_Hud_Pos = [-20, 40, 100]
  50.  
  51. # Barra da Hud(Base da posição é a posição dos Inputs)
  52. Bar_Hud_Pos = [-14, 43, 99]
  53.  
  54. # Posição dos Inputs em relação ao inimigo
  55. Enemy_Pos = [0, -80]
  56.  
  57. # Posição dos Inputs em relação ao ator
  58. Actor_Pos = [0, -80]
  59.  
  60.  
  61. #--------------------------------------------------------
  62. # ================= Configuração de Inputs ========================
  63. #--------------------------------------------------------
  64. # Mapeamento de Teclas do RPG Maker VX Ace, para auxiliar na configuração
  65. # X = Tecla A  ;  Y = Tecla S  ;  Z = Tecla D
  66. # L = Tecla Q  ;  R = Tecla W  ;  SHIFT
  67. # RIGHT = Direcional(Direita) ; LEFT Direcional(Esquerda)
  68. # Up = Direcional(Cima) ; DOWN = Direcional(Baixo)
  69. # ----------- Input 0 -----------------------
  70. Input[0] = {
  71. :triggers => [:X, :B, :Y, :C, :LEFT, :RIGHT, :DOWN, :UP], # Teclas desse Input,
  72. :pics => ['A', 'X', 'S', 'Z', 'LEFT', 'RIGHT', 'DOWN', 'UP'], # Imagens do Input
  73. :time => 300, #Tempo limite para o input
  74. :num_times => 6, #Quantidade de teclas que o input terá
  75. :random? => true, #Randomizar as teclas? se false ele seguirá exatamente a mesma ordem acima
  76. :position? => 'enemy', #pode ser, 'actor', 'enemy' ou [x, y] a posição
  77. :success_se => 'Save', #SE que tocará caso acerte a sequencia
  78. :failure_se => 'Buzzer2', #SE que tocará caso erre a sequencia
  79. }
  80.  
  81. # ----------- Input 1 -----------------------
  82. Input[1] = {
  83. :triggers => [:X], # Teclas desse Input,
  84. :pics => ['A'], # Imagens do Input
  85. :time => 30, #Tempo limite para o input
  86. :num_times => 1, #Quantidade de teclas que o input terá
  87. :random? => true, #Randomizar as teclas? se false ele seguirá exatamente a mesma ordem acima
  88. :position? => [200, 200], #can be, 'actor', 'enemy' , or [x, y] a position
  89. :success_se => 'Save', #SE que tocará caso acerte a sequencia
  90. :failure_se => 'Buzzer2', #SE que tocará caso erre a sequencia
  91. }
  92.  
  93. # Mapa de teclas : coloque todas as teclas possíveis para o
  94. # erro de input, caso o jogador aperte a tecla errada irá
  95. # falhar a sequencia.
  96. Key_Map = [:X, :Y, :C, :B, :LEFT, :RIGHT, :UP, :DOWN]
  97. end
  98.  
  99. # AQUI COMEÇA O SCRIPT!!!!!!!!!!!
  100. #==============================================================================
  101. # ** Scene_Battle
  102. #------------------------------------------------------------------------------
  103. #  Esta classe executa o processamento da tela de batalha.
  104. #==============================================================================
  105.  
  106. class Scene_Battle < Scene_Base
  107. alias :akea_itt_process_action :process_action
  108. alias :akea_itt_use_item :use_item
  109. alias :akea_itt_start :start
  110. alias :akea_itt_terminate :terminate
  111.   #--------------------------------------------------------------------------
  112.   # * Inicialização do processo
  113.   #--------------------------------------------------------------------------
  114.   def start
  115.     akea_itt_start
  116.     @akea_itt_pic = Sprite.new
  117.     @akea_itt_pic.z = Akea_ITT::Base_Hud_Pos[2]
  118.     @akea_itt_bar = Sprite.new
  119.     @akea_itt_bar.bitmap = Cache.akea(Akea_ITT::Bar_Hud)
  120.     @akea_itt_bar.opacity = 0
  121.     @akea_itt_bar.z = Akea_ITT::Bar_Hud_Pos[2]
  122.     @akea_itt_bar_base = Sprite.new
  123.     @akea_itt_bar_base.bitmap = Cache.akea(Akea_ITT::Base_Hud)
  124.     @akea_itt_bar_base.opacity = 0
  125.     @akea_itt_bar_base.z = Akea_ITT::Base_Hud_Pos[2]
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # * Uso de habilidades/itens
  129.   #--------------------------------------------------------------------------
  130.   def use_item
  131.     akea_itt_use_item
  132.     battle_notes = @subject.current_action.item.note
  133.     if @subject.current_action.item.id == 1 && @subject.actor? && @subject.equips[0]
  134.       battle_notes = @subject.equips[0].note
  135.     end
  136.     @akea_itt = []
  137.     @akea_trigger_shuffle = -1
  138.     for n in 0...battle_notes.size
  139.       if battle_notes[n..n+9] == "<getinput "
  140.         y = 0
  141.         y += 1 until battle_notes[n+10+y] == '|'
  142.         w = 0
  143.         w += 1 until battle_notes[n+11+y+w] == '|'
  144.         z = 0
  145.         z += 1 until battle_notes[n+11+y+w+z] == '>'
  146.         insert_akea_input(battle_notes[n+10..n+9+y].to_i, battle_notes[n+11+y..n+10+y+w].to_i, battle_notes[n+13+w..n+12+y+w+z].to_i)
  147.       end
  148.     end
  149.     party_id = all_battle_members.index(@subject)
  150.     start_akea_input_trigger
  151.     until @akea_itt.empty?
  152.       break unless party_id
  153.       move_akea_input_bars
  154.       self.class.superclass.instance_method(:update).bind(self).call
  155.       if @akea_input_timer <= 0 && @akea_input_success
  156.         next unless akea_input_animation
  157.         RPG::SE.new(Akea_ITT::Input[@akea_itt.first[0]][:success_se]).play
  158.         @subject.actor? ? call_akea_skill : @akea_itt = []
  159.       elsif @akea_input_timer <= 0 || check_input == 2
  160.         @akea_input_timer = 0
  161.         next unless akea_input_animation
  162.         RPG::SE.new(Akea_ITT::Input[@akea_itt.first[0]][:failure_se]).play
  163.         @subject.actor? ? @akea_itt = [] : call_akea_skill
  164.       elsif check_input == 1
  165.         Sound.play_ok
  166.         @akea_num_triggers -= 1
  167.         if @akea_num_triggers == 0
  168.           @akea_input_success = true
  169.           @akea_input_timer = 0
  170.         else
  171.           if Akea_ITT::Input[@akea_itt.first[0]][:random?]
  172.             @akea_trigger_shuffle = rand(Akea_ITT::Input[@akea_itt.first[0]][:triggers].size)
  173.           else
  174.             @akea_trigger_shuffle += 1
  175.           end
  176.           while @akea_itt_pic.opacity > 0
  177.             self.class.superclass.instance_method(:update).bind(self).call
  178.             @akea_itt_pic.opacity -= 30
  179.           end
  180.           @akea_itt_pic.bitmap.dispose
  181.           @akea_itt_pic.opacity = 255
  182.           @akea_itt_pic.bitmap = Cache.akea(Akea_ITT::Input[@akea_itt.first[0]][:pics][@akea_trigger_shuffle])
  183.         end
  184.       end
  185.       @akea_input_timer -= 1
  186.     end
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # * Inserir o input na array
  190.   #--------------------------------------------------------------------------
  191.   def insert_akea_input(n, id, chance)
  192.     p [n, id, chance]
  193.     @akea_itt << [n, id] if rand(100) < chance
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Animação de fade do input
  197.   #--------------------------------------------------------------------------
  198.   def akea_input_animation
  199.     @akea_itt_pic.opacity -= 30
  200.     @akea_itt_bar_base.opacity -= 30
  201.     @akea_itt_bar.opacity -= 30
  202.     return false if @akea_itt_pic.opacity > 0
  203.     return true
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # * Inicialização do processo de input
  207.   #--------------------------------------------------------------------------
  208.   def start_akea_input_trigger
  209.     return if @akea_itt.empty?
  210.     @akea_input_success = false
  211.     if Akea_ITT::Input[@akea_itt.first[0]][:random?]
  212.       @akea_trigger_shuffle = rand(Akea_ITT::Input[@akea_itt.first[0]][:triggers].size)
  213.     else
  214.       @akea_trigger_shuffle += 1
  215.     end
  216.     @akea_num_triggers = Akea_ITT::Input[@akea_itt.first[0]][:num_times]
  217.     if Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'actor' || (Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'enemy' && @subject.enemy?)
  218.       @akea_itt_pic.x = @subject.screen_x + Akea_ITT::Actor_Pos[0]
  219.       @akea_itt_pic.y = @subject.screen_y + Akea_ITT::Actor_Pos[1]
  220.     elsif Akea_ITT::Input[@akea_itt.first[0]][:position?] == 'enemy'
  221.       targets = @subject.current_action.make_targets.compact
  222.       @akea_itt_pic.x = targets[0].screen_x + Akea_ITT::Enemy_Pos[0]
  223.       @akea_itt_pic.y = targets[0].screen_y + Akea_ITT::Enemy_Pos[1]
  224.     else
  225.       @akea_itt_pic.x = Akea_ITT::Input[@akea_itt.first[0]][:position?][0]
  226.       @akea_itt_pic.y = Akea_ITT::Input[@akea_itt.first[0]][:position?][1]
  227.     end
  228.     @akea_itt_bar.x = @akea_itt_pic.x + Akea_ITT::Bar_Hud_Pos[0]
  229.     @akea_itt_bar.y = @akea_itt_pic.y + Akea_ITT::Bar_Hud_Pos[1]
  230.     @akea_itt_bar_base.x = @akea_itt_pic.x + Akea_ITT::Base_Hud_Pos[0]
  231.     @akea_itt_bar_base.y = @akea_itt_pic.y + Akea_ITT::Base_Hud_Pos[1]
  232.     @akea_input_timer = Akea_ITT::Input[@akea_itt.first[0]][:time]
  233.     @akea_itt_pic.bitmap.dispose if @akea_itt_pic.bitmap
  234.     @akea_itt_pic.opacity = @akea_itt_bar.opacity = @akea_itt_bar_base.opacity = 255
  235.     @akea_itt_bar.zoom_x = 1
  236.     @akea_itt_pic.bitmap = Cache.akea(Akea_ITT::Input[@akea_itt.first[0]][:pics][@akea_trigger_shuffle])
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Movimento das barras de Input
  240.   #--------------------------------------------------------------------------
  241.   def move_akea_input_bars
  242.     @akea_itt_bar.zoom_x = @akea_input_timer.to_f/Akea_ITT::Input[@akea_itt.first[0]][:time]
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * Verificador de teclas
  246.   #--------------------------------------------------------------------------
  247.   def check_input
  248.     Akea_ITT::Key_Map.each{|key|
  249.     if Input.trigger?(key)
  250.       return 2 if key != Akea_ITT::Input[@akea_itt.first[0]][:triggers][@akea_trigger_shuffle]
  251.     end
  252.     }
  253.     return 1 if Input.trigger?(Akea_ITT::Input[@akea_itt.first[0]][:triggers][@akea_trigger_shuffle])
  254.     return 0
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # * Chamada de invocação de habilidade
  258.   #--------------------------------------------------------------------------
  259.   def call_akea_skill
  260.     @akea_trigger_shuffle = -1
  261.     party_id = all_battle_members.index(@subject)
  262.     BattleManager.add_input_trigger_action(party_id)
  263.     if all_battle_members[party_id].actor?
  264.       $game_party.members[party_id].input.set_skill(@akea_itt.first[1])
  265.     else
  266.       targets = @subject.current_action.make_targets.compact
  267.       $game_troop.members[party_id - $game_party.members.size].force_action(@akea_itt.first[1], $game_party.members.index(targets[0]))
  268.     end
  269.     @akea_itt.shift
  270.     akea_itt_use_item
  271.     self.class.superclass.instance_method(:update).bind(self).call until akea_input_animation
  272.     BattleManager.remove_action_trigger
  273.     unless @akea_itt.empty?
  274.       @akea_input_success = false
  275.       start_akea_input_trigger
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * Finalização do processo
  280.   #--------------------------------------------------------------------------
  281.   def terminate
  282.     @akea_itt_bar_base.bitmap.dispose
  283.     @akea_itt_bar_base.dispose
  284.     @akea_itt_bar.bitmap.dispose
  285.     @akea_itt_bar.dispose
  286.     @akea_itt_pic.bitmap.dispose if @akea_itt_pic.bitmap
  287.     @akea_itt_pic.dispose    
  288.     akea_itt_terminate
  289.   end
  290. end
  291.  
  292.  
  293. #==============================================================================
  294. # ** BattleManager
  295. #------------------------------------------------------------------------------
  296. #  Este módulo gerencia o andamento da batalha.
  297. #==============================================================================
  298.  
  299. module BattleManager
  300.   #--------------------------------------------------------------------------
  301.   # * Criação da seqüencia de ações
  302.   #--------------------------------------------------------------------------
  303.   def self.add_input_trigger_action(id)
  304.     @action_battlers = [] unless @action_battlers.is_a?(Array)
  305.     @action_battlers.unshift($game_party.members[id])
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Remove um actor
  309.   #--------------------------------------------------------------------------
  310.   def self.remove_action_trigger
  311.     @action_battlers.shift
  312.   end
  313. end
  314.  
  315.  
  316. #==============================================================================
  317. # ** Cache
  318. #------------------------------------------------------------------------------
  319. #  Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  320. # Para acelerar o carregamento e preservar memória, este módulo matém o
  321. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  322. # pré-existentes quando mesmo Bitmap é requerido novamente.
  323. #==============================================================================
  324.  
  325.  
  326. module Cache
  327.   #--------------------------------------------------------------------------
  328.   # * Carregamento dos gráficos de animação
  329.   #     filename : nome do arquivo
  330.   #     hue      : informações da alteração de tonalidade
  331.   #--------------------------------------------------------------------------
  332.   def self.akea(filename)
  333.     load_bitmap("Graphics/Akea/", filename)
  334.   end
  335. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement